diff --git a/src/connector/odbc/README.md b/src/connector/odbc/README.md index 5a9706fd1f..e026884a07 100644 --- a/src/connector/odbc/README.md +++ b/src/connector/odbc/README.md @@ -30,6 +30,7 @@ SQLSetConnectAttr SQLDescribeCol SQLNumParams 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 @@ -61,6 +62,7 @@ rm -rf debug && cmake -B debug && cmake --build debug && cmake --install debug & - open your `Command Prompt` with Administrator's priviledge - 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` +- add a new user dsn: run `odbcconf CONFIGDSN TAOS "DSN=TAOS_DSN|Server=:` # 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. @@ -72,11 +74,15 @@ taosd -c ./debug/test/cfg ``` ## create data in linux ``` -./debug/build/bin/tcodbc 'Driver=TAOS;UID=;PWD=;Host=:6030;server_enc=UTF-8' ./src/connector/odbc/tests/create_data.stmts +./debug/build/bin/tcodbc --dsn TAOS_DSN --uid --pwd --sts ./src/connector/odbc/tests/create_data.stmts +-- +./debug/build/bin/tcodbc --dcs 'Driver=TAOS;UID=;PWD=;Server=:;client_enc=UTF-8' ./src/connector/odbc/tests/create_data.stmts ``` ## query data in windows ``` -.\debug\build\bin\tcodbc "Driver=TAOS;UID=;PWD=;Host=:6030;server_enc=UTF-8" .\src\connector\odbc\tests\query_data.stmts +.\debug\build\bin\tcodbc --dsn TAOS_DSN --uid --pwd --sts .\src\connector\odbc\tests\query_data.stmts +-- +.\debug\build\bin\tcodbc --dcs "Driver=TAOS;UID=;PWD=;Server=:;client_enc=UTF-8" .\src\connector\odbc\tests\query_data.stmts ``` diff --git a/src/connector/odbc/src/todbc.c b/src/connector/odbc/src/todbc.c index efd4570d77..30c0de70f0 100644 --- a/src/connector/odbc/src/todbc.c +++ b/src/connector/odbc/src/todbc.c @@ -2877,22 +2877,25 @@ SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle, #ifdef _MSC_VER -#define LOG(fmt, ...) \ -do { \ - FILE *fout = fopen("C:\\test\\test.log", "ab+"); \ - if (!fout) break; \ - fprintf(fout, "%s" fmt "\n", "", ##__VA_ARGS__); \ - fprintf(stderr, "%s" fmt "\n", "", ##__VA_ARGS__); \ - fclose(fout); \ +#define POST_INSTALLER_ERROR(hwndParent, code, fmt, ...) \ +do { \ + char buf[4096]; \ + snprintf(buf, sizeof(buf), "%s[%d]%s():" fmt "", \ + basename((char*)__FILE__), __LINE__, __func__, \ + ##__VA_ARGS__); \ + SQLPostInstallerError(code, buf); \ + if (hwndParent) { \ + MessageBox(hwndParent, buf, "Error", MB_OK|MB_ICONEXCLAMATION); \ + } \ } while (0) typedef struct kv_s kv_t; struct kv_s { - char *line; - int val; + char *line; + 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; @@ -2900,13 +2903,13 @@ static BOOL get_driver_dll_path(char *buf, size_t len) (LPCSTR) &ConfigDSN, &hm) == 0) { 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; } - if (GetModuleFileName(hm, buf, len) == 0) + if (GetModuleFileName(hm, buf, (DWORD)len) == 0) { 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 TRUE; @@ -2923,8 +2926,7 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes) do { char driver_dll[MAX_PATH + 1]; - r = get_driver_dll_path(driver_dll, sizeof(driver_dll)); - LOG("path: [%s]", driver_dll); + r = get_driver_dll_path(hwndParent, driver_dll, sizeof(driver_dll)); if (!r) break; dsn.line = strdup("DSN=TAOS_DEMO"); @@ -2933,7 +2935,6 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes) const char *p = lpszAttributes; int ikvs = 0; while (p && *p) { - LOG("attr: [%s]", p); line = strdup(p); if (!line) { r = FALSE; break; } char *v = strchr(line, '='); @@ -2974,23 +2975,17 @@ static BOOL doDSNAdd(HWND hwndParent, LPCSTR lpszDriver, LPCSTR lpszAttributes) dsn.val = v - dsn.line + 1; 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 { - LOG("DSN/Driver[%s/%s]", dsn.line+dsn.val, lpszDriver); 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"); - LOG("r:%d", r); } for (int i=0; r && i