Commit 5f5da75c authored by pem@mysql.com's avatar pem@mysql.com

Merge mysql.com:/usr/local/bk/mysql-5.0

into mysql.com:/home/pem/work/mysql-5.0
parents 26955036 8f410d51
......@@ -839,7 +839,9 @@ static int get_options(int argc, char **argv)
opt_reconnect= 0;
connect_flag= 0; /* Not in interactive mode */
}
if (!(charset_info= get_charset_by_csname(default_charset,
if (strcmp(default_charset, charset_info->csname) &&
!(charset_info= get_charset_by_csname(default_charset,
MY_CS_PRIMARY, MYF(MY_WME))))
exit(1);
if (argc > 1)
......
......@@ -311,7 +311,8 @@ static int get_options(int *argc, char ***argv)
}
/* TODO: This variable is not yet used */
if (!(charset_info= get_charset_by_csname(default_charset,
if (strcmp(default_charset, charset_info->csname) &&
!(charset_info= get_charset_by_csname(default_charset,
MY_CS_PRIMARY, MYF(MY_WME))))
exit(1);
if (*argc > 0 && opt_alldbs)
......
......@@ -536,7 +536,8 @@ static int get_options(int *argc, char ***argv)
my_progname);
return(1);
}
if (!(charset_info= get_charset_by_csname(default_charset,
if (strcmp(default_charset, charset_info->csname) &&
!(charset_info= get_charset_by_csname(default_charset,
MY_CS_PRIMARY, MYF(MY_WME))))
exit(1);
if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
......
......@@ -238,7 +238,8 @@ static int get_options(int *argc, char ***argv)
fprintf(stderr, "You can't use --ignore (-i) and --replace (-r) at the same time.\n");
return(1);
}
if (!(charset_info= get_charset_by_csname(default_charset,
if (strcmp(default_charset, charset_info->csname) &&
!(charset_info= get_charset_by_csname(default_charset,
MY_CS_PRIMARY, MYF(MY_WME))))
exit(1);
if (*argc < 2)
......
......@@ -57,9 +57,6 @@ typedef int my_socket;
#include "mysql_com.h"
#include "mysql_version.h"
#include "typelib.h"
#ifndef DBUG_OFF
#define CHECK_EXTRA_ARGUMENTS
#endif
#include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */
......@@ -537,6 +534,8 @@ typedef struct st_mysql_stmt
char *query; /* query buffer */
MEM_ROOT mem_root; /* root allocations */
my_ulonglong last_fetched_column; /* last fetched column */
my_ulonglong affected_rows; /* copy of mysql->affected_rows
after statement execution */
unsigned long stmt_id; /* Id for prepared statement */
unsigned int last_errno; /* error code */
unsigned int param_count; /* parameters count */
......@@ -575,6 +574,7 @@ typedef struct st_mysql_methods
int (*unbuffered_fetch)(MYSQL *mysql, char **row);
void (*free_embedded_thd)(MYSQL *mysql);
const char *(*read_statistic)(MYSQL *mysql);
int (*next_result)(MYSQL *mysql);
#endif
} MYSQL_METHODS;
......
......@@ -1653,14 +1653,6 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length)
DBUG_ENTER("mysql_prepare");
DBUG_ASSERT(mysql != 0);
#ifdef CHECK_EXTRA_ARGUMENTS
if (!query)
{
set_mysql_error(mysql, CR_NULL_POINTER, unknown_sqlstate);
DBUG_RETURN(0);
}
#endif
if (!(stmt= (MYSQL_STMT *) my_malloc(sizeof(MYSQL_STMT),
MYF(MY_WME | MY_ZEROFILL))) ||
!(stmt->query= my_strdup_with_length((byte *) query, length, MYF(0))))
......@@ -2018,6 +2010,7 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
DBUG_RETURN(1);
}
stmt->affected_rows= mysql->affected_rows;
DBUG_RETURN(0);
}
......@@ -2086,19 +2079,6 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt)
{
DBUG_ENTER("mysql_execute");
if (stmt->state == MY_ST_UNKNOWN)
{
set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate);
DBUG_RETURN(1);
}
#ifdef CHECK_EXTRA_ARGUMENTS
if (stmt->param_count && !stmt->param_buffers)
{
/* Parameters exists, but no bound buffers */
set_stmt_error(stmt, CR_NOT_ALL_PARAMS_BOUND, unknown_sqlstate);
DBUG_RETURN(1);
}
#endif
if ((*stmt->mysql->methods->stmt_execute)(stmt))
DBUG_RETURN(1);
......@@ -2127,7 +2107,7 @@ ulong STDCALL mysql_param_count(MYSQL_STMT * stmt)
my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt)
{
return stmt->mysql->last_used_con->affected_rows;
return stmt->affected_rows;
}
......@@ -2144,19 +2124,6 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
MYSQL_BIND *param, *end;
DBUG_ENTER("mysql_bind_param");
#ifdef CHECK_EXTRA_ARGUMENTS
if (stmt->state == MY_ST_UNKNOWN)
{
set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate);
DBUG_RETURN(1);
}
if (!stmt->param_count)
{
set_stmt_error(stmt, CR_NO_PARAMETERS_EXISTS, unknown_sqlstate);
DBUG_RETURN(1);
}
#endif
/* Allocated on prepare */
memcpy((char*) stmt->params, (char*) bind,
sizeof(MYSQL_BIND) * stmt->param_count);
......@@ -2279,11 +2246,6 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number,
DBUG_PRINT("enter",("param no : %d, data : %lx, length : %ld",
param_number, data, length));
if (param_number >= stmt->param_count)
{
set_stmt_error(stmt, CR_INVALID_PARAMETER_NO, unknown_sqlstate);
DBUG_RETURN(1);
}
param= stmt->params+param_number;
if (param->buffer_type < MYSQL_TYPE_TINY_BLOB ||
param->buffer_type > MYSQL_TYPE_STRING)
......@@ -2853,18 +2815,6 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_ENTER("mysql_bind_result");
DBUG_ASSERT(stmt != 0);
#ifdef CHECK_EXTRA_ARGUMENTS
if (stmt->state == MY_ST_UNKNOWN)
{
set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate);
DBUG_RETURN(1);
}
if (!bind)
{
set_stmt_error(stmt, CR_NULL_POINTER, unknown_sqlstate);
DBUG_RETURN(1);
}
#endif
if (!(bind_count= stmt->field_count) &&
!(bind_count= alloc_stmt_fields(stmt)))
DBUG_RETURN(0);
......@@ -3035,6 +2985,15 @@ int STDCALL mysql_fetch(MYSQL_STMT *stmt)
}
else /* un-buffered */
{
if (mysql->status != MYSQL_STATUS_GET_RESULT)
{
if (!stmt->field_count)
goto no_data;
set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
DBUG_RETURN(1);
}
if((*mysql->methods->unbuffered_fetch)(mysql, ( char **)&row))
{
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
......@@ -3065,7 +3024,7 @@ no_data:
mysql_fetch_column()
stmt Prepared statement handler
bind Where data should be placed. Should be filled in as
when calling mysql_bind_param()
when calling mysql_bind_result()
column Column to fetch (first column is 0)
ulong offset Offset in result data (to fetch blob in pieces)
This is normally 0
......@@ -3083,14 +3042,6 @@ int STDCALL mysql_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind,
if (!stmt->current_row)
goto no_data;
#ifdef CHECK_EXTRA_ARGUMENTS
if (column >= stmt->field_count)
{
set_stmt_errmsg(stmt, "Invalid column descriptor",1, unknown_sqlstate);
DBUG_RETURN(1);
}
#endif
if (param->null_field)
{
if (bind->is_null)
......@@ -3224,6 +3175,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
DBUG_RETURN(0);
}
mysql->affected_rows= result->row_count= result->data->rows;
stmt->affected_rows= result->row_count;
result->data_cursor= result->data->data;
result->fields= stmt->fields;
result->field_count= stmt->field_count;
......@@ -3511,7 +3463,6 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql)
/*
Reads and returns the next query results
*/
int STDCALL mysql_next_result(MYSQL *mysql)
{
DBUG_ENTER("mysql_next_result");
......@@ -3530,8 +3481,8 @@ int STDCALL mysql_next_result(MYSQL *mysql)
mysql->affected_rows= ~(my_ulonglong) 0;
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
DBUG_RETURN((*mysql->methods->read_query_result)(mysql));
DBUG_RETURN((*mysql->methods->next_result)(mysql));
DBUG_RETURN(-1); /* No more results */
}
......
......@@ -245,6 +245,18 @@ static MYSQL_RES * emb_mysql_store_result(MYSQL *mysql)
return mysql_store_result(mysql);
}
int emb_next_result(MYSQL *mysql)
{
THD *thd= (THD*)mysql->thd;
DBUG_ENTER("emb_next_result");
if (emb_advanced_command(mysql, COM_QUERY,0,0,
thd->query_rest.ptr(),thd->query_rest.length(),1)
|| emb_mysql_read_query_result(mysql))
DBUG_RETURN(1);
DBUG_RETURN(0); /* No more results */
}
MYSQL_METHODS embedded_methods=
{
......@@ -259,7 +271,8 @@ MYSQL_METHODS embedded_methods=
emb_read_binary_rows,
emb_unbuffered_fetch,
emb_free_embedded_thd,
emb_read_statistic
emb_read_statistic,
emb_next_result
};
C_MODE_END
......@@ -676,7 +689,10 @@ send_ok(THD *thd,ha_rows affected_rows,ulonglong id,const char *message)
mysql->affected_rows= affected_rows;
mysql->insert_id= id;
if (message)
{
strmake(thd->net.last_error, message, sizeof(thd->net.last_error)-1);
mysql->info= thd->net.last_error;
}
DBUG_VOID_RETURN;
}
......
......@@ -64,12 +64,6 @@ test
select cast(_koi8r'' as char character set cp1251);
cast(_koi8r'' as char character set cp1251)
select convert(_latin1'test', "latin1_german1_ci", "latin1_swedish_ci");
convert(_latin1'test', "latin1_german1_ci", "latin1_swedish_ci")
test
select convert(_koi8r'', "koi8r_general_ci", "cp1251_general_ci");
convert(_koi8r'', "koi8r_general_ci", "cp1251_general_ci")
create table t1 select cast(_koi8r'' as char character set cp1251) as t;
show create table t1;
Table Create Table
......
......@@ -167,3 +167,5 @@ select hex(s1) from t1;
hex(s1)
41
drop table t1;
create table t1 (a char(160) character set utf8, primary key(a));
ERROR HY000: Incorrect sub part key. The used key part isn't a string, the used length is longer than the key part or the storage engine doesn't support unique sub keys
......@@ -51,6 +51,20 @@ t1 CREATE TABLE `t1` (
`version` char(40) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select charset(charset(_utf8'a')), charset(collation(_utf8'a'));
charset(charset(_utf8'a')) charset(collation(_utf8'a'))
utf8 utf8
select collation(charset(_utf8'a')), collation(collation(_utf8'a'));
collation(charset(_utf8'a')) collation(collation(_utf8'a'))
utf8_general_ci utf8_general_ci
create table t1 select charset(_utf8'a'), collation(_utf8'a');
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`charset(_utf8'a')` char(64) character set utf8 NOT NULL default '',
`collation(_utf8'a')` char(64) character set utf8 NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select TRUE,FALSE,NULL;
TRUE FALSE NULL
1 0 NULL
......@@ -186,7 +186,7 @@ create table ```a` (i int);
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=NO_AUTO_VALUE_ON_ZERO */;
DROP TABLE IF EXISTS ```a`;
CREATE TABLE ``a` (
CREATE TABLE ```a` (
`i` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
......
......@@ -106,7 +106,7 @@ show create table t1;
Table Create Table
t1 CREATE TABLE t1 (
test_set set('val1','val2','val3') NOT NULL default '',
name char(20) default 'O''Brien' COMMENT 'O''Brien as default',
`name` char(20) default 'O''Brien' COMMENT 'O''Brien as default',
c int(11) NOT NULL default '0' COMMENT 'int column',
`c-b` int(11) default NULL COMMENT 'name with a space',
`space ` int(11) default NULL COMMENT 'name with a space'
......@@ -265,3 +265,51 @@ c decimal(4,3) YES NULL
d double(4,3) YES NULL
f float(4,3) YES NULL
drop table t1;
SET sql_mode='';
SET sql_quote_show_create=OFF;
CREATE TABLE ```ab``cd``` (i INT);
SHOW CREATE TABLE ```ab``cd```;
Table Create Table
`ab`cd` CREATE TABLE ```ab``cd``` (
i int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE ```ab``cd```;
CREATE TABLE ```ab````cd``` (i INT);
SHOW CREATE TABLE ```ab````cd```;
Table Create Table
`ab``cd` CREATE TABLE ```ab````cd``` (
i int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE ```ab````cd```;
CREATE TABLE ```a` (i INT);
SHOW CREATE TABLE ```a`;
Table Create Table
`a CREATE TABLE ```a` (
i int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE ```a`;
SET sql_mode='ANSI_QUOTES';
CREATE TABLE """a" (i INT);
SHOW CREATE TABLE """a";
Table Create Table
"a CREATE TABLE """a" (
i int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE """a";
SET sql_mode='';
SET sql_quote_show_create=OFF;
CREATE TABLE t1 (i INT);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE t1 (
i int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE `table` (i INT);
SHOW CREATE TABLE `table`;
Table Create Table
table CREATE TABLE `table` (
i int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE `table`;
SET sql_quote_show_create=ON;
......@@ -28,8 +28,6 @@ select CAST(DATE "2004-01-22 21:45:33" AS CHAR(4) BINARY);
set names binary;
select cast(_latin1'test' as char character set latin2);
select cast(_koi8r'' as char character set cp1251);
select convert(_latin1'test', "latin1_german1_ci", "latin1_swedish_ci");
select convert(_koi8r'', "koi8r_general_ci", "cp1251_general_ci");
create table t1 select cast(_koi8r'' as char character set cp1251) as t;
show create table t1;
drop table t1;
......
......@@ -147,11 +147,6 @@ UPDATE t1 SET utf8_f=CONVERT(koi8_ru_f USING utf8);
SET CHARACTER SET koi8r;
SELECT * FROM t1;
#
# codecovarage for Item_func_conv_charset3
#
select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1;
explain extended select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1;
ALTER TABLE t1 ADD bin_f CHAR(32) BYTE NOT NULL;
UPDATE t1 SET bin_f=koi8_ru_f;
......
......@@ -98,3 +98,10 @@ create table t1 (s1 text character set utf8);
insert into t1 values (0x41FF);
select hex(s1) from t1;
drop table t1;
#
# Bug 2699
# UTF8 breaks primary keys for cols > 85 characters
#
--error 1089
create table t1 (a char(160) character set utf8, primary key(a));
......@@ -23,4 +23,10 @@ create table t1 (version char(40)) select database(), user(), version() as 'vers
show create table t1;
drop table t1;
select charset(charset(_utf8'a')), charset(collation(_utf8'a'));
select collation(charset(_utf8'a')), collation(collation(_utf8'a'));
create table t1 select charset(_utf8'a'), collation(_utf8'a');
show create table t1;
drop table t1;
select TRUE,FALSE,NULL;
......@@ -142,3 +142,43 @@ drop table t1;
create table t1 (c decimal(3,3), d double(3,3), f float(3,3));
show columns from t1;
drop table t1;
#
# Test for Bug #2593 "SHOW CREATE TABLE doesn't properly double quotes"
#
SET sql_mode='';
SET sql_quote_show_create=OFF;
CREATE TABLE ```ab``cd``` (i INT);
SHOW CREATE TABLE ```ab``cd```;
DROP TABLE ```ab``cd```;
CREATE TABLE ```ab````cd``` (i INT);
SHOW CREATE TABLE ```ab````cd```;
DROP TABLE ```ab````cd```;
CREATE TABLE ```a` (i INT);
SHOW CREATE TABLE ```a`;
DROP TABLE ```a`;
SET sql_mode='ANSI_QUOTES';
CREATE TABLE """a" (i INT);
SHOW CREATE TABLE """a";
DROP TABLE """a";
# to test quotes around keywords.. :
SET sql_mode='';
SET sql_quote_show_create=OFF;
CREATE TABLE t1 (i INT);
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE `table` (i INT);
SHOW CREATE TABLE `table`;
DROP TABLE `table`;
SET sql_quote_show_create=ON;
......@@ -1420,7 +1420,8 @@ static MYSQL_METHODS client_methods=
cli_read_binary_rows,
cli_unbuffered_fetch,
NULL,
cli_read_statistic
cli_read_statistic,
cli_read_query_result
#endif
};
......
......@@ -598,6 +598,8 @@ void Item_param::set_time(TIME *tm, timestamp_type type)
ltime.second_part= tm->second_part;
ltime.neg= tm->neg;
ltime.time_type= type;
item_is_time= true;
......
......@@ -2124,42 +2124,6 @@ void Item_func_conv_charset::print(String *str)
str->append(')');
}
String *Item_func_conv_charset3::val_str(String *str)
{
char cs1[30], cs2[30];
String to_cs_buff(cs1, sizeof(cs1), default_charset_info);
String from_cs_buff(cs2, sizeof(cs2), default_charset_info);
String *arg= args[0]->val_str(str);
String *to_cs= args[1]->val_str(&to_cs_buff);
String *from_cs= args[2]->val_str(&from_cs_buff);
CHARSET_INFO *from_charset;
CHARSET_INFO *to_charset;
if (!arg || args[0]->null_value ||
!to_cs || args[1]->null_value ||
!from_cs || args[2]->null_value ||
!(from_charset=get_charset_by_name(from_cs->ptr(), MYF(MY_WME))) ||
!(to_charset=get_charset_by_name(to_cs->ptr(), MYF(MY_WME))))
{
null_value= 1;
return 0;
}
if (str_value.copy(arg->ptr(), arg->length(), from_charset, to_charset))
{
null_value= 1;
return 0;
}
null_value= 0;
return &str_value;
}
void Item_func_conv_charset3::fix_length_and_dec()
{
max_length = args[0]->max_length;
}
String *Item_func_set_collation::val_str(String *str)
{
str=args[0]->val_str(str);
......@@ -2226,7 +2190,7 @@ String *Item_func_charset::val_str(String *str)
if ((null_value=(args[0]->null_value || !res->charset())))
return 0;
str->copy(res->charset()->csname,strlen(res->charset()->csname),
&my_charset_latin1, default_charset());
&my_charset_latin1, collation.collation);
return str;
}
......@@ -2237,7 +2201,7 @@ String *Item_func_collation::val_str(String *str)
if ((null_value=(args[0]->null_value || !res->charset())))
return 0;
str->copy(res->charset()->name,strlen(res->charset()->name),
&my_charset_latin1, default_charset());
&my_charset_latin1, collation.collation);
return str;
}
......
......@@ -619,16 +619,6 @@ public:
void print(String *str) { print_op(str); }
};
class Item_func_conv_charset3 :public Item_str_func
{
public:
Item_func_conv_charset3(Item *arg1,Item *arg2,Item *arg3)
:Item_str_func(arg1,arg2,arg3) {}
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "convert"; }
};
class Item_func_charset :public Item_str_func
{
public:
......@@ -637,8 +627,8 @@ public:
const char *func_name() const { return "charset"; }
void fix_length_and_dec()
{
max_length=40; // should be enough
collation.set(system_charset_info);
max_length= 64 * collation.collation->mbmaxlen; // should be enough
};
};
......@@ -650,8 +640,8 @@ public:
const char *func_name() const { return "collation"; }
void fix_length_and_dec()
{
max_length=40; // should be enough
collation.set(system_charset_info);
max_length= 64 * collation.collation->mbmaxlen; // should be enough
};
};
......
......@@ -801,6 +801,8 @@ uint find_type(TYPELIB *lib, const char *find, uint length, bool part_match);
uint check_word(TYPELIB *lib, const char *val, const char *end,
const char **end_of_word);
bool is_keyword(const char *name, uint len);
/* sql_parse.cc */
void free_items(Item *item);
void cleanup_items(Item *item);
......
......@@ -588,6 +588,7 @@ public:
struct st_mysql_bind *client_params;
char *extra_data;
ulong extra_length;
String query_rest;
#endif
NET net; // client connection descriptor
MEM_ROOT warn_root; // For warnings and errors
......
......@@ -171,6 +171,23 @@ static int find_keyword(LEX *lex, uint len, bool function)
return 0;
}
/*
Check if name is a keyword
SYNOPSIS
is_keyword()
name checked name
len length of checked name
RETURN VALUES
0 name is a keyword
1 name isn't a keyword
*/
bool is_keyword(const char *name, uint len)
{
return get_hash_symbol(name,len,0)!=0;
}
/* make a copy of token before ptr and set yytoklen */
......@@ -183,6 +200,13 @@ static LEX_STRING get_token(LEX *lex,uint length)
return tmp;
}
/*
todo:
There are no dangerous charsets in mysql for function
get_quoted_token yet. But it should be fixed in the
future to operate multichar strings (like ucs2)
*/
static LEX_STRING get_quoted_token(LEX *lex,uint length, char quote)
{
LEX_STRING tmp;
......@@ -410,7 +434,6 @@ inline static uint int_token(const char *str,uint length)
return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
}
/*
yylex remember the following states from the following yylex()
......@@ -660,37 +683,14 @@ int yylex(void *arg, void *yythd)
uint double_quotes= 0;
char quote_char= c; // Used char
lex->tok_start=lex->ptr; // Skip first `
while ((c=yyGet()))
{
#ifdef USE_MB
if (use_mb(cs))
{
while ((c= yyGet()))
{
if (c == quote_char)
{
if (yyPeek() != quote_char)
break;
c= yyGet();
double_quotes++;
continue;
}
if (c == (uchar) NAMES_SEP_CHAR)
break;
if (my_mbcharlen(cs, c) > 1)
{
int l;
if ((l = my_ismbchar(cs,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query)) == 0)
break;
lex->ptr += l-1;
}
}
}
else
if (my_mbcharlen(cs, c) == 1)
#endif
{
while ((c=yyGet()))
{
if (c == (uchar) NAMES_SEP_CHAR)
break; /* Old .frm format can't handle this char */
if (c == quote_char)
{
if (yyPeek() != quote_char)
......@@ -699,9 +699,18 @@ int yylex(void *arg, void *yythd)
double_quotes++;
continue;
}
if (c == (uchar) NAMES_SEP_CHAR)
}
#ifdef USE_MB
else
{
int l;
if ((l = my_ismbchar(cs,
(const char *)lex->ptr-1,
(const char *)lex->end_of_query)) == 0)
break;
lex->ptr += l-1;
}
#endif
}
if (double_quotes)
yylval->lex_str=get_quoted_token(lex,yyLength() - double_quotes,
......@@ -883,8 +892,13 @@ int yylex(void *arg, void *yythd)
}
/* fall true */
case MY_LEX_EOL:
lex->next_state=MY_LEX_END; // Mark for next loop
return(END_OF_INPUT);
if (lex->ptr >= lex->end_of_query)
{
lex->next_state=MY_LEX_END; // Mark for next loop
return(END_OF_INPUT);
}
state=MY_LEX_CHAR;
break;
case MY_LEX_END:
lex->next_state=MY_LEX_END;
return(0); // We found end of input last time
......
......@@ -1411,11 +1411,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
char *packet= thd->lex->found_colon;
/*
Multiple queries exits, execute them individually
in embedded server - just store them to be executed later
*/
#ifndef EMBEDDED_LIBRARY
if (thd->lock || thd->open_tables || thd->derived_tables)
close_thread_tables(thd);
ulong length= thd->query_length-(ulong)(thd->lex->found_colon-thd->query);
#endif
ulong length= thd->query_length-(ulong)(packet-thd->query);
/* Remove garbage at start of query */
while (my_isspace(thd->charset(), *packet) && length > 0)
......@@ -1428,7 +1430,22 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_id= query_id++;
VOID(pthread_mutex_unlock(&LOCK_thread_count));
#ifndef EMBEDDED_LIBRARY
mysql_parse(thd, packet, length);
#else
/*
'packet' can point inside the query_rest's buffer
so we have to do memmove here
*/
if (thd->query_rest.length() > length)
{
memmove(thd->query_rest.c_ptr(), packet, length);
thd->query_rest.length(length);
}
else
thd->query_rest.copy(length);
break;
#endif /*EMBEDDED_LIBRARY*/
}
if (!(specialflag & SPECIAL_NO_PRIOR))
......
......@@ -1085,8 +1085,7 @@ mysqld_dump_create_info(THD *thd, TABLE *table, int fd)
DBUG_RETURN(0);
}
/* possible TODO: call find_keyword() from sql_lex.cc here */
static bool require_quotes(const char *name, uint length)
static inline const char *require_quotes(const char *name, uint length)
{
uint i, d, c;
for (i=0; i<length; i+=d)
......@@ -1094,7 +1093,37 @@ static bool require_quotes(const char *name, uint length)
c=((uchar *)name)[i];
d=my_mbcharlen(system_charset_info, c);
if (d==1 && !system_charset_info->ident_map[c])
return 1;
return name+i;
}
return 0;
}
/*
Looking for char in multibyte string
SYNOPSIS
look_for_char()
name string for looking at
length length of name
q '\'' or '\"' for looking for
RETURN VALUES
# pointer to found char in string
0 string doesn't contain required char
*/
static inline const char *look_for_char(const char *name,
uint length, char q)
{
const char *cur= name;
const char *end= cur+length;
uint symbol_length;
for (; cur<end; cur+= symbol_length)
{
char c= *cur;
symbol_length= my_mbcharlen(system_charset_info, c);
if (symbol_length==1 && c==q)
return cur;
}
return 0;
}
......@@ -1103,21 +1132,52 @@ void
append_identifier(THD *thd, String *packet, const char *name, uint length)
{
char qtype;
uint part_len;
const char *qplace;
if (thd->variables.sql_mode & MODE_ANSI_QUOTES)
qtype= '\"';
else
qtype= '`';
if ((thd->options & OPTION_QUOTE_SHOW_CREATE) ||
require_quotes(name, length))
if (is_keyword(name,length))
{
packet->append(&qtype, 1);
packet->append(&qtype, 1, system_charset_info);
packet->append(name, length, system_charset_info);
packet->append(&qtype, 1);
packet->append(&qtype, 1, system_charset_info);
}
else
{
packet->append(name, length, system_charset_info);
if (!(qplace= require_quotes(name, length)))
{
if (!(thd->options & OPTION_QUOTE_SHOW_CREATE))
packet->append(name, length, system_charset_info);
else
{
packet->append(&qtype, 1, system_charset_info);
packet->append(name, length, system_charset_info);
packet->append(&qtype, 1, system_charset_info);
}
}
else
{
packet->shrink(packet->length()+length+2);
packet->append(&qtype, 1, system_charset_info);
if (*qplace != qtype)
qplace= look_for_char(qplace+1,length-(qplace-name)-1,qtype);
while (qplace)
{
if ((part_len= qplace-name))
{
packet->append(name, part_len, system_charset_info);
length-= part_len;
}
packet->append(qplace, 1, system_charset_info);
name= qplace;
qplace= look_for_char(name+1,length-1,qtype);
}
packet->append(name, length, system_charset_info);
packet->append(&qtype, 1, system_charset_info);
}
}
}
......
......@@ -873,7 +873,12 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
column->field_name);
DBUG_RETURN(-1);
}
key_part_info->length=(uint8) length;
if (length > file->max_key_part_length())
{
my_error(ER_WRONG_SUB_KEY,MYF(0));
DBUG_RETURN(-1);
}
key_part_info->length=(uint16) length;
/* Use packed keys for long strings on the first column */
if (!(db_options & HA_OPTION_NO_PACK_KEYS) &&
(length >= KEY_DEFAULT_PACK_LENGTH &&
......
......@@ -3620,8 +3620,6 @@ simple_expr:
}
| CONVERT_SYM '(' expr USING charset_name ')'
{ $$= new Item_func_conv_charset($3,$5); }
| CONVERT_SYM '(' expr ',' expr ',' expr ')'
{ $$= new Item_func_conv_charset3($3,$7,$5); }
| DEFAULT '(' simple_ident ')'
{ $$= new Item_default_value($3); }
| VALUES '(' simple_ident ')'
......
......@@ -153,6 +153,17 @@ static void print_st_error(MYSQL_STMT *stmt, const char *msg)
else if (msg) fprintf(stderr, " [MySQL] %s\n", msg);
}
/*
This is to be what mysql_query() is for mysql_real_query(), for
mysql_prepare(): a variant without the 'length' parameter.
*/
MYSQL_STMT *STDCALL
mysql_simple_prepare(MYSQL *mysql, const char *query)
{
return mysql_prepare(mysql, query, strlen(query));
}
/********************************************************
* connect to the server *
*********************************************************/
......@@ -459,14 +470,14 @@ uint my_process_stmt_result(MYSQL_STMT *stmt)
/********************************************************
* process the stmt result set *
*********************************************************/
uint my_stmt_result(const char *buff, unsigned long length)
uint my_stmt_result(const char *buff)
{
MYSQL_STMT *stmt;
uint row_count;
int rc;
fprintf(stdout,"\n\n %s", buff);
stmt= mysql_prepare(mysql,buff,length);
stmt= mysql_simple_prepare(mysql,buff);
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -605,7 +616,7 @@ static void execute_prepare_query(const char *query, ulonglong exp_count)
ulonglong affected_rows;
int rc;
stmt= mysql_prepare(mysql,query,strlen(query));
stmt= mysql_simple_prepare(mysql,query);
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -913,7 +924,7 @@ static void test_prepare_simple()
/* alter table */
strmov(query,"ALTER TABLE test_prepare_simple ADD new char(20)");
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -921,7 +932,7 @@ static void test_prepare_simple()
/* insert */
strmov(query,"INSERT INTO test_prepare_simple VALUES(?,?)");
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -929,7 +940,7 @@ static void test_prepare_simple()
/* update */
strmov(query,"UPDATE test_prepare_simple SET id=? WHERE id=? AND name= ?");
stmt = mysql_prepare(mysql, query, 100);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,3);
......@@ -937,7 +948,7 @@ static void test_prepare_simple()
/* delete */
strmov(query,"DELETE FROM test_prepare_simple WHERE id=10");
stmt = mysql_prepare(mysql, query, 60);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -948,18 +959,16 @@ static void test_prepare_simple()
/* delete */
strmov(query,"DELETE FROM test_prepare_simple WHERE id=?");
stmt = mysql_prepare(mysql, query, 50);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,1);
rc = mysql_execute(stmt);
mystmt_r(stmt, rc);
mysql_stmt_close(stmt);
/* select */
strmov(query,"SELECT * FROM test_prepare_simple WHERE id=? AND name= ?");
stmt = mysql_prepare(mysql, query, 100);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -997,7 +1006,7 @@ static void test_prepare_field_result()
/* insert */
strmov(query,"SELECT int_c,var_c,date_c as date,ts_c,char_c FROM \
test_prepare_field_result as t1 WHERE int_c=?");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,1);
......@@ -1045,11 +1054,11 @@ static void test_prepare_syntax()
myquery(rc);
strmov(query,"INSERT INTO test_prepare_syntax VALUES(?");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init_r(stmt);
strmov(query,"SELECT id,name FROM test_prepare_syntax WHERE id=? AND WHERE");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init_r(stmt);
/* now fetch the results ..*/
......@@ -1095,7 +1104,7 @@ static void test_prepare()
/* insert by prepare */
strxmov(query,"INSERT INTO my_prepare VALUES(?,?,?,?,?,?,?)",NullS);
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,7);
......@@ -1159,9 +1168,9 @@ static void test_prepare()
myquery(rc);
/* test the results now, only one row should exists */
assert(tiny_data == (char) my_stmt_result("SELECT * FROM my_prepare",50));
assert(tiny_data == (char) my_stmt_result("SELECT * FROM my_prepare"));
stmt = mysql_prepare(mysql,"SELECT * FROM my_prepare",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM my_prepare");
mystmt_init(stmt);
rc = mysql_bind_result(stmt, bind);
......@@ -1266,7 +1275,7 @@ static void test_double_compare()
myquery(rc);
strmov(query, "UPDATE test_double_compare SET col1=100 WHERE col1 = ? AND col2 = ? AND COL3 = ?");
stmt = mysql_prepare(mysql,query, strlen(query));
stmt = mysql_simple_prepare(mysql,query);
mystmt_init(stmt);
verify_param_count(stmt,3);
......@@ -1347,11 +1356,11 @@ static void test_null()
/* insert by prepare, wrong column name */
strmov(query,"INSERT INTO test_null(col3,col2) VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init_r(stmt);
strmov(query,"INSERT INTO test_null(col1,col2) VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -1393,7 +1402,7 @@ static void test_null()
myquery(rc);
nData*= 2;
assert(nData == my_stmt_result("SELECT * FROM test_null", 30));
assert(nData == my_stmt_result("SELECT * FROM test_null"));
/* Fetch results */
bind[0].buffer_type= MYSQL_TYPE_LONG;
......@@ -1403,7 +1412,7 @@ static void test_null()
bind[0].is_null= &is_null[0];
bind[1].is_null= &is_null[1];
stmt = mysql_prepare(mysql,"SELECT * FROM test_null",30);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_null");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -1475,9 +1484,9 @@ static void test_fetch_null()
strmov((char *)query , "SELECT * FROM test_fetch_null");
assert(3 == my_stmt_result(query,50));
assert(3 == my_stmt_result(query));
stmt = mysql_prepare(mysql, query, 50);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
rc = mysql_bind_result(stmt,bind);
......@@ -1516,7 +1525,7 @@ static void test_select_version()
myheader("test_select_version");
stmt = mysql_prepare(mysql, "SELECT @@version", 30);
stmt = mysql_simple_prepare(mysql, "SELECT @@version");
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -1538,7 +1547,7 @@ static void test_select_simple()
myheader("test_select_simple");
stmt = mysql_prepare(mysql, "SHOW TABLES FROM mysql", 50);
stmt = mysql_simple_prepare(mysql, "SHOW TABLES FROM mysql");
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -1630,7 +1639,7 @@ static void test_select_prepare()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"SELECT * FROM test_select",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_select");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -1660,7 +1669,7 @@ static void test_select_prepare()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"SELECT * FROM test_select",25);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_select");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -1715,7 +1724,7 @@ static void test_select()
myquery(rc);
strmov(query,"SELECT * FROM test_select WHERE id=? AND name=?");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -1774,7 +1783,7 @@ session_id char(9) NOT NULL, \
myquery(rc);
strmov(query,"SELECT * FROM test_select WHERE session_id = ?");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,1);
......@@ -1852,7 +1861,7 @@ static void test_bug1180()
myquery(rc);
strmov(query,"SELECT * FROM test_select WHERE ?=\"1111\" and session_id = \"abc\"");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,1);
......@@ -1932,7 +1941,7 @@ static void test_bug1644()
myquery(rc);
strmov(query, "INSERT INTO foo_dfr VALUES (?,?,?,? )");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt, 4);
......@@ -2030,7 +2039,7 @@ static void test_select_show()
rc = mysql_query(mysql, "CREATE TABLE test_show(id int(4) NOT NULL primary key, name char(2))");
myquery(rc);
stmt = mysql_prepare(mysql, "show columns from test_show", 30);
stmt = mysql_simple_prepare(mysql, "show columns from test_show");
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -2041,11 +2050,11 @@ static void test_select_show()
my_process_stmt_result(stmt);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "show tables from mysql like ?", 50);
stmt = mysql_simple_prepare(mysql, "show tables from mysql like ?");
mystmt_init_r(stmt);
strxmov(query,"show tables from ", current_db, " like \'test_show\'", NullS);
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -2054,7 +2063,7 @@ static void test_select_show()
my_process_stmt_result(stmt);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "describe test_show", 30);
stmt = mysql_simple_prepare(mysql, "describe test_show");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -2063,7 +2072,7 @@ static void test_select_show()
my_process_stmt_result(stmt);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "show keys from test_show", 30);
stmt = mysql_simple_prepare(mysql, "show keys from test_show");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -2115,7 +2124,7 @@ static void test_simple_update()
/* insert by prepare */
strmov(query,"UPDATE test_update SET col2=? WHERE col1=?");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -2190,11 +2199,11 @@ static void test_long_data()
myquery(rc);
strmov(query,"INSERT INTO test_long_data(col1,col2) VALUES(?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init_r(stmt);
strmov(query,"INSERT INTO test_long_data(col1,col2,col3) VALUES(?,?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,3);
......@@ -2282,7 +2291,7 @@ static void test_long_data_str()
myquery(rc);
strmov(query,"INSERT INTO test_long_data_str VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -2373,7 +2382,7 @@ static void test_long_data_str1()
myquery(rc);
strmov(query,"INSERT INTO test_long_data_str VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -2462,7 +2471,7 @@ static void test_long_data_bin()
myquery(rc);
strmov(query,"INSERT INTO test_long_data_bin VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -2557,7 +2566,7 @@ static void test_simple_delete()
/* insert by prepare */
strmov(query,"DELETE FROM test_simple_delete WHERE col1=? AND col2=? AND col3=100");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -2637,7 +2646,7 @@ static void test_update()
myquery(rc);
strmov(query,"INSERT INTO test_update(col2,col3) VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -2667,7 +2676,7 @@ static void test_update()
mysql_stmt_close(stmt);
strmov(query,"UPDATE test_update SET col2=? WHERE col3=?");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -2733,7 +2742,7 @@ static void test_prepare_noparam()
/* insert by prepare */
strmov(query,"INSERT INTO my_prepare VALUES(10,'venu')");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -2812,7 +2821,7 @@ static void test_bind_result()
bind[1].length= &length1;
bind[1].is_null= &is_null[1];
stmt = mysql_prepare(mysql, "SELECT * FROM test_bind_result", 50);
stmt = mysql_simple_prepare(mysql, "SELECT * FROM test_bind_result");
mystmt_init(stmt);
rc = mysql_bind_result(stmt,bind);
......@@ -2933,7 +2942,7 @@ static void test_bind_result_ext()
bind[7].length= &bLength;
bind[7].buffer_length= sizeof(bData);
stmt = mysql_prepare(mysql, "select * from test_bind_result", 50);
stmt = mysql_simple_prepare(mysql, "select * from test_bind_result");
mystmt_init(stmt);
rc = mysql_bind_result(stmt,bind);
......@@ -3058,7 +3067,7 @@ static void test_bind_result_ext1()
bind[i].length= &length[i];
}
stmt = mysql_prepare(mysql, "select * from test_bind_result", 50);
stmt = mysql_simple_prepare(mysql, "select * from test_bind_result");
mystmt_init(stmt);
rc = mysql_bind_result(stmt,bind);
......@@ -3118,7 +3127,7 @@ static void bind_fetch(int row_count)
MYSQL_BIND bind[7];
my_bool is_null[7];
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_fetch VALUES(?,?,?,?,?,?,?)",100);
stmt = mysql_simple_prepare(mysql,"INSERT INTO test_bind_fetch VALUES(?,?,?,?,?,?,?)");
mystmt_init(stmt);
verify_param_count(stmt, 7);
......@@ -3151,9 +3160,9 @@ static void bind_fetch(int row_count)
mysql_stmt_close(stmt);
assert(row_count == (int)
my_stmt_result("SELECT * FROM test_bind_fetch",50));
my_stmt_result("SELECT * FROM test_bind_fetch"));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_fetch",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_bind_fetch");
myquery(rc);
for (i= 0; i < (int) array_elements(bind); i++)
......@@ -3321,9 +3330,9 @@ static void test_fetch_date()
bind[6].buffer_length= sizeof(ts_6);
bind[6].length= &ts6_length;
assert(1 == my_stmt_result("SELECT * FROM test_bind_result",50));
assert(1 == my_stmt_result("SELECT * FROM test_bind_result"));
stmt = mysql_prepare(mysql, "SELECT * FROM test_bind_result", 50);
stmt = mysql_simple_prepare(mysql, "SELECT * FROM test_bind_result");
mystmt_init(stmt);
rc = mysql_bind_result(stmt,bind);
......@@ -3651,7 +3660,7 @@ static void test_prepare_ext()
/* insert by prepare - all integers */
strmov(query,(char *)"INSERT INTO test_prepare_ext(c1,c2,c3,c4,c5,c6) VALUES(?,?,?,?,?,?)");
stmt = mysql_prepare(mysql,query, strlen(query));
stmt = mysql_simple_prepare(mysql,query);
mystmt_init(stmt);
verify_param_count(stmt,6);
......@@ -3704,7 +3713,7 @@ static void test_prepare_ext()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"SELECT c1,c2,c3,c4,c5,c6 FROM test_prepare_ext",100);
stmt = mysql_simple_prepare(mysql,"SELECT c1,c2,c3,c4,c5,c6 FROM test_prepare_ext");
mystmt_init(stmt);
/* get the result */
......@@ -3850,7 +3859,7 @@ static void test_insert()
myquery(rc);
/* insert by prepare */
stmt = mysql_prepare(mysql, "INSERT INTO test_prep_insert VALUES(?,?)", 70);
stmt = mysql_simple_prepare(mysql, "INSERT INTO test_prep_insert VALUES(?,?)");
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -3922,7 +3931,7 @@ static void test_prepare_resultset()
name varchar(50),extra double)");
myquery(rc);
stmt = mysql_prepare(mysql, "SELECT * FROM test_prepare_resultset", 60);
stmt = mysql_simple_prepare(mysql, "SELECT * FROM test_prepare_resultset");
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -4034,25 +4043,25 @@ static void test_stmt_close()
myquery(rc);
strmov(query,"ALTER TABLE test_stmt_close ADD name varchar(20)");
stmt1= mysql_prepare(lmysql, query, 70);
stmt1= mysql_simple_prepare(lmysql, query);
mystmt_init(stmt1);
verify_param_count(stmt1, 0);
strmov(query,"INSERT INTO test_stmt_close(id) VALUES(?)");
stmt_x= mysql_prepare(mysql, query, 70);
stmt_x= mysql_simple_prepare(mysql, query);
mystmt_init(stmt_x);
verify_param_count(stmt_x, 1);
strmov(query,"UPDATE test_stmt_close SET id=? WHERE id=?");
stmt3= mysql_prepare(lmysql, query, 70);
stmt3= mysql_simple_prepare(lmysql, query);
mystmt_init(stmt3);
verify_param_count(stmt3, 2);
strmov(query,"SELECT * FROM test_stmt_close WHERE id=?");
stmt2= mysql_prepare(lmysql, query, 70);
stmt2= mysql_simple_prepare(lmysql, query);
mystmt_init(stmt2);
verify_param_count(stmt2, 1);
......@@ -4119,7 +4128,7 @@ static void test_set_variable()
mysql_autocommit(mysql, TRUE);
stmt1 = mysql_prepare(mysql, "show variables like 'max_error_count'", 50);
stmt1 = mysql_simple_prepare(mysql, "show variables like 'max_error_count'");
mystmt_init(stmt1);
get_bind[0].buffer_type= MYSQL_TYPE_STRING;
......@@ -4150,7 +4159,7 @@ static void test_set_variable()
rc = mysql_fetch(stmt1);
assert(rc == MYSQL_NO_DATA);
stmt = mysql_prepare(mysql, "set max_error_count=?", 50);
stmt = mysql_simple_prepare(mysql, "set max_error_count=?");
mystmt_init(stmt);
set_bind[0].buffer_type= MYSQL_TYPE_LONG;
......@@ -4225,7 +4234,7 @@ static void test_insert_meta()
myquery(rc);
strmov(query,"INSERT INTO test_prep_insert VALUES(10,'venu1','test')");
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -4236,7 +4245,7 @@ static void test_insert_meta()
mysql_stmt_close(stmt);
strmov(query,"INSERT INTO test_prep_insert VALUES(?,'venu',?)");
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -4288,7 +4297,7 @@ static void test_update_meta()
myquery(rc);
strmov(query,"UPDATE test_prep_update SET col1=10, col2='venu1' WHERE col3='test'");
stmt = mysql_prepare(mysql, query, 100);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -4299,7 +4308,7 @@ static void test_update_meta()
mysql_stmt_close(stmt);
strmov(query,"UPDATE test_prep_update SET col1=?, col2='venu' WHERE col3=?");
stmt = mysql_prepare(mysql, query, 100);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -4355,7 +4364,7 @@ static void test_select_meta()
myquery(rc);
strmov(query,"SELECT * FROM test_prep_select WHERE col1=10");
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,0);
......@@ -4364,7 +4373,7 @@ static void test_select_meta()
mytest_r(result);
strmov(query,"SELECT col1, col3 from test_prep_select WHERE col1=? AND col3='test' AND col2= ?");
stmt = mysql_prepare(mysql, query, 120);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
verify_param_count(stmt,2);
......@@ -4499,10 +4508,10 @@ static void test_multi_stmt()
rc = mysql_query(mysql,"INSERT INTO test_multi_table values(10,'mysql')");
myquery(rc);
stmt = mysql_prepare(mysql, "SELECT * FROM test_multi_table WHERE id = ?", 100);
stmt = mysql_simple_prepare(mysql, "SELECT * FROM test_multi_table WHERE id = ?");
mystmt_init(stmt);
stmt2 = mysql_prepare(mysql, "UPDATE test_multi_table SET name='updated' WHERE id=10",100);
stmt2 = mysql_simple_prepare(mysql, "UPDATE test_multi_table SET name='updated' WHERE id=10");
mystmt_init(stmt2);
verify_param_count(stmt,1);
......@@ -4544,7 +4553,7 @@ static void test_multi_stmt()
assert(rc == MYSQL_NO_DATA);
/* alter the table schema now */
stmt1 = mysql_prepare(mysql,"DELETE FROM test_multi_table WHERE id = ? AND name=?",100);
stmt1 = mysql_simple_prepare(mysql,"DELETE FROM test_multi_table WHERE id = ? AND name=?");
mystmt_init(stmt1);
verify_param_count(stmt1,2);
......@@ -4584,7 +4593,7 @@ static void test_multi_stmt()
rc = mysql_fetch(stmt);
assert(rc == MYSQL_NO_DATA);
assert(0 == my_stmt_result("SELECT * FROM test_multi_table",50));
assert(0 == my_stmt_result("SELECT * FROM test_multi_table"));
mysql_stmt_close(stmt);
mysql_stmt_close(stmt2);
......@@ -4631,7 +4640,7 @@ static void test_manual_sample()
/* Prepare a insert query with 3 parameters */
strmov(query, "INSERT INTO test_table(col1,col2,col3) values(?,?,?)");
if (!(stmt = mysql_prepare(mysql,query,strlen(query))))
if (!(stmt = mysql_simple_prepare(mysql,query)))
{
fprintf(stderr, "\n prepare, insert failed");
fprintf(stderr, "\n %s", mysql_error(mysql));
......@@ -4735,7 +4744,7 @@ static void test_manual_sample()
fprintf(stderr, "\n %s", mysql_stmt_error(stmt));
exit(0);
}
assert(2 == my_stmt_result("SELECT * FROM test_table",50));
assert(2 == my_stmt_result("SELECT * FROM test_table"));
/* DROP THE TABLE */
if (mysql_query(mysql,"DROP TABLE test_table"))
......@@ -4770,7 +4779,7 @@ static void test_prepare_alter()
rc = mysql_query(mysql,"INSERT INTO test_prep_alter values(10,'venu'),(20,'mysql')");
myquery(rc);
stmt = mysql_prepare(mysql, "INSERT INTO test_prep_alter VALUES(?,'monty')", 100);
stmt = mysql_simple_prepare(mysql, "INSERT INTO test_prep_alter VALUES(?,'monty')");
mystmt_init(stmt);
verify_param_count(stmt,1);
......@@ -4796,7 +4805,7 @@ static void test_prepare_alter()
rc = mysql_execute(stmt);
mystmt(stmt, rc);
assert(4 == my_stmt_result("SELECT * FROM test_prep_alter",50));
assert(4 == my_stmt_result("SELECT * FROM test_prep_alter"));
mysql_stmt_close(stmt);
}
......@@ -4978,7 +4987,7 @@ static void test_store_result()
bind[1].is_null= &is_null[1];
length1= 0;
stmt = mysql_prepare(mysql, "SELECT * FROM test_store_result", 50);
stmt = mysql_simple_prepare(mysql, "SELECT * FROM test_store_result");
mystmt_init(stmt);
rc = mysql_bind_result(stmt,bind);
......@@ -5089,7 +5098,7 @@ static void test_store_result1()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"SELECT * FROM test_store_result",100);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_store_result");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -5160,7 +5169,7 @@ static void test_store_result2()
bind[0].is_null= 0;
strmov((char *)query , "SELECT col1 FROM test_store_result where col1= ?");
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
rc = mysql_bind_param(stmt,bind);
......@@ -5252,7 +5261,7 @@ static void test_subselect()
bind[0].length= 0;
bind[0].is_null= 0;
stmt = mysql_prepare(mysql, "INSERT INTO test_sub2(id) SELECT * FROM test_sub1 WHERE id=?", 100);
stmt = mysql_simple_prepare(mysql, "INSERT INTO test_sub2(id) SELECT * FROM test_sub1 WHERE id=?", 100);
mystmt_init(stmt);
rc = mysql_bind_param(stmt,bind);
......@@ -5275,13 +5284,13 @@ static void test_subselect()
mysql_stmt_close(stmt);
assert(3 == my_stmt_result("SELECT * FROM test_sub2",50));
assert(3 == my_stmt_result("SELECT * FROM test_sub2"));
strmov((char *)query , "SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=?)");
assert(1 == my_stmt_result("SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=8)",100));
assert(1 == my_stmt_result("SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=7)",100));
assert(1 == my_stmt_result("SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=8)"));
assert(1 == my_stmt_result("SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=7)"));
stmt = mysql_prepare(mysql, query, 150);
stmt = mysql_simple_prepare(mysql, query, 150);
mystmt_init(stmt);
rc = mysql_bind_param(stmt,bind);
......@@ -5335,7 +5344,7 @@ static void test_bind_date_conv(uint row_count)
ulong second_part;
uint year, month, day, hour, minute, sec;
stmt = mysql_prepare(mysql,"INSERT INTO test_date VALUES(?,?,?,?)", 100);
stmt = mysql_simple_prepare(mysql,"INSERT INTO test_date VALUES(?,?,?,?)");
mystmt_init(stmt);
verify_param_count(stmt, 4);
......@@ -5389,9 +5398,9 @@ static void test_bind_date_conv(uint row_count)
mysql_stmt_close(stmt);
assert(row_count == my_stmt_result("SELECT * FROM test_date",50));
assert(row_count == my_stmt_result("SELECT * FROM test_date"));
stmt = mysql_prepare(mysql,"SELECT * FROM test_date",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_date");
myquery(rc);
rc = mysql_bind_result(stmt, bind);
......@@ -5586,30 +5595,27 @@ static void test_pure_coverage()
rc = mysql_query(mysql,"CREATE TABLE test_pure(c1 int, c2 varchar(20))");
myquery(rc);
stmt = mysql_prepare(mysql,"insert into test_pure(c67788) values(10)",100);
stmt = mysql_simple_prepare(mysql,"insert into test_pure(c67788) values(10)");
mystmt_init_r(stmt);
#ifndef DBUG_OFF
stmt = mysql_prepare(mysql,(const char *)0,0);
mystmt_init_r(stmt);
stmt = mysql_prepare(mysql,"insert into test_pure(c2) values(10)",100);
/* Query without params and result should allow to bind 0 arrays */
stmt = mysql_simple_prepare(mysql,"insert into test_pure(c2) values(10)");
mystmt_init(stmt);
rc = mysql_bind_param(stmt, (MYSQL_BIND*)0);
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_bind_param(stmt, bind);
mystmt_r(stmt, rc);
rc = mysql_bind_result(stmt, (MYSQL_BIND*)0);
mystmt(stmt, rc);
mysql_stmt_close(stmt);
#endif
stmt = mysql_prepare(mysql,"insert into test_pure(c2) values(?)",100);
stmt = mysql_simple_prepare(mysql,"insert into test_pure(c2) values(?)");
mystmt_init(stmt);
#ifndef DBUG_OFF
rc = mysql_execute(stmt);
mystmt_r(stmt, rc);/* No parameters supplied */
#endif
bind[0].length= &length;
bind[0].is_null= 0;
bind[0].buffer_length= 0;
......@@ -5622,28 +5628,20 @@ static void test_pure_coverage()
rc = mysql_bind_param(stmt, bind);
mystmt(stmt, rc);
rc = mysql_send_long_data(stmt, 20, (char *)"venu", 4);
mystmt_r(stmt, rc); /* wrong param number */
rc = mysql_stmt_store_result(stmt);
mystmt(stmt, rc);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql,"select * from test_pure",100);
stmt = mysql_simple_prepare(mysql,"select * from test_pure");
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
#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);
mystmt(stmt, rc);
......@@ -5682,7 +5680,7 @@ static void test_buffers()
,('Database'),('Open-Source'),('Popular')");
myquery(rc);
stmt = mysql_prepare(mysql,"select str from test_buffer",100);
stmt = mysql_simple_prepare(mysql,"select str from test_buffer");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -5760,7 +5758,7 @@ static void test_open_direct()
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);
stmt = mysql_simple_prepare(mysql,"INSERT INTO test_open_direct values(10,'mysql')");
mystmt_init(stmt);
rc = mysql_query(mysql, "SELECT * FROM test_open_direct");
......@@ -5799,7 +5797,7 @@ static void test_open_direct()
mysql_stmt_close(stmt);
/* run a direct query in the middle of a fetch */
stmt= mysql_prepare(mysql,"SELECT * FROM test_open_direct",100);
stmt= mysql_simple_prepare(mysql,"SELECT * FROM test_open_direct");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -5818,7 +5816,7 @@ static void test_open_direct()
myquery(rc);
/* run a direct query with store result */
stmt= mysql_prepare(mysql,"SELECT * FROM test_open_direct",100);
stmt= mysql_simple_prepare(mysql,"SELECT * FROM test_open_direct");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -5849,8 +5847,8 @@ static void test_fetch_nobuffs()
myheader("test_fetch_nobuffs");
stmt = mysql_prepare(mysql,"SELECT DATABASE(), CURRENT_USER(), \
CURRENT_DATE(), CURRENT_TIME()",100);
stmt = mysql_simple_prepare(mysql,"SELECT DATABASE(), CURRENT_USER(), \
CURRENT_DATE(), CURRENT_TIME()");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -5923,7 +5921,7 @@ static void test_ushort_bug()
myquery(rc);
stmt = mysql_prepare(mysql,"SELECT * FROM test_ushort",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_ushort");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6007,7 +6005,7 @@ static void test_sshort_bug()
myquery(rc);
stmt = mysql_prepare(mysql,"SELECT * FROM test_sshort",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_sshort");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6091,7 +6089,7 @@ static void test_stiny_bug()
myquery(rc);
stmt = mysql_prepare(mysql,"SELECT * FROM test_stiny",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_stiny");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6176,7 +6174,7 @@ static void test_field_misc()
mysql_free_result(result);
stmt = mysql_prepare(mysql,"SELECT @@autocommit",20);
stmt = mysql_simple_prepare(mysql,"SELECT @@autocommit");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6196,7 +6194,7 @@ static void test_field_misc()
mysql_free_result(result);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "SELECT @@table_type", 30);
stmt = mysql_simple_prepare(mysql, "SELECT @@table_type");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6220,7 +6218,7 @@ static void test_field_misc()
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "SELECT @@table_type", 30);
stmt = mysql_simple_prepare(mysql, "SELECT @@table_type");
mystmt_init(stmt);
result = mysql_get_metadata(stmt);
......@@ -6240,7 +6238,7 @@ static void test_field_misc()
mysql_free_result(result);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "SELECT @@max_error_count", 30);
stmt = mysql_simple_prepare(mysql, "SELECT @@max_error_count");
mystmt_init(stmt);
result = mysql_get_metadata(stmt);
......@@ -6260,7 +6258,7 @@ static void test_field_misc()
mysql_free_result(result);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "SELECT @@max_allowed_packet", 30);
stmt = mysql_simple_prepare(mysql, "SELECT @@max_allowed_packet");
mystmt_init(stmt);
result = mysql_get_metadata(stmt);
......@@ -6280,7 +6278,7 @@ static void test_field_misc()
mysql_free_result(result);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "SELECT @@sql_warnings", 30);
stmt = mysql_simple_prepare(mysql, "SELECT @@sql_warnings");
mystmt_init(stmt);
result = mysql_get_metadata(stmt);
......@@ -6341,7 +6339,7 @@ static void test_set_option()
mysql_free_result(result);
fprintf(stdout,"\n with SQL_SELECT_LIMIT=2 (prepare)");
stmt = mysql_prepare(mysql, "SELECT * FROM test_limit", 50);
stmt = mysql_simple_prepare(mysql, "SELECT * FROM test_limit");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6356,7 +6354,7 @@ static void test_set_option()
rc= mysql_query(mysql,"SET OPTION SQL_SELECT_LIMIT=DEFAULT");
myquery(rc);
stmt = mysql_prepare(mysql, "SELECT * FROM test_limit", 50);
stmt = mysql_simple_prepare(mysql, "SELECT * FROM test_limit");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6433,18 +6431,20 @@ static void test_prepare_grant()
execute_prepare_query("INSERT INTO test_grant(a) VALUES(NULL)",1);
execute_prepare_query("INSERT INTO test_grant VALUES(NULL)",1);
execute_prepare_query("UPDATE test_grant SET a=9 WHERE a=1",1);
assert(4 == my_stmt_result("SELECT a FROM test_grant",50));
assert(4 == my_stmt_result("SELECT a FROM test_grant"));
/* Both DELETE expected to fail as user does not have DELETE privs */
rc = mysql_query(mysql,"DELETE FROM test_grant");
myquery_r(rc);
stmt= mysql_prepare(mysql,"DELETE FROM test_grant",50);
stmt= mysql_simple_prepare(mysql,"DELETE FROM test_grant");
mystmt_init(stmt);
rc = mysql_execute(stmt);
myquery_r(rc);
assert(4 == my_stmt_result("SELECT * FROM test_grant",50));
assert(4 == my_stmt_result("SELECT * FROM test_grant"));
mysql_close(lmysql);
mysql= org_mysql;
......@@ -6487,7 +6487,7 @@ static void test_frm_bug()
rc= mysql_query(mysql,"flush tables");
myquery(rc);
stmt = mysql_prepare(mysql, "show variables like 'datadir'", 50);
stmt = mysql_simple_prepare(mysql, "show variables like 'datadir'");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6570,7 +6570,7 @@ static void test_decimal_bug()
rc = mysql_query(mysql, "insert into test_decimal_bug value(8),(10.22),(5.61)");
myquery(rc);
stmt = mysql_prepare(mysql,"select c1 from test_decimal_bug where c1= ?",50);
stmt = mysql_simple_prepare(mysql,"select c1 from test_decimal_bug where c1= ?");
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_DOUBLE;
......@@ -6666,7 +6666,7 @@ static void test_explain_bug()
rc = mysql_query(mysql, "CREATE TABLE test_explain(id int, name char(2))");
myquery(rc);
stmt = mysql_prepare(mysql, "explain test_explain", 30);
stmt = mysql_simple_prepare(mysql, "explain test_explain");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6702,7 +6702,7 @@ static void test_explain_bug()
mysql_free_result(result);
mysql_stmt_close(stmt);
stmt = mysql_prepare(mysql, "explain select id, name FROM test_explain", 50);
stmt = mysql_simple_prepare(mysql, "explain select id, name FROM test_explain");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -6950,10 +6950,10 @@ static void test_logs()
myheader("test_logs");
rc = mysql_real_query(mysql, "DROP TABLE IF EXISTS test_logs", 100);
rc = mysql_query(mysql, "DROP TABLE IF EXISTS test_logs");
myquery(rc);
rc = mysql_real_query(mysql, "CREATE TABLE test_logs(id smallint, name varchar(20))", 100);
rc = mysql_query(mysql, "CREATE TABLE test_logs(id smallint, name varchar(20))");
myquery(rc);
length= (ulong)(strmov((char *)data,"INSERT INTO test_logs VALUES(?,?)") - data);
......@@ -7015,7 +7015,7 @@ static void test_logs()
mysql_stmt_close(stmt);
length= (ulong)(strmov((char *)data, "SELECT * FROM test_logs WHERE id=?") - data);
stmt = mysql_prepare(mysql, data, length+2);
stmt = mysql_prepare(mysql, data, length);
mystmt_init(stmt);
rc = mysql_bind_param(stmt, bind);
......@@ -7125,7 +7125,7 @@ static void test_nstmts()
mysql_stmt_close(stmt);
}
stmt = mysql_prepare(mysql," select count(*) from test_nstmts", 50);
stmt = mysql_simple_prepare(mysql," select count(*) from test_nstmts");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -7172,7 +7172,7 @@ static void test_fetch_seek()
rc = mysql_query(mysql, "insert into test_seek(c2) values('venu'),('mysql'),('open'),('source')");
myquery(rc);
stmt = mysql_prepare(mysql,"select * from test_seek",50);
stmt = mysql_simple_prepare(mysql,"select * from test_seek");
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_LONG;
......@@ -7267,7 +7267,7 @@ static void test_fetch_offset()
rc = mysql_query(mysql, "insert into test_column values('abcdefghij'),(null)");
myquery(rc);
stmt = mysql_prepare(mysql,"select * from test_column",50);
stmt = mysql_simple_prepare(mysql,"select * from test_column");
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_STRING;
......@@ -7291,9 +7291,6 @@ static void test_fetch_offset()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
rc = mysql_fetch_column(stmt,bind,4,0);
mystmt_r(stmt,rc);
data[0]= '\0';
rc = mysql_fetch_column(stmt,bind,0,0);
mystmt(stmt,rc);
......@@ -7350,7 +7347,7 @@ static void test_fetch_column()
rc = mysql_query(mysql, "insert into test_column(c2) values('venu'),('mysql')");
myquery(rc);
stmt = mysql_prepare(mysql,"select * from test_column order by c2 desc", 50);
stmt = mysql_simple_prepare(mysql,"select * from test_column order by c2 desc");
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_LONG;
......@@ -7411,9 +7408,6 @@ static void test_fetch_column()
fprintf(stdout, "\n col 0: %d(%ld)", c1, l1);
assert(c1 == 1 && l1 == 4);
rc = mysql_fetch_column(stmt,bind,10,0);
mystmt_r(stmt,rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
......@@ -7537,7 +7531,7 @@ static void test_mem_overun()
assert(1 == my_process_result(mysql));
stmt = mysql_prepare(mysql, "select * from t_mem_overun",30);
stmt = mysql_simple_prepare(mysql, "select * from t_mem_overun");
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -7583,7 +7577,7 @@ static void test_free_result()
rc = mysql_query(mysql, "insert into test_free_result values(),(),()");
myquery(rc);
stmt = mysql_prepare(mysql,"select * from test_free_result",50);
stmt = mysql_simple_prepare(mysql,"select * from test_free_result");
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_LONG;
......@@ -7662,7 +7656,7 @@ static void test_free_store_result()
rc = mysql_query(mysql, "insert into test_free_result values(),(),()");
myquery(rc);
stmt = mysql_prepare(mysql,"select * from test_free_result",50);
stmt = mysql_simple_prepare(mysql,"select * from test_free_result");
mystmt_init(stmt);
bind[0].buffer_type= MYSQL_TYPE_LONG;
......@@ -7749,7 +7743,7 @@ static void test_sqlmode()
strcpy(query, "INSERT INTO test_piping VALUES(?||?)");
fprintf(stdout,"\n query: %s", query);
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
fprintf(stdout,"\n total parameters: %ld", mysql_param_count(stmt));
......@@ -7781,7 +7775,7 @@ static void test_sqlmode()
strcpy(query, "SELECT connection_id ()");
fprintf(stdout,"\n query: %s", query);
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init_r(stmt);
/* ANSI */
......@@ -7792,7 +7786,7 @@ static void test_sqlmode()
strcpy(query, "INSERT INTO test_piping VALUES(?||?)");
fprintf(stdout,"\n query: %s", query);
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
fprintf(stdout,"\n total parameters: %ld", mysql_param_count(stmt));
......@@ -7809,7 +7803,7 @@ static void test_sqlmode()
/* ANSI mode spaces ... */
strcpy(query, "SELECT connection_id ()");
fprintf(stdout,"\n query: %s", query);
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -7832,7 +7826,7 @@ static void test_sqlmode()
strcpy(query, "SELECT connection_id ()");
fprintf(stdout,"\n query: %s", query);
stmt = mysql_prepare(mysql, query, 70);
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
rc = mysql_execute(stmt);
......@@ -7873,7 +7867,7 @@ static void test_ts()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_ts VALUES(?,?,?),(?,?,?)",50);
stmt = mysql_simple_prepare(mysql,"INSERT INTO test_ts VALUES(?,?,?),(?,?,?)");
mystmt_init(stmt);
ts.year= 2003;
......@@ -7912,7 +7906,7 @@ static void test_ts()
verify_col_data("test_ts","b","21:07:46");
verify_col_data("test_ts","c","2003-07-12 21:07:46");
stmt = mysql_prepare(mysql,"SELECT * FROM test_ts",50);
stmt = mysql_simple_prepare(mysql,"SELECT * FROM test_ts");
mystmt_init(stmt);
prep_res = mysql_get_metadata(stmt);
......@@ -7983,7 +7977,7 @@ static void test_bug1500()
rc= mysql_commit(mysql);
myquery(rc);
stmt= mysql_prepare(mysql,"SELECT i FROM test_bg1500 WHERE i IN (?,?,?)",44);
stmt= mysql_simple_prepare(mysql,"SELECT i FROM test_bg1500 WHERE i IN (?,?,?)");
mystmt_init(stmt);
verify_param_count(stmt,3);
......@@ -8018,8 +8012,8 @@ static void test_bug1500()
rc= mysql_commit(mysql);
myquery(rc);
stmt= mysql_prepare(mysql,
"SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (?)",53);
stmt= mysql_simple_prepare(mysql,
"SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (?)");
mystmt_init(stmt);
verify_param_count(stmt,1);
......@@ -8046,8 +8040,8 @@ static void test_bug1500()
mysql_stmt_close(stmt);
/* This should work too */
stmt= mysql_prepare(mysql,
"SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (CONCAT(?,'digger'))", 70);
stmt= mysql_simple_prepare(mysql,
"SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (CONCAT(?,'digger'))");
mystmt_init(stmt);
verify_param_count(stmt,1);
......@@ -8084,7 +8078,7 @@ static void test_bug1946()
rc= mysql_query(mysql,"CREATE TABLE prepare_command(ID INT)");
myquery(rc);
stmt = mysql_prepare(mysql, query, strlen(query));
stmt = mysql_simple_prepare(mysql, query);
mystmt_init(stmt);
rc= mysql_real_query(mysql, query, strlen(query));
assert(rc != 0);
......@@ -8095,6 +8089,163 @@ static void test_bug1946()
rc= mysql_query(mysql,"DROP TABLE prepare_command");
}
static void test_parse_error_and_bad_length()
{
MYSQL_STMT *stmt;
int rc;
/* check that we get 4 syntax errors over the 4 calls */
myheader("test_parse_error_and_bad_length");
rc= mysql_query(mysql,"SHOW DATABAAAA");
assert(rc);
fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql));
rc= mysql_real_query(mysql,"SHOW DATABASES",100);
assert(rc);
fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql));
stmt= mysql_simple_prepare(mysql,"SHOW DATABAAAA");
assert(!stmt);
fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql));
stmt= mysql_prepare(mysql,"SHOW DATABASES",100);
assert(!stmt);
fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql));
}
static void test_bug2247()
{
MYSQL_STMT *stmt;
MYSQL_RES *res;
int rc;
int i;
const char *create= "CREATE TABLE bug2247(id INT UNIQUE AUTO_INCREMENT)";
const char *insert= "INSERT INTO bug2247 VALUES (NULL)";
const char *select= "SELECT id FROM bug2247";
const char *update= "UPDATE bug2247 SET id=id+10";
const char *drop= "DROP TABLE IF EXISTS bug2247";
ulonglong exp_count;
enum { NUM_ROWS= 5 };
myheader("test_bug2247");
fprintf(stdout, "\nChecking if stmt_affected_rows is not affected by\n"
"mysql_query ... ");
/* create table and insert few rows */
rc = mysql_query(mysql, drop);
myquery(rc);
rc= mysql_query(mysql, create);
myquery(rc);
stmt= mysql_prepare(mysql, insert, strlen(insert));
mystmt_init(stmt);
for (i= 0; i < NUM_ROWS; ++i)
{
rc= mysql_execute(stmt);
mystmt(stmt, rc);
}
exp_count= mysql_stmt_affected_rows(stmt);
assert(exp_count == 1);
rc= mysql_query(mysql, select);
myquery(rc);
/*
mysql_store_result overwrites mysql->affected_rows. Check that
mysql_stmt_affected_rows() returns the same value, whereas
mysql_affected_rows() value is correct.
*/
res= mysql_store_result(mysql);
mytest(res);
assert(mysql_affected_rows(mysql) == NUM_ROWS);
assert(exp_count == mysql_stmt_affected_rows(stmt));
rc= mysql_query(mysql, update);
myquery(rc);
assert(mysql_affected_rows(mysql) == NUM_ROWS);
assert(exp_count == mysql_stmt_affected_rows(stmt));
mysql_free_result(res);
mysql_stmt_close(stmt);
/* check that mysql_stmt_store_result modifies mysql_stmt_affected_rows */
stmt= mysql_prepare(mysql, select, strlen(select));
mystmt_init(stmt);
rc= mysql_execute(stmt);
mystmt(stmt, rc);
rc= mysql_stmt_store_result(stmt);
mystmt(stmt, rc);
exp_count= mysql_stmt_affected_rows(stmt);
assert(exp_count == NUM_ROWS);
rc= mysql_query(mysql, insert);
myquery(rc);
assert(mysql_affected_rows(mysql) == 1);
assert(mysql_stmt_affected_rows(stmt) == exp_count);
mysql_stmt_close(stmt);
fprintf(stdout, "OK");
}
/*
Test for bug#2248 "mysql_fetch without prior mysql_execute hangs"
*/
static void test_bug2248()
{
MYSQL_STMT *stmt;
int rc;
const char *query1= "SELECT DATABASE()";
const char *query2= "INSERT INTO test_bug2248 VALUES (10)";
myheader("test_bug2248");
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bug2248");
myquery(rc);
rc= mysql_query(mysql, "CREATE TABLE test_bug2248 (id int)");
myquery(rc);
stmt= mysql_prepare(mysql, query1, strlen(query1));
mystmt_init(stmt);
/* This should not hang */
rc= mysql_fetch(stmt);
mystmt_r(stmt,rc);
/* And this too */
rc= mysql_stmt_store_result(stmt);
mystmt_r(stmt,rc);
mysql_stmt_close(stmt);
stmt= mysql_prepare(mysql, query2, strlen(query2));
mystmt_init(stmt);
rc= mysql_execute(stmt);
mystmt(stmt,rc);
/* This too should not hang but should return proper error */
rc= mysql_fetch(stmt);
assert(rc==MYSQL_NO_DATA);
/* This too should not hang but should not bark */
rc= mysql_stmt_store_result(stmt);
mystmt(stmt,rc);
/* This should return proper error */
rc= mysql_fetch(stmt);
mystmt_r(stmt,rc);
assert(rc==MYSQL_NO_DATA);
mysql_stmt_close(stmt);
rc= mysql_query(mysql,"DROP TABLE test_bug2248");
myquery(rc);
}
/*
Read and parse arguments and MySQL options from my.cnf
......@@ -8340,6 +8491,12 @@ int main(int argc, char **argv)
test_bug1644(); /* BUG#1644 */
test_bug1946(); /* test that placeholders are allowed only in
prepared queries */
test_bug2248(); /* BUG#2248 */
test_parse_error_and_bad_length(); /* test if bad length param in
mysql_prepare() triggers error */
test_bug2247(); /* test that mysql_stmt_affected_rows() returns
number of rows affected by last prepared
statement execution */
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