diff --git a/client/mysql.cc b/client/mysql.cc index fcc381e3ae7..b79dda51317 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -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) diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 1768d948373..03ab45957d4 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -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) diff --git a/client/mysqldump.c b/client/mysqldump.c index 1383e0e0d02..345c7f0b945 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -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)) diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 5ad6d1dc429..d47ae48b1ac 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -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) diff --git a/include/mysql.h b/include/mysql.h index d1b467f9649..cd5d01d6f44 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -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; diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index b05b83f8a06..b3f4ccc4b4d 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -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 */ } diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index e36e878d4b1..188227c21f9 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -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; } diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index c60d8e19fb4..877a349d188 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -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 diff --git a/mysql-test/r/ctype_many.result b/mysql-test/r/ctype_many.result index 173d41ecdd1..8bfc6e98226 100644 --- a/mysql-test/r/ctype_many.result +++ b/mysql-test/r/ctype_many.result @@ -340,129 +340,6 @@ CYR CAPIT SOFT SIGN CYR CAPIT E ü ü CYR CAPIT YU à à CYR CAPIT YA ñ ñ -select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1; -CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci') comment -a LAT SMALL A -b LAT SMALL B -c LAT SMALL C -d LAT SMALL D -e LAT SMALL E -f LAT SMALL F -g LAT SMALL G -h LAT SMALL H -i LAT SMALL I -j LAT SMALL J -k LAT SMALL K -l LAT SMALL L -m LAT SMALL M -n LAT SMALL N -o LAT SMALL O -p LAT SMALL P -q LAT SMALL Q -r LAT SMALL R -s LAT SMALL S -t LAT SMALL T -u LAT SMALL U -v LAT SMALL V -w LAT SMALL W -x LAT SMALL X -y LAT SMALL Y -z LAT SMALL Z -A LAT CAPIT A -B LAT CAPIT B -C LAT CAPIT C -D LAT CAPIT D -E LAT CAPIT E -F LAT CAPIT F -G LAT CAPIT G -H LAT CAPIT H -I LAT CAPIT I -J LAT CAPIT J -K LAT CAPIT K -L LAT CAPIT L -M LAT CAPIT M -N LAT CAPIT N -O LAT CAPIT O -P LAT CAPIT P -Q LAT CAPIT Q -R LAT CAPIT R -S LAT CAPIT S -T LAT CAPIT T -U LAT CAPIT U -V LAT CAPIT V -W LAT CAPIT W -X LAT CAPIT X -Y LAT CAPIT Y -Z LAT CAPIT Z -â CYR SMALL A -÷ CYR SMALL BE -þ CYR SMALL VE -ú CYR SMALL GE -ä CYR SMALL DE -å CYR SMALL IE -? CYR SMALL IO -ã CYR SMALL ZHE -ÿ CYR SMALL ZE -ê CYR SMALL I -ì CYR SMALL KA -í CYR SMALL EL -î CYR SMALL EM -ï CYR SMALL EN -ð CYR SMALL O -ò CYR SMALL PE -ô CYR SMALL ER -õ CYR SMALL ES -æ CYR SMALL TE -è CYR SMALL U -ö CYR SMALL EF -é CYR SMALL HA -ç CYR SMALL TSE -à CYR SMALL CHE -ù CYR SMALL SHA -ü CYR SMALL SCHA -ñ CYR SMALL HARD SIGN -ý CYR SMALL YERU -û CYR SMALL SOFT SIGN -ø CYR SMALL E -á CYR SMALL YU -ó CYR SMALL YA -Â CYR CAPIT A -× CYR CAPIT BE -Þ CYR CAPIT VE -Ú CYR CAPIT GE -Ä CYR CAPIT DE -Å CYR CAPIT IE -? CYR CAPIT IO -Ã CYR CAPIT ZHE -ß CYR CAPIT ZE -Ê CYR CAPIT I -Ì CYR CAPIT KA -Í CYR CAPIT EL -Î CYR CAPIT EM -Ï CYR CAPIT EN -Ð CYR CAPIT O -Ò CYR CAPIT PE -Ô CYR CAPIT ER -Õ CYR CAPIT ES -Æ CYR CAPIT TE -È CYR CAPIT U -Ö CYR CAPIT EF -É CYR CAPIT HA -Ç CYR CAPIT TSE -À CYR CAPIT CHE -Ù CYR CAPIT SHA -Ü CYR CAPIT SCHA -Ñ CYR CAPIT HARD SIGN -Ý CYR CAPIT YERU -Û CYR CAPIT SOFT SIGN -Ø CYR CAPIT E -Á CYR CAPIT YU -Ó CYR CAPIT YA -explain extended select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 116 -Warnings: -Note 1003 select high_priority convert(test.t1.koi8_ru_f,_latin1'utf8_general_ci',_latin1'cp1251_general_ci') AS `CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci')`,test.t1.comment AS `comment` from test.t1 ALTER TABLE t1 ADD bin_f CHAR(32) BYTE NOT NULL; UPDATE t1 SET bin_f=koi8_ru_f; SELECT COUNT(DISTINCT bin_f),COUNT(DISTINCT koi8_ru_f),COUNT(DISTINCT utf8_f) FROM t1; diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 658a7b8f5f6..8b7178993a7 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -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 diff --git a/mysql-test/r/func_system.result b/mysql-test/r/func_system.result index a0437ca1c56..338902e3f3a 100644 --- a/mysql-test/r/func_system.result +++ b/mysql-test/r/func_system.result @@ -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 diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index fd9e2a1f42b..0e642f48f3c 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -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; diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 71bc803f576..194ef7d5612 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -266,3 +266,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; diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index ab0242990fc..fab35bb334a 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -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; diff --git a/mysql-test/t/ctype_many.test b/mysql-test/t/ctype_many.test index 7b44439aa50..26057e7c997 100644 --- a/mysql-test/t/ctype_many.test +++ b/mysql-test/t/ctype_many.test @@ -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; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 0615de99b7a..49b1ed94757 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -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)); diff --git a/mysql-test/t/func_system.test b/mysql-test/t/func_system.test index f3b9b4ffc3f..a05b80ca56b 100644 --- a/mysql-test/t/func_system.test +++ b/mysql-test/t/func_system.test @@ -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; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index d262f02c978..1d64cfd2105 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -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; diff --git a/sql-common/client.c b/sql-common/client.c index 3902e9b3e1d..af64bb2b210 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -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 }; diff --git a/sql/item.cc b/sql/item.cc index 78d4224cac8..d0502b30d88 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -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; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index fd1222d5f1a..ed6e44262c7 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -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; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 465300e721e..4832ddbd1b1 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -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 }; }; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 39851838cb2..e17847ebe24 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -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); diff --git a/sql/sql_class.h b/sql/sql_class.h index 2638d633e8f..b7ef30b4e79 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -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 diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 58dc334b86e..f37f133f105 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -203,6 +203,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 */ @@ -215,6 +232,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; @@ -442,7 +466,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() @@ -692,37 +715,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) @@ -731,9 +731,18 @@ int yylex(void *arg, void *yythd) double_quotes++; continue; } - if (c == (uchar) NAMES_SEP_CHAR) - break; } +#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, @@ -915,8 +924,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 diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7a0ddc3c5c8..ae507c34272 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -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)) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 3a5f260bf0f..158d9b1acb0 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -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; iident_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 (; curvariables.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); + } } } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c2f46c9999e..3b593e57d82 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -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 && diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index cf56c9c2074..4c217b325ec 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -3636,8 +3636,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 ')' diff --git a/tests/client_test.c b/tests/client_test.c index b7ba580438f..6792652b708 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -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,29 +5595,26 @@ 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); + /* 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); - stmt = mysql_prepare(mysql,"insert into test_pure(c2) values(10)",100); - mystmt_init(stmt); - - rc = mysql_bind_param(stmt, bind); - mystmt_r(stmt, rc); - - mysql_stmt_close(stmt); -#endif - - stmt = mysql_prepare(mysql,"insert into test_pure(c2) values(?)",100); - mystmt_init(stmt); - -#ifndef DBUG_OFF rc = mysql_execute(stmt); - mystmt_r(stmt, rc);/* No parameters supplied */ -#endif + mystmt(stmt, rc); + + rc = mysql_bind_result(stmt, (MYSQL_BIND*)0); + mystmt(stmt, rc); + + mysql_stmt_close(stmt); + + stmt = mysql_simple_prepare(mysql,"insert into test_pure(c2) values(?)"); + mystmt_init(stmt); bind[0].length= &length; bind[0].is_null= 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);