// sel_num.c
// VC++ 2010 Express
// マルチバイト文字セット
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <sqlext.h>
#include <stdio.h>
#define DRIVER "Microsoft Access Driver (*.mdb)"
#define DATABASE "C:\\projects\\vc++\\odbctest\\odbctest.mdb"
int main()
{
HENV henv;
HDBC hdbc;
HSTMT hstmt;
SQLCHAR CompliteConnect[255];
SWORD len;
SQLCHAR sqlchar[256];
RETCODE rc;
char number[7+1];
int i;
// データベースへの接続
rc = SQLAllocEnv(&henv);
rc = SQLAllocConnect(henv, &hdbc);
rc = SQLDriverConnect(hdbc, NULL,
(SQLCHAR *)"Driver={"DRIVER"}; DBQ="DATABASE,
SQL_NTS, CompliteConnect, _countof(CompliteConnect), &len, SQL_DRIVER_NOPROMPT);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
fprintf(stderr
, "データベースファイルを開けません\n"); return 1;
}
// 検索
while (1) {
if (strcmp(number
, "q") == 0) { break;
}
"select 住所 from 郵便番号データ where 郵便番号='%s'", number);
rc = SQLAllocStmt(hdbc, &hstmt);
rc = SQLExecDirect(hstmt, sqlchar, SQL_NTS);
for (i = 0; ; i++) {
rc = SQLFetch(hstmt);
if (rc == SQL_NO_DATA) break;
if (rc == SQL_ERROR) break;
SQLGetData
(hstmt
, 1, SQL_C_CHAR
, sqlchar
, _countof
(sqlchar
), &strlen); }
rc = SQLFreeStmt(hstmt, SQL_DROP);
if (i == 0) {
}
}
rc = SQLDisconnect(hdbc);
rc = SQLFreeConnect(hdbc);
rc = SQLFreeEnv(henv);
return 0;
}
Ly8gc2VsX251bS5jCi8vIFZDKysgMjAxMCBFeHByZXNzCi8vIOODnuODq+ODgeODkOOCpOODiOaWh+Wtl+OCu+ODg+ODiAoKI2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwoKI2luY2x1ZGUgPFdpbmRvd3MuaD4KI2luY2x1ZGUgPHNxbGV4dC5oPgojaW5jbHVkZSA8c3Rk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