Commit 7133dab0 authored by unknown's avatar unknown

Merge sanja.is.com.ua:/home/bell/mysql/mysql-4.1

into sanja.is.com.ua:/home/bell/mysql/work-select-4.1


sql/sql_class.h:
  Auto merged
sql/sql_prepare.cc:
  Auto merged
parents 43b99e58 545c9dff
......@@ -59,7 +59,7 @@ const char *client_errors[]=
"No parameters exists in the statement",
"Invalid parameter number",
"Can't send long data for non string or binary data types (parameter: %d)",
"Using un supported parameter type: %d (parameter: %d)"
"Using un supported buffer type: %d (parameter: %d)",
"Shared memory (%lu)",
"Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)",
......@@ -114,7 +114,7 @@ const char *client_errors[]=
"No parameters exists in the statement",
"Invalid parameter number",
"Can't send long data for non string or binary data types (parameter: %d)",
"Using un supported parameter type: %d (parameter: %d)"
"Using un supported buffer type: %d (parameter: %d)",
"Shared memory (%lu)",
"Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)",
......@@ -167,7 +167,7 @@ const char *client_errors[]=
"No parameters exists in the statement",
"Invalid parameter number",
"Can't send long data for non string or binary data types (parameter: %d)",
"Using un supported parameter type: %d (parameter: %d)"
"Using un supported buffer type: %d (parameter: %d)",
"Shared memory (%lu)",
"Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)",
......
......@@ -3925,6 +3925,28 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length)
DBUG_RETURN(stmt);
}
/*
Get the execute query meta information for non-select
statements (on demand).
*/
unsigned int alloc_stmt_fields(MYSQL_STMT *stmt)
{
MYSQL_FIELD *fields;
if (!stmt->mysql->field_count)
return 0;
stmt->field_count= stmt->mysql->field_count;
fields= stmt->mysql->fields;
if (!(stmt->fields= (MYSQL_FIELD *) alloc_root(&stmt->mem_root,
sizeof(fields))) ||
!(stmt->bind= (MYSQL_BIND *) alloc_root(&stmt->mem_root,
sizeof(MYSQL_BIND ) * stmt->field_count)))
return 0;
memcpy((char *)stmt->fields, (char *)fields, sizeof(fields));
return stmt->field_count;
}
/*
Returns prepared meta information in the form of resultset
......@@ -3938,8 +3960,10 @@ mysql_prepare_result(MYSQL_STMT *stmt)
DBUG_ENTER("mysql_prepare_result");
if (!stmt->field_count || !stmt->fields)
{
if (!alloc_stmt_fields(stmt))
DBUG_RETURN(0);
}
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
sizeof(ulong)*stmt->field_count,
MYF(MY_WME | MY_ZEROFILL))))
......@@ -4436,7 +4460,7 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
default:
sprintf(stmt->last_error,
ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE),
param->buffer_type, param->param_number);
param->buffer_type, count);
DBUG_RETURN(1);
}
}
......@@ -4984,6 +5008,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
{
MYSQL_BIND *param, *end;
ulong bind_count;
uint param_count= 0;
DBUG_ENTER("mysql_bind_result");
DBUG_ASSERT(stmt != 0);
......@@ -4999,7 +5024,10 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_RETURN(1);
}
#endif
bind_count= stmt->field_count;
if (!(bind_count= stmt->field_count) &&
!(bind_count= alloc_stmt_fields(stmt)))
DBUG_RETURN(0);
memcpy((char*) stmt->bind, (char*) bind,
sizeof(MYSQL_BIND)*bind_count);
......@@ -5015,6 +5043,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
if (!param->length)
param->length= &param->buffer_length;
param->param_number= param_count++;
/* Setup data copy functions for the different supported types */
switch (param->buffer_type) {
case MYSQL_TYPE_TINY:
......@@ -5066,7 +5095,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
default:
sprintf(stmt->last_error,
ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE),
param->buffer_type, param->param_number);
param->buffer_type, param_count);
DBUG_RETURN(1);
}
}
......@@ -5303,6 +5332,7 @@ static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list)
free_root(&stmt->mem_root, MYF(0));
if (!skip_list)
stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list);
stmt->mysql->status= MYSQL_STATUS_READY;
my_free((gptr) stmt, MYF(MY_WME));
DBUG_RETURN(error);
}
......
......@@ -327,6 +327,7 @@ public:
typedef struct st_prep_stmt
{
THD *thd;
LEX lex;
Item_param **param;
Item *free_list;
MEM_ROOT mem_root;
......
......@@ -690,6 +690,7 @@ static bool init_param_items(PREP_STMT *stmt)
List<Item> &params= stmt->thd->lex.param_list;
Item_param **to;
stmt->lex= stmt->thd->lex;
if (!stmt->param_count)
stmt->param= (Item_param **)0;
else
......@@ -711,7 +712,7 @@ static bool init_param_items(PREP_STMT *stmt)
static void init_stmt_execute(PREP_STMT *stmt)
{
THD *thd= stmt->thd;
TABLE_LIST *tables=(TABLE_LIST*) thd->lex.select_lex.table_list.first;
TABLE_LIST *tables= (TABLE_LIST*) thd->lex.select_lex.table_list.first;
/*
TODO: When the new table structure is ready, then have a status bit
......@@ -719,7 +720,7 @@ static void init_stmt_execute(PREP_STMT *stmt)
and open the tables back.
*/
if (tables)
tables->table=0; //safety - nasty init
tables->table= 0; //safety - nasty init
}
/*
......@@ -802,10 +803,8 @@ void mysql_stmt_execute(THD *thd, char *packet)
DBUG_VOID_RETURN;
}
if (my_pthread_setspecific_ptr(THR_THD, stmt->thd) ||
my_pthread_setspecific_ptr(THR_MALLOC, &stmt->thd->mem_root))
DBUG_VOID_RETURN;
LEX thd_lex= thd->lex;
thd->lex= stmt->lex;
init_stmt_execute(stmt);
if (stmt->param_count && setup_params_data(stmt))
......@@ -820,17 +819,14 @@ void mysql_stmt_execute(THD *thd, char *packet)
mysql_delete(), mysql_update() and mysql_select() to not to
have re-check on setup_* and other things ..
*/
THD *cur_thd= stmt->thd;
cur_thd->protocol= &cur_thd->protocol_prep; // Switch to binary protocol
mysql_execute_command(cur_thd);
cur_thd->protocol= &cur_thd->protocol_simple; // Use normal protocol
thd->protocol= &thd->protocol_prep; // Switch to binary protocol
mysql_execute_command(thd);
thd->protocol= &thd->protocol_simple; // Use normal protocol
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR);
my_pthread_setspecific_ptr(THR_THD, thd);
my_pthread_setspecific_ptr(THR_MALLOC, &thd->mem_root);
thd->lex= thd_lex;
DBUG_VOID_RETURN;
}
......
......@@ -180,10 +180,10 @@ static void client_connect()
/* set AUTOCOMMIT to ON*/
mysql_autocommit(mysql, TRUE);
fprintf(stdout, "\n Creating a test database '%s' ...", current_db);
sprintf(buff,"CREATE DATABASE IF NOT EXISTS %s", current_db);
strxmov(buff,"CREATE DATABASE IF NOT EXISTS ", current_db, NullS);
rc = mysql_query(mysql, buff);
myquery(rc);
sprintf(buff,"USE %s", current_db);
strxmov(buff,"USE ", current_db, NullS);
rc = mysql_query(mysql, buff);
myquery(rc);
......@@ -201,7 +201,7 @@ static void client_disconnect()
{
char buff[255];
fprintf(stdout, "\n droping the test database '%s' ...", current_db);
sprintf(buff,"DROP DATABASE IF EXISTS %s", current_db);
strxmov(buff,"DROP DATABASE IF EXISTS ", current_db, NullS);
mysql_query(mysql, buff);
fprintf(stdout, " OK");
fprintf(stdout, "\n closing the connection ...");
......@@ -464,8 +464,7 @@ static void verify_col_data(const char *table, const char *col,
if (table && col)
{
sprintf(query, "SELECT %s FROM %s LIMIT 1", col, table);
strxmov(query,"SELECT ",col," FROM ",table," LIMIT 1", NullS);
fprintf(stdout,"\n %s", query);
rc = mysql_query(mysql, query);
myquery(rc);
......@@ -1877,7 +1876,7 @@ static void test_long_data_str()
mystmt(stmt, rc);
length = 40;
sprintf(data,"MySQL AB");
strmov(data,"MySQL AB");
/* supply data in pieces */
for(i=0; i < 4; i++)
......@@ -1906,11 +1905,11 @@ static void test_long_data_str()
myassert(1 == my_process_result_set(result));
mysql_free_result(result);
sprintf(data,"%d", i*5);
my_sprintf(data,(data,"%d", i*5));
verify_col_data("test_long_data_str","LENGTH(longstr)", data);
data[0]='\0';
while (i--)
sprintf(data,"%s%s", data,"MySQL");
strxmov(data,data,"MySQL",NullS);
verify_col_data("test_long_data_str","longstr", data);
}
......@@ -1995,10 +1994,10 @@ static void test_long_data_str1()
myassert(1 == my_process_result_set(result));
mysql_free_result(result);
sprintf(data,"%ld",(long)i*length);
my_sprintf(data,(data,"%ld",(long)i*length));
verify_col_data("test_long_data_str","length(longstr)",data);
sprintf(data,"%d",i*2);
my_sprintf(data,(data,"%d",i*2));
verify_col_data("test_long_data_str","length(blb)",data);
}
......@@ -2052,7 +2051,7 @@ static void test_long_data_bin()
mystmt(stmt, rc);
length = 10;
sprintf(data,"MySQL AB");
strmov(data,"MySQL AB");
/* supply data in pieces */
{
......@@ -2408,8 +2407,6 @@ static void test_bind_result()
if (is_null[0])
fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
fprintf(stdout,"\n row 3: %d,%s(%lu)", nData, szData, length1);
myassert(is_null[0]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
......@@ -3660,63 +3657,97 @@ static void test_stmt_close()
*********************************************************/
static void test_set_variable()
{
MYSQL_STMT *stmt;
int rc, select_limit=88;
char query[200];
MYSQL_BIND bind[1];
MYSQL_RES *result;
MYSQL_STMT *stmt, *stmt1;
int rc;
int set_count, def_count, get_count;
ulong length;
char var[NAME_LEN+1];
MYSQL_BIND set_bind[1], get_bind[2];
myheader("test_set_variable");
rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
mysql_autocommit(mysql, TRUE);
strmov(query,"SET GLOBAL delayed_insert_limit=?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
stmt1 = mysql_prepare(mysql, "show variables like 'max_error_count'", 50);
mystmt_init(stmt1);
verify_param_count(stmt,1);
get_bind[0].buffer_type= MYSQL_TYPE_STRING;
get_bind[0].buffer= (char *)var;
get_bind[0].is_null= 0;
get_bind[0].length= &length;
get_bind[0].buffer_length= (int)NAME_LEN;
length= NAME_LEN;
result= mysql_param_result(stmt);
mytest_r(result);
get_bind[1].buffer_type= MYSQL_TYPE_LONG;
get_bind[1].buffer= (char *)&get_count;
get_bind[1].is_null= 0;
get_bind[1].length= 0;
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer=(char *)&select_limit;
bind[0].is_null=0;
rc = mysql_execute(stmt1);
mystmt(stmt1, rc);
rc = mysql_bind_param(stmt, bind);
rc = mysql_bind_result(stmt1, get_bind);
mystmt(stmt1, rc);
rc = mysql_fetch(stmt1);
mystmt(stmt1, rc);
fprintf(stdout, "\n max_error_count(default): %d", get_count);
def_count= get_count;
myassert(strcmp(var,"max_error_count") == 0);
rc = mysql_fetch(stmt1);
myassert(rc == MYSQL_NO_DATA);
stmt = mysql_prepare(mysql, "set max_error_count=?", 50);
mystmt_init(stmt);
set_bind[0].buffer_type= MYSQL_TYPE_LONG;
set_bind[0].buffer= (char *)&set_count;
set_bind[0].is_null= 0;
set_bind[0].length= 0;
rc = mysql_bind_param(stmt, set_bind);
mystmt(stmt,rc);
set_count= 31;
rc= mysql_execute(stmt);
mystmt(stmt,rc);
mysql_store_result(mysql);
mysql_commit(mysql);
strmov(query,"show variables like 'delayed_insert_limit'");
rc = mysql_query(mysql,query);
myquery(rc);
rc = mysql_execute(stmt1);
mystmt(stmt1, rc);
verify_col_data(NullS, NullS, "88");
rc = mysql_fetch(stmt1);
mystmt(stmt1, rc);
#ifdef TO_BE_FIXED
fprintf(stdout, "\n max_error_count : %d", get_count);
myassert(get_count == set_count);
select_limit= 100;/* reset to default */
rc = mysql_fetch(stmt1);
myassert(rc == MYSQL_NO_DATA);
/* restore back to default */
set_count= def_count;
rc= mysql_execute(stmt);
mystmt(stmt,rc);
mystmt(stmt, rc);
mysql_store_result(mysql);
mysql_stmt_close(stmt);
rc = mysql_execute(stmt1);
mystmt(stmt1, rc);
rc = mysql_query(mysql,query);
myquery(rc);
rc = mysql_fetch(stmt1);
mystmt(stmt1, rc);
verify_col_data(NullS, NullS, "100");
#endif
mysql_stmt_close(stmt);
}
fprintf(stdout, "\n max_error_count(default): %d", get_count);
myassert(get_count == set_count);
rc = mysql_fetch(stmt1);
myassert(rc == MYSQL_NO_DATA);
mysql_stmt_close(stmt);
mysql_stmt_close(stmt1);
}
#if NOT_USED
/* Insert meta info .. */
......@@ -4002,10 +4033,10 @@ static void test_func_fields()
/* Multiple stmts .. */
static void test_multi_stmt()
{
#if TO_BE_FIXED_IN_SERVER
MYSQL_STMT *stmt, *stmt1;
MYSQL_STMT *stmt, *stmt1, *stmt2;
int rc, id;
char name[50]={0};
char name[50];
MYSQL_BIND bind[2];
ulong length[2];
my_bool is_null[2];
......@@ -4023,16 +4054,22 @@ static void test_multi_stmt()
stmt = mysql_prepare(mysql, "SELECT * FROM test_multi_table WHERE id = ?", 100);
mystmt_init(stmt);
stmt2 = mysql_prepare(mysql, "UPDATE test_multi_table SET name='updated' WHERE id=10",100);
mystmt_init(stmt2);
verify_param_count(stmt,1);
bind[0].buffer_type= MYSQL_TYPE_SHORT;
bind[0].buffer= (char *)&id;
bind[0].is_null= &is_null[0];
bind[0].length= &length[0];
is_null[0]= 0;
length[0]= 0;
bind[1].buffer_type = MYSQL_TYPE_STRING;
bind[1].buffer = (char *)&name;
bind[1].buffer = (char *)name;
bind[1].length = &length[1];
bind[1].is_null= &is_null[0];
bind[1].is_null= &is_null[1];
rc = mysql_bind_param(stmt, bind);
mystmt(stmt, rc);
......@@ -4048,8 +4085,8 @@ static void test_multi_stmt()
rc = mysql_fetch(stmt);
mystmt(stmt, rc);
fprintf(stdout, "\n int_data: %d", id);
fprintf(stdout, "\n str_data: %s(%lu)", name, length);
fprintf(stdout, "\n int_data: %d(%lu)", id, length[0]);
fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]);
myassert(id == 10);
myassert(strcmp(name,"mysql")==0);
......@@ -4065,6 +4102,27 @@ static void test_multi_stmt()
rc = mysql_bind_param(stmt1, bind);
mystmt(stmt1, rc);
rc = mysql_execute(stmt2);
mystmt(stmt2, rc);
rc = (int)mysql_stmt_affected_rows(stmt2);
fprintf(stdout,"\n total rows affected(update): %d", rc);
myassert(rc == 1);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_fetch(stmt);
mystmt(stmt, rc);
fprintf(stdout, "\n int_data: %d(%lu)", id, length[0]);
fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]);
myassert(id == 10);
myassert(strcmp(name,"updated")==0);
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
rc = mysql_execute(stmt1);
mystmt(stmt1, rc);
......@@ -4083,7 +4141,8 @@ static void test_multi_stmt()
myassert(0 == my_stmt_result("SELECT * FROM test_multi_table",50));
mysql_stmt_close(stmt);
#endif
mysql_stmt_close(stmt2);
}
......@@ -4441,8 +4500,6 @@ static void test_store_result()
if (is_null[0])
fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
fprintf(stdout,"\n row 3: %ld,%s(%lu)", nData, szData, length1);
myassert(is_null[0]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
......@@ -4478,8 +4535,6 @@ static void test_store_result()
if (is_null[0])
fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
fprintf(stdout,"\n row 3: %ld,%s(%lu)", nData, szData, length1);
myassert(is_null[0]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
......@@ -5039,6 +5094,10 @@ static void test_pure_coverage()
#ifndef DBUG_OFF
rc = mysql_bind_result(stmt, (MYSQL_BIND *)0);
mystmt_r(stmt, rc);
bind[0].buffer_type= MYSQL_TYPE_GEOMETRY;
rc = mysql_bind_result(stmt, bind);
mystmt_r(stmt, rc); /* unsupported buffer type */
#endif
rc = mysql_stmt_store_result(stmt);
......
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