// odbctest.c
// VC++ 2010 Express
// マルチバイト文字セット
#include <Windows.h>
#include <sqlext.h>
#include <stdio.h>
int main()
{
HENV henv;
HDBC hdbc;
SQLCHAR CompliteConnect[255];
SWORD len;
HSTMT hstmt;
SQLCHAR number[7+1];
SQLCHAR todofuken[20+1];
SQLCHAR sikutyoson[100+1];
RETCODE rc;
rc = SQLAllocEnv(&henv);
rc = SQLAllocConnect(henv, &hdbc);
rc = SQLDriverConnect(hdbc, NULL,
(SQLCHAR *)"Driver={Microsoft Text Driver (*.txt; *.csv)}"
"; DefaultDir=C:\\projects\\vc++\\odbctest",
SQL_NTS, CompliteConnect, _countof(CompliteConnect), &len, SQL_DRIVER_NOPROMPT);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
fprintf(stderr
, "データベースファイルを開けません\n"); return 1;
}
rc = SQLAllocStmt(hdbc, &hstmt);
rc = SQLExecDirect(hstmt, (SQLCHAR *)"select * from osaka.csv", SQL_NTS);
while (1) {
rc = SQLFetch(hstmt);
if (rc == SQL_NO_DATA) break;
if (rc == SQL_ERROR) break;
SQLGetData(hstmt, 1, SQL_C_CHAR, number, _countof(number), NULL);
SQLGetData(hstmt, 2, SQL_C_CHAR, todofuken, _countof(todofuken), NULL);
SQLGetData(hstmt, 3, SQL_C_CHAR, sikutyoson, _countof(sikutyoson), NULL);
printf("%s,%s,%s\n", number
, todofuken
, sikutyoson
); }
rc = SQLFreeStmt(hstmt, SQL_DROP);
rc = SQLDisconnect(hdbc);
rc = SQLFreeConnect(hdbc);
rc = SQLFreeEnv(henv);
return 0;
}
Ly8gb2RiY3Rlc3QuYwovLyBWQysrIDIwMTAgRXhwcmVzcwovLyDjg57jg6vjg4Hjg5DjgqTjg4jmloflrZfjgrvjg4Pjg4gKCiNpbmNsdWRlIDxXaW5kb3dzLmg+CiNpbmNsdWRlIDxzcWxleHQuaD4KI2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpCnsKCUhFTlYgaGVudjs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