提交 1eec11e9 编写于 作者: F freemine

first version of runnable win odbc driver

上级 9be73e7b
...@@ -29,6 +29,14 @@ IF (TD_LINUX_64) ...@@ -29,6 +29,14 @@ IF (TD_LINUX_64)
ENDIF () ENDIF ()
IF (TD_WINDOWS_64) IF (TD_WINDOWS_64)
find_package(ODBC)
if (NOT ODBC_FOUND)
message(FATAL_ERROR "you need to install ODBC first")
else ()
message(STATUS "ODBC_INCLUDE_DIRS: ${ODBC_INCLUDE_DIRS}")
message(STATUS "ODBC_LIBRARIES: ${ODBC_LIBRARIES}")
message(STATUS "ODBC_CONFIG: ${ODBC_CONFIG}")
endif ()
find_package(FLEX) find_package(FLEX)
if(NOT FLEX_FOUND) if(NOT FLEX_FOUND)
message(FATAL_ERROR "you need to install flex first") message(FATAL_ERROR "you need to install flex first")
......
...@@ -16,8 +16,7 @@ IF (TD_LINUX_64) ...@@ -16,8 +16,7 @@ IF (TD_LINUX_64)
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)
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})")
ENDIF () ENDIF ()
...@@ -32,11 +31,20 @@ IF (TD_WINDOWS_64) ...@@ -32,11 +31,20 @@ IF (TD_WINDOWS_64)
) )
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
# generate dynamic library (*.so) # generate dynamic library (*.dll)
ADD_LIBRARY(todbc SHARED ${SRC} ${todbc_flex_scanner_src}) ADD_LIBRARY(todbc SHARED
SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1) ${SRC}
SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1) ${todbc_flex_scanner_src}
${CMAKE_CURRENT_BINARY_DIR}/todbc.rc
todbc.def)
TARGET_LINK_LIBRARIES(todbc taos_static) TARGET_LINK_LIBRARIES(todbc taos_static)
target_include_directories(todbc PUBLIC target_include_directories(todbc PUBLIC .)
.) target_compile_definitions(todbc PRIVATE "todbc_EXPORT")
CONFIGURE_FILE("todbc.rc.in"
"${CMAKE_CURRENT_BINARY_DIR}/todbc.rc")
SET_TARGET_PROPERTIES(todbc PROPERTIES LINK_FLAGS
/DEF:todbc.def)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /GL")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL")
ENDIF () ENDIF ()
...@@ -17,19 +17,17 @@ ...@@ -17,19 +17,17 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "todbc_log.h"
#include "todbc_flex.h"
#include "taos.h" #include "taos.h"
#include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "todbc_util.h" #include "todbc_util.h"
#include "todbc_conv.h" #include "todbc_conv.h"
#include <sql.h>
#include <sqlext.h> #include <sqlext.h>
#include <time.h>
#define GET_REF(obj) atomic_load_64(&obj->refcount) #define GET_REF(obj) atomic_load_64(&obj->refcount)
#define INC_REF(obj) atomic_add_fetch_64(&obj->refcount, 1) #define INC_REF(obj) atomic_add_fetch_64(&obj->refcount, 1)
#define DEC_REF(obj) atomic_sub_fetch_64(&obj->refcount, 1) #define DEC_REF(obj) atomic_sub_fetch_64(&obj->refcount, 1)
...@@ -1919,7 +1917,7 @@ static SQLRETURN doSQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle, ...@@ -1919,7 +1917,7 @@ static SQLRETURN doSQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT *StringLength) SQLSMALLINT *StringLength)
{ {
// if this function is not exported, isql will never call SQLGetDiagRec // if this function is not exported, isql will never call SQLGetDiagRec
return SQL_ERROR; return SQL_SUCCESS;
} }
SQLRETURN SQL_API SQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLRETURN SQL_API SQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle,
......
EXPORTS
SQLAllocEnv
SQLFreeEnv
SQLAllocConnect
SQLFreeConnect
SQLConnect
SQLDisconnect
SQLAllocStmt
SQLAllocHandle
SQLFreeStmt
SQLExecDirect
SQLExecDirectW
SQLNumResultCols
SQLRowCount
SQLColAttribute
SQLGetData
SQLFetch
SQLPrepare
SQLExecute
SQLGetDiagField
SQLGetDiagRec
SQLBindParameter
SQLDriverConnect
SQLSetConnectAttr
SQLDescribeCol
SQLNumParams
SQLSetStmtAttr
1 VERSIONINFO
FILEVERSION ${TD_VER_NUMBER}
PRODUCTVERSION ${TD_VER_NUMBER}
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x0L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "ODBC Driver for TDengine"
VALUE "FileVersion", "${TD_VER_NUMBER}"
VALUE "InternalName", "todbc.dll(${TD_VER_CPUTYPE})"
VALUE "LegalCopyright", "Copyright (C) 2020 TAOS Data"
VALUE "OriginalFilename", ""
VALUE "ProductName", "todbc.dll(${TD_VER_CPUTYPE})"
VALUE "ProductVersion", "${TD_VER_NUMBER}"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
\ No newline at end of file
INSTALLDRIVER "TAOS ODBC|Driver=todbc.dll|FileUsage=0|ConnectFunctions=YYN"
...@@ -14,9 +14,6 @@ ...@@ -14,9 +14,6 @@
*/ */
#include "todbc_conv.h" #include "todbc_conv.h"
#include "todbc_util.h"
#include "os.h"
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
#ifndef _todbc_conv_h_ #ifndef _todbc_conv_h_
#define _todbc_conv_h_ #define _todbc_conv_h_
#include "todbc_flex_workaround.h" #include "os.h"
#include <stddef.h> #include <iconv.h>
#include <sql.h>
#include "iconv.h"
typedef enum { typedef enum {
......
...@@ -13,18 +13,10 @@ ...@@ -13,18 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _todbc_flex_workaround_h_ #ifndef _TODBC_FLEX_H_
#define _todbc_flex_workaround_h_ #define _TODBC_FLEX_H_
#ifdef _MSC_VER int todbc_parse_conn_string(const char *conn, char **dsn, char **uid, char **pwd, char **host);
#include <winsock2.h>
#include <windows.h>
#endif
#ifndef INT8_MIN
#include <stdint.h>
#endif
#include <sql.h>
#include <sqlext.h>
#endif // _todbc_flex_workaround_h_ #endif // _TODBC_FLEX_H_
...@@ -16,13 +16,7 @@ ...@@ -16,13 +16,7 @@
#ifndef _todbc_log_h_ #ifndef _todbc_log_h_
#define _todbc_log_h_ #define _todbc_log_h_
#ifdef _MSC_VER #include "os.h"
#include "msvcLibgen.h"
#else
#include <libgen.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#define D(fmt, ...) \ #define D(fmt, ...) \
fprintf(stderr, \ fprintf(stderr, \
......
%{ %{
#include "todbc_util.h" #include "todbc_flex.h"
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -105,8 +104,7 @@ do { \ ...@@ -105,8 +104,7 @@ do { \
<EQ>[{] { CHG_STATE(BRACE1); } <EQ>[{] { CHG_STATE(BRACE1); }
<EQ>.|\n { return -1; } <EQ>.|\n { return -1; }
<BRACE1>[[:space:]]+ { } <BRACE1>[^{}\n]+ { set_val(); CHG_STATE(BRACE2); }
<BRACE1>[^{}\n[:space:]]+ { set_val(); CHG_STATE(BRACE2); }
<BRACE1>.|\n { return -1; } <BRACE1>.|\n { return -1; }
<BRACE2>[[:space:]]+ { } <BRACE2>[[:space:]]+ { }
......
...@@ -14,11 +14,10 @@ ...@@ -14,11 +14,10 @@
*/ */
#include "todbc_util.h" #include "todbc_util.h"
#include "todbc_log.h"
#include <iconv.h>
#include <sqlext.h>
#include "iconv.h"
#include <stdlib.h>
#include <string.h>
const char* sql_sql_type(int type) { const char* sql_sql_type(int type) {
switch (type) { switch (type) {
......
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
#ifndef _TODBC_UTIL_H_ #ifndef _TODBC_UTIL_H_
#define _TODBC_UTIL_H_ #define _TODBC_UTIL_H_
#include "todbc_flex_workaround.h" #include "os.h"
#include "todbc_log.h"
#include <sql.h>
#include <sqltypes.h>
const char* sql_sql_type(int type); const char* sql_sql_type(int type);
const char* sql_c_type(int type); const char* sql_c_type(int type);
...@@ -26,8 +27,6 @@ const char* sql_c_type(int type); ...@@ -26,8 +27,6 @@ const char* sql_c_type(int type);
int is_valid_sql_c_type(int type); int is_valid_sql_c_type(int type);
int is_valid_sql_sql_type(int type); int is_valid_sql_sql_type(int type);
int todbc_parse_conn_string(const char *conn, char **dsn, char **uid, char **pwd, char **host);
int string_conv(const char *fromcode, const char *tocode, int string_conv(const char *fromcode, const char *tocode,
const unsigned char *src, size_t sbytes, const unsigned char *src, size_t sbytes,
unsigned char *dst, size_t dbytes, unsigned char *dst, size_t dbytes,
......
...@@ -9,5 +9,5 @@ ENDIF () ...@@ -9,5 +9,5 @@ ENDIF ()
IF (TD_WINDOWS_64) IF (TD_WINDOWS_64)
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(tcodbc main.c) ADD_EXECUTABLE(tcodbc main.c)
# TARGET_LINK_LIBRARIES(tcodbc odbc) TARGET_LINK_LIBRARIES(tcodbc odbc32 os)
ENDIF () ENDIF ()
#include "../src/todbc_log.h"
#ifdef _MSC_VER
#include <winsock2.h>
#include <windows.h>
#include "os.h" #include "os.h"
#endif
#include <sql.h> #include <sql.h>
#include <sqlext.h> #include <sqlext.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "os.h"
#include "../src/todbc_log.h"
// static const char *dsn = "TAOS_DSN";
// static const char *uid = "root";
// static const char *pwd = "taosdata";
#define CHK_TEST(statement) \ #define CHK_TEST(statement) \
do { \ do { \
D("testing: %s", #statement); \ D("testing: %s", #statement); \
...@@ -425,7 +424,7 @@ int test_sqls_in_stmt(SQLHENV env, SQLHDBC conn, SQLHSTMT stmt, const char *sqls ...@@ -425,7 +424,7 @@ int test_sqls_in_stmt(SQLHENV env, SQLHDBC conn, SQLHSTMT stmt, const char *sqls
ssize_t n = 0; ssize_t n = 0;
#ifdef _MSC_VER #ifdef _MSC_VER
n = taosGetlineImp(&line, &len, f); n = taosGetline(&line, &len, f);
#else #else
n = getline(&line, &len, f); n = getline(&line, &len, f);
#endif #endif
...@@ -503,7 +502,12 @@ int main(int argc, char *argv[]) { ...@@ -503,7 +502,12 @@ int main(int argc, char *argv[]) {
const char *connstr = (argc>4) ? argv[4] : NULL; const char *connstr = (argc>4) ? argv[4] : NULL;
const char *sqls = (argc>5) ? argv[5] : NULL; const char *sqls = (argc>5) ? argv[5] : NULL;
if (1) { dsn = NULL;
uid = NULL;
pwd = NULL;
connstr = argv[1];
sqls = argv[2];
if (0) {
CHK_TEST(test_env()); CHK_TEST(test_env());
CHK_TEST(test1(dsn, uid, pwd)); CHK_TEST(test1(dsn, uid, pwd));
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "msvcProcess.h" #include "msvcProcess.h"
#include "msvcDirect.h" #include "msvcDirect.h"
#include "msvcFcntl.h" #include "msvcFcntl.h"
#include "msvcLibgen.h"
#include "msvcStdio.h" #include "msvcStdio.h"
#include "sys/msvcStat.h" #include "sys/msvcStat.h"
#include "sys/msvcTypes.h" #include "sys/msvcTypes.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册