// sel_addr.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 addr[200];
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) {
break;
}
"select * from 郵便番号データ where 住所 like '%%%s%%'", addr);
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); SQLGetData
(hstmt
, 2, 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;
}
Ly8gc2VsX2FkZHIuYwovLyBWQysrIDIwMTAgRXhwcmVzcwovLyDjg57jg6vjg4Hjg5DjgqTjg4jmloflrZfjgrvjg4Pjg4gKCiNkZWZpbmUgX0NSVF9TRUNVUkVfTk9fV0FSTklOR1MKCiNpbmNsdWRlIDxXaW5kb3dzLmg+CiNpb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