You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
Added support for indicator variables
Fixed windows compilation bug
This commit is contained in:
@@ -59,7 +59,7 @@ enum enum_stmt_attr_type
|
|||||||
STMT_ATTR_PREFETCH_ROWS,
|
STMT_ATTR_PREFETCH_ROWS,
|
||||||
STMT_ATTR_PREBIND_PARAMS=200,
|
STMT_ATTR_PREBIND_PARAMS=200,
|
||||||
STMT_ATTR_ARRAY_SIZE,
|
STMT_ATTR_ARRAY_SIZE,
|
||||||
STMT_ATTR_BIND_TYPE
|
STMT_ATTR_ROW_SIZE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum enum_cursor_type
|
enum enum_cursor_type
|
||||||
@@ -72,16 +72,11 @@ enum enum_cursor_type
|
|||||||
|
|
||||||
enum enum_indicator_type
|
enum enum_indicator_type
|
||||||
{
|
{
|
||||||
|
STMT_INDICATOR_NTS=-1,
|
||||||
STMT_INDICATOR_NONE=0,
|
STMT_INDICATOR_NONE=0,
|
||||||
STMT_INDICATOR_NULL=1,
|
STMT_INDICATOR_NULL=1,
|
||||||
STMT_INDICATOR_DEFAULT=2,
|
STMT_INDICATOR_DEFAULT=2,
|
||||||
STMT_INDICATOR_NTS=4
|
STMT_INDICATOR_IGNORE=3
|
||||||
};
|
|
||||||
|
|
||||||
enum enum_bind_type
|
|
||||||
{
|
|
||||||
STMT_BIND_ROW=0,
|
|
||||||
STMT_BIND_COLUMN
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum mysql_stmt_state
|
typedef enum mysql_stmt_state
|
||||||
@@ -115,9 +110,9 @@ typedef struct st_mysql_bind
|
|||||||
union {
|
union {
|
||||||
unsigned long offset; /* offset position for char/binary fetch */
|
unsigned long offset; /* offset position for char/binary fetch */
|
||||||
struct {
|
struct {
|
||||||
uchar *indicator;
|
unsigned char *indicator;
|
||||||
};
|
};
|
||||||
};
|
} u;
|
||||||
unsigned long length_value; /* Used if length is 0 */
|
unsigned long length_value; /* Used if length is 0 */
|
||||||
unsigned int flags; /* special flags, e.g. for dummy bind */
|
unsigned int flags; /* special flags, e.g. for dummy bind */
|
||||||
unsigned int pack_length; /* Internal length for packed data */
|
unsigned int pack_length; /* Internal length for packed data */
|
||||||
@@ -228,7 +223,7 @@ struct st_mysql_stmt
|
|||||||
mysql_stmt_use_or_store_func default_rset_handler;
|
mysql_stmt_use_or_store_func default_rset_handler;
|
||||||
struct st_mysqlnd_stmt_methods *m;
|
struct st_mysqlnd_stmt_methods *m;
|
||||||
unsigned int array_size;
|
unsigned int array_size;
|
||||||
enum enum_bind_type bind_type;
|
size_t row_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*ps_field_fetch_func)(MYSQL_BIND *r_param, const MYSQL_FIELD * field, unsigned char **row);
|
typedef void (*ps_field_fetch_func)(MYSQL_BIND *r_param, const MYSQL_FIELD * field, unsigned char **row);
|
||||||
|
@@ -306,7 +306,7 @@ static void convert_froma_string(MYSQL_BIND *r_param, char *buffer, size_t len)
|
|||||||
case MYSQL_TYPE_NEWDECIMAL:
|
case MYSQL_TYPE_NEWDECIMAL:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
char *start= buffer + r_param->offset; /* stmt_fetch_column sets offset */
|
char *start= buffer + r_param->u.offset; /* stmt_fetch_column sets offset */
|
||||||
char *end= buffer + len;
|
char *end= buffer + len;
|
||||||
size_t copylen= 0;
|
size_t copylen= 0;
|
||||||
|
|
||||||
|
@@ -405,7 +405,10 @@ static void *ma_get_buffer_offset(MYSQL_STMT *stmt, enum enum_field_types type,
|
|||||||
{
|
{
|
||||||
if (stmt->array_size)
|
if (stmt->array_size)
|
||||||
{
|
{
|
||||||
int len= mysql_ps_fetch_functions[type].pack_len;
|
int len;
|
||||||
|
if (stmt->row_size)
|
||||||
|
return buffer + stmt->row_size * row_nr;
|
||||||
|
len= mysql_ps_fetch_functions[type].pack_len;
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
return buffer + len * row_nr;
|
return buffer + len * row_nr;
|
||||||
return ((void **)buffer)[row_nr];
|
return ((void **)buffer)[row_nr];
|
||||||
@@ -415,31 +418,34 @@ static void *ma_get_buffer_offset(MYSQL_STMT *stmt, enum enum_field_types type,
|
|||||||
|
|
||||||
int store_param(MYSQL_STMT *stmt, int column, unsigned char **p, unsigned long row_nr)
|
int store_param(MYSQL_STMT *stmt, int column, unsigned char **p, unsigned long row_nr)
|
||||||
{
|
{
|
||||||
|
void *buf= ma_get_buffer_offset(stmt, stmt->params[column].buffer_type,
|
||||||
|
stmt->params[column].buffer, row_nr);
|
||||||
switch (stmt->params[column].buffer_type) {
|
switch (stmt->params[column].buffer_type) {
|
||||||
case MYSQL_TYPE_TINY:
|
case MYSQL_TYPE_TINY:
|
||||||
int1store(*p, ((uchar *)stmt->params[column].buffer)[row_nr]);
|
int1store(*p, (*(uchar *)buf));
|
||||||
(*p) += 1;
|
(*p) += 1;
|
||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_SHORT:
|
case MYSQL_TYPE_SHORT:
|
||||||
case MYSQL_TYPE_YEAR:
|
case MYSQL_TYPE_YEAR:
|
||||||
int2store(*p, ((short *)stmt->params[column].buffer)[row_nr]);
|
int2store(*p, (*(short *)buf));
|
||||||
(*p) += 2;
|
(*p) += 2;
|
||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_FLOAT:
|
case MYSQL_TYPE_FLOAT:
|
||||||
float4store(*p, ((float *)stmt->params[column].buffer)[row_nr]);
|
float4store(*p, (*(float *)buf));
|
||||||
(*p) += 4;
|
(*p) += 4;
|
||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_DOUBLE:
|
case MYSQL_TYPE_DOUBLE:
|
||||||
float8store(*p, ((double *)stmt->params[column].buffer)[row_nr]);
|
float8store(*p, (*(double *)buf));
|
||||||
(*p) += 8;
|
(*p) += 8;
|
||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_LONGLONG:
|
case MYSQL_TYPE_LONGLONG:
|
||||||
int8store(*p, ((ulonglong *)stmt->params[column].buffer)[row_nr]);
|
int8store(*p, (*(ulonglong *)buf));
|
||||||
(*p) += 8;
|
(*p) += 8;
|
||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_LONG:
|
case MYSQL_TYPE_LONG:
|
||||||
case MYSQL_TYPE_INT24:
|
case MYSQL_TYPE_INT24:
|
||||||
int4store(*p, ((int32 *)stmt->params[column].buffer)[row_nr]);
|
int4store(*p, (*(int32 *)buf));
|
||||||
|
//stmt->params[column].buffer)[row_nr]);
|
||||||
(*p)+= 4;
|
(*p)+= 4;
|
||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_TIME:
|
case MYSQL_TYPE_TIME:
|
||||||
@@ -528,18 +534,23 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p, unsigned long r
|
|||||||
case MYSQL_TYPE_DECIMAL:
|
case MYSQL_TYPE_DECIMAL:
|
||||||
case MYSQL_TYPE_NEWDECIMAL:
|
case MYSQL_TYPE_NEWDECIMAL:
|
||||||
{
|
{
|
||||||
ulong len= (ulong)STMT_NUM_OFS(long, stmt->params[column].length, row_nr);
|
ulong len;
|
||||||
/* to is after p. The latter hasn't been moved */
|
/* to is after p. The latter hasn't been moved */
|
||||||
uchar *to;
|
uchar *to;
|
||||||
|
void *buf= ma_get_buffer_offset(stmt, stmt->params[column].buffer_type,
|
||||||
if ((long)len == -1)
|
stmt->params[column].buffer, row_nr);
|
||||||
len= strlen(ma_get_buffer_offset(stmt, stmt->params[column].buffer_type,
|
|
||||||
stmt->params[column].buffer, row_nr));
|
if (stmt->row_size)
|
||||||
|
len= *stmt->params[column].length;
|
||||||
|
else
|
||||||
|
len= (ulong)STMT_NUM_OFS(long, stmt->params[column].length, row_nr);
|
||||||
|
|
||||||
|
if ((long)len == STMT_INDICATOR_NTS)
|
||||||
|
len= strlen((char *)buf);
|
||||||
to = mysql_net_store_length(*p, len);
|
to = mysql_net_store_length(*p, len);
|
||||||
|
|
||||||
if (len)
|
if (len)
|
||||||
memcpy(to, ma_get_buffer_offset(stmt, stmt->params[column].buffer_type,
|
memcpy(to, buf, len);
|
||||||
stmt->params[column].buffer, row_nr), len);
|
|
||||||
(*p) = to + len;
|
(*p) = to + len;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -585,9 +596,9 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
|
|||||||
size_t free_bytes= 0;
|
size_t free_bytes= 0;
|
||||||
size_t null_byte_offset;
|
size_t null_byte_offset;
|
||||||
uint i, j, num_rows= 1;
|
uint i, j, num_rows= 1;
|
||||||
my_bool bulk_supported=
|
my_bool bulk_supported= stmt->array_size > 0 &&
|
||||||
!(stmt->mysql->server_capabilities & CLIENT_MYSQL) &&
|
(!(stmt->mysql->server_capabilities & CLIENT_MYSQL) &&
|
||||||
(stmt->mysql->server_capabilities & MARIADB_CLIENT_STMT_BULK_OPERATIONS);
|
(stmt->mysql->server_capabilities & MARIADB_CLIENT_STMT_BULK_OPERATIONS));
|
||||||
|
|
||||||
uchar *start= NULL, *p;
|
uchar *start= NULL, *p;
|
||||||
|
|
||||||
@@ -610,22 +621,24 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
|
|||||||
|
|
||||||
if (stmt->param_count)
|
if (stmt->param_count)
|
||||||
{
|
{
|
||||||
size_t null_count= (stmt->param_count + 7) / 8;
|
if (!stmt->array_size)
|
||||||
|
|
||||||
free_bytes= length - (p - start);
|
|
||||||
if (null_count + 20 > free_bytes)
|
|
||||||
{
|
{
|
||||||
size_t offset= p - start;
|
size_t null_count= (stmt->param_count + 7) / 8;
|
||||||
length+= offset + null_count + 20;
|
|
||||||
if (!(start= (uchar *)realloc(start, length)))
|
free_bytes= length - (p - start);
|
||||||
goto mem_error;
|
if (null_count + 20 > free_bytes)
|
||||||
p= start + offset;
|
{
|
||||||
|
size_t offset= p - start;
|
||||||
|
length+= offset + null_count + 20;
|
||||||
|
if (!(start= (uchar *)realloc(start, length)))
|
||||||
|
goto mem_error;
|
||||||
|
p= start + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
null_byte_offset= p - start;
|
||||||
|
memset(p, 0, null_count);
|
||||||
|
p += null_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
null_byte_offset= p - start;
|
|
||||||
memset(p, 0, null_count);
|
|
||||||
p += null_count;
|
|
||||||
|
|
||||||
int1store(p, stmt->send_types_to_server);
|
int1store(p, stmt->send_types_to_server);
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
@@ -649,7 +662,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
|
|||||||
/* this differs from mysqlnd, c api supports unsinged !! */
|
/* this differs from mysqlnd, c api supports unsinged !! */
|
||||||
uint buffer_type= stmt->params[i].buffer_type | (stmt->params[i].is_unsigned ? 32768 : 0);
|
uint buffer_type= stmt->params[i].buffer_type | (stmt->params[i].is_unsigned ? 32768 : 0);
|
||||||
/* check if parameter requires indicator variable */
|
/* check if parameter requires indicator variable */
|
||||||
if (bulk_supported && stmt->params[i].indicator)
|
if (bulk_supported && stmt->params[i].u.indicator)
|
||||||
buffer_type|= 16384;
|
buffer_type|= 16384;
|
||||||
int2store(p, buffer_type);
|
int2store(p, buffer_type);
|
||||||
p+= 2;
|
p+= 2;
|
||||||
@@ -665,9 +678,12 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
|
|||||||
my_bool has_data= TRUE;
|
my_bool has_data= TRUE;
|
||||||
uchar indicator= 0;
|
uchar indicator= 0;
|
||||||
|
|
||||||
if (bulk_supported && stmt->params[i].indicator)
|
if (bulk_supported && stmt->params[i].u.indicator)
|
||||||
{
|
{
|
||||||
indicator= stmt->params[i].indicator[j];
|
if (stmt->row_size)
|
||||||
|
indicator= *(uchar *)(stmt->params[i].u.indicator + j * stmt->row_size);
|
||||||
|
else
|
||||||
|
indicator= stmt->params[i].u.indicator[j];
|
||||||
/* check if we need to send data */
|
/* check if we need to send data */
|
||||||
if (indicator == STMT_INDICATOR_NULL ||
|
if (indicator == STMT_INDICATOR_NULL ||
|
||||||
indicator == STMT_INDICATOR_DEFAULT)
|
indicator == STMT_INDICATOR_DEFAULT)
|
||||||
@@ -703,10 +719,13 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
|
|||||||
case MYSQL_TYPE_BIT:
|
case MYSQL_TYPE_BIT:
|
||||||
case MYSQL_TYPE_SET:
|
case MYSQL_TYPE_SET:
|
||||||
size+= 5; /* max 8 bytes for size */
|
size+= 5; /* max 8 bytes for size */
|
||||||
if (stmt->params[i].length[j] == -1)
|
if (indicator == STMT_INDICATOR_NTS || (!stmt->row_size && stmt->params[i].length[j] == -1))
|
||||||
size+= strlen(ma_get_buffer_offset(stmt, stmt->params[i].buffer_type, stmt->params[i].buffer,j));
|
size+= strlen(ma_get_buffer_offset(stmt, stmt->params[i].buffer_type, stmt->params[i].buffer,j));
|
||||||
else
|
else
|
||||||
size+= (size_t)stmt->params[i].length[j];
|
if (!stmt->row_size)
|
||||||
|
size+= (size_t)stmt->params[i].length[j];
|
||||||
|
else
|
||||||
|
size+= (size_t)*stmt->params[i].length;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
size+= mysql_ps_fetch_functions[stmt->params[i].buffer_type].pack_len;
|
size+= mysql_ps_fetch_functions[stmt->params[i].buffer_type].pack_len;
|
||||||
@@ -722,12 +741,12 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req
|
|||||||
goto mem_error;
|
goto mem_error;
|
||||||
p= start + offset;
|
p= start + offset;
|
||||||
}
|
}
|
||||||
if (bulk_supported && (indicator || stmt->params[i].indicator))
|
if (bulk_supported && (indicator || stmt->params[i].u.indicator))
|
||||||
{
|
{
|
||||||
int1store(p, indicator);
|
int1store(p, indicator);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (num_rows == 1)
|
if (!stmt->array_size)
|
||||||
{
|
{
|
||||||
if ((stmt->params[i].is_null && *stmt->params[i].is_null) ||
|
if ((stmt->params[i].is_null && *stmt->params[i].is_null) ||
|
||||||
stmt->params[i].buffer_type == MYSQL_TYPE_NULL ||
|
stmt->params[i].buffer_type == MYSQL_TYPE_NULL ||
|
||||||
@@ -789,8 +808,8 @@ my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type a
|
|||||||
case STMT_ATTR_ARRAY_SIZE:
|
case STMT_ATTR_ARRAY_SIZE:
|
||||||
*(unsigned int *)value= stmt->array_size;
|
*(unsigned int *)value= stmt->array_size;
|
||||||
break;
|
break;
|
||||||
case STMT_ATTR_BIND_TYPE:
|
case STMT_ATTR_ROW_SIZE:
|
||||||
*(enum enum_bind_type *)value= stmt->bind_type;
|
*(size_t *)value= stmt->row_size;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return(1);
|
return(1);
|
||||||
@@ -824,8 +843,9 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type a
|
|||||||
case STMT_ATTR_ARRAY_SIZE:
|
case STMT_ATTR_ARRAY_SIZE:
|
||||||
stmt->array_size= *(unsigned int *)value;
|
stmt->array_size= *(unsigned int *)value;
|
||||||
break;
|
break;
|
||||||
case STMT_ATTR_BIND_TYPE:
|
case STMT_ATTR_ROW_SIZE:
|
||||||
stmt->bind_type= *(enum enum_bind_type *)value;
|
stmt->row_size= *(size_t *)value;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0);
|
SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0);
|
||||||
return(1);
|
return(1);
|
||||||
@@ -843,11 +863,10 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind)
|
|||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we want to call mariadb_stmt_execute_direct the number of parameters
|
/* If number of parameters was specified via mysql_stmt_attr_set we need to realloc
|
||||||
is unknown, since we didn't prepare the statement at this point.
|
them, e.g. for mariadb_stmt_execute_direct()
|
||||||
Number of parameters needs to be set manually via mysql_stmt_attr_set()
|
*/
|
||||||
function */
|
if ((stmt->state < MYSQL_STMT_PREPARED || stmt->state >= MYSQL_STMT_EXECUTED) &&
|
||||||
if (stmt->state < MYSQL_STMT_PREPARED &&
|
|
||||||
!(mysql->server_capabilities & CLIENT_MYSQL))
|
!(mysql->server_capabilities & CLIENT_MYSQL))
|
||||||
{
|
{
|
||||||
if (!stmt->params && stmt->param_count)
|
if (!stmt->params && stmt->param_count)
|
||||||
@@ -1179,7 +1198,7 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned
|
|||||||
if (!bind[0].error)
|
if (!bind[0].error)
|
||||||
bind[0].error= &bind[0].error_value;
|
bind[0].error= &bind[0].error_value;
|
||||||
*bind[0].error= 0;
|
*bind[0].error= 0;
|
||||||
bind[0].offset= offset;
|
bind[0].u.offset= offset;
|
||||||
save_ptr= stmt->bind[column].row_ptr;
|
save_ptr= stmt->bind[column].row_ptr;
|
||||||
mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].row_ptr);
|
mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].row_ptr);
|
||||||
stmt->bind[column].row_ptr= save_ptr;
|
stmt->bind[column].row_ptr= save_ptr;
|
||||||
|
@@ -26,7 +26,8 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include
|
|||||||
ADD_DEFINITIONS(-DLIBMARIADB)
|
ADD_DEFINITIONS(-DLIBMARIADB)
|
||||||
|
|
||||||
SET(API_TESTS "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs"
|
SET(API_TESTS "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs"
|
||||||
"sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "features-10_2" )
|
"sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "features-10_2"
|
||||||
|
"bulk1" )
|
||||||
IF(WITH_DYNCOL)
|
IF(WITH_DYNCOL)
|
||||||
SET(API_TESTS ${API_TESTS} "dyncol")
|
SET(API_TESTS ${API_TESTS} "dyncol")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
@@ -534,7 +534,7 @@ static int test_mysql_insert_id(MYSQL *mysql)
|
|||||||
according to the manual, this might be 20 or 300, but it looks like
|
according to the manual, this might be 20 or 300, but it looks like
|
||||||
auto_increment column takes priority over last_insert_id().
|
auto_increment column takes priority over last_insert_id().
|
||||||
*/
|
*/
|
||||||
diag("res: %ld", res);
|
diag("res: %lld", res);
|
||||||
FAIL_UNLESS(res == 20, "");
|
FAIL_UNLESS(res == 20, "");
|
||||||
/* If first autogenerated number fails and 2nd works: */
|
/* If first autogenerated number fails and 2nd works: */
|
||||||
rc= mysql_query(mysql, "drop table t2");
|
rc= mysql_query(mysql, "drop table t2");
|
||||||
|
@@ -712,7 +712,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql)
|
|||||||
rc= mariadb_convert_string(in_string[UTF8], &in_len, csinfo[UTF8], buffer, &out_len, csinfo[i], &error);
|
rc= mariadb_convert_string(in_string[UTF8], &in_len, csinfo[UTF8], buffer, &out_len, csinfo[i], &error);
|
||||||
|
|
||||||
FAIL_IF(rc==-1, "Conversion failed");
|
FAIL_IF(rc==-1, "Conversion failed");
|
||||||
diag("rc=%d oct_len: %d", rc, in_oct_len[i]);
|
diag("rc=%lu oct_len: %lu", rc, in_oct_len[i]);
|
||||||
FAIL_IF(rc != in_oct_len[i], "Incorrect number of written bytes");
|
FAIL_IF(rc != in_oct_len[i], "Incorrect number of written bytes");
|
||||||
|
|
||||||
if (memcmp(buffer, in_string[i], rc) != 0)
|
if (memcmp(buffer, in_string[i], rc) != 0)
|
||||||
|
@@ -921,7 +921,7 @@ static int test_sess_track_db(MYSQL *mysql)
|
|||||||
|
|
||||||
if (!(mysql->server_capabilities & CLIENT_SESSION_TRACKING))
|
if (!(mysql->server_capabilities & CLIENT_SESSION_TRACKING))
|
||||||
{
|
{
|
||||||
diag("Server doesn't support session tracking (cap=%u)", mysql->server_capabilities);
|
diag("Server doesn't support session tracking (cap=%llu)", mysql->server_capabilities);
|
||||||
return SKIP;
|
return SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -946,7 +946,7 @@ static int test_sess_track_db(MYSQL *mysql)
|
|||||||
FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "Expected charset 'utf8'");
|
FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "Expected charset 'utf8'");
|
||||||
if (!mysql_session_track_get_first(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len))
|
if (!mysql_session_track_get_first(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len))
|
||||||
do {
|
do {
|
||||||
printf("# SESSION_TRACK_VARIABLES: %*.*s\n", len, len, data);
|
printf("# SESSION_TRACK_VARIABLES: %*.*s\n", (int)len, (int)len, data);
|
||||||
} while (!mysql_session_track_get_next(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len));
|
} while (!mysql_session_track_get_next(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len));
|
||||||
|
|
||||||
rc= mysql_query(mysql, "SET NAMES latin1");
|
rc= mysql_query(mysql, "SET NAMES latin1");
|
||||||
@@ -969,7 +969,7 @@ static int test_sess_track_db(MYSQL *mysql)
|
|||||||
|
|
||||||
if (!mysql_session_track_get_first(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len))
|
if (!mysql_session_track_get_first(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len))
|
||||||
do {
|
do {
|
||||||
printf("# SESSION_TRACK_VARIABLES: %*.*s\n", len, len, data);
|
printf("# SESSION_TRACK_VARIABLES: %*.*s\n", (int)len, (int)len, data);
|
||||||
} while (!mysql_session_track_get_next(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len));
|
} while (!mysql_session_track_get_next(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len));
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
@@ -61,7 +61,7 @@ static int com_multi_1(MYSQL *mysql)
|
|||||||
rc= mysql_query(mysql, "select 1");
|
rc= mysql_query(mysql, "select 1");
|
||||||
check_mysql_rc(rc, mysql);
|
check_mysql_rc(rc, mysql);
|
||||||
res= mysql_store_result(mysql);
|
res= mysql_store_result(mysql);
|
||||||
FAIL_UNLESS(res, "2 simple query no result");
|
FAIL_UNLESS(res != NULL, "2 simple query no result");
|
||||||
mysql_free_result(res);
|
mysql_free_result(res);
|
||||||
|
|
||||||
/* question: how will result sets look like ? */
|
/* question: how will result sets look like ? */
|
||||||
@@ -211,9 +211,12 @@ static int com_multi_ps2(MYSQL *mysql)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int execute_direct(MYSQL *mysql)
|
static int execute_direct(MYSQL *mysql)
|
||||||
{
|
{
|
||||||
long rc= 0, i= 0;
|
int rc= 0;
|
||||||
|
long i= 0;
|
||||||
MYSQL_STMT *stmt;
|
MYSQL_STMT *stmt;
|
||||||
MYSQL_BIND bind;
|
MYSQL_BIND bind;
|
||||||
unsigned int param_count= 1;
|
unsigned int param_count= 1;
|
||||||
@@ -261,12 +264,53 @@ static int execute_direct(MYSQL *mysql)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int execute_direct_example(MYSQL *mysql)
|
||||||
|
{
|
||||||
|
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
|
||||||
|
MYSQL_BIND bind[2];
|
||||||
|
int intval= 1;
|
||||||
|
int param_count= 2;
|
||||||
|
char *strval= "execute_direct_example";
|
||||||
|
|
||||||
|
/* Direct execution without parameters */
|
||||||
|
if (mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS execute_direct", -1))
|
||||||
|
goto error;
|
||||||
|
if (mariadb_stmt_execute_direct(stmt, "CREATE TABLE execute_direct (a int, b varchar(20))", -1))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
memset(bind, 0, sizeof(MYSQL_BIND) * 2);
|
||||||
|
bind[0].buffer_type= MYSQL_TYPE_SHORT;
|
||||||
|
bind[0].buffer= &intval;
|
||||||
|
bind[1].buffer_type= MYSQL_TYPE_STRING;
|
||||||
|
bind[1].buffer= strval;
|
||||||
|
bind[1].buffer_length= strlen(strval);
|
||||||
|
|
||||||
|
/* set number of parameters */
|
||||||
|
if (mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
/* bind parameters */
|
||||||
|
if (mysql_stmt_bind_param(stmt, bind))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (mariadb_stmt_execute_direct(stmt, "INSERT INTO execute_direct VALUES (?,?)", -1))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
return OK;
|
||||||
|
error:
|
||||||
|
printf("Error: %s\n", mysql_stmt_error(stmt));
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
struct my_tests_st my_tests[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
{"com_multi_1", com_multi_1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
{"com_multi_1", com_multi_1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||||
{"com_multi_2", com_multi_2, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
{"com_multi_2", com_multi_2, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||||
{"com_multi_ps1", com_multi_ps1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
{"com_multi_ps1", com_multi_ps1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||||
{"com_multi_ps2", com_multi_ps2, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
{"com_multi_ps2", com_multi_ps2, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||||
{"execute_direct", execute_direct, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"execute_direct", execute_direct, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
|
{"execute_direct_example", execute_direct_example, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{NULL, NULL, 0, 0, NULL, NULL}
|
{NULL, NULL, 0, 0, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1054,16 +1054,16 @@ static int test_get_info(MYSQL *mysql)
|
|||||||
|
|
||||||
rc= mariadb_get_infov(mysql, MARIADB_MAX_ALLOWED_PACKET, &sval);
|
rc= mariadb_get_infov(mysql, MARIADB_MAX_ALLOWED_PACKET, &sval);
|
||||||
FAIL_IF(rc, "mysql_get_info failed");
|
FAIL_IF(rc, "mysql_get_info failed");
|
||||||
diag("max_allowed_packet: %d", sval);
|
diag("max_allowed_packet: %lu", sval);
|
||||||
rc= mariadb_get_infov(mysql, MARIADB_NET_BUFFER_LENGTH, &sval);
|
rc= mariadb_get_infov(mysql, MARIADB_NET_BUFFER_LENGTH, &sval);
|
||||||
FAIL_IF(rc, "mysql_get_info failed");
|
FAIL_IF(rc, "mysql_get_info failed");
|
||||||
diag("net_buffer_length: %d", sval);
|
diag("net_buffer_length: %lu", sval);
|
||||||
rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION_ID, &sval);
|
rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION_ID, &sval);
|
||||||
FAIL_IF(rc, "mysql_get_info failed");
|
FAIL_IF(rc, "mysql_get_info failed");
|
||||||
diag("client_version_id: %d", sval);
|
diag("client_version_id: %lu", sval);
|
||||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval);
|
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval);
|
||||||
FAIL_IF(rc, "mysql_get_info failed");
|
FAIL_IF(rc, "mysql_get_info failed");
|
||||||
diag("server_version_id: %d", sval);
|
diag("server_version_id: %lu", sval);
|
||||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_MARIADB_CHARSET_INFO, &cs);
|
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_MARIADB_CHARSET_INFO, &cs);
|
||||||
FAIL_IF(rc, "mysql_get_info failed");
|
FAIL_IF(rc, "mysql_get_info failed");
|
||||||
diag("charset name: %s", cs.csname);
|
diag("charset name: %s", cs.csname);
|
||||||
|
@@ -43,7 +43,7 @@ static int aurora1(MYSQL *my)
|
|||||||
|
|
||||||
res= mysql_store_result(mysql);
|
res= mysql_store_result(mysql);
|
||||||
|
|
||||||
diag("Num_rows: %d", mysql_num_rows(res));
|
diag("Num_rows: %lld", mysql_num_rows(res));
|
||||||
mysql_free_result(res);
|
mysql_free_result(res);
|
||||||
|
|
||||||
mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &my_schema);
|
mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &my_schema);
|
||||||
@@ -127,7 +127,7 @@ static int test_reconnect(MYSQL *my)
|
|||||||
|
|
||||||
if ((res= mysql_store_result(mysql)))
|
if ((res= mysql_store_result(mysql)))
|
||||||
{
|
{
|
||||||
diag("num_rows: %d", mysql_num_rows(res));
|
diag("num_rows: %lld", mysql_num_rows(res));
|
||||||
mysql_free_result(res);
|
mysql_free_result(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user