Skip to content
Permalink
Browse files

ODBC-267 Cleaned setup library build and linking

Connection test now uses ODBC API, and not driver internals. Driver is
not linked directly. Removed dependencies on the C/C as well DSN info from the dialog is passed to the
connection API in the string, and not in the internal DSN structure.
Added connection string to the connetion test result window.
  • Loading branch information
lawrinn committed Oct 13, 2019
1 parent f098cc9 commit 1317196159ff80752e68cb0a1cf2dcc32b0f8ce9
Showing with 186 additions and 166 deletions.
  1. +6 −6 CMakeLists.txt
  2. +72 −8 dsn/odbc_dsn.c
  3. +11 −0 ma_common.c
  4. +0 −6 ma_platform_win32.c
  5. +96 −96 test/scroll.c
  6. +1 −50 test/tap.h
@@ -57,8 +57,7 @@ SET(DSN_DIALOG_FILES ${CMAKE_SOURCE_DIR}/dsn/odbc_dsn.c
${CMAKE_SOURCE_DIR}/dsn/odbc_dsn.rc
${CMAKE_SOURCE_DIR}/dsn/resource.h
ma_dsn.c
ma_driver.c
ma_error.c
# ma_error.c
ma_common.c)

MACRO(ADD_OPTION _name _text _default)
@@ -201,15 +200,16 @@ IF(WIN32)
ma_legacy_helpers.h
ma_typeconv.h
ma_bulk.h)
SET(DSN_DIALOG_FILES ${DSN_DIALOG_FILES}
ma_platform_win32.c)
# SET(DSN_DIALOG_FILES ${DSN_DIALOG_FILES}
# ma_platform_win32.c)

SET(PLATFORM_DEPENDENCIES ws2_32 Shlwapi)
IF (MSVC)
MESSAGE(STATUS "MSVC_VERSION= ${MSVC_VERSION}")
IF (NOT(MSVC_VERSION LESS 1900))
MESSAGE(STATUS "Configuring to link connector against legacy_stdio_definitions")
SET(PLATFORM_DEPENDENCIES ${PLATFORM_DEPENDENCIES} legacy_stdio_definitions)
SET(LEGACY_STDIO legacy_stdio_definitions)
SET(PLATFORM_DEPENDENCIES ${PLATFORM_DEPENDENCIES} ${LEGACY_STDIO})
ENDIF()
ENDIF()
ELSE()
@@ -328,7 +328,7 @@ IF(WIN32)
####### MAODBCS #######
ADD_LIBRARY(maodbcs SHARED ${DSN_DIALOG_FILES} ${CMAKE_SOURCE_DIR}/dsn/mariadb_odbc_setup.def)
SET_TARGET_PROPERTIES(maodbcs PROPERTIES LANGUAGE C)
TARGET_LINK_LIBRARIES(maodbcs comctl32 ${MARIADB_LIB} maodbc ${ODBC_INSTLIBS})
TARGET_LINK_LIBRARIES(maodbcs comctl32 ${LEGACY_STDIO} Shlwapi ${ODBC_LIBS} ${ODBC_INSTLIBS})

ADD_EXECUTABLE(dsn_test dsn_test.c)
TARGET_LINK_LIBRARIES(dsn_test ${MARIADB_LIB})
@@ -31,6 +31,7 @@

#pragma comment(lib, "ComCtl32.lib")

#define CONNSTR_BUFFER_SIZE 1024
#define LASTPAGE 5

HINSTANCE hInstance;
@@ -455,19 +456,32 @@ void DSN_Set_CharacterSets(SQLHANDLE Connection)
}


static SQLRETURN TestDSN(MADB_Dsn *Dsn, SQLHANDLE *Conn)
static SQLRETURN TestDSN(MADB_Dsn *Dsn, SQLHANDLE *Conn, SQLCHAR *ConnStrBuffer)
{
SQLHANDLE Connection= NULL;
SQLRETURN Result;
char * InitCommand= Dsn->InitCommand;
SQLCHAR LocalBuffer[CONNSTR_BUFFER_SIZE], *ConnStr= LocalBuffer;
char *InitCommand= Dsn->InitCommand;
char *DsName= Dsn->DSNName;
char *Description= Dsn->Description;

Dsn->InitCommand= NULL;
Dsn->DSNName= NULL;
Dsn->Description= NULL;

if (ConnStrBuffer != NULL)
{
ConnStr= ConnStrBuffer;
}
MADB_DsnToString(Dsn, ConnStr, CONNSTR_BUFFER_SIZE);

SQLAllocHandle(SQL_HANDLE_DBC, Environment, (SQLHANDLE *)&Connection);
assert(Connection != NULL);
Result= ((MADB_Dbc *)Connection)->Methods->ConnectDB((MADB_Dbc *)Connection, Dsn);
Result= SQLDriverConnect(Connection, NULL, ConnStr, CONNSTR_BUFFER_SIZE, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);

Dsn->InitCommand= InitCommand;
Dsn->DSNName= DsName;
Dsn->Description= Description;

if (Conn != NULL)
{
@@ -483,27 +497,77 @@ static SQLRETURN TestDSN(MADB_Dsn *Dsn, SQLHANDLE *Conn)
}


/* Connstr has to be null-terminated */
char* HidePwd(char *ConnStr)
{
char *Ptr= ConnStr;

while (*Ptr)
{
BOOL IsPwd= FALSE;
char *KeyValBorder= strchr(Ptr, '=');
char StopChr= ';';

Ptr= ltrim(Ptr);

if (_strnicmp(Ptr, "PWD", 3) == 0 || _strnicmp(Ptr, "PASSWORD", 8) == 0)
{
IsPwd= TRUE;
}
if (KeyValBorder != NULL)
{
Ptr= ltrim(KeyValBorder + 1);
}
if (*Ptr == '{')
{
StopChr= '}';
}
while (*Ptr && *Ptr != StopChr)
{
if (IsPwd)
{
*Ptr= '*';
}
++Ptr;
}
++Ptr;
}

return ConnStr;
}


void MADB_WIN_TestDsn(my_bool ShowSuccess)
{
SQLHANDLE Connection;
SQLRETURN ret;
MADB_Dsn *Dsn= (MADB_Dsn *)GetWindowLongPtr(GetParent(hwndTab[0]), DWLP_USER);
SQLCHAR ConnStr[CONNSTR_BUFFER_SIZE];

GetDialogFields();

ret= TestDSN(Dsn, &Connection);
ret= TestDSN(Dsn, &Connection, ConnStr);

if (ShowSuccess)
{
char Info[1024];

HidePwd(ConnStr);

if (SQL_SUCCEEDED(ret))
{
_snprintf(Info, 1024, "Connection successfully established\n\nServer information: %s", mysql_get_server_info(((MADB_Dbc *)Connection)->mariadb));
char DbmsName[16], DbmsVer[16];
SQLGetInfo(Connection, SQL_DBMS_NAME, DbmsName, sizeof(DbmsName), NULL);
SQLGetInfo(Connection, SQL_DBMS_VER, DbmsVer, sizeof(DbmsVer), NULL);
_snprintf(Info, sizeof(Info), "Connection successfully established\n\nServer Information: %s %s\n\nConnection String:\n\n%s", DbmsName, DbmsVer, ConnStr);
MessageBox(hwndTab[CurrentPage], Info, "Connection test", MB_ICONINFORMATION| MB_OK);
}
else
{
MessageBox(hwndTab[CurrentPage], ((MADB_Dbc *)Connection)->Error.SqlErrorMsg, "Connection test", MB_ICONINFORMATION| MB_OK);
SQLCHAR SqlState[6], ErrMsg[SQL_MAX_MESSAGE_LENGTH];
SQLGetDiagRec(SQL_HANDLE_DBC, Connection, 1, SqlState, NULL, ErrMsg, SQL_MAX_MESSAGE_LENGTH, NULL);
_snprintf(Info, sizeof(Info), "Connection failed: [%s] %s\n\nConnection String:\n\n%s", SqlState, ErrMsg, ConnStr);
MessageBox(hwndTab[CurrentPage], Info, "Connection test", MB_ICONINFORMATION| MB_OK);
}
}

@@ -838,7 +902,7 @@ BOOL DSNDialog(HWND hwndParent,
Dsn->Driver= _strdup(lpszDriver);
}

if (SQL_SUCCEEDED(TestDSN(Dsn, NULL)))
if (SQL_SUCCEEDED(TestDSN(Dsn, NULL, NULL)))
{
return MADB_SaveDSN(Dsn);
}
@@ -870,7 +934,7 @@ BOOL DSNDialog(HWND hwndParent,

if (hwndParent == NULL)
{
if (SQL_SUCCEEDED(TestDSN(Dsn, NULL)))
if (SQL_SUCCEEDED(TestDSN(Dsn, NULL, NULL)))
{
return MADB_SaveDSN(Dsn);
}
@@ -62,3 +62,14 @@ char* trim(char *Str)
}
/* }}} */

/* Windows only common functions */
#ifdef _WIN32

/* {{{ strcasestr() */
char* strcasestr(const char* HayStack, const char* Needle)
{
return StrStrIA(HayStack, Needle);
}
/* }}} */

#endif
@@ -323,9 +323,3 @@ BOOL MADB_DSN_PossibleConnect(MADB_Dsn *Dsn)
}
/* }}} */

/* {{{ strcasestr() */
char* strcasestr(const char* HayStack, const char* Needle)
{
return StrStrIA(HayStack, Needle);
}
/* }}} */

0 comments on commit 1317196

Please sign in to comment.
You can’t perform that action at this time.