1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

- Added new function mariadb_get_connection_type which returns -1 on

error, or MARIADB_CONNECTION_{UNIX_SOCKET,TCP,NAMEDPIPE,SHAREDMEM}
- Disabled asynchronous API for named pipes and shared memory connecit++ions
- Added package suffix ("alpha")
- removed myodbc_remove_escape api function
- Fixed return value (length) for named pipe read/write operations
This commit is contained in:
Georg Richter
2015-11-23 10:58:28 +01:00
parent f30bb95c6a
commit ebe3cc9935
13 changed files with 87 additions and 53 deletions

View File

@@ -4,6 +4,8 @@
# This is the LGPL libmariadb project. # This is the LGPL libmariadb project.
PROJECT(mariadb-connector-c C) PROJECT(mariadb-connector-c C)
SET(PACKAGE_STATUS_SUFFIX "alpha")
SET(CPACK_PACKAGE_VERSION_MAJOR 3) SET(CPACK_PACKAGE_VERSION_MAJOR 3)
SET(CPACK_PACKAGE_VERSION_MINOR 0) SET(CPACK_PACKAGE_VERSION_MINOR 0)
SET(CPACK_PACKAGE_VERSION_PATCH 0) SET(CPACK_PACKAGE_VERSION_PATCH 0)
@@ -264,12 +266,16 @@ SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab")
SET(CPACK_PACKAGE_DESCRIPTION "MariaDB Connector/C. A library for connecting to MariaDB and MySQL servers") SET(CPACK_PACKAGE_DESCRIPTION "MariaDB Connector/C. A library for connecting to MariaDB and MySQL servers")
SET(CPACK_PACKAGE_NAME "mariadb_connector_c") SET(CPACK_PACKAGE_NAME "mariadb_connector_c")
STRING(TOLOWER ${CMAKE_SYSTEM_NAME} system_name) STRING(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LIB") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LIB")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
INCLUDE(cmake/ConnectorName.cmake) INCLUDE(cmake/ConnectorName.cmake)
IF(NOT PACKAGE_STATUS_SUFFIX)
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src") SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src")
SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
ELSE()
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-src")
SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
ENDIF()
# Build source packages # Build source packages
IF(GIT_BUILD_SRCPKG) IF(GIT_BUILD_SRCPKG)
# get branch name # get branch name

View File

@@ -84,6 +84,7 @@ extern const char *mariadb_client_errors[]; /* Error messages */
#define CR_EVENT_CREATE_FAILED 5000 #define CR_EVENT_CREATE_FAILED 5000
#define CR_BIND_ADDR_FAILED 5001 #define CR_BIND_ADDR_FAILED 5001
#define CR_ASYNC_NOT_SUPPORTED 5002
#define SQLSTATE_UNKNOWN "HY000" #define SQLSTATE_UNKNOWN "HY000"

View File

@@ -50,7 +50,8 @@ enum enum_pvio_io_event
enum enum_pvio_type { enum enum_pvio_type {
PVIO_TYPE_UNIXSOCKET= 0, PVIO_TYPE_UNIXSOCKET= 0,
PVIO_TYPE_SOCKET, PVIO_TYPE_SOCKET,
PVIO_TYPE_NAMEDPIPE PVIO_TYPE_NAMEDPIPE,
PVIO_TYPE_SHAREDMEM,
}; };
enum enum_pvio_operation { enum enum_pvio_operation {

View File

@@ -469,7 +469,6 @@ unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
void STDCALL mysql_debug(const char *debug); void STDCALL mysql_debug(const char *debug);
#define mysql_debug_init(A) mysql_debug((A)); #define mysql_debug_init(A) mysql_debug((A));
void STDCALL mysql_debug_end(void); void STDCALL mysql_debug_end(void);
void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
unsigned int STDCALL mysql_thread_safe(void); unsigned int STDCALL mysql_thread_safe(void);
unsigned int STDCALL mysql_warning_count(MYSQL *mysql); unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
const char * STDCALL mysql_sqlstate(MYSQL *mysql); const char * STDCALL mysql_sqlstate(MYSQL *mysql);
@@ -493,6 +492,7 @@ unsigned long STDCALL mysql_hex_string(char *to, const char *from, size_t len);
my_socket STDCALL mysql_get_socket(const MYSQL *mysql); my_socket STDCALL mysql_get_socket(const MYSQL *mysql);
unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql); unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql);
unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql); unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql);
int STDCALL mariadb_get_connection_type(MYSQL *mysql);
/* Async API */ /* Async API */
int STDCALL mysql_close_start(MYSQL *sock); int STDCALL mysql_close_start(MYSQL *sock);

View File

@@ -364,6 +364,12 @@ typedef struct st_udf_init
my_bool const_item; /* 0 if result is independent of arguments */ my_bool const_item; /* 0 if result is independent of arguments */
} UDF_INIT; } UDF_INIT;
/* Connection types */
#define MARIADB_CONNECTION_UNIXSOCKET 0
#define MARIADB_CONNECTION_TCP 1
#define MARIADB_CONNECTION_NAMEDPIPE 2
#define MARIADB_CONNECTION_SHAREDMEM 3
/* Constants when using compression */ /* Constants when using compression */
#define NET_HEADER_SIZE 4 /* standard header size */ #define NET_HEADER_SIZE 4 /* standard header size */
#define COMP_HEADER_SIZE 3 /* compression header extra size */ #define COMP_HEADER_SIZE 3 /* compression header extra size */

View File

@@ -34,7 +34,7 @@ SET(EXPORT_SYMBOLS
mariadb_dyncol_val_double mariadb_dyncol_val_double
mariadb_dyncol_val_long mariadb_dyncol_val_long
mariadb_dyncol_val_str mariadb_dyncol_val_str
myodbc_remove_escape mariadb_get_connection_type
mysql_affected_rows mysql_affected_rows
mysql_autocommit mysql_autocommit
mysql_autocommit_cont mysql_autocommit_cont

View File

@@ -149,6 +149,7 @@ const char *mariadb_client_errors[] =
{ {
/* 5000 */ "Creating an event failed (Errorcode: %d)", /* 5000 */ "Creating an event failed (Errorcode: %d)",
/* 5001 */ "Bind to local interface '-.%64s' failed (Errorcode: %d)", /* 5001 */ "Bind to local interface '-.%64s' failed (Errorcode: %d)",
/* 5002 */ "Connection type doesn't support asynchronous IO operations",
"" ""
}; };

View File

@@ -3069,32 +3069,6 @@ mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
return (ulong)mysql_cset_escape_slashes(mysql->charset, to, from, length); return (ulong)mysql_cset_escape_slashes(mysql->charset, to, from, length);
} }
void STDCALL
myodbc_remove_escape(MYSQL *mysql,char *name)
{
char *to;
my_bool use_mb_flag= (mysql->charset->char_maxlen > 1);
char *end= 0;
if (use_mb_flag)
for (end=name; *end ; end++) ;
for (to=name ; *name ; name++)
{
int l;
if (use_mb_flag && (l = mysql->charset->mb_valid(name , end)))
{
while (l--)
*to++ = *name++;
name--;
continue;
}
if (*name == '\\' && name[1])
name++;
*to++= *name;
}
*to=0;
}
void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs)
{ {
DBUG_ENTER("mysql_get_character_set_info"); DBUG_ENTER("mysql_get_character_set_info");
@@ -3295,6 +3269,15 @@ mysql_get_socket(const MYSQL *mysql)
return sock; return sock;
} }
int STDCALL mariadb_get_connection_type(MYSQL *mysql)
{
/* check if we are connected */
if (!mysql || !mysql->net.pvio)
return -1;
return (int)mysql->net.pvio->type;
}
/* /*
* Default methods for a connection. These methods are * Default methods for a connection. These methods are
* stored in mysql->methods and can be overwritten by * stored in mysql->methods and can be overwritten by

View File

@@ -71,7 +71,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo)
* pvio_socket * pvio_socket
* pvio_namedpipe * pvio_namedpipe
*/ */
char *pvio_plugins[] = {"pvio_socket", "pvio_npipe"}; char *pvio_plugins[] = {"pvio_socket", "pvio_npipe", "pvio_shmem"};
int type; int type;
MARIADB_PVIO_PLUGIN *pvio_plugin; MARIADB_PVIO_PLUGIN *pvio_plugin;
MARIADB_PVIO *pvio= NULL; MARIADB_PVIO *pvio= NULL;
@@ -86,6 +86,9 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo)
case PVIO_TYPE_NAMEDPIPE: case PVIO_TYPE_NAMEDPIPE:
type= 1; type= 1;
break; break;
case PVIO_TYPE_SHAREDMEM:
type= 2;
break;
#endif #endif
default: default:
return NULL; return NULL;
@@ -96,7 +99,6 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo)
pvio_plugins[type], pvio_plugins[type],
MARIADB_CLIENT_PVIO_PLUGIN))) MARIADB_CLIENT_PVIO_PLUGIN)))
{ {
/* error handling */
return NULL; return NULL;
} }
@@ -111,6 +113,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo)
/* register error routine and methods */ /* register error routine and methods */
pvio->methods= pvio_plugin->methods; pvio->methods= pvio_plugin->methods;
pvio->set_error= my_set_error; pvio->set_error= my_set_error;
pvio->type= cinfo->type;
/* set tineouts */ /* set tineouts */
if (pvio->methods->set_timeout) if (pvio->methods->set_timeout)
@@ -180,9 +183,14 @@ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t lengt
struct mysql_async_context *b= pvio->mysql->options.extension->async_context; struct mysql_async_context *b= pvio->mysql->options.extension->async_context;
int timeout= pvio->timeout[PVIO_READ_TIMEOUT]; int timeout= pvio->timeout[PVIO_READ_TIMEOUT];
if (!pvio->methods->async_read)
{
PVIO_SET_ERROR(pvio->mysql, CR_ASYNC_NOT_SUPPORTED, unknown_sqlstate, 0);
return -1;
}
for (;;) for (;;)
{ {
/* todo: async */
if (pvio->methods->async_read) if (pvio->methods->async_read)
res= pvio->methods->async_read(pvio, buffer, length); res= pvio->methods->async_read(pvio, buffer, length);
if (res >= 0 || IS_BLOCKING_ERROR()) if (res >= 0 || IS_BLOCKING_ERROR())

View File

@@ -180,7 +180,6 @@ static my_bool net_realloc(NET *net, size_t length)
} }
/* Remove unwanted characters from connection */ /* Remove unwanted characters from connection */
void net_clear(NET *net) void net_clear(NET *net)
{ {
DBUG_ENTER("net_clear"); DBUG_ENTER("net_clear");
@@ -189,9 +188,7 @@ void net_clear(NET *net)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/* Flush write_buffer if not empty. */ /* Flush write_buffer if not empty. */
int net_flush(NET *net) int net_flush(NET *net)
{ {
int error=0; int error=0;
@@ -207,12 +204,10 @@ int net_flush(NET *net)
DBUG_RETURN(error); DBUG_RETURN(error);
} }
/***************************************************************************** /*****************************************************************************
** Write something to server/client buffer ** Write something to server/client buffer
*****************************************************************************/ *****************************************************************************/
/* /*
** Write a logical packet with packet header ** Write a logical packet with packet header
** Format: Packet length (3 bytes), packet number(1 byte) ** Format: Packet length (3 bytes), packet number(1 byte)

View File

@@ -34,7 +34,9 @@
my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
int pvio_npipe_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); int pvio_npipe_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
size_t pvio_npipe_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
size_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); size_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
size_t pvio_npipe_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
my_bool pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value); my_bool pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
@@ -118,10 +120,10 @@ size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
goto end; goto end;
} }
if (GetLastError() == ERROR_IO_PENDING) if (GetLastError() == ERROR_IO_PENDING)
r= pvio_npipe_wait_io_or_timeout(pvio, 1, 0); {
if (!pvio_npipe_wait_io_or_timeout(pvio, 1, 0))
if (!r)
r= cpipe->rw_size; r= cpipe->rw_size;
}
end: end:
return r; return r;
} }
@@ -143,10 +145,10 @@ size_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
goto end; goto end;
} }
if (GetLastError() == ERROR_IO_PENDING) if (GetLastError() == ERROR_IO_PENDING)
r= pvio_npipe_wait_io_or_timeout(pvio, 1, 0); {
if (!pvio_npipe_wait_io_or_timeout(pvio, 1, 0))
if (!r)
r= cpipe->rw_size; r= cpipe->rw_size;
}
end: end:
return r; return r;
} }
@@ -216,7 +218,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
if (!pvio || !cinfo) if (!pvio || !cinfo)
return 1; return 1;
if (!(cpipe= (struct st_pvio_npipe *)LocalAlloc(sizeof(struct st_pvio_npipe), 0))) if (!(cpipe= (struct st_pvio_npipe *)LocalAlloc(LMEM_ZEROINIT, sizeof(struct st_pvio_npipe))))
{ {
PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, "");
return 1; return 1;

View File

@@ -30,6 +30,19 @@
#define SL(s) (s), sizeof(s) #define SL(s) (s), sizeof(s)
my_bool skip_async= 0;
static int test_async(MYSQL *mysql)
{
int type= mariadb_get_connection_type(mysql);
if (type > MARIADB_CONNECTION_TCP)
{
skip_async= 1;
diag("Asnyc IO not supported");
}
return OK;
}
static int static int
wait_for_mysql(MYSQL *mysql, int status) wait_for_mysql(MYSQL *mysql, int status)
{ {
@@ -126,6 +139,9 @@ static int async1(MYSQL *my)
uint default_timeout; uint default_timeout;
int i; int i;
if (skip_async)
return SKIP;
for (i=0; i < 100; i++) for (i=0; i < 100; i++)
{ {
@@ -196,7 +212,12 @@ static int test_conc131(MYSQL *my)
{ {
int rc; int rc;
/* this test needs to run under valgrind */ /* this test needs to run under valgrind */
MYSQL *mysql=mysql_init(NULL); MYSQL *mysql;
if (skip_async)
return SKIP;
mysql= mysql_init(NULL);
rc= mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); rc= mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0);
check_mysql_rc(rc, mysql); check_mysql_rc(rc, mysql);
mysql_close(mysql); mysql_close(mysql);
@@ -205,13 +226,19 @@ static int test_conc131(MYSQL *my)
static int test_conc129(MYSQL *my) static int test_conc129(MYSQL *my)
{ {
MYSQL *mysql= mysql_init(NULL); MYSQL *mysql;
if (skip_async)
return SKIP;
mysql= mysql_init(NULL);
FAIL_IF(mysql_close_start(mysql), "No error expected"); FAIL_IF(mysql_close_start(mysql), "No error expected");
return OK; return OK;
} }
struct my_tests_st my_tests[] = { struct my_tests_st my_tests[] = {
{"test_async", test_async, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"async1", async1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"async1", async1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc131", test_conc131, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_conc131", test_conc131, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_conc129", test_conc129, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_conc129", test_conc129, TEST_CONNECTION_NONE, 0, NULL, NULL},

View File

@@ -57,7 +57,11 @@ IF(NOT WIX_DIR)
SET(WIX_DIR $ENV{WIX}/bin) SET(WIX_DIR $ENV{WIX}/bin)
ENDIF() ENDIF()
IF(NOT PACKAGE_STATUS_SUFFIX)
SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PLATFORM}.msi") SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PLATFORM}.msi")
ELSE()
SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PACKAGE_STATUS_SUFFIX}-${PLATFORM}.msi")
ENDIF()
IF(WITH_SIGNCODE) IF(WITH_SIGNCODE)
IF(EXISTS "/tools/sign.bat") IF(EXISTS "/tools/sign.bat")