mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Few misc cases check from PHP - client_test
Fix the buffer_length ovveride when length ptr is NULL - libmysql libmysql/libmysql.c: Fix the buffer_length ovveride when length ptr is NULL tests/client_test.c: Few misc cases check from PHP
This commit is contained in:
@ -4377,6 +4377,7 @@ my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt)
|
||||
static my_bool int_is_null_true= 1; /* Used for MYSQL_TYPE_NULL */
|
||||
static my_bool int_is_null_false= 0;
|
||||
static my_bool int_is_null_dummy;
|
||||
static unsigned long param_length_is_dummy;
|
||||
|
||||
/*
|
||||
Setup the parameter data buffers from application
|
||||
@ -5062,7 +5063,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
|
||||
param->is_null= &int_is_null_dummy;
|
||||
|
||||
if (!param->length)
|
||||
param->length= ¶m->buffer_length;
|
||||
param->length= ¶m_length_is_dummy;
|
||||
|
||||
param->param_number= param_count++;
|
||||
/* Setup data copy functions for the different supported types */
|
||||
|
@ -176,6 +176,7 @@ static void client_connect()
|
||||
{
|
||||
myerror("connection failed");
|
||||
mysql_close(mysql);
|
||||
fprintf(stdout,"\n Check the connection options using --help or -?\n");
|
||||
exit(0);
|
||||
}
|
||||
fprintf(stdout," OK");
|
||||
@ -5275,6 +5276,119 @@ static void test_buffers()
|
||||
mysql_stmt_close(stmt);
|
||||
}
|
||||
|
||||
/*
|
||||
Test the direct query execution in the middle of open stmts
|
||||
*/
|
||||
static void test_open_direct()
|
||||
{
|
||||
MYSQL_STMT *stmt;
|
||||
MYSQL_RES *result;
|
||||
int rc;
|
||||
|
||||
myheader("test_open_direct");
|
||||
|
||||
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_open_direct");
|
||||
myquery(rc);
|
||||
|
||||
rc = mysql_query(mysql,"CREATE TABLE test_open_direct(id int, name char(6))");
|
||||
myquery(rc);
|
||||
|
||||
stmt = mysql_prepare(mysql,"INSERT INTO test_open_direct values(10,'mysql')", 100);
|
||||
mystmt_init(stmt);
|
||||
|
||||
rc = mysql_query(mysql, "SELECT * FROM test_open_direct");
|
||||
myquery(rc);
|
||||
|
||||
result = mysql_store_result(mysql);
|
||||
mytest(result);
|
||||
|
||||
myassert(0 == my_process_result_set(result));
|
||||
|
||||
rc = mysql_execute(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
fprintf(stdout, "\n total affected rows: %lld", mysql_stmt_affected_rows(stmt));
|
||||
myassert(1 == mysql_stmt_affected_rows(stmt));
|
||||
|
||||
rc = mysql_query(mysql, "SELECT * FROM test_open_direct");
|
||||
myquery(rc);
|
||||
|
||||
result = mysql_store_result(mysql);
|
||||
mytest(result);
|
||||
|
||||
myassert(1 == my_process_result_set(result));
|
||||
|
||||
rc = mysql_execute(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
fprintf(stdout, "\n total affected rows: %lld", mysql_stmt_affected_rows(stmt));
|
||||
myassert(1 == mysql_stmt_affected_rows(stmt));
|
||||
|
||||
rc = mysql_query(mysql, "SELECT * FROM test_open_direct");
|
||||
myquery(rc);
|
||||
|
||||
result = mysql_store_result(mysql);
|
||||
mytest(result);
|
||||
|
||||
myassert(2 == my_process_result_set(result));
|
||||
mysql_stmt_close(stmt);
|
||||
}
|
||||
|
||||
/*
|
||||
To test fetch without prior bound buffers
|
||||
*/
|
||||
static void test_fetch_nobuffs()
|
||||
{
|
||||
MYSQL_STMT *stmt;
|
||||
MYSQL_BIND bind[4];
|
||||
char str[4][50];
|
||||
int rc;
|
||||
|
||||
myheader("test_fetch_nobuffs");
|
||||
|
||||
stmt = mysql_prepare(mysql,"SELECT DATABASE(), CURRENT_USER(), CURRENT_DATE(), CURRENT_TIME()",100);
|
||||
mystmt_init(stmt);
|
||||
|
||||
rc = mysql_execute(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = 0;
|
||||
while (mysql_fetch(stmt) != MYSQL_NO_DATA)
|
||||
rc++;
|
||||
fprintf(stdout, "\n total rows: %d", rc);
|
||||
myassert(rc == 1);
|
||||
|
||||
bind[0].buffer_type= MYSQL_TYPE_STRING;
|
||||
bind[0].buffer= (char *)str[0];
|
||||
bind[0].is_null= 0;
|
||||
bind[0].length= 0;
|
||||
bind[0].buffer_length= sizeof(str[0]);
|
||||
bind[1]= bind[2]= bind[3]= bind[0];
|
||||
bind[1].buffer= (char *)str[1];
|
||||
bind[2].buffer= (char *)str[2];
|
||||
bind[3].buffer= (char *)str[3];
|
||||
|
||||
rc = mysql_bind_result(stmt, bind);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = mysql_execute(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = 0;
|
||||
while (mysql_fetch(stmt) != MYSQL_NO_DATA)
|
||||
{
|
||||
rc++;
|
||||
fprintf(stdout, "\n CURRENT_DATABASE(): %s(%ld)", str[0]);
|
||||
fprintf(stdout, "\n CURRENT_USER() : %s(%ld)", str[1]);
|
||||
fprintf(stdout, "\n CURRENT_DATE() : %s(%ld)", str[2]);
|
||||
fprintf(stdout, "\n CURRENT_TIME() : %s(%ld)", str[3]);
|
||||
}
|
||||
fprintf(stdout, "\n total rows: %d", rc);
|
||||
myassert(rc == 1);
|
||||
|
||||
mysql_stmt_close(stmt);
|
||||
}
|
||||
|
||||
static struct my_option myctest_long_options[] =
|
||||
{
|
||||
{"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
|
||||
@ -5304,6 +5418,7 @@ static void usage(void)
|
||||
/*
|
||||
* show the usage string when the user asks for this
|
||||
*/
|
||||
putc('\n',stdout);
|
||||
puts("***********************************************************************\n");
|
||||
puts(" Test for client-server protocol 4.1");
|
||||
puts(" By Monty & Venu \n");
|
||||
@ -5330,7 +5445,7 @@ static void usage(void)
|
||||
#endif
|
||||
fprintf(stdout,"\
|
||||
-t, --count=... Execute the test count times.\n");
|
||||
fprintf(stdout,"*********************************************************************\n");
|
||||
puts("***********************************************************************\n");
|
||||
}
|
||||
|
||||
static my_bool
|
||||
@ -5413,6 +5528,8 @@ int main(int argc, char **argv)
|
||||
|
||||
start_time= time((time_t *)0);
|
||||
|
||||
test_fetch_nobuffs(); /* to fecth without prior bound buffers */
|
||||
test_open_direct(); /* direct execution in the middle of open stmts */
|
||||
test_fetch_null(); /* to fetch null data */
|
||||
test_fetch_date(); /* to fetch date,time and timestamp */
|
||||
test_fetch_str(); /* to fetch string to all types */
|
||||
|
Reference in New Issue
Block a user