提交 61e2195b 编写于 作者: F freemine

ConfigDSN windows port'

上级 557aa20d
...@@ -30,6 +30,7 @@ SQLSetConnectAttr ...@@ -30,6 +30,7 @@ SQLSetConnectAttr
SQLDescribeCol SQLDescribeCol
SQLNumParams SQLNumParams
SQLSetStmtAttr SQLSetStmtAttr
ConfigDSN
` `
- **internationalized, you can specify different charset/code page for easy going. eg.: insert `utf-8.zh_cn` characters into database located in linux machine, while query them out in `gb2312/gb18030/...` code page in your chinese windows machine, or vice-versa. and much fun, insert `gb2312/gb18030/...` characters into database located in linux box from - **internationalized, you can specify different charset/code page for easy going. eg.: insert `utf-8.zh_cn` characters into database located in linux machine, while query them out in `gb2312/gb18030/...` code page in your chinese windows machine, or vice-versa. and much fun, insert `gb2312/gb18030/...` characters into database located in linux box from
...@@ -61,6 +62,7 @@ rm -rf debug && cmake -B debug && cmake --build debug && cmake --install debug & ...@@ -61,6 +62,7 @@ rm -rf debug && cmake -B debug && cmake --build debug && cmake --install debug &
- open your `Command Prompt` with Administrator's priviledge - open your `Command Prompt` with Administrator's priviledge
- remove previously installed TAOS ODBC driver: run `C:\TDengine\todbcinst -u -f -n TAOS` - remove previously installed TAOS ODBC driver: run `C:\TDengine\todbcinst -u -f -n TAOS`
- install TAOS ODBC driver that was just built: run `C:\TDengine\todbcinst -i -n TAOS -p C:\TDengine\driver` - install TAOS ODBC driver that was just built: run `C:\TDengine\todbcinst -i -n TAOS -p C:\TDengine\driver`
- add a new user dsn: run `odbcconf CONFIGDSN TAOS "DSN=TAOS_DSN|Server=<fqdn>:<port>`
# Test # Test
we highly suggest that you build both in linux(ubuntu) and windows(windows 10) platform, because currently TAOS only has it's server-side port on linux platform. we highly suggest that you build both in linux(ubuntu) and windows(windows 10) platform, because currently TAOS only has it's server-side port on linux platform.
...@@ -72,11 +74,15 @@ taosd -c ./debug/test/cfg ...@@ -72,11 +74,15 @@ taosd -c ./debug/test/cfg
``` ```
## create data in linux ## create data in linux
``` ```
./debug/build/bin/tcodbc 'Driver=TAOS;UID=<uid>;PWD=<pwd>;Host=<fqdn>:6030;server_enc=UTF-8' ./src/connector/odbc/tests/create_data.stmts ./debug/build/bin/tcodbc --dsn TAOS_DSN --uid <uid> --pwd <pwd> --sts ./src/connector/odbc/tests/create_data.stmts
--<or with driver connection string -->
./debug/build/bin/tcodbc --dcs 'Driver=TAOS;UID=<uid>;PWD=<pwd>;Server=<fqdn>:<port>;client_enc=UTF-8' ./src/connector/odbc/tests/create_data.stmts
``` ```
## query data in windows ## query data in windows
``` ```
.\debug\build\bin\tcodbc "Driver=TAOS;UID=<uid>;PWD=<pwd>;Host=<fqdn>:6030;server_enc=UTF-8" .\src\connector\odbc\tests\query_data.stmts .\debug\build\bin\tcodbc --dsn TAOS_DSN --uid <uid> --pwd <pwd> --sts .\src\connector\odbc\tests\query_data.stmts
--<or with driver connection string -->
.\debug\build\bin\tcodbc --dcs "Driver=TAOS;UID=<uid>;PWD=<pwd>;Server=<fqdn>:<port>;client_enc=UTF-8" .\src\connector\odbc\tests\query_data.stmts
``` ```
...@@ -2877,22 +2877,25 @@ SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle, ...@@ -2877,22 +2877,25 @@ SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle,
#ifdef _MSC_VER #ifdef _MSC_VER
#define LOG(fmt, ...) \ #define POST_INSTALLER_ERROR(hwndParent, code, fmt, ...) \
do { \ do { \
FILE *fout = fopen("C:\\test\\test.log", "ab+"); \ char buf[4096]; \
if (!fout) break; \ snprintf(buf, sizeof(buf), "%s[%d]%s():" fmt "", \
fprintf(fout, "%s" fmt "\n", "", ##__VA_ARGS__); \ basename((char*)__FILE__), __LINE__, __func__, \
fprintf(stderr, "%s" fmt "\n", "", ##__VA_ARGS__); \ ##__VA_ARGS__); \
fclose(fout); \ SQLPostInstallerError(code, buf); \
if (hwndParent) { \
MessageBox(hwndParent, buf, "Error", MB_OK|MB_ICONEXCLAMATION); \
} \
} while (0) } while (0)
typedef struct kv_s kv_t; typedef struct kv_s kv_t;
struct kv_s { struct kv_s {
char *line; char *line;
int val; size_t val;
}; };
static BOOL get_driver_dll_path(char *buf, size_t len) static BOOL get_driver_dll_path(HWND hwndParent, char *buf, size_t len)
{ {
HMODULE hm = NULL; HMODULE hm = NULL;
...@@ -2900,13 +2903,13 @@ static BOOL get_driver_dll_path(char *buf, size_t len) ...@@ -2900,13 +2903,13 @@ static BOOL get_driver_dll_path(char *buf, size_t len)
(LPCSTR) &ConfigDSN, &hm) == 0) (LPCSTR) &ConfigDSN, &hm) == 0)
{ {
int ret = GetLastError(); int ret = GetLastError();
LOG("GetModuleHandle failed, error = %d\n", ret); POST_INSTALLER_ERROR(hwndParent, ODBC_ERROR_REQUEST_FAILED, "GetModuleHandle failed, error = %d\n", ret);
return FALSE; return FALSE;
} }
if (GetModuleFileName(hm, buf, len) == 0) if (GetModuleFileName(hm, buf, (DWORD)len) == 0)
{ {
int ret = GetLastError(); int ret = GetLastError();
LOG("GetModuleFileName failed, error = %d\n", ret); POST_INSTALLER_ERROR(hwndParent, ODBC_ERROR_REQUEST_FAILED, "GetModuleFileName failed, error = %d\n", ret);
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
...@@ -2923,8 +2926,7 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes) ...@@ -2923,8 +2926,7 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes)
do { do {
char driver_dll[MAX_PATH + 1]; char driver_dll[MAX_PATH + 1];
r = get_driver_dll_path(driver_dll, sizeof(driver_dll)); r = get_driver_dll_path(hwndParent, driver_dll, sizeof(driver_dll));
LOG("path: [%s]", driver_dll);
if (!r) break; if (!r) break;
dsn.line = strdup("DSN=TAOS_DEMO"); dsn.line = strdup("DSN=TAOS_DEMO");
...@@ -2933,7 +2935,6 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes) ...@@ -2933,7 +2935,6 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes)
const char *p = lpszAttributes; const char *p = lpszAttributes;
int ikvs = 0; int ikvs = 0;
while (p && *p) { while (p && *p) {
LOG("attr: [%s]", p);
line = strdup(p); line = strdup(p);
if (!line) { r = FALSE; break; } if (!line) { r = FALSE; break; }
char *v = strchr(line, '='); char *v = strchr(line, '=');
...@@ -2974,23 +2975,17 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes) ...@@ -2974,23 +2975,17 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes)
dsn.val = v - dsn.line + 1; dsn.val = v - dsn.line + 1;
if ((!dsn.line)) { if ((!dsn.line)) {
if (!r) LOG("lack of either DSN or Driver"); if (!r) POST_INSTALLER_ERROR(hwndParent, ODBC_ERROR_REQUEST_FAILED, "lack of either DSN or Driver");
} else { } else {
LOG("DSN/Driver[%s/%s]", dsn.line+dsn.val, lpszDriver);
if (r) r = SQLWritePrivateProfileString("ODBC Data Sources", dsn.line+dsn.val, lpszDriver, "Odbc.ini"); if (r) r = SQLWritePrivateProfileString("ODBC Data Sources", dsn.line+dsn.val, lpszDriver, "Odbc.ini");
LOG("r:%d", r);
LOG("DSN/Driver_dll[%s/%s]", dsn.line+dsn.val, driver_dll);
if (r) r = SQLWritePrivateProfileString(dsn.line+dsn.val, "Driver", driver_dll, "Odbc.ini"); if (r) r = SQLWritePrivateProfileString(dsn.line+dsn.val, "Driver", driver_dll, "Odbc.ini");
LOG("r:%d", r);
} }
for (int i=0; r && i<ikvs; ++i) { for (int i=0; r && i<ikvs; ++i) {
const char *k = kvs[i].line; const char *k = kvs[i].line;
const char *v = NULL; const char *v = NULL;
if (kvs[i].val) v = kvs[i].line + kvs[i].val; if (kvs[i].val) v = kvs[i].line + kvs[i].val;
LOG("DSN[%s]/%s/%s", dsn.line+dsn.val, k, v);
r = SQLWritePrivateProfileString(dsn.line+dsn.val, k, v, "Odbc.ini"); r = SQLWritePrivateProfileString(dsn.line+dsn.val, k, v, "Odbc.ini");
LOG("r:%d", r);
} }
} while (0); } while (0);
...@@ -3004,7 +2999,6 @@ static BOOL doDSNConfig(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttribute ...@@ -3004,7 +2999,6 @@ static BOOL doDSNConfig(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttribute
{ {
const char *p = lpszAttributes; const char *p = lpszAttributes;
while (p && *p) { while (p && *p) {
LOG("attr: [%s]", p);
p += strlen(p) + 1; p += strlen(p) + 1;
} }
return FALSE; return FALSE;
...@@ -3021,7 +3015,6 @@ static BOOL doDSNRemove(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttribute ...@@ -3021,7 +3015,6 @@ static BOOL doDSNRemove(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttribute
const char *p = lpszAttributes; const char *p = lpszAttributes;
int ikvs = 0; int ikvs = 0;
while (p && *p) { while (p && *p) {
LOG("attr: [%s]", p);
line = strdup(p); line = strdup(p);
if (!line) { r = FALSE; break; } if (!line) { r = FALSE; break; }
char *v = strchr(line, '='); char *v = strchr(line, '=');
...@@ -3049,26 +3042,21 @@ static BOOL doDSNRemove(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttribute ...@@ -3049,26 +3042,21 @@ static BOOL doDSNRemove(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttribute
if (!r) break; if (!r) break;
if (!dsn.line) { if (!dsn.line) {
LOG("lack of DSN"); POST_INSTALLER_ERROR(hwndParent, ODBC_ERROR_REQUEST_FAILED, "lack of DSN");
r = FALSE; r = FALSE;
break; break;
} }
LOG("delete ODBC Data Sources/[%s]", dsn.line+dsn.val);
r = SQLWritePrivateProfileString("ODBC Data Sources", dsn.line+dsn.val, NULL, "Odbc.ini"); r = SQLWritePrivateProfileString("ODBC Data Sources", dsn.line+dsn.val, NULL, "Odbc.ini");
LOG("r:%d", r);
if (!r) break; if (!r) break;
char buf[8192]; char buf[8192];
LOG("fetch DSN[%s]", dsn.line+dsn.val);
r = SQLGetPrivateProfileString(dsn.line+dsn.val, NULL, "null", buf, sizeof(buf), "Odbc.ini"); r = SQLGetPrivateProfileString(dsn.line+dsn.val, NULL, "null", buf, sizeof(buf), "Odbc.ini");
LOG("r:%d", r);
if (!r) break; if (!r) break;
int n = 0; int n = 0;
char *s = buf; char *s = buf;
while (s && *s && n++<10) { while (s && *s && n++<10) {
LOG("delete %s/[%s]", dsn.line+dsn.val, s);
SQLWritePrivateProfileString(dsn.line+dsn.val, s, NULL, "Odbc.ini"); SQLWritePrivateProfileString(dsn.line+dsn.val, s, NULL, "Odbc.ini");
s += strlen(s) + 1; s += strlen(s) + 1;
} }
...@@ -3089,7 +3077,6 @@ static BOOL doConfigDSN(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCST ...@@ -3089,7 +3077,6 @@ static BOOL doConfigDSN(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCST
case ODBC_REMOVE_DSN: sReq = "ODBC_REMOVE_DSN"; break; case ODBC_REMOVE_DSN: sReq = "ODBC_REMOVE_DSN"; break;
default: sReq = "UNKNOWN"; break; default: sReq = "UNKNOWN"; break;
} }
LOG("req:[%s];Driver:[%s];Attr:[%s]", sReq, lpszDriver, lpszAttributes);
switch(fRequest) { switch(fRequest) {
case ODBC_ADD_DSN: { case ODBC_ADD_DSN: {
r = doDSNAdd(hwndParent, lpszDriver, lpszAttributes); r = doDSNAdd(hwndParent, lpszDriver, lpszAttributes);
...@@ -3101,6 +3088,7 @@ static BOOL doConfigDSN(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCST ...@@ -3101,6 +3088,7 @@ static BOOL doConfigDSN(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCST
r = doDSNRemove(hwndParent, lpszDriver, lpszAttributes); r = doDSNRemove(hwndParent, lpszDriver, lpszAttributes);
} break; } break;
default: { default: {
POST_INSTALLER_ERROR(hwndParent, ODBC_ERROR_GENERAL_ERR, "not implemented yet");
r = FALSE; r = FALSE;
} break; } break;
} }
...@@ -3116,12 +3104,14 @@ BOOL INSTAPI ConfigDSN(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR ...@@ -3116,12 +3104,14 @@ BOOL INSTAPI ConfigDSN(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR
BOOL INSTAPI ConfigTranslator(HWND hwndParent, DWORD *pvOption) BOOL INSTAPI ConfigTranslator(HWND hwndParent, DWORD *pvOption)
{ {
POST_INSTALLER_ERROR(hwndParent, ODBC_ERROR_GENERAL_ERR, "not implemented yet");
return FALSE; return FALSE;
} }
BOOL INSTAPI ConfigDriver(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszArgs, BOOL INSTAPI ConfigDriver(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszArgs,
LPSTR lpszMsg, WORD cbMsgMax, WORD *pcbMsgOut) LPSTR lpszMsg, WORD cbMsgMax, WORD *pcbMsgOut)
{ {
POST_INSTALLER_ERROR(hwndParent, ODBC_ERROR_GENERAL_ERR, "not implemented yet");
return FALSE; return FALSE;
} }
......
...@@ -57,7 +57,7 @@ do { \ ...@@ -57,7 +57,7 @@ do { \
yyextra->pwd = strdup(yytext); \ yyextra->pwd = strdup(yytext); \
break; \ break; \
} \ } \
if (strcasecmp(yyextra->key, "HOST")==0) { \ if (strcasecmp(yyextra->key, "Server")==0) { \
free(yyextra->server); \ free(yyextra->server); \
yyextra->server = strdup(yytext); \ yyextra->server = strdup(yytext); \
break; \ break; \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册