Fix for mysql_list_fields & reset stmt buffers from stmt_free_result

Windows build fix 


VC++Files/sql/mysqld.dsp:
  Added sql_state.c to wrk space
include/mysql_com.h:
  Windows build fix (mismatch declaration of my_bool and bool from defination)
include/thr_alarm.h:
  Windows build fix
libmysql/libmysql.c:
  Fix for mysql_list_fields & reset stmt buffers from stmt_free_result
tests/client_test.c:
  Updated test for DEFAULT value for mysql_list_fields()
  New tests for mysql_stmt_free_result()
This commit is contained in:
unknown 2003-06-08 09:11:14 -07:00
commit 0bb5b9eadd
5 changed files with 204 additions and 52 deletions

View file

@ -180,7 +180,7 @@ static void client_connect()
if (!(mysql = mysql_init(NULL)))
{
myerror("mysql_init() failed");
myerror("mysql_init() failed");
exit(0);
}
@ -535,7 +535,7 @@ static void verify_prepare_field(MYSQL_RES *result,
unsigned int no,const char *name, const char *org_name,
enum enum_field_types type, const char *table,
const char *org_table, const char *db,
unsigned long length)
unsigned long length, const char *def)
{
MYSQL_FIELD *field;
@ -554,6 +554,7 @@ static void verify_prepare_field(MYSQL_RES *result,
fprintf(stdout,"\n length :`%ld`\t(expected: `%ld`)", field->length, length);
fprintf(stdout,"\n maxlength:`%ld`", field->max_length);
fprintf(stdout,"\n charsetnr:`%d`", field->charsetnr);
fprintf(stdout,"\n default :`%s`\t(expected: `%s`)", field->def ? field->def : "(null)", def ? def: "(null)");
fprintf(stdout,"\n");
myassert(strcmp(field->name,name) == 0);
myassert(strcmp(field->org_name,org_name) == 0);
@ -562,6 +563,8 @@ static void verify_prepare_field(MYSQL_RES *result,
myassert(strcmp(field->org_table,org_table) == 0);
myassert(strcmp(field->db,db) == 0);
myassert(field->length == length);
if (def)
myassert(strcmp(field->def,def) == 0);
}
/*
@ -1021,15 +1024,15 @@ static void test_prepare_field_result()
fprintf(stdout,"\n\n field attributes:\n");
verify_prepare_field(result,0,"int_c","int_c",MYSQL_TYPE_LONG,
"t1","test_prepare_field_result",current_db,11);
"t1","test_prepare_field_result",current_db,11,0);
verify_prepare_field(result,1,"var_c","var_c",MYSQL_TYPE_VAR_STRING,
"t1","test_prepare_field_result",current_db,50);
"t1","test_prepare_field_result",current_db,50,0);
verify_prepare_field(result,2,"date","date_c",MYSQL_TYPE_DATE,
"t1","test_prepare_field_result",current_db,10);
"t1","test_prepare_field_result",current_db,10,0);
verify_prepare_field(result,3,"ts_c","ts_c",MYSQL_TYPE_TIMESTAMP,
"t1","test_prepare_field_result",current_db,19);
"t1","test_prepare_field_result",current_db,19,0);
verify_prepare_field(result,4,"char_c","char_c",MYSQL_TYPE_STRING,
"t1","test_prepare_field_result",current_db,3);
"t1","test_prepare_field_result",current_db,3,0);
verify_field_count(result, 5);
mysql_free_result(result);
@ -5830,7 +5833,7 @@ static void test_field_misc()
"@@autocommit","", /* field and its org name */
MYSQL_TYPE_LONGLONG, /* field type */
"", "", /* table and its org name */
"",1); /* db name, length(its bool flag)*/
"",1,0); /* db name, length(its bool flag)*/
mysql_free_result(result);
@ -5849,7 +5852,7 @@ static void test_field_misc()
"@@autocommit","", /* field and its org name */
MYSQL_TYPE_LONGLONG, /* field type */
"", "", /* table and its org name */
"",1); /* db name, length(its bool flag)*/
"",1,0); /* db name, length(its bool flag)*/
mysql_free_result(result);
mysql_stmt_close(stmt);
@ -5893,7 +5896,7 @@ static void test_field_misc()
"@@table_type","", /* field and its org name */
MYSQL_TYPE_STRING, /* field type */
"", "", /* table and its org name */
"",type_length); /* db name, length */
"",type_length,0); /* db name, length */
mysql_free_result(result);
mysql_stmt_close(stmt);
@ -5913,7 +5916,7 @@ static void test_field_misc()
"@@max_error_count","", /* field and its org name */
MYSQL_TYPE_LONGLONG, /* field type */
"", "", /* table and its org name */
"",10); /* db name, length */
"",10,0); /* db name, length */
mysql_free_result(result);
mysql_stmt_close(stmt);
@ -5933,7 +5936,7 @@ static void test_field_misc()
"@@max_allowed_packet","", /* field and its org name */
MYSQL_TYPE_LONGLONG, /* field type */
"", "", /* table and its org name */
"",10); /* db name, length */
"",10,0); /* db name, length */
mysql_free_result(result);
mysql_stmt_close(stmt);
@ -5953,7 +5956,7 @@ static void test_field_misc()
"@@sql_warnings","", /* field and its org name */
MYSQL_TYPE_LONGLONG, /* field type */
"", "", /* table and its org name */
"",1); /* db name, length */
"",1,0); /* db name, length */
mysql_free_result(result);
mysql_stmt_close(stmt);
@ -6340,39 +6343,22 @@ static void test_explain_bug()
myassert(6 == mysql_num_fields(result));
verify_prepare_field(result,0,"Field","",MYSQL_TYPE_STRING,
"","","",NAME_LEN);
"","","",NAME_LEN,0);
verify_prepare_field(result,1,"Type","",MYSQL_TYPE_STRING,
"","","",40);
#if 0
"","","",40,0);
verify_prepare_field(result,2,"Collation","",MYSQL_TYPE_STRING,
"","","",40);
verify_prepare_field(result,3,"Null","",MYSQL_TYPE_STRING,
"","","",1);
verify_prepare_field(result,4,"Key","",MYSQL_TYPE_STRING,
"","","",3);
verify_prepare_field(result,5,"Default","",MYSQL_TYPE_STRING,
"","","",NAME_LEN);
verify_prepare_field(result,6,"Extra","",MYSQL_TYPE_STRING,
"","","",20);
#else
verify_prepare_field(result,2,"Null","",MYSQL_TYPE_STRING,
"","","",1);
"","","",1,0);
verify_prepare_field(result,3,"Key","",MYSQL_TYPE_STRING,
"","","",3);
"","","",3,0);
verify_prepare_field(result,4,"Default","",MYSQL_TYPE_STRING,
"","","",NAME_LEN);
"","","",NAME_LEN,0);
verify_prepare_field(result,5,"Extra","",MYSQL_TYPE_STRING,
"","","",20);
#endif
"","","",20,0);
mysql_free_result(result);
mysql_stmt_close(stmt);
@ -6393,34 +6379,34 @@ static void test_explain_bug()
myassert(10 == mysql_num_fields(result));
verify_prepare_field(result,0,"id","",MYSQL_TYPE_LONGLONG,
"","","",3);
"","","",3,0);
verify_prepare_field(result,1,"select_type","",MYSQL_TYPE_STRING,
"","","",19);
"","","",19,0);
verify_prepare_field(result,2,"table","",MYSQL_TYPE_STRING,
"","","",NAME_LEN);
"","","",NAME_LEN,0);
verify_prepare_field(result,3,"type","",MYSQL_TYPE_STRING,
"","","",10);
"","","",10,0);
verify_prepare_field(result,4,"possible_keys","",MYSQL_TYPE_STRING,
"","","",NAME_LEN*32);
"","","",NAME_LEN*32,0);
verify_prepare_field(result,5,"key","",MYSQL_TYPE_STRING,
"","","",NAME_LEN);
"","","",NAME_LEN,0);
verify_prepare_field(result,6,"key_len","",MYSQL_TYPE_LONGLONG,
"","","",3);
"","","",3,0);
verify_prepare_field(result,7,"ref","",MYSQL_TYPE_STRING,
"","","",NAME_LEN*16);
"","","",NAME_LEN*16,0);
verify_prepare_field(result,8,"rows","",MYSQL_TYPE_LONGLONG,
"","","",10);
"","","",10,0);
verify_prepare_field(result,9,"Extra","",MYSQL_TYPE_STRING,
"","","",255);
"","","",255,0);
mysql_free_result(result);
mysql_stmt_close(stmt);
@ -7053,6 +7039,9 @@ static void test_fetch_column()
fprintf(stdout, "\n col 0: %d(%ld)", c1, l1);
myassert(c1 == 1 && l1 == 4);
rc = mysql_fetch_column(stmt,bind,10,0);
mystmt_r(stmt,rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
@ -7110,13 +7099,20 @@ static void test_list_fields()
rc= mysql_query(mysql,"drop table if exists test_list_fields");
myquery(rc);
rc = mysql_query(mysql, "create table test_list_fields(c1 int primary key auto_increment, c2 char(10))");
rc = mysql_query(mysql, "create table test_list_fields(c1 int primary key auto_increment, c2 char(10) default 'mysql')");
myquery(rc);
result = mysql_list_fields(mysql, "test_list_fields",NULL);
mytest(result);
myassert( 0 == my_process_result_set(result));
verify_prepare_field(result,0,"c1","c1",MYSQL_TYPE_LONG,
"test_list_fields","test_list_fields",current_db,11,"0");
verify_prepare_field(result,1,"c2","c2",MYSQL_TYPE_STRING,
"test_list_fields","test_list_fields",current_db,10,"mysql");
mysql_free_result(result);
}
@ -7188,6 +7184,149 @@ static void test_mem_overun()
mysql_stmt_close(stmt);
}
/*
To test mysql_stmt_free_result()
*/
static void test_free_result()
{
MYSQL_STMT *stmt;
MYSQL_BIND bind[1];
char c2[5];
ulong length;
int rc, c1;
myheader("test_free_result");
rc= mysql_query(mysql,"drop table if exists test_free_result");
myquery(rc);
rc = mysql_query(mysql, "create table test_free_result(c1 int primary key auto_increment)");
myquery(rc);
rc = mysql_query(mysql, "insert into test_free_result values(),(),()");
myquery(rc);
stmt = mysql_prepare(mysql,"select * from test_free_result",50);
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (char *)c2;
bind[0].buffer_length= 7;
bind[0].is_null= 0;
bind[0].length= &length;
rc = mysql_execute(stmt);
mystmt(stmt,rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
c2[0]= '\0'; length= 0;
rc = mysql_fetch_column(stmt,bind,0,0);
mystmt(stmt,rc);
fprintf(stdout, "\n col 1: %s(%ld)", c2, length);
myassert(strncmp(c2,"1",1)==0 && length == 1);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
c1= 0, length= 0;
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (char *)&c1;
bind[0].buffer_length= 0;
bind[0].is_null= 0;
bind[0].length= &length;
rc = mysql_fetch_column(stmt,bind,0,0);
mystmt(stmt,rc);
fprintf(stdout, "\n col 0: %d(%ld)", c1, length);
myassert(c1 == 2 && length == 4);
rc = mysql_query(mysql,"drop table test_free_result");
myquery_r(rc); /* error should be, COMMANDS OUT OF SYNC */
rc = mysql_stmt_free_result(stmt);
mystmt(stmt,rc);
rc = mysql_query(mysql,"drop table test_free_result");
myquery(rc); /* should be successful */
mysql_stmt_close(stmt);
}
/*
To test mysql_stmt_free_result()
*/
static void test_free_store_result()
{
MYSQL_STMT *stmt;
MYSQL_BIND bind[1];
char c2[5];
ulong length;
int rc, c1;
myheader("test_free_store_result");
rc= mysql_query(mysql,"drop table if exists test_free_result");
myquery(rc);
rc = mysql_query(mysql, "create table test_free_result(c1 int primary key auto_increment)");
myquery(rc);
rc = mysql_query(mysql, "insert into test_free_result values(),(),()");
myquery(rc);
stmt = mysql_prepare(mysql,"select * from test_free_result",50);
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (char *)c2;
bind[0].buffer_length= 7;
bind[0].is_null= 0;
bind[0].length= &length;
rc = mysql_execute(stmt);
mystmt(stmt,rc);
rc = mysql_stmt_store_result(stmt);
mystmt(stmt,rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
c2[0]= '\0'; length= 0;
rc = mysql_fetch_column(stmt,bind,0,0);
mystmt(stmt,rc);
fprintf(stdout, "\n col 1: %s(%ld)", c2, length);
myassert(strncmp(c2,"1",1)==0 && length == 1);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
c1= 0, length= 0;
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (char *)&c1;
bind[0].buffer_length= 0;
bind[0].is_null= 0;
bind[0].length= &length;
rc = mysql_fetch_column(stmt,bind,0,0);
mystmt(stmt,rc);
fprintf(stdout, "\n col 0: %d(%ld)", c1, length);
myassert(c1 == 2 && length == 4);
rc = mysql_stmt_free_result(stmt);
mystmt(stmt,rc);
rc = mysql_query(mysql,"drop table test_free_result");
myquery(rc);
mysql_stmt_close(stmt);
}
/*
Read and parse arguments and MySQL options from my.cnf
*/
@ -7428,6 +7567,11 @@ int main(int argc, char **argv)
test_open_direct(); /* direct execution in the middle of open stmts */
test_fetch_offset(); /* to test mysql_fetch_column with offset */
test_fetch_column(); /* to test mysql_fetch_column */
test_mem_overun(); /* test DBD ovverun bug */
test_list_fields(); /* test COM_LIST_FIELDS for DEFAULT */
test_free_result(); /* test mysql_stmt_free_result() */
test_free_store_result(); /* test to make sure stmt results are cleared
during stmt_free_result() */
end_time= time((time_t *)0);
total_time+= difftime(end_time, start_time);