提交 cc496e12 编写于 作者: F freemine

add todbcinst to help user install/uninstall taos odbc driver

上级 8b146842
......@@ -9,7 +9,7 @@ ELSEIF (TD_WINDOWS)
ELSE ()
SET(CMAKE_INSTALL_PREFIX C:/TDengine)
ENDIF ()
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/go DESTINATION connector)
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/nodejs DESTINATION connector)
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/python DESTINATION connector)
......@@ -19,13 +19,17 @@ ELSEIF (TD_WINDOWS)
INSTALL(FILES ${TD_COMMUNITY_DIR}/src/inc/taoserror.h DESTINATION include)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.lib DESTINATION driver)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.exp DESTINATION driver)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.dll DESTINATION driver)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.dll DESTINATION driver)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/todbc.lib DESTINATION driver)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/todbc.exp DESTINATION driver)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/todbc.dll DESTINATION driver)
IF (TD_POWER)
INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/power.exe DESTINATION .)
ELSE ()
INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taos.exe DESTINATION .)
ELSE ()
INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taos.exe DESTINATION .)
INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taosdemo.exe DESTINATION .)
INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/todbcinst.exe DESTINATION .)
ENDIF ()
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
......
......@@ -20,6 +20,7 @@ IF (TD_LINUX_64)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wconversion")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wconversion")
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tools)
ADD_SUBDIRECTORY(tests)
endif()
endif()
......@@ -42,6 +43,7 @@ IF (TD_WINDOWS_64)
message(FATAL_ERROR "you need to install flex first")
else ()
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tools)
ADD_SUBDIRECTORY(tests)
endif()
ENDIF ()
......@@ -9,5 +9,5 @@ ENDIF ()
IF (TD_WINDOWS_64)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(tcodbc main.c)
TARGET_LINK_LIBRARIES(tcodbc odbc32 os)
TARGET_LINK_LIBRARIES(tcodbc odbc32 odbccp32 user32 legacy_stdio_definitions os)
ENDIF ()
......@@ -7,6 +7,7 @@
#endif
#include <sql.h>
#include <sqlext.h>
#include <odbcinst.h>
#include <stdio.h>
#include <string.h>
......@@ -496,6 +497,13 @@ int main(int argc, char *argv[]) {
return 0;
}
if (argc==2 && strcmp(argv[1], "uninstall")==0) {
DWORD usage = 0;
BOOL ok = SQLRemoveDriver("TAOS ODBC", TRUE, &usage);
D("ok/usage: %d/%d", ok, usage);
return ok ? 0 : 1;
}
const char *dsn = (argc>1) ? argv[1] : NULL;
const char *uid = (argc>2) ? argv[2] : NULL;
const char *pwd = (argc>3) ? argv[3] : NULL;
......
PROJECT(TDengine)
IF (TD_LINUX)
ADD_EXECUTABLE(todbcinst main.c)
TARGET_LINK_LIBRARIES(todbcinst odbc)
ENDIF ()
IF (TD_WINDOWS_64)
ADD_EXECUTABLE(todbcinst main.c)
TARGET_LINK_LIBRARIES(todbcinst odbc32 odbccp32 user32 legacy_stdio_definitions os)
ENDIF ()
#include "../src/todbc_log.h"
#ifdef _MSC_VER
#include <winsock2.h>
#include <windows.h>
#include "os.h"
#endif
#include <odbcinst.h>
#include <stdio.h>
#include <string.h>
static void usage(const char *arg0);
static int do_install(int i, int argc, char *argv[]);
static int do_uninstall(int i, int argc, char *argv[]);
int main(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
const char *arg = argv[i];
if (strcmp(arg, "-h") == 0) {
usage(argv[0]);
return 0;
} else if (strcmp(arg, "-i") == 0 ) {
i = do_install(i + 1, argc, argv);
if (i > 0) continue;
return i == 0 ? 0 : 1;
} else if (strcmp(arg, "-u") == 0 ) {
i = do_uninstall(i + 1, argc, argv);
if (i > 0) continue;
return i == 0 ? 0 : 1;
} else {
fprintf(stderr, "unknown argument: [%s]\n", arg);
return 1;
}
}
}
static void usage(const char *arg0) {
fprintf(stderr, "%s -h | -i -n [TaosDriverName] -p [TaosDriverPath] | -u [-f] [TaosDriverName]\n", arg0);
return;
}
static int do_install(int i, int argc, char *argv[]) {
int forceful = 0;
const char* driverName = NULL;
const char* driverFile = "todbc.dll";
const char* driverPath = NULL;
for (; i < argc; ++i) {
const char *arg = argv[i];
if (strcmp(arg, "-n") == 0) {
i += 1;
if (i >= argc) {
fprintf(stderr, "expecting TaosDriverName, but got nothing\n");
return -1;
}
arg = argv[i];
if (strstr(arg, "TAOS") != arg) {
fprintf(stderr, "TaosDriverName shall begin with 'TAOS': [%s]\n", arg);
return -1;
}
driverName = arg;
} else if (strcmp(arg, "-p") == 0) {
i += 1;
if (i >= argc) {
fprintf(stderr, "expecting TaosDriverPath, but got nothing\n");
return -1;
}
driverPath = argv[i];
} else {
fprintf(stderr, "unknown argument: [%s]\n", arg);
return -1;
}
}
if (!driverName) {
fprintf(stderr, "TaosDriverName not specified\n");
return -1;
}
if (!driverPath) {
fprintf(stderr, "TaosDriverPath not specified\n");
return -1;
}
char buf[8192];
snprintf(buf, sizeof(buf), "%s%cDriver=%s%cFileUage=0%cConnectFunctions=YYN%c",
driverName, 0, driverFile, 0, 0, 0);
BOOL ok = TRUE;
DWORD usageCount = 1;
char installed[PATH_MAX + 1];
WORD len = 0;
ok = SQLInstallDriverEx(buf, driverPath, installed, sizeof(installed), &len, ODBC_INSTALL_INQUIRY, &usageCount);
if (!ok) {
fprintf(stderr, "failed to query TaosDriverName: [%s]\n", driverName);
return -1;
}
if (stricmp(driverPath, installed)) {
fprintf(stderr, "previously installed TaosDriver [%s] has different target path [%s]\n"
"it shall be uninstalled before you can install it to different path [%s]\n",
driverName, installed, driverPath);
return -1;
}
ok = SQLInstallDriverEx(buf, driverPath, installed, sizeof(installed), &len, ODBC_INSTALL_COMPLETE, &usageCount);
if (!ok) {
fprintf(stderr, "failed to install TaosDriverName: [%s][%s]\n", driverName, driverPath);
return -1;
}
return argc;
}
static int do_uninstall(int i, int argc, char *argv[]) {
int forceful = 0;
const char* driverName = NULL;
for (; i < argc; ++i) {
const char *arg = argv[i];
if (strcmp(arg, "-f") == 0) {
forceful = 1;
} else if (strcmp(arg, "-n") == 0) {
i += 1;
if (i >= argc) {
fprintf(stderr, "expecting TaosDriverName, but got nothing\n");
return -1;
}
arg = argv[i];
if (strstr(arg, "TAOS") != arg) {
fprintf(stderr, "TaosDriverName shall begin with 'TAOS': [%s]\n", arg);
return -1;
}
driverName = arg;
} else {
fprintf(stderr, "unknown argument: [%s]\n", arg);
return -1;
}
}
if (!driverName) {
fprintf(stderr, "TaosDriverName not specified\n");
return -1;
}
BOOL ok = TRUE;
DWORD usageCount = 1;
do {
ok = SQLRemoveDriver(driverName, FALSE, &usageCount);
if (!ok) {
fprintf(stderr, "failed to remove driver [%s]\n", driverName);
return -1;
}
if (!forceful) return argc;
} while (usageCount > 0);
return argc;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册