Skip to content

Commit

Permalink
Added connection string SOCKET for connecting to unix sockets
Browse files Browse the repository at this point in the history
Added cmake option DIRECT_LINK_TESTS to link tests directly against the connector
  • Loading branch information
lawrinn committed Mar 16, 2015
1 parent f7a63dc commit 2e8fc0c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
1 change: 0 additions & 1 deletion cmake/FindDM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ ELSE()
MESSAGE(STATUS "Found ODBC Driver Manager includes: ${ODBC_INCLUDE_DIR}")
ENDIF()


# Try to find DM libraries, giving precedence to special variables
FIND_PATH(ODBC_LIB_DIR libodbc.so
HINTS ${DM_LIB_DIR}
Expand Down
22 changes: 14 additions & 8 deletions ma_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ MADB_Dbc *MADB_DbcInit(SQLHANDLE OutputHandle)
Connection->Environment->Dbcs= list_add(Connection->Environment->Dbcs, &Connection->ListItem);
LeaveCriticalSection(&Connection->cs);

if (!(Connection->mariadb= mysql_init(NULL)))
{
MADB_SetError(&Connection->Error, MADB_ERR_HY001, NULL, 0);
goto cleanup;
}

return Connection;
cleanup:
if (Connection)
Expand Down Expand Up @@ -546,12 +552,6 @@ SQLRETURN MADB_DbcConnectDB(MADB_Dbc *Connection,

MADB_CLEAR_ERROR(&Connection->Error);

if (!(Connection->mariadb= mysql_init(NULL)))
{
MADB_SetError(&Connection->Error, MADB_ERR_HY001, NULL, 0);
goto end;
}

/* If a client character set was specified in DSN, we will always use it.
Otherwise for ANSI applications we will use the current character set,
for unicode connections we use utf8
Expand Down Expand Up @@ -611,9 +611,15 @@ SQLRETURN MADB_DbcConnectDB(MADB_Dbc *Connection,
/* enable truncation reporting */
mysql_options(Connection->mariadb, MYSQL_REPORT_DATA_TRUNCATION, &ReportDataTruncation);

if (Dsn->Socket)
{
int protocol= MYSQL_PROTOCOL_SOCKET;
mysql_options(Connection->mariadb, MYSQL_OPT_PROTOCOL, (void*)&protocol);
}

if (!mysql_real_connect(Connection->mariadb,
Dsn->ServerName, Dsn->UserName, Dsn->Password,
Dsn->Catalog && Dsn->Catalog[0] ? Dsn->Catalog : NULL, Dsn->Port, NULL, client_flags))
Dsn->Socket ? "localhost" : Dsn->ServerName, Dsn->UserName, Dsn->Password,
Dsn->Catalog && Dsn->Catalog[0] ? Dsn->Catalog : NULL, Dsn->Port, Dsn->Socket, client_flags))
{
goto err;
}
Expand Down
1 change: 1 addition & 0 deletions ma_dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MADB_DsnKey DsnKeys[]=
{"PASSWORD", offsetof(MADB_Dsn, Password), DSN_TYPE_STRING,0,1},
{"DB", offsetof(MADB_Dsn, Catalog), DSN_TYPE_COMBO,0,1},
{"OPTION", offsetof(MADB_Dsn, Options), DSN_TYPE_INT, 0,1},
{"SOCKET", offsetof(MADB_Dsn, Socket), DSN_TYPE_STRING,0,0},
{NULL, 0, DSN_TYPE_BOOL}
};

Expand Down
1 change: 1 addition & 0 deletions ma_odbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ typedef struct st_madb_dsn
my_bool MultiStatements;
/* TRUE means "no prompt" */
my_bool ConnectPrompt;
char *Socket;
/* --- Internal --- */
int isPrompt;
MADB_DsnKey *Keys;
Expand Down
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ SET (ODBC_TESTS

FOREACH (ODBC_TEST ${ODBC_TESTS})
ADD_EXECUTABLE(${ODBC_TEST} ${ODBC_TEST}.c tap.h)
TARGET_LINK_LIBRARIES(${ODBC_TEST} ${ODBC_LIBS} ${MARIADB_LIB})
IF (DIRECT_LINK_TESTS)
TARGET_LINK_LIBRARIES(${ODBC_TEST} maodbc ${MARIADB_LIB})
ELSE()
TARGET_LINK_LIBRARIES(${ODBC_TEST} ${ODBC_LIBS} ${MARIADB_LIB})
ENDIF()
ADD_TEST(${ODBC_TEST} ${EXECUTABLE_OUTPUT_PATH}/${ODBC_TEST})
SET_TESTS_PROPERTIES(${ODBC_TEST} PROPERTIES TIMEOUT 120)
ENDFOREACH()
Expand Down
2 changes: 1 addition & 1 deletion test/tap.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ unsigned long my_options= 67108866;
SQLHANDLE Env, Connection, Stmt;

unsigned int my_port= 3306;
char ma_strport[]= ";PORT=3306";
char ma_strport[12]= ";PORT=3306";

/* To use in tests for conversion of strings to (sql)wchar strings */
SQLWCHAR sqlwchar_buff[1024], sqlwchar_empty[]= {0};
Expand Down

0 comments on commit 2e8fc0c

Please sign in to comment.