first version of runnable win odbc driver

This commit is contained in:
freemine 2020-10-27 21:41:16 +08:00
parent 9be73e7b6c
commit 1eec11e987
16 changed files with 123 additions and 62 deletions

View File

@ -29,6 +29,14 @@ IF (TD_LINUX_64)
ENDIF ()
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)
if(NOT FLEX_FOUND)
message(FATAL_ERROR "you need to install flex first")

View File

@ -16,8 +16,7 @@ IF (TD_LINUX_64)
SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1)
SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1)
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})")
ENDIF ()
@ -32,11 +31,20 @@ IF (TD_WINDOWS_64)
)
AUX_SOURCE_DIRECTORY(. SRC)
# generate dynamic library (*.so)
ADD_LIBRARY(todbc SHARED ${SRC} ${todbc_flex_scanner_src})
SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1)
SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1)
# generate dynamic library (*.dll)
ADD_LIBRARY(todbc SHARED
${SRC}
${todbc_flex_scanner_src}
${CMAKE_CURRENT_BINARY_DIR}/todbc.rc
todbc.def)
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 ()

View File

@ -17,19 +17,17 @@
#define _XOPEN_SOURCE
#define _DEFAULT_SOURCE
#include "todbc_log.h"
#include "todbc_flex.h"
#include "taos.h"
#include "os.h"
#include "taoserror.h"
#include "todbc_util.h"
#include "todbc_conv.h"
#include <sql.h>
#include <sqlext.h>
#include <time.h>
#define GET_REF(obj) atomic_load_64(&obj->refcount)
#define INC_REF(obj) atomic_add_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,
SQLSMALLINT *StringLength)
{
// 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,

View File

@ -0,0 +1,28 @@
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

View File

@ -0,0 +1,31 @@
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

View File

@ -0,0 +1,5 @@
INSTALLDRIVER "TAOS ODBC|Driver=todbc.dll|FileUsage=0|ConnectFunctions=YYN"

View File

@ -14,9 +14,6 @@
*/
#include "todbc_conv.h"
#include "todbc_util.h"
#include "os.h"
#include <errno.h>
#include <limits.h>

View File

@ -16,10 +16,9 @@
#ifndef _todbc_conv_h_
#define _todbc_conv_h_
#include "todbc_flex_workaround.h"
#include <stddef.h>
#include "iconv.h"
#include "os.h"
#include <iconv.h>
#include <sql.h>
typedef enum {

View File

@ -13,18 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _todbc_flex_workaround_h_
#define _todbc_flex_workaround_h_
#ifndef _TODBC_FLEX_H_
#define _TODBC_FLEX_H_
#ifdef _MSC_VER
#include <winsock2.h>
#include <windows.h>
#endif
#ifndef INT8_MIN
#include <stdint.h>
#endif
#include <sql.h>
#include <sqlext.h>
int todbc_parse_conn_string(const char *conn, char **dsn, char **uid, char **pwd, char **host);
#endif // _todbc_flex_workaround_h_
#endif // _TODBC_FLEX_H_

View File

@ -16,13 +16,7 @@
#ifndef _todbc_log_h_
#define _todbc_log_h_
#ifdef _MSC_VER
#include "msvcLibgen.h"
#else
#include <libgen.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "os.h"
#define D(fmt, ...) \
fprintf(stderr, \

View File

@ -1,6 +1,5 @@
%{
#include "todbc_util.h"
#include "todbc_flex.h"
#include <stdio.h>
#ifdef _MSC_VER
@ -105,8 +104,7 @@ do { \
<EQ>[{] { CHG_STATE(BRACE1); }
<EQ>.|\n { return -1; }
<BRACE1>[[:space:]]+ { }
<BRACE1>[^{}\n[:space:]]+ { set_val(); CHG_STATE(BRACE2); }
<BRACE1>[^{}\n]+ { set_val(); CHG_STATE(BRACE2); }
<BRACE1>.|\n { return -1; }
<BRACE2>[[:space:]]+ { }

View File

@ -14,11 +14,10 @@
*/
#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) {
switch (type) {

View File

@ -16,9 +16,10 @@
#ifndef _TODBC_UTIL_H_
#define _TODBC_UTIL_H_
#include "todbc_flex_workaround.h"
#include "todbc_log.h"
#include "os.h"
#include <sql.h>
#include <sqltypes.h>
const char* sql_sql_type(int type);
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_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,
const unsigned char *src, size_t sbytes,
unsigned char *dst, size_t dbytes,

View File

@ -9,5 +9,5 @@ ENDIF ()
IF (TD_WINDOWS_64)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(tcodbc main.c)
# TARGET_LINK_LIBRARIES(tcodbc odbc)
TARGET_LINK_LIBRARIES(tcodbc odbc32 os)
ENDIF ()

View File

@ -1,17 +1,16 @@
#include "../src/todbc_log.h"
#ifdef _MSC_VER
#include <winsock2.h>
#include <windows.h>
#include "os.h"
#endif
#include <sql.h>
#include <sqlext.h>
#include <stdio.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) \
do { \
D("testing: %s", #statement); \
@ -425,7 +424,7 @@ int test_sqls_in_stmt(SQLHENV env, SQLHDBC conn, SQLHSTMT stmt, const char *sqls
ssize_t n = 0;
#ifdef _MSC_VER
n = taosGetlineImp(&line, &len, f);
n = taosGetline(&line, &len, f);
#else
n = getline(&line, &len, f);
#endif
@ -503,7 +502,12 @@ int main(int argc, char *argv[]) {
const char *connstr = (argc>4) ? argv[4] : 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(test1(dsn, uid, pwd));

View File

@ -43,6 +43,7 @@
#include "msvcProcess.h"
#include "msvcDirect.h"
#include "msvcFcntl.h"
#include "msvcLibgen.h"
#include "msvcStdio.h"
#include "sys/msvcStat.h"
#include "sys/msvcTypes.h"