提交 51c4b89a 编写于 作者: F freemine

before windows port

上级 77ea55f0
...@@ -15,7 +15,7 @@ IF (TD_LINUX_64) ...@@ -15,7 +15,7 @@ IF (TD_LINUX_64)
ADD_LIBRARY(todbc SHARED ${SRC} ${todbc_flex_scanner_src}) ADD_LIBRARY(todbc SHARED ${SRC} ${todbc_flex_scanner_src})
SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1)
SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1) SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1)
TARGET_LINK_LIBRARIES(todbc taos) TARGET_LINK_LIBRARIES(todbc taos odbcinst)
target_include_directories(todbc PUBLIC .) target_include_directories(todbc PUBLIC .)
install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${CMAKE_BINARY_DIR})") install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${CMAKE_BINARY_DIR})")
......
...@@ -27,8 +27,19 @@ ...@@ -27,8 +27,19 @@
#include "todbc_util.h" #include "todbc_util.h"
#include "todbc_conv.h" #include "todbc_conv.h"
#include "os.h"
#include <odbcinst.h>
#include <sqlext.h> #include <sqlext.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define UTF8_ENC "UTF-8" #define UTF8_ENC "UTF-8"
#define UTF16_ENC "UCS-2LE" #define UTF16_ENC "UCS-2LE"
#define UNICODE_ENC "UCS-4LE" #define UNICODE_ENC "UCS-4LE"
...@@ -549,9 +560,20 @@ static SQLRETURN doSQLConnect(SQLHDBC ConnectionHandle, ...@@ -549,9 +560,20 @@ static SQLRETURN doSQLConnect(SQLHDBC ConnectionHandle,
const char *auth = NULL; const char *auth = NULL;
do { do {
D("server: %s", serverName);
D("user: %s", userName);
D("auth: %s", auth);
tsdb_conv(client_to_server, &buffer, (const char*)ServerName, (size_t)NameLength1, &serverName, NULL); tsdb_conv(client_to_server, &buffer, (const char*)ServerName, (size_t)NameLength1, &serverName, NULL);
tsdb_conv(client_to_server, &buffer, (const char*)UserName, (size_t)NameLength2, &userName, NULL); tsdb_conv(client_to_server, &buffer, (const char*)UserName, (size_t)NameLength2, &userName, NULL);
tsdb_conv(client_to_server, &buffer, (const char*)Authentication, (size_t)NameLength3, &auth, NULL); tsdb_conv(client_to_server, &buffer, (const char*)Authentication, (size_t)NameLength3, &auth, NULL);
D("server: %s", serverName);
D("user: %s", userName);
D("auth: %s", auth);
char haha[4096]; haha[0] = '\0';
int n = SQLGetPrivateProfileString(serverName, "Server", "null", haha, sizeof(haha)-1, NULL);
D("n: %d", n);
D("haha: [%s]", haha);
if ((!serverName) || (!userName) || (!auth)) { if ((!serverName) || (!userName) || (!auth)) {
SET_ERROR(conn, "HY001", TSDB_CODE_ODBC_OOM, ""); SET_ERROR(conn, "HY001", TSDB_CODE_ODBC_OOM, "");
break; break;
...@@ -2847,6 +2869,21 @@ SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle, ...@@ -2847,6 +2869,21 @@ SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle,
return r; return r;
} }
BOOL INSTAPI ConfigDSN(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes)
{
return FALSE;
}
BOOL INSTAPI ConfigTranslator(HWND hwndParent, DWORD *pvOption)
{
return FALSE;
}
BOOL INSTAPI ConfigDriver(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszArgs,
LPSTR lpszMsg, WORD cbMsgMax, WORD *pcbMsgOut)
{
return FALSE;
}
......
...@@ -25,4 +25,7 @@ SQLSetConnectAttr ...@@ -25,4 +25,7 @@ SQLSetConnectAttr
SQLDescribeCol SQLDescribeCol
SQLNumParams SQLNumParams
SQLSetStmtAttr SQLSetStmtAttr
ConfigDSN
ConfigTranslator
ConfigDriver
...@@ -86,9 +86,9 @@ static int open_connect(const char *dsn, const char *uid, const char *pwd, SQLHE ...@@ -86,9 +86,9 @@ static int open_connect(const char *dsn, const char *uid, const char *pwd, SQLHE
CHK_RESULT(r, SQL_HANDLE_ENV, env, ""); CHK_RESULT(r, SQL_HANDLE_ENV, env, "");
if (r!=SQL_SUCCESS) break; if (r!=SQL_SUCCESS) break;
do { do {
r = SQLConnect(conn, (SQLCHAR*)dsn, (SQLSMALLINT)strlen(dsn), r = SQLConnect(conn, (SQLCHAR*)dsn, (SQLSMALLINT)(dsn ? strlen(dsn) : 0),
(SQLCHAR*)uid, (SQLSMALLINT)strlen(uid), (SQLCHAR*)uid, (SQLSMALLINT)(uid ? strlen(uid) : 0),
(SQLCHAR*)pwd, (SQLSMALLINT)strlen(pwd)); (SQLCHAR*)pwd, (SQLSMALLINT)(pwd ? strlen(pwd) : 0));
CHK_RESULT(r, SQL_HANDLE_DBC, conn, ""); CHK_RESULT(r, SQL_HANDLE_DBC, conn, "");
if (r==SQL_SUCCESS) { if (r==SQL_SUCCESS) {
*pEnv = env; *pEnv = env;
...@@ -119,7 +119,7 @@ static int open_driver_connect(const char *connstr, SQLHENV *pEnv, SQLHDBC *pCon ...@@ -119,7 +119,7 @@ static int open_driver_connect(const char *connstr, SQLHENV *pEnv, SQLHDBC *pCon
SQLHDBC ConnectionHandle = conn; SQLHDBC ConnectionHandle = conn;
SQLHWND WindowHandle = NULL; SQLHWND WindowHandle = NULL;
SQLCHAR * InConnectionString = (SQLCHAR*)connstr; SQLCHAR * InConnectionString = (SQLCHAR*)connstr;
SQLSMALLINT StringLength1 = (SQLSMALLINT)strlen(connstr); SQLSMALLINT StringLength1 = (SQLSMALLINT)(connstr ? strlen(connstr) : 0);
SQLCHAR * OutConnectionString = buf; SQLCHAR * OutConnectionString = buf;
SQLSMALLINT BufferLength = sizeof(buf); SQLSMALLINT BufferLength = sizeof(buf);
SQLSMALLINT * StringLength2Ptr = &blen; SQLSMALLINT * StringLength2Ptr = &blen;
...@@ -525,64 +525,149 @@ int test_sqls(const char *dsn, const char *uid, const char *pwd, const char *con ...@@ -525,64 +525,149 @@ int test_sqls(const char *dsn, const char *uid, const char *pwd, const char *con
} else { } else {
CHK_TEST(open_driver_connect(connstr, &env, &conn)); CHK_TEST(open_driver_connect(connstr, &env, &conn));
} }
r = test_sqls_in_conn(env, conn, sqls); if (sqls) {
r = test_sqls_in_conn(env, conn, sqls);
}
SQLDisconnect(conn); SQLDisconnect(conn);
SQLFreeConnect(conn); SQLFreeConnect(conn);
SQLFreeEnv(env); SQLFreeEnv(env);
return r ? 1 : 0; return r ? 1 : 0;
} }
void usage(const char *arg0) {
fprintf(stdout, "%s usage:\n", arg0);
fprintf(stdout, "%s [--dsn <dsn>] [--uid <uid>] [--pwd <pwd>] [--dcs <dcs>] [--sts <sts>]\n", arg0);
fprintf(stdout, " --dsn <dsn>: DSN\n");
fprintf(stdout, " --uid <uid>: UID\n");
fprintf(stdout, " --pwd <pwd>: PWD\n");
fprintf(stdout, " --dcs <dcs>: driver connection string\n");
fprintf(stdout, " --sts <sts>: file where statements store\n");
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc==1) { // if (argc==1) {
CHK_TEST(test_env()); // CHK_TEST(test_env());
return 0; // CHK_TEST(test1("TAOS_DSN", "root", "taoxsdata"));
// D("Done!");
// return 0;
// }
const char *dsn = NULL;
const char *uid = NULL;
const char *pwd = NULL;
const char *dcs = NULL; // driver connection string
const char *sts = NULL; // statements file
for (size_t i=1; i<argc; ++i) {
const char *arg = argv[i];
if (strcmp(arg, "-h")==0) {
usage(argv[0]);
return 0;
}
if (strcmp(arg, "--dsn")==0) {
++i;
if (i>=argc) {
D("<dsn> expected but got nothing");
return 1;
}
if (dcs) {
D("--dcs has already been specified");
return 1;
}
dsn = argv[i];
continue;
}
if (strcmp(arg, "--uid")==0) {
++i;
if (i>=argc) {
D("<uid> expected but got nothing");
return 1;
}
uid = argv[i];
continue;
}
if (strcmp(arg, "--pwd")==0) {
++i;
if (i>=argc) {
D("<pwd> expected but got nothing");
return 1;
}
pwd = argv[i];
continue;
}
if (strcmp(arg, "--dcs")==0) {
++i;
if (i>=argc) {
D("<dcs> expected but got nothing");
return 1;
}
if (dsn || uid || pwd) {
D("either of --dsn/--uid/--pwd has already been specified");
return 1;
}
dcs = argv[i];
continue;
}
if (strcmp(arg, "--sts")==0) {
++i;
if (i>=argc) {
D("<sts> expected but got nothing");
return 1;
}
sts = argv[i];
continue;
}
} }
CHK_TEST(test_sqls(dsn, uid, pwd, dcs, sts));
D("Done!");
return 0;
const char *dsn = (argc>1) ? argv[1] : NULL;
const char *uid = (argc>2) ? argv[2] : NULL;
const char *pwd = (argc>3) ? argv[3] : NULL;
const char *connstr = (argc>4) ? argv[4] : NULL;
const char *sqls = (argc>5) ? argv[5] : NULL;
dsn = NULL;
uid = NULL;
pwd = NULL;
connstr = argv[1];
sqls = argv[2];
if (0) { if (0) {
CHK_TEST(test_env()); const char *dsn = (argc>1) ? argv[1] : NULL;
const char *uid = (argc>2) ? argv[2] : NULL;
CHK_TEST(test1(dsn, uid, pwd)); const char *pwd = (argc>3) ? argv[3] : NULL;
const char *connstr = (argc>4) ? argv[4] : NULL;
const char *statements[] = { const char *sqls = (argc>5) ? argv[5] : NULL;
"drop database if exists m",
"create database m", dsn = NULL;
"use m", uid = NULL;
"drop database m", pwd = NULL;
NULL connstr = argv[1];
}; sqls = argv[2];
CHK_TEST(test_statements(dsn, uid, pwd, statements)); if (0) {
CHK_TEST(test_env());
if (connstr)
CHK_TEST(test_driver_connect(connstr)); CHK_TEST(test1(dsn, uid, pwd));
if (connstr) { const char *statements[] = {
SQLHENV env = {0}; "drop database if exists m",
SQLHDBC conn = {0}; "create database m",
CHK_TEST(open_driver_connect(connstr, &env, &conn)); "use m",
int r = tests(env, conn); "drop database m",
SQLDisconnect(conn); NULL
SQLFreeConnect(conn); };
SQLFreeEnv(env); CHK_TEST(test_statements(dsn, uid, pwd, statements));
if (r) return 1;
if (connstr)
CHK_TEST(test_driver_connect(connstr));
if (connstr) {
SQLHENV env = {0};
SQLHDBC conn = {0};
CHK_TEST(open_driver_connect(connstr, &env, &conn));
int r = tests(env, conn);
SQLDisconnect(conn);
SQLFreeConnect(conn);
SQLFreeEnv(env);
if (r) return 1;
}
} }
}
if ((dsn || connstr) && 1) { if ((dsn || connstr) && 1) {
CHK_TEST(test_sqls(dsn, uid, pwd, connstr, sqls)); CHK_TEST(test_sqls(dsn, uid, pwd, connstr, sqls));
} }
D("Done!"); D("Done!");
return 0; return 0;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册