Commit d764294f authored by venu@myvenu.com's avatar venu@myvenu.com

Fix for mysql_list_fields & reset stmt buffers from stmt_free_result

  Windows build fix 
parent b68eab61
......@@ -1137,6 +1137,10 @@ SOURCE=.\sql_show.cpp
# End Source File
# Begin Source File
SOURCE=.\sql_state.c
# End Source File
# Begin Source File
SOURCE=.\sql_string.cpp
!IF "$(CFG)" == "mysqld - Win32 Release"
......
......@@ -324,7 +324,7 @@ my_bool check_scramble(const char *, const char *message,
unsigned long *salt,my_bool old_ver);
char *get_tty_password(char *opt_message);
void hash_password(unsigned long *result, const char *password);
const char *mysql_errno_to_sqlstate(uint mysql_errno);
const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
/* Some other useful functions */
......
......@@ -100,7 +100,7 @@ typedef struct st_alarm {
#define thr_alarm_init(A) (*(A))=0
#define thr_alarm_in_use(A) (*(A)!= 0)
void init_thr_alarm(uint max_alarm);
my_bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff);
bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff);
void thr_alarm_kill(pthread_t thread_id);
void thr_end_alarm(thr_alarm_t *alarmed);
void end_thr_alarm(my_bool free_structures);
......
......@@ -990,7 +990,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128);
if (simple_command(mysql,COM_FIELD_LIST,buff,(ulong) (end-buff),1) ||
!(query = read_rows(mysql,(MYSQL_FIELD*) 0,
protocol_41(mysql) ? 7 : 6)))
protocol_41(mysql) ? 8 : 6)))
DBUG_RETURN(NULL);
free_old_query(mysql);
......@@ -1027,7 +1027,7 @@ mysql_list_processes(MYSQL *mysql)
pos=(uchar*) mysql->net.read_pos;
field_count=(uint) net_field_length(&pos);
if (!(fields = read_rows(mysql,(MYSQL_FIELD*) 0,
protocol_41(mysql) ? 6 : 5)))
protocol_41(mysql) ? 7 : 5)))
DBUG_RETURN(NULL);
if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0,
mysql->server_capabilities)))
......@@ -3055,7 +3055,8 @@ int STDCALL mysql_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind,
#ifdef CHECK_EXTRA_ARGUMENTS
if (!bind || icol >= stmt->field_count)
{
DBUG_PRINT("error",("Invalid column position"));
set_stmt_errmsg(stmt, "Invalid column descriptor or offset",1,
unknown_sqlstate);
DBUG_RETURN(1);
}
#endif
......@@ -3377,6 +3378,9 @@ my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt)
mysql->status= MYSQL_STATUS_READY;
}
mysql_free_result(stmt->result);
stmt->result= 0;
stmt->result_buffered= 0;
stmt->current_row= 0;
DBUG_RETURN(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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment