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

Minor prepared statement fixes for time/date/datetime/timestamp types

Added flag MADB_BIND_DUMMY which allows binding empty buffers
This commit is contained in:
holzboote@googlemail.com
2013-10-26 18:55:24 +02:00
parent daf291349f
commit 9552507348
7 changed files with 110 additions and 38 deletions

View File

@@ -24,6 +24,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "my_test.h"
#include "ma_common.h"
static int test_conc60(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
char *stmtstr= "SELECT * FROM agendas";
int rc;
rc= mysql_stmt_prepare(stmt, stmtstr, strlen(stmtstr));
check_stmt_rc(rc, stmt);
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_store_result(stmt);
check_stmt_rc(rc, stmt);
diag("rows: %u", mysql_stmt_num_rows(stmt));
while (mysql_stmt_fetch(stmt));
mysql_stmt_close(stmt);
return(OK);
}
/*
Bug#28075 "COM_DEBUG crashes mysqld"
*/
@@ -949,6 +974,7 @@ static int test_connect_attrs(MYSQL *my)
struct my_tests_st my_tests[] = {
{"test_connect_attrs", test_connect_attrs, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc60", test_conc60, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc49", test_conc49, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_bug28075", test_bug28075, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_bug28505", test_bug28505, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},

View File

@@ -99,7 +99,7 @@ static int test_bind_date_conv(MYSQL *mysql, uint row_count)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, "INSERT INTO test_date VALUES(?, ?, ?, ?)", strlen("INSERT INTO test_date VALUES(?, ?, ?, ?)"));
rc= mysql_stmt_prepare(stmt, "INSERT INTO test_date VALUES(?, ?, ?, ?)", strlen("INSERT INTO test_date VALUES(?, ?, ?, ?)") + 1);
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 4, "param_count != 4");
@@ -4734,13 +4734,13 @@ int test_notrunc(MYSQL *mysql)
{
MYSQL_STMT *stmt;
my_bool trunc= 1;
MYSQL_BIND bind[1];
char buffer[5];
MYSQL_BIND bind[2];
char buffer[5], buffer2[5];
int rc;
my_bool error= 0;
unsigned long len= 1;
unsigned long len= 1, len2;
char *query= "SELECT '1234567890' FROM DUAL";
char *query= "SELECT '1234567890', 'foo' FROM DUAL";
mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &trunc);
@@ -4752,21 +4752,30 @@ int test_notrunc(MYSQL *mysql)
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
memset(bind, 0, sizeof(MYSQL_BIND));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= buffer;
bind[0].buffer_length= 3;
bind[0].length= &len;
bind[0].error= &error;
strcpy(buffer, "bar");
// rc= mysql_stmt_bind_result(stmt, bind);
// check_stmt_rc(rc, stmt);
memset(bind, 0, sizeof(MYSQL_BIND) * 2);
bind[0].buffer_type= MYSQL_TYPE_NULL;
bind[0].buffer= buffer;
bind[0].buffer_length= 1;
bind[0].length= &len;
bind[0].flags|= MADB_BIND_DUMMY;
bind[0].error= &error;
bind[1].buffer_type= MYSQL_TYPE_STRING;
bind[1].buffer= buffer2;
bind[1].buffer_length= 5;
rc= mysql_stmt_bind_result(stmt, bind);
check_stmt_rc(rc, stmt);
mysql_stmt_store_result(stmt);
rc= mysql_stmt_fetch(stmt);
diag("rc= %d len=%lu", rc, len);
mysql_stmt_close(stmt);
FAIL_IF(rc!= 0, "expected rc= 0");
FAIL_IF(strcmp(buffer, "bar"), "Bind dummy failed");
FAIL_IF(strcmp(buffer2, "foo"), "Invalid second buffer");
return OK;
}