fork download
  1. // odbctest.c
  2. // VC++ 2010 Express
  3. // マルチバイト文字セット
  4.  
  5. #include <Windows.h>
  6. #include <sqlext.h>
  7. #include <stdio.h>
  8.  
  9. int main()
  10. {
  11. HENV henv;
  12. HDBC hdbc;
  13. SQLCHAR CompliteConnect[255];
  14. SWORD len;
  15. HSTMT hstmt;
  16. SQLCHAR number[7+1];
  17. SQLCHAR todofuken[20+1];
  18. SQLCHAR sikutyoson[100+1];
  19. RETCODE rc;
  20.  
  21. rc = SQLAllocEnv(&henv);
  22. rc = SQLAllocConnect(henv, &hdbc);
  23. rc = SQLDriverConnect(hdbc, NULL,
  24. (SQLCHAR *)"Driver={Microsoft Text Driver (*.txt; *.csv)}"
  25. "; DefaultDir=C:\\projects\\vc++\\odbctest",
  26. SQL_NTS, CompliteConnect, _countof(CompliteConnect), &len, SQL_DRIVER_NOPROMPT);
  27. if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
  28. fprintf(stderr, "データベースファイルを開けません\n");
  29. return 1;
  30. }
  31. rc = SQLAllocStmt(hdbc, &hstmt);
  32.  
  33. rc = SQLExecDirect(hstmt, (SQLCHAR *)"select * from osaka.csv", SQL_NTS);
  34. while (1) {
  35. rc = SQLFetch(hstmt);
  36. if (rc == SQL_NO_DATA) break;
  37. if (rc == SQL_ERROR) break;
  38. SQLGetData(hstmt, 1, SQL_C_CHAR, number, _countof(number), NULL);
  39. SQLGetData(hstmt, 2, SQL_C_CHAR, todofuken, _countof(todofuken), NULL);
  40. SQLGetData(hstmt, 3, SQL_C_CHAR, sikutyoson, _countof(sikutyoson), NULL);
  41. printf("%s,%s,%s\n", number, todofuken, sikutyoson);
  42. }
  43.  
  44. rc = SQLFreeStmt(hstmt, SQL_DROP);
  45. rc = SQLDisconnect(hdbc);
  46. rc = SQLFreeConnect(hdbc);
  47. rc = SQLFreeEnv(henv);
  48.  
  49. return 0;
  50. }
  51.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty