diff options
-rw-r--r-- | client/mysqltest.c | 90 | ||||
-rw-r--r-- | include/mysql_com.h | 6 | ||||
-rw-r--r-- | mysql-test/r/mysqltest.result | 7 | ||||
-rw-r--r-- | mysql-test/t/client_test.test | 2 | ||||
-rw-r--r-- | mysql-test/t/comments.test | 3 | ||||
-rw-r--r-- | mysql-test/t/join_outer.test | 15 | ||||
-rw-r--r-- | mysql-test/t/key.test | 3 | ||||
-rw-r--r-- | mysql-test/t/mysqltest.test | 97 | ||||
-rw-r--r-- | mysql-test/t/show_check.test | 3 | ||||
-rw-r--r-- | mysql-test/t/temp_table.test | 6 | ||||
-rw-r--r-- | mysql-test/t/type_ranges.test | 3 | ||||
-rw-r--r-- | sql/mysqld.cc | 4 | ||||
-rw-r--r-- | sql/net_serv.cc | 12 | ||||
-rw-r--r-- | sql/protocol.cc | 9 | ||||
-rw-r--r-- | sql/protocol.h | 1 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 26 | ||||
-rw-r--r-- | sql/sql_show.cc | 6 | ||||
-rw-r--r-- | tests/client_test.c | 1107 |
18 files changed, 837 insertions, 563 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index 21f93b1fc6a..aef36823dfc 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -42,7 +42,7 @@ **********************************************************************/ -#define MTEST_VERSION "2.3" +#define MTEST_VERSION "2.4" #include <my_global.h> #include <mysql_embed.h> @@ -243,8 +243,7 @@ VAR var_reg[10]; HASH var_hash; my_bool disable_query_log=0, disable_result_log=0, disable_warnings=0; my_bool disable_info= 1; /* By default off */ -/* default for disable_abort_on_error: false = abort on unmasked error */ -my_bool disable_abort_on_error= 0; +my_bool abort_on_error= 1; struct connection cons[MAX_CONS]; struct connection* cur_con, *next_con, *cons_end; @@ -370,7 +369,7 @@ const char *command_names[]= }; TYPELIB command_typelib= {array_elements(command_names),"", - command_names}; + command_names, 0}; DYNAMIC_STRING ds_res; static void die(const char *fmt, ...); @@ -744,7 +743,7 @@ err: DBUG_RETURN(0); } -static VAR* var_obtain(char* name, int len) +static VAR *var_obtain(const char* name, int len) { VAR* v; if ((v = (VAR*)hash_search(&var_hash, name, len))) @@ -754,28 +753,33 @@ static VAR* var_obtain(char* name, int len) return v; } -int var_set(char* var_name, char* var_name_end, char* var_val, - char* var_val_end) +int var_set(const char *var_name, const char *var_name_end, + const char *var_val, const char *var_val_end) { int digit; VAR* v; + DBUG_ENTER("var_set"); + DBUG_PRINT("enter", ("var_name: '%.*s' = '%.*s' (length: %d)", + (int) (var_name_end - var_name), var_name, + (int) (var_val_end - var_val), var_val, + (int) (var_val_end - var_val))); + if (*var_name++ != '$') - { - --var_name; - *var_name_end = 0; - die("Variable name in %s does not start with '$'", var_name); - } + { + var_name--; + die("Variable name in %s does not start with '$'", var_name); + } digit = *var_name - '0'; if (!(digit < 10 && digit >= 0)) - { - v = var_obtain(var_name, var_name_end - var_name); - } + { + v = var_obtain(var_name, (uint) (var_name_end - var_name)); + } else - v = var_reg + digit; - + v = var_reg + digit; return eval_expr(v, var_val, (const char**)&var_val_end); } + int open_file(const char* name) { char buff[FN_REFLEN]; @@ -1244,18 +1248,22 @@ int do_let(struct st_query* q) return var_set(var_name, var_name_end, var_val_start, q->end); } -/* Store an integer (typically the returncode of the last SQL) */ -/* statement in the mysqltest builtin variable $mysql_errno, by */ -/* simulating of a user statement "let $mysql_errno= <integer>" */ -int var_set_errno(int sql_errno ) + +/* + Store an integer (typically the returncode of the last SQL) + statement in the mysqltest builtin variable $mysql_errno, by + simulating of a user statement "let $mysql_errno= <integer>" +*/ + +int var_set_errno(int sql_errno) { - char var_name[] = "$mysql_errno", var_val[30]; - sprintf(var_val, "%d", sql_errno); - /* On some odd systems, the return value from sprintf() isn't */ - /* always the length of the string, so we use strlen() */ - return var_set(var_name, var_name + 12, var_val, var_val + strlen(var_val)); + const char *var_name= "$mysql_errno"; + char var_val[21]; + uint length= my_sprintf(var_val, (var_val, "%d", sql_errno)); + return var_set(var_name, var_name + 12, var_val, var_val + length); } + int do_rpl_probe(struct st_query* q __attribute__((unused))) { DBUG_ENTER("do_rpl_probe"); @@ -1264,12 +1272,14 @@ int do_rpl_probe(struct st_query* q __attribute__((unused))) DBUG_RETURN(0); } + int do_enable_rpl_parse(struct st_query* q __attribute__((unused))) { mysql_enable_rpl_parse(&cur_con->mysql); return 0; } + int do_disable_rpl_parse(struct st_query* q __attribute__((unused))) { mysql_disable_rpl_parse(&cur_con->mysql); @@ -2013,7 +2023,7 @@ int read_query(struct st_query** q_ptr) memcpy((gptr) q->expected_errno, (gptr) global_expected_errno, sizeof(global_expected_errno)); q->expected_errors= global_expected_errors; - q->abort_on_error= (global_expected_errors == 0 && !disable_abort_on_error); + q->abort_on_error= (global_expected_errors == 0 && abort_on_error); bzero((gptr) global_expected_errno, sizeof(global_expected_errno)); global_expected_errors=0; if (p[0] == '-' && p[1] == '-') @@ -2422,7 +2432,7 @@ static int run_query(MYSQL *mysql, struct st_query *q, int flags) if (ps_protocol_enabled && disable_info && (flags & QUERY_SEND) && (flags & QUERY_REAP) && ps_match_re(q->query)) - return run_query_stmt (mysql, q, flags); + return run_query_stmt(mysql, q, flags); return run_query_normal(mysql, q, flags); } @@ -2659,9 +2669,12 @@ end: dynstr_free(&ds_tmp); if (q->type == Q_EVAL) dynstr_free(&eval_query); - /* We save the return code (mysql_errno(mysql)) from the last call sent */ - /* to the server into the mysqltest builtin variable $mysql_errno. This */ - /* variable then can be used from the test case itself. */ + + /* + We save the return code (mysql_errno(mysql)) from the last call sent + to the server into the mysqltest builtin variable $mysql_errno. This + variable then can be used from the test case itself. + */ var_set_errno(mysql_errno(mysql)); DBUG_RETURN(error); } @@ -3012,6 +3025,7 @@ end: dynstr_free(&ds_tmp); if (q->type == Q_EVAL) dynstr_free(&eval_query); + var_set_errno(mysql_stmt_errno(stmt)); mysql_stmt_close(stmt); DBUG_RETURN(error); } @@ -3319,7 +3333,7 @@ static VAR* var_from_env(const char *name, const char *def_val) if (!(tmp = getenv(name))) tmp = def_val; - v = var_init(0, name, 0, tmp, 0); + v = var_init(0, name, strlen(name), tmp, strlen(tmp)); my_hash_insert(&var_hash, (byte*)v); return v; } @@ -3416,9 +3430,11 @@ int main(int argc, char **argv) init_var_hash(&cur_con->mysql); - /* Initialize $mysql_errno with -1, so we can */ - /* - distinguish it from valid values ( >= 0 ) and */ - /* - detect if there was never a command sent to the server */ + /* + Initialize $mysql_errno with -1, so we can + - distinguish it from valid values ( >= 0 ) and + - detect if there was never a command sent to the server + */ var_set_errno(-1); while (!read_query(&q)) @@ -3440,8 +3456,8 @@ int main(int argc, char **argv) case Q_DISABLE_RPL_PARSE: do_disable_rpl_parse(q); break; case Q_ENABLE_QUERY_LOG: disable_query_log=0; break; case Q_DISABLE_QUERY_LOG: disable_query_log=1; break; - case Q_ENABLE_ABORT_ON_ERROR: disable_abort_on_error=0; break; - case Q_DISABLE_ABORT_ON_ERROR: disable_abort_on_error=1; break; + case Q_ENABLE_ABORT_ON_ERROR: abort_on_error=1; break; + case Q_DISABLE_ABORT_ON_ERROR: abort_on_error=0; break; case Q_ENABLE_RESULT_LOG: disable_result_log=0; break; case Q_DISABLE_RESULT_LOG: disable_result_log=1; break; case Q_ENABLE_WARNINGS: disable_warnings=0; break; diff --git a/include/mysql_com.h b/include/mysql_com.h index 4686acc098f..6a6136bd974 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -282,13 +282,7 @@ void my_net_local_init(NET *net); void net_end(NET *net); void net_clear(NET *net); my_bool net_realloc(NET *net, unsigned long length); - -#ifndef EMBEDDED_LIBRARY /* To be removed by HF */ my_bool net_flush(NET *net); -#else -#define net_flush(A) -#endif - my_bool my_net_write(NET *net,const char *packet,unsigned long len); my_bool net_write_command(NET *net,unsigned char command, const char *header, unsigned long head_len, diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 5dc9ede1ca6..d75dbd5d00c 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -7,11 +7,6 @@ otto select otto from (select 1 as otto) as t1; otto 1 -select otto from (select 1 as otto) as t1; -otto -1 -select friedrich from (select 1 as otto) as t1; -ERROR 42S22: Unknown column 'friedrich' in 'field list' select friedrich from (select 1 as otto) as t1; ERROR 42S22: Unknown column 'friedrich' in 'field list' select otto from (select 1 as otto) as t1; @@ -147,5 +142,3 @@ after_--enable_abort_on_error 1064 select 3 from t1 ; ERROR 42S02: Table 'test.t1' doesn't exist -select 3 from t1 ; -ERROR 42S02: Table 'test.t1' doesn't exist diff --git a/mysql-test/t/client_test.test b/mysql-test/t/client_test.test index b56e8038d9b..830c5f1b8a2 100644 --- a/mysql-test/t/client_test.test +++ b/mysql-test/t/client_test.test @@ -1,2 +1,2 @@ --disable_result_log ---exec $TESTS_BINDIR/client_test --testcase --user=root --socket=$MASTER_MYSOCK --port=$MYSQL_TCP_PORT +--exec $TESTS_BINDIR/client_test --testcase --user=root --socket=$MASTER_MYSOCK --port=$MYSQL_TCP_PORT --silent diff --git a/mysql-test/t/comments.test b/mysql-test/t/comments.test index 2fc6237907c..087df60f3f5 100644 --- a/mysql-test/t/comments.test +++ b/mysql-test/t/comments.test @@ -5,7 +5,8 @@ select 1+2/*hello*/+3; select 1 /* long multi line comment */; -!$1065 ; +--error 1065 + ; select 1 /*!32301 +1 */; select 1 /*!52301 +1 */; select 1--1; diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index 0c4c9614d88..bc96318ae2e 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -34,11 +34,14 @@ explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a); # The next query should rearange the left joins to get this to work -!$1120 explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); -!$1120 select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); +--error 1120 +explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); +--error 1120 +select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); # The next query should give an error in MySQL -!$1120 select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a); +--error 1120 +select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a); # Test of inner join select t1.*,t2.* from t1 inner join t2 using (a); @@ -94,7 +97,8 @@ WHERE t1.uniq_id = 4 ORDER BY t2.c_amount; INSERT INTO t2 VALUES (2,3,3000,6000,0,0,746584,837484,'yes'); -!$1062 INSERT INTO t2 VALUES (2,3,3000,6000,0,0,746584,837484,'yes'); +--error 1062 +INSERT INTO t2 VALUES (2,3,3000,6000,0,0,746584,837484,'yes'); INSERT INTO t2 VALUES (7,3,1000,2000,0,0,746294,937484,'yes'); #3rd select should show that one record is returned with null entries for the @@ -288,7 +292,8 @@ insert into t3 values (1); insert into t4 values (1,1); insert into t5 values (1,1); -!$1120 explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23; +--error 1120 +explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23; drop table t1,t2,t3,t4,t5; diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index 4be34cac30e..5ee2f68ab83 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -146,7 +146,8 @@ create table t1 ); INSERT INTO t1 VALUES (1, 1, 1, 1, 'a'); INSERT INTO t1 VALUES (1, 1, 1, 1, 'b'); -!$1062 INSERT INTO t1 VALUES (1, 1, 1, 1, 'a'); +--error 1062 +INSERT INTO t1 VALUES (1, 1, 1, 1, 'a'); drop table t1; # diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index b7007e1a519..0802c18ed6c 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -20,12 +20,10 @@ eval select $mysql_errno as "before_use_test" ; select otto from (select 1 as otto) as t1; # expectation = response -!$0 select otto from (select 1 as otto) as t1; --error 0 select otto from (select 1 as otto) as t1; # expectation <> response --- // !$1054 select otto from (select 1 as otto) as t1; -- // --error 1054 -- // select otto from (select 1 as otto) as t1; @@ -38,12 +36,10 @@ select otto from (select 1 as otto) as t1; # ---------------------------------------------------------------------------- # expectation <> response -#!$0 select friedrich from (select 1 as otto) as t1; #--error 0 #select friedrich from (select 1 as otto) as t1; # expectation = response -!$1054 select friedrich from (select 1 as otto) as t1; --error 1054 select friedrich from (select 1 as otto) as t1; @@ -94,130 +90,130 @@ select friedrich from (select 1 as otto) as t1; # # The following test cases often initialize $mysql_errno to 1064 by # a command with wrong syntax. -# Example: !$1064 To prevent the abort after the error. +# Example: --error 1064 To prevent the abort after the error. # garbage ; # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# 1. check mysql_errno = 0 after successful statement +# check mysql_errno = 0 after successful statement # ---------------------------------------------------------------------------- select otto from (select 1 as otto) as t1; eval select $mysql_errno as "after_successful_stmt_errno" ; #---------------------------------------------------------------------------- -# 2. check mysql_errno = 1064 after statement with wrong syntax +# check mysql_errno = 1064 after statement with wrong syntax # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; eval select $mysql_errno as "after_wrong_syntax_errno" ; # ---------------------------------------------------------------------------- -# 3. check if let $my_var= 'abc' ; affects $mysql_errno +# check if let $my_var= 'abc' ; affects $mysql_errno # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; let $my_var= 'abc' ; eval select $mysql_errno as "after_let_var_equal_value" ; # ---------------------------------------------------------------------------- -# 4. check if set @my_var= 'abc' ; affects $mysql_errno +# check if set @my_var= 'abc' ; affects $mysql_errno # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; set @my_var= 'abc' ; eval select $mysql_errno as "after_set_var_equal_value" ; # ---------------------------------------------------------------------------- -# 5. check if the setting of --disable-warnings itself affects $mysql_errno -# (May be --<whatever> modifies $mysql_errno.) +# check if the setting of --disable-warnings itself affects $mysql_errno +# (May be --<whatever> modifies $mysql_errno.) # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; --disable_warnings eval select $mysql_errno as "after_disable_warnings_command" ; # ---------------------------------------------------------------------------- -# 6. check if --disable-warnings + command with warning affects the errno -# stored within $mysql_errno -# (May be disabled warnings affect $mysql_errno.) +# check if --disable-warnings + command with warning affects the errno +# stored within $mysql_errno +# (May be disabled warnings affect $mysql_errno.) # ---------------------------------------------------------------------------- drop table if exists t1 ; -!$1064 +--error 1064 garbage ; drop table if exists t1 ; eval select $mysql_errno as "after_disable_warnings" ; --enable_warnings # ---------------------------------------------------------------------------- -# 7. check if masked errors affect $mysql_errno +# check if masked errors affect $mysql_errno # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; --error 1146 select 3 from t1 ; eval select $mysql_errno as "after_minus_masked" ; -!$1064 +--error 1064 garbage ; -!$1146 +--error 1146 select 3 from t1 ; eval select $mysql_errno as "after_!_masked" ; # ---------------------------------------------------------------------------- -# 8. Will manipulations of $mysql_errno be possible and visible ? +# Will manipulations of $mysql_errno be possible and visible ? # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; let $mysql_errno= -1; eval select $mysql_errno as "after_let_errno_equal_value" ; # ---------------------------------------------------------------------------- -# 9. How affect actions on prepared statements $mysql_errno ? +# How affect actions on prepared statements $mysql_errno ? # ---------------------------------------------------------------------------- # failing prepare -!$1064 +--error 1064 garbage ; -!$1146 +--error 1146 prepare stmt from "select 3 from t1" ; eval select $mysql_errno as "after_failing_prepare" ; create table t1 ( f1 char(10)); # successful prepare -!$1064 +--error 1064 garbage ; prepare stmt from "select 3 from t1" ; eval select $mysql_errno as "after_successful_prepare" ; # successful execute -!$1064 +--error 1064 garbage ; execute stmt; eval select $mysql_errno as "after_successful_execute" ; # failing execute (table dropped) drop table t1; -!$1064 +--error 1064 garbage ; -!$1146 +--error 1146 execute stmt; eval select $mysql_errno as "after_failing_execute" ; # failing execute (unknown statement) -!$1064 +--error 1064 garbage ; -!$1243 +--error 1243 execute __stmt_; eval select $mysql_errno as "after_failing_execute" ; # successful deallocate -!$1064 +--error 1064 garbage ; deallocate prepare stmt; eval select $mysql_errno as "after_successful_deallocate" ; # failing deallocate ( statement handle does not exist ) -!$1064 +--error 1064 garbage ; -!$1243 +--error 1243 deallocate prepare __stmt_; eval select $mysql_errno as "after_failing_deallocate" ; @@ -231,7 +227,7 @@ eval select $mysql_errno as "after_failing_deallocate" ; # The default is "--enable_abort_on_error". # # "Maskings" are -# !$<error number> and --error <error number> +# --error <error number> and --error <error number> # in the line before the failing statement. # # There are some additional test case for $mysql_errno @@ -240,58 +236,53 @@ eval select $mysql_errno as "after_failing_deallocate" ; # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# 1. Switch the abort on error off and check the effect on $mysql_errno +# Switch the abort on error off and check the effect on $mysql_errno # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; --disable_abort_on_error eval select $mysql_errno as "after_--disable_abort_on_error" ; # ---------------------------------------------------------------------------- -# 2. "unmasked" failing statement should not cause an abort +# "unmasked" failing statement should not cause an abort # ---------------------------------------------------------------------------- select 3 from t1 ; # ---------------------------------------------------------------------------- -# 3. masked failing statements +# masked failing statements # ---------------------------------------------------------------------------- # expected error = response --error 1146 select 3 from t1 ; -!$1146 +--error 1146 select 3 from t1 ; eval select $mysql_errno as "after_!errno_masked_error" ; # expected error <> response # --error 1000 # select 3 from t1 ; -# !$1000 +# --error 1000 # select 3 from t1 ; # ---------------------------------------------------------------------------- -# 4. Switch the abort on error on and check the effect on $mysql_errno +# Switch the abort on error on and check the effect on $mysql_errno # ---------------------------------------------------------------------------- -!$1064 +--error 1064 garbage ; --enable_abort_on_error eval select $mysql_errno as "after_--enable_abort_on_error" ; # ---------------------------------------------------------------------------- -# 5. masked failing statements +# masked failing statements # ---------------------------------------------------------------------------- # expected error = response --error 1146 select 3 from t1 ; -!$1146 -select 3 from t1 ; # ---------------------------------------------------------------------------- -# 6. check that the old default behaviour is not changed +# check that the old default behaviour is not changed # Please remove the '#' to get the abort on error # ---------------------------------------------------------------------------- #--error 1064 #select 3 from t1 ; # -#!$1064 -#select 3 from t1 ; -# #select 3 from t1 ; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index 681127eab5e..efbe2e9371d 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -21,7 +21,8 @@ check table t1 changed; check table t1 medium; check table t1 extended; show index from t1; -!$1062 insert into t1 values (5,5,5); +--error 1062 +insert into t1 values (5,5,5); optimize table t1; optimize table t1; drop table t1; diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test index 2181d3eb74c..74276c7668c 100644 --- a/mysql-test/t/temp_table.test +++ b/mysql-test/t/temp_table.test @@ -20,8 +20,10 @@ create TEMPORARY TABLE t2 engine=heap select * from t1; create TEMPORARY TABLE IF NOT EXISTS t2 (a int) engine=heap; # This should give errors -!$1050 CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null); -!$1050 ALTER TABLE t1 RENAME t2; +--error 1050 +CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null); +--error 1050 +ALTER TABLE t1 RENAME t2; select * from t2; alter table t2 add primary key (a,b); diff --git a/mysql-test/t/type_ranges.test b/mysql-test/t/type_ranges.test index 09b5867e7a8..572dc0af313 100644 --- a/mysql-test/t/type_ranges.test +++ b/mysql-test/t/type_ranges.test @@ -135,7 +135,8 @@ drop table t1,t2; create table t1 (c int); insert into t1 values(1),(2); create table t2 select * from t1; -!$1060 create table t3 select * from t1, t2; # Should give an error +--error 1060 +create table t3 select * from t1, t2; # Should give an error create table t3 select t1.c AS c1, t2.c AS c2,1 as "const" from t1, t2; show full columns from t3; drop table t1,t2,t3; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7062334edbb..d06aba3387e 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5026,12 +5026,12 @@ The minimum value for this variable is 4096.", "Persistent buffer for query parsing and execution", (gptr*) &global_system_variables.query_prealloc_size, (gptr*) &max_system_variables.query_prealloc_size, 0, GET_ULONG, - REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, 1024, ~0L, 0, 1024, 0}, + REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, 16384, ~0L, 0, 1024, 0}, {"range_alloc_block_size", OPT_RANGE_ALLOC_BLOCK_SIZE, "Allocation block size for storing ranges during optimization", (gptr*) &global_system_variables.range_alloc_block_size, (gptr*) &max_system_variables.range_alloc_block_size, 0, GET_ULONG, - REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, 1024, ~0L, 0, 1024, 0}, + REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, 4096, ~0L, 0, 1024, 0}, {"read_buffer_size", OPT_RECORD_BUFFER, "Each thread that does a sequential scan allocates a buffer of this size for each table it scans. If you do many sequential scans, you may want to increase this value.", (gptr*) &global_system_variables.read_buff_size, diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 457b2052a45..5985cf63ed6 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -53,19 +53,9 @@ #include <errno.h> #ifdef EMBEDDED_LIBRARY - #undef MYSQL_SERVER - -#ifndef MYSQL_CLIENT +#undef MYSQL_CLIENT #define MYSQL_CLIENT -#endif - -#undef net_flush - -extern "C" { -my_bool net_flush(NET *net); -} - #endif /*EMBEDDED_LIBRARY */ diff --git a/sql/protocol.cc b/sql/protocol.cc index 598d102ec29..eaa0fd55b25 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -470,6 +470,15 @@ void Protocol::init(THD *thd_arg) } +bool Protocol::flush() +{ +#ifndef EMBEDDED_LIBRARY + return net_flush(&thd->net); +#else + return 0; +#endif +} + /* Send name and type of result to client. diff --git a/sql/protocol.h b/sql/protocol.h index d7ce5425ad1..a3b6da55da3 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -75,6 +75,7 @@ public: field_count=item_list->elements; return 0; } + virtual bool flush(); virtual void prepare_for_resend()=0; virtual bool store_null()=0; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index b5e12c4d208..4ae69e40342 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -153,6 +153,8 @@ static bool send_prep_stmt(Prepared_statement *stmt, uint columns) { NET *net= &stmt->thd->net; char buff[9]; + DBUG_ENTER("send_prep_stmt"); + buff[0]= 0; /* OK packet indicator */ int4store(buff+1, stmt->id); int2store(buff+5, columns); @@ -161,12 +163,11 @@ static bool send_prep_stmt(Prepared_statement *stmt, uint columns) Send types and names of placeholders to the client XXX: fix this nasty upcast from List<Item_param> to List<Item> */ - return my_net_write(net, buff, sizeof(buff)) || - (stmt->param_count && - stmt->thd->protocol_simple.send_fields((List<Item> *) - &stmt->lex->param_list, 0)) || - net_flush(net); - return 0; + DBUG_RETURN(my_net_write(net, buff, sizeof(buff)) || + (stmt->param_count && + stmt->thd->protocol_simple.send_fields((List<Item> *) + &stmt->lex->param_list, + 0))); } #else static bool send_prep_stmt(Prepared_statement *stmt, @@ -1088,7 +1089,7 @@ static int mysql_test_select(Prepared_statement *stmt, { if (lex->describe) { - if (send_prep_stmt(stmt, 0)) + if (send_prep_stmt(stmt, 0) || thd->protocol->flush()) goto err_prep; } else @@ -1106,11 +1107,8 @@ static int mysql_test_select(Prepared_statement *stmt, prepared in unit->prepare call above. */ if (send_prep_stmt(stmt, lex->result->field_count(fields)) || - lex->result->send_fields(fields, 0) -#ifndef EMBEDDED_LIBRARY - || net_flush(&thd->net) -#endif - ) + lex->result->send_fields(fields, 0) || + thd->protocol->flush()) goto err_prep; } } @@ -1389,7 +1387,6 @@ static int send_prepare_results(Prepared_statement *stmt, bool text_protocol) enum enum_sql_command sql_command= lex->sql_command; int res= 0; DBUG_ENTER("send_prepare_results"); - DBUG_PRINT("enter",("command: %d, param_count: %ld", sql_command, stmt->param_count)); @@ -1475,7 +1472,8 @@ static int send_prepare_results(Prepared_statement *stmt, bool text_protocol) goto error; } if (res == 0) - DBUG_RETURN(text_protocol? 0 : send_prep_stmt(stmt, 0)); + DBUG_RETURN(text_protocol? 0 : (send_prep_stmt(stmt, 0) || + thd->protocol->flush())); error: if (res < 0) send_error(thd, thd->killed ? ER_SERVER_SHUTDOWN : 0); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 2af4cb3fc23..bda490e2916 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1081,7 +1081,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild) restore_record(table,default_values); // Get empty record if (thd->protocol->send_fields(&field_list,2)) DBUG_VOID_RETURN; - net_flush(&thd->net); + thd->protocol->flush(); DBUG_VOID_RETURN; } @@ -1098,13 +1098,11 @@ mysqld_dump_create_info(THD *thd, TABLE *table, int fd) if (store_create_info(thd, table, packet)) DBUG_RETURN(-1); - //if (protocol->convert) - // protocol->convert->convert((char*) packet->ptr(), packet->length()); if (fd < 0) { if (protocol->write()) DBUG_RETURN(-1); - net_flush(&thd->net); + protocol->flush(); } else { diff --git a/tests/client_test.c b/tests/client_test.c index 48676ae7e12..70e1b26aeaa 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (C) 2003-2004 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ #include <my_getopt.h> #include <m_string.h> +#define VER "2.0" #define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ /* set default options */ @@ -37,7 +38,7 @@ static char *opt_password= 0; static char *opt_host= 0; static char *opt_unix_socket= 0; static unsigned int opt_port; -static my_bool tty_password= 0; +static my_bool tty_password= 0, opt_silent= 0; static MYSQL *mysql= 0; static char query[MAX_TEST_QUERY_LENGTH]; @@ -52,6 +53,7 @@ static double total_time; const char *default_dbug_option= "d:t:o,/tmp/client_test.trace"; #define myheader(str) \ +if (opt_silent < 2) \ { \ fprintf(stdout, "\n\n#####################################\n"); \ fprintf(stdout, "%d of (%d/%d): %s", test_count++, iter_count, \ @@ -59,6 +61,7 @@ const char *default_dbug_option= "d:t:o,/tmp/client_test.trace"; fprintf(stdout, " \n#####################################\n"); \ } #define myheader_r(str) \ +if (!opt_silent) \ { \ fprintf(stdout, "\n\n#####################################\n"); \ fprintf(stdout, "%s", str); \ @@ -144,32 +147,39 @@ DIE_UNLESS(stmt == 0);\ static void print_error(const char *msg) { - if (mysql && mysql_errno(mysql)) + if (!opt_silent) { - if (mysql->server_version) - fprintf(stdout, "\n [MySQL-%s]", mysql->server_version); - else - fprintf(stdout, "\n [MySQL]"); - fprintf(stdout, "[%d] %s\n", mysql_errno(mysql), mysql_error(mysql)); + if (mysql && mysql_errno(mysql)) + { + if (mysql->server_version) + fprintf(stdout, "\n [MySQL-%s]", mysql->server_version); + else + fprintf(stdout, "\n [MySQL]"); + fprintf(stdout, "[%d] %s\n", mysql_errno(mysql), mysql_error(mysql)); + } + else if (msg) + fprintf(stderr, " [MySQL] %s\n", msg); } - else if (msg) fprintf(stderr, " [MySQL] %s\n", msg); } static void print_st_error(MYSQL_STMT *stmt, const char *msg) { - if (stmt && mysql_stmt_errno(stmt)) + if (!opt_silent) { - if (stmt->mysql && stmt->mysql->server_version) - fprintf(stdout, "\n [MySQL-%s]", stmt->mysql->server_version); - else - fprintf(stdout, "\n [MySQL]"); + if (stmt && mysql_stmt_errno(stmt)) + { + if (stmt->mysql && stmt->mysql->server_version) + fprintf(stdout, "\n [MySQL-%s]", stmt->mysql->server_version); + else + fprintf(stdout, "\n [MySQL]"); - fprintf(stdout, "[%d] %s\n", mysql_stmt_errno(stmt), - mysql_stmt_error(stmt)); + fprintf(stdout, "[%d] %s\n", mysql_stmt_errno(stmt), + mysql_stmt_error(stmt)); + } + else if (msg) + fprintf(stderr, " [MySQL] %s\n", msg); } - else if (msg) - fprintf(stderr, " [MySQL] %s\n", msg); } @@ -198,8 +208,9 @@ static void client_connect() int rc; myheader_r("client_connect"); - fprintf(stdout, "\n Establishing a connection to '%s' ...", - opt_host ? opt_host : ""); + if (!opt_silent) + fprintf(stdout, "\n Establishing a connection to '%s' ...", + opt_host ? opt_host : ""); if (!(mysql= mysql_init(NULL))) { @@ -217,12 +228,14 @@ static void client_connect() exit(1); } - fprintf(stdout, " OK"); + if (!opt_silent) + fprintf(stdout, " OK"); /* set AUTOCOMMIT to ON*/ mysql_autocommit(mysql, TRUE); - fprintf(stdout, "\n Creating a test database '%s' ...", current_db); + if (!opt_silent) + fprintf(stdout, "\n Creating a test database '%s' ...", current_db); strxmov(query, "CREATE DATABASE IF NOT EXISTS ", current_db, NullS); rc= mysql_query(mysql, query); @@ -232,7 +245,8 @@ static void client_connect() rc= mysql_query(mysql, query); myquery(rc); - fprintf(stdout, " OK"); + if (!opt_silent) + fprintf(stdout, " OK"); } @@ -244,13 +258,16 @@ static void client_disconnect() if (mysql) { - fprintf(stdout, "\n dropping the test database '%s' ...", current_db); + if (!opt_silent) + fprintf(stdout, "\n dropping the test database '%s' ...", current_db); strxmov(query, "DROP DATABASE IF EXISTS ", current_db, NullS); mysql_query(mysql, query); - fprintf(stdout, " OK"); + if (!opt_silent) + fprintf(stdout, " OK"); - fprintf(stdout, "\n closing the connection ..."); + if (!opt_silent) + fprintf(stdout, "\n closing the connection ..."); mysql_close(mysql); fprintf(stdout, " OK\n"); } @@ -331,8 +348,11 @@ static void my_print_result_metadata(MYSQL_RES *result) unsigned int field_count; mysql_field_seek(result, 0); - fputc('\n', stdout); - fputc('\n', stdout); + if (!opt_silent) + { + fputc('\n', stdout); + fputc('\n', stdout); + } field_count= mysql_num_fields(result); for(i= 0; i< field_count; i++) @@ -345,18 +365,25 @@ static void my_print_result_metadata(MYSQL_RES *result) j= 4; field->max_length= j; } - my_print_dashes(result); - fputc('\t', stdout); - fputc('|', stdout); + if (!opt_silent) + { + my_print_dashes(result); + fputc('\t', stdout); + fputc('|', stdout); + } mysql_field_seek(result, 0); for(i= 0; i< field_count; i++) { field= mysql_fetch_field(result); - fprintf(stdout, " %-*s |", (int) field->max_length, field->name); + if (!opt_silent) + fprintf(stdout, " %-*s |", (int) field->max_length, field->name); + } + if (!opt_silent) + { + fputc('\n', stdout); + my_print_dashes(result); } - fputc('\n', stdout); - my_print_dashes(result); } @@ -377,31 +404,43 @@ int my_process_result_set(MYSQL_RES *result) while ((row= mysql_fetch_row(result)) != NULL) { mysql_field_seek(result, 0); - fputc('\t', stdout); - fputc('|', stdout); + if (!opt_silent) + { + fputc('\t', stdout); + fputc('|', stdout); + } for(i= 0; i< mysql_num_fields(result); i++) { field= mysql_fetch_field(result); - if (row[i] == NULL) - fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); - else if (IS_NUM(field->type)) - fprintf(stdout, " %*s |", (int) field->max_length, row[i]); - else - fprintf(stdout, " %-*s |", (int) field->max_length, row[i]); + if (!opt_silent) + { + if (row[i] == NULL) + fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); + else if (IS_NUM(field->type)) + fprintf(stdout, " %*s |", (int) field->max_length, row[i]); + else + fprintf(stdout, " %-*s |", (int) field->max_length, row[i]); + } + } + if (!opt_silent) + { + fputc('\t', stdout); + fputc('\n', stdout); } - fputc('\t', stdout); - fputc('\n', stdout); row_count++; } - if (row_count) - my_print_dashes(result); + if (!opt_silent) + { + if (row_count) + my_print_dashes(result); - if (mysql_errno(mysql) != 0) - fprintf(stderr, "\n\tmysql_fetch_row() failed\n"); - else - fprintf(stdout, "\n\t%d %s returned\n", row_count, - row_count == 1 ? "row" : "rows"); + if (mysql_errno(mysql) != 0) + fprintf(stderr, "\n\tmysql_fetch_row() failed\n"); + else + fprintf(stdout, "\n\t%d %s returned\n", row_count, + row_count == 1 ? "row" : "rows"); + } return row_count; } @@ -470,34 +509,44 @@ int my_process_stmt_result(MYSQL_STMT *stmt) mysql_field_seek(result, 0); while (mysql_stmt_fetch(stmt) == 0) { - fputc('\t', stdout); - fputc('|', stdout); - + if (!opt_silent) + { + fputc('\t', stdout); + fputc('|', stdout); + } mysql_field_seek(result, 0); for (i= 0; i < field_count; i++) { field= mysql_fetch_field(result); - if (is_null[i]) - fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); - else if (length[i] == 0) + if (!opt_silent) { - data[i][0]= '\0'; /* unmodified buffer */ - fprintf(stdout, " %*s |", (int) field->max_length, data[i]); + if (is_null[i]) + fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); + else if (length[i] == 0) + { + data[i][0]= '\0'; /* unmodified buffer */ + fprintf(stdout, " %*s |", (int) field->max_length, data[i]); + } + else if (IS_NUM(field->type)) + fprintf(stdout, " %*s |", (int) field->max_length, data[i]); + else + fprintf(stdout, " %-*s |", (int) field->max_length, data[i]); } - else if (IS_NUM(field->type)) - fprintf(stdout, " %*s |", (int) field->max_length, data[i]); - else - fprintf(stdout, " %-*s |", (int) field->max_length, data[i]); } - fputc('\t', stdout); - fputc('\n', stdout); + if (!opt_silent) + { + fputc('\t', stdout); + fputc('\n', stdout); + } row_count++; } - if (row_count) - my_print_dashes(result); - - fprintf(stdout, "\n\t%d %s returned\n", row_count, - row_count == 1 ? "row" : "rows"); + if (!opt_silent) + { + if (row_count) + my_print_dashes(result); + fprintf(stdout, "\n\t%d %s returned\n", row_count, + row_count == 1 ? "row" : "rows"); + } mysql_free_result(result); return row_count; } @@ -511,7 +560,8 @@ int my_stmt_result(const char *buff) int row_count; int rc; - fprintf(stdout, "\n\n %s", buff); + if (!opt_silent) + fprintf(stdout, "\n\n %s", buff); stmt= mysql_simple_prepare(mysql, buff); check_stmt(stmt); @@ -537,7 +587,8 @@ static void verify_col_data(const char *table, const char *col, if (table && col) { strxmov(query, "SELECT ", col, " FROM ", table, " LIMIT 1", NullS); - fprintf(stdout, "\n %s", query); + if (!opt_silent) + fprintf(stdout, "\n %s", query); rc= mysql_query(mysql, query); myquery(rc); @@ -565,10 +616,12 @@ static void verify_col_data(const char *table, const char *col, /* Utility function to verify the field members */ static void verify_prepare_field(MYSQL_RES *result, - unsigned int no, const char *name, const char *org_name, - enum enum_field_types type, const char *table, - const char *org_table, const char *db, - unsigned long length, const char *def) + unsigned int no, const char *name, + const char *org_name, + enum enum_field_types type, + const char *table, + const char *org_table, const char *db, + unsigned long length, const char *def) { MYSQL_FIELD *field; @@ -577,23 +630,26 @@ static void verify_prepare_field(MYSQL_RES *result, fprintf(stdout, "\n *** ERROR: FAILED TO GET THE RESULT ***"); exit(1); } - fprintf(stdout, "\n field[%d]:", no); - fprintf(stdout, "\n name :`%s`\t(expected: `%s`)", field->name, name); - fprintf(stdout, "\n org_name :`%s`\t(expected: `%s`)", - field->org_name, org_name); - fprintf(stdout, "\n type :`%d`\t(expected: `%d`)", field->type, type); - fprintf(stdout, "\n table :`%s`\t(expected: `%s`)", - field->table, table); - fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)", - field->org_table, org_table); - fprintf(stdout, "\n database :`%s`\t(expected: `%s`)", field->db, db); - fprintf(stdout, "\n length :`%ld`\t(expected: `%ld`)", - field->length, length); - fprintf(stdout, "\n maxlength:`%ld`", field->max_length); - fprintf(stdout, "\n charsetnr:`%d`", field->charsetnr); - fprintf(stdout, "\n default :`%s`\t(expected: `%s`)", - field->def ? field->def : "(null)", def ? def: "(null)"); - fprintf(stdout, "\n"); + if (!opt_silent) + { + fprintf(stdout, "\n field[%d]:", no); + fprintf(stdout, "\n name :`%s`\t(expected: `%s`)", field->name, name); + fprintf(stdout, "\n org_name :`%s`\t(expected: `%s`)", + field->org_name, org_name); + fprintf(stdout, "\n type :`%d`\t(expected: `%d`)", field->type, type); + fprintf(stdout, "\n table :`%s`\t(expected: `%s`)", + field->table, table); + fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)", + field->org_table, org_table); + fprintf(stdout, "\n database :`%s`\t(expected: `%s`)", field->db, db); + fprintf(stdout, "\n length :`%ld`\t(expected: `%ld`)", + field->length, length); + fprintf(stdout, "\n maxlength:`%ld`", field->max_length); + fprintf(stdout, "\n charsetnr:`%d`", field->charsetnr); + fprintf(stdout, "\n default :`%s`\t(expected: `%s`)", + field->def ? field->def : "(null)", def ? def: "(null)"); + fprintf(stdout, "\n"); + } DIE_UNLESS(strcmp(field->name, name) == 0); DIE_UNLESS(strcmp(field->org_name, org_name) == 0); DIE_UNLESS(field->type == type); @@ -611,8 +667,9 @@ static void verify_prepare_field(MYSQL_RES *result, static void verify_param_count(MYSQL_STMT *stmt, long exp_count) { long param_count= mysql_stmt_param_count(stmt); - fprintf(stdout, "\n total parameters in stmt: `%ld` (expected: `%ld`)", - param_count, exp_count); + if (!opt_silent) + fprintf(stdout, "\n total parameters in stmt: `%ld` (expected: `%ld`)", + param_count, exp_count); DIE_UNLESS(param_count == exp_count); } @@ -622,8 +679,9 @@ static void verify_param_count(MYSQL_STMT *stmt, long exp_count) static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count) { ulonglong affected_rows= mysql_stmt_affected_rows(stmt); - fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", - affected_rows, exp_count); + if (!opt_silent) + fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", + affected_rows, exp_count); DIE_UNLESS(affected_rows == exp_count); } @@ -633,7 +691,8 @@ static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count) static void verify_affected_rows(ulonglong exp_count) { ulonglong affected_rows= mysql_affected_rows(mysql); - fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", + if (!opt_silent) + fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", affected_rows, exp_count); DIE_UNLESS(affected_rows == exp_count); } @@ -644,8 +703,9 @@ static void verify_affected_rows(ulonglong exp_count) static void verify_field_count(MYSQL_RES *result, uint exp_count) { uint field_count= mysql_num_fields(result); - fprintf(stdout, "\n total fields in the result set: `%d` (expected: `%d`)", - field_count, exp_count); + if (!opt_silent) + fprintf(stdout, "\n total fields in the result set: `%d` (expected: `%d`)", + field_count, exp_count); DIE_UNLESS(field_count == exp_count); } @@ -665,8 +725,9 @@ static void execute_prepare_query(const char *query, ulonglong exp_count) myquery(rc); affected_rows= mysql_stmt_affected_rows(stmt); - fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", - affected_rows, exp_count); + if (!opt_silent) + fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)", + affected_rows, exp_count); DIE_UNLESS(affected_rows == exp_count); mysql_stmt_close(stmt); @@ -722,7 +783,8 @@ static my_bool thread_query(char *query) my_bool error; error= 0; - fprintf(stdout, "\n in thread_query(%s)", query); + if (!opt_silent) + fprintf(stdout, "\n in thread_query(%s)", query); if (!(l_mysql= mysql_init(NULL))) { myerror("mysql_init() failed"); @@ -753,6 +815,7 @@ end: static void test_debug_example() { + DBUG_ENTER("fill_tables"); int rc; MYSQL_RES *result; @@ -1033,7 +1096,8 @@ static void test_prepare_field_result() my_print_result_metadata(result); - fprintf(stdout, "\n\n field attributes:\n"); + if (!opt_silent) + fprintf(stdout, "\n\n field attributes:\n"); verify_prepare_field(result, 0, "int_c", "int_c", MYSQL_TYPE_LONG, "t1", "test_prepare_field_result", current_db, 11, 0); verify_prepare_field(result, 1, "var_c", "var_c", MYSQL_TYPE_VAR_STRING, @@ -1207,17 +1271,20 @@ static void test_prepare() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n"); + if (!opt_silent) + { + fprintf(stdout, "\n"); - fprintf(stdout, "\n\t tiny : %d (%lu)", tiny_data, length[0]); - fprintf(stdout, "\n\t short : %d (%lu)", small_data, length[3]); - fprintf(stdout, "\n\t int : %d (%lu)", int_data, length[2]); - fprintf(stdout, "\n\t big : %lld (%lu)", big_data, length[4]); + fprintf(stdout, "\n\t tiny : %d (%lu)", tiny_data, length[0]); + fprintf(stdout, "\n\t short : %d (%lu)", small_data, length[3]); + fprintf(stdout, "\n\t int : %d (%lu)", int_data, length[2]); + fprintf(stdout, "\n\t big : %lld (%lu)", big_data, length[4]); - fprintf(stdout, "\n\t float : %f (%lu)", real_data, length[5]); - fprintf(stdout, "\n\t double : %f (%lu)", double_data, length[6]); + fprintf(stdout, "\n\t float : %f (%lu)", real_data, length[5]); + fprintf(stdout, "\n\t double : %f (%lu)", double_data, length[6]); - fprintf(stdout, "\n\t str : %s (%lu)", str_data, length[1]); + fprintf(stdout, "\n\t str : %s (%lu)", str_data, length[1]); + } DIE_UNLESS(tiny_data == o_tiny_data); DIE_UNLESS(is_null[0] == 0); @@ -1578,11 +1645,13 @@ static void test_fetch_null() rc++; for (i= 0; i < 10; i++) { - fprintf(stdout, "\n data[%d] : %s", i, - is_null[i] ? "NULL" : "NOT NULL"); + if (!opt_silent) + fprintf(stdout, "\n data[%d] : %s", i, + is_null[i] ? "NULL" : "NOT NULL"); DIE_UNLESS(is_null[i]); } - fprintf(stdout, "\n data[%d]: %d", i, nData); + if (!opt_silent) + fprintf(stdout, "\n data[%d]: %d", i, nData); DIE_UNLESS(nData == 1000 || nData == 88 || nData == 389789); DIE_UNLESS(is_null[i] == 0); DIE_UNLESS(length[i] == 4); @@ -2367,7 +2436,8 @@ static void test_long_data() /* execute */ rc= mysql_stmt_execute(stmt); - fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); + if (!opt_silent) + fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); check_execute(stmt, rc); rc= mysql_commit(mysql); @@ -2450,7 +2520,8 @@ static void test_long_data_str() } /* execute */ rc= mysql_stmt_execute(stmt); - fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); + if (!opt_silent) + fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); check_execute(stmt, rc); mysql_stmt_close(stmt); @@ -2541,7 +2612,8 @@ static void test_long_data_str1() /* execute */ rc= mysql_stmt_execute(stmt); - fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); + if (!opt_silent) + fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); check_execute(stmt, rc); mysql_stmt_close(stmt); @@ -2692,7 +2764,8 @@ static void test_long_data_bin() } /* execute */ rc= mysql_stmt_execute(stmt); - fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); + if (!opt_silent) + fprintf(stdout, " mysql_stmt_execute() returned %d\n", rc); check_execute(stmt, rc); mysql_stmt_close(stmt); @@ -2999,7 +3072,8 @@ static void test_bind_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %d, %s(%lu)", nData, szData, length1); + if (!opt_silent) + fprintf(stdout, "\n row 1: %d, %s(%lu)", nData, szData, length1); DIE_UNLESS(nData == 10); DIE_UNLESS(strcmp(szData, "venu") == 0); DIE_UNLESS(length1 == 4); @@ -3007,7 +3081,8 @@ static void test_bind_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 2: %d, %s(%lu)", nData, szData, length1); + if (!opt_silent) + fprintf(stdout, "\n row 2: %d, %s(%lu)", nData, szData, length1); DIE_UNLESS(nData == 20); DIE_UNLESS(strcmp(szData, "MySQL") == 0); DIE_UNLESS(length1 == 5); @@ -3016,7 +3091,7 @@ static void test_bind_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - if (is_null[0]) + if (!opt_silent && is_null[0]) fprintf(stdout, "\n row 3: NULL, %s(%lu)", szData, length1); DIE_UNLESS(is_null[0]); DIE_UNLESS(strcmp(szData, "monty") == 0); @@ -3114,19 +3189,21 @@ static void test_bind_result_ext() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data (tiny) : %d", t_data); - fprintf(stdout, "\n data (short) : %d", s_data); - fprintf(stdout, "\n data (int) : %d", i_data); - fprintf(stdout, "\n data (big) : %lld", b_data); - - fprintf(stdout, "\n data (float) : %f", f_data); - fprintf(stdout, "\n data (double) : %f", d_data); + if (!opt_silent) + { + fprintf(stdout, "\n data (tiny) : %d", t_data); + fprintf(stdout, "\n data (short) : %d", s_data); + fprintf(stdout, "\n data (int) : %d", i_data); + fprintf(stdout, "\n data (big) : %lld", b_data); - fprintf(stdout, "\n data (str) : %s(%lu)", szData, szLength); + fprintf(stdout, "\n data (float) : %f", f_data); + fprintf(stdout, "\n data (double) : %f", d_data); - bData[bLength]= '\0'; /* bData is binary */ - fprintf(stdout, "\n data (bin) : %s(%lu)", bData, bLength); + fprintf(stdout, "\n data (str) : %s(%lu)", szData, szLength); + bData[bLength]= '\0'; /* bData is binary */ + fprintf(stdout, "\n data (bin) : %s(%lu)", bData, bLength); + } DIE_UNLESS(t_data == 19); DIE_UNLESS(s_data == 2999); @@ -3234,16 +3311,19 @@ static void test_bind_result_ext1() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data (tiny) : %s(%lu)", t_data, length[0]); - fprintf(stdout, "\n data (short) : %f(%lu)", s_data, length[1]); - fprintf(stdout, "\n data (int) : %d(%lu)", i_data, length[2]); - fprintf(stdout, "\n data (big) : %d(%lu)", b_data, length[3]); + if (!opt_silent) + { + fprintf(stdout, "\n data (tiny) : %s(%lu)", t_data, length[0]); + fprintf(stdout, "\n data (short) : %f(%lu)", s_data, length[1]); + fprintf(stdout, "\n data (int) : %d(%lu)", i_data, length[2]); + fprintf(stdout, "\n data (big) : %d(%lu)", b_data, length[3]); - fprintf(stdout, "\n data (float) : %d(%lu)", f_data, length[4]); - fprintf(stdout, "\n data (double) : %s(%lu)", d_data, length[5]); + fprintf(stdout, "\n data (float) : %d(%lu)", f_data, length[4]); + fprintf(stdout, "\n data (double) : %s(%lu)", d_data, length[5]); - fprintf(stdout, "\n data (bin) : %ld(%lu)", bData, length[6]); - fprintf(stdout, "\n data (str) : %g(%lu)", szData, length[7]); + fprintf(stdout, "\n data (bin) : %ld(%lu)", bData, length[6]); + fprintf(stdout, "\n data (str) : %g(%lu)", szData, length[7]); + } DIE_UNLESS(strcmp(t_data, "120") == 0); DIE_UNLESS(i_data == 3999); @@ -3368,15 +3448,17 @@ static void bind_fetch(int row_count) rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n"); - fprintf(stdout, "\n tiny : %ld(%lu)", (ulong) i8_data, length[0]); - fprintf(stdout, "\n short : %ld(%lu)", (ulong) i16_data, length[1]); - fprintf(stdout, "\n int : %ld(%lu)", (ulong) i32_data, length[2]); - fprintf(stdout, "\n longlong : %ld(%lu)", (ulong) i64_data, length[3]); - fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]); - fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]); - fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]); - + if (!opt_silent) + { + fprintf(stdout, "\n"); + fprintf(stdout, "\n tiny : %ld(%lu)", (ulong) i8_data, length[0]); + fprintf(stdout, "\n short : %ld(%lu)", (ulong) i16_data, length[1]); + fprintf(stdout, "\n int : %ld(%lu)", (ulong) i32_data, length[2]); + fprintf(stdout, "\n longlong : %ld(%lu)", (ulong) i64_data, length[3]); + fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]); + fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]); + fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]); + } rc= 10+row_count; /* TINY */ @@ -3518,13 +3600,16 @@ static void test_fetch_date() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n date : %s(%lu)", date, d_length); - fprintf(stdout, "\n time : %s(%lu)", time, t_length); - fprintf(stdout, "\n ts : %s(%lu)", ts, ts_length); - fprintf(stdout, "\n year : %d(%lu)", year, y_length); - fprintf(stdout, "\n dt : %s(%lu)", dt, dt_length); - fprintf(stdout, "\n ts(4) : %s(%lu)", ts_4, ts4_length); - fprintf(stdout, "\n ts(6) : %s(%lu)", ts_6, ts6_length); + if (!opt_silent) + { + fprintf(stdout, "\n date : %s(%lu)", date, d_length); + fprintf(stdout, "\n time : %s(%lu)", time, t_length); + fprintf(stdout, "\n ts : %s(%lu)", ts, ts_length); + fprintf(stdout, "\n year : %d(%lu)", year, y_length); + fprintf(stdout, "\n dt : %s(%lu)", dt, dt_length); + fprintf(stdout, "\n ts(4) : %s(%lu)", ts_4, ts4_length); + fprintf(stdout, "\n ts(6) : %s(%lu)", ts_6, ts6_length); + } DIE_UNLESS(strcmp(date, "2002-01-02") == 0); DIE_UNLESS(d_length == 10); @@ -3851,7 +3936,8 @@ static void test_field_names() myheader("test_field_names"); - fprintf(stdout, "\n %d, %d, %d", MYSQL_TYPE_DECIMAL, MYSQL_TYPE_NEWDATE, MYSQL_TYPE_ENUM); + if (!opt_silent) + fprintf(stdout, "\n %d, %d, %d", MYSQL_TYPE_DECIMAL, MYSQL_TYPE_NEWDATE, MYSQL_TYPE_ENUM); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_field_names1"); myquery(rc); @@ -3902,7 +3988,8 @@ static void test_warnings() rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); myquery(rc); - fprintf(stdout, "\n total warnings: %d", mysql_warning_count(mysql)); + if (!opt_silent) + fprintf(stdout, "\n total warnings: %d", mysql_warning_count(mysql)); rc= mysql_query(mysql, "SHOW WARNINGS"); myquery(rc); @@ -4084,23 +4171,27 @@ static void test_field_flags() mytest(result); mysql_field_seek(result, 0); - fputc('\n', stdout); + if (!opt_silent) + fputc('\n', stdout); for(i= 0; i< mysql_num_fields(result); i++) { field= mysql_fetch_field(result); - fprintf(stdout, "\n field:%d", i); - if (field->flags & NOT_NULL_FLAG) - fprintf(stdout, "\n NOT_NULL_FLAG"); - if (field->flags & PRI_KEY_FLAG) - fprintf(stdout, "\n PRI_KEY_FLAG"); - if (field->flags & UNIQUE_KEY_FLAG) - fprintf(stdout, "\n UNIQUE_KEY_FLAG"); - if (field->flags & MULTIPLE_KEY_FLAG) - fprintf(stdout, "\n MULTIPLE_KEY_FLAG"); - if (field->flags & AUTO_INCREMENT_FLAG) - fprintf(stdout, "\n AUTO_INCREMENT_FLAG"); + if (!opt_silent) + { + fprintf(stdout, "\n field:%d", i); + if (field->flags & NOT_NULL_FLAG) + fprintf(stdout, "\n NOT_NULL_FLAG"); + if (field->flags & PRI_KEY_FLAG) + fprintf(stdout, "\n PRI_KEY_FLAG"); + if (field->flags & UNIQUE_KEY_FLAG) + fprintf(stdout, "\n UNIQUE_KEY_FLAG"); + if (field->flags & MULTIPLE_KEY_FLAG) + fprintf(stdout, "\n MULTIPLE_KEY_FLAG"); + if (field->flags & AUTO_INCREMENT_FLAG) + fprintf(stdout, "\n AUTO_INCREMENT_FLAG"); + } } mysql_free_result(result); } @@ -4119,7 +4210,8 @@ static void test_stmt_close() myheader("test_stmt_close"); - fprintf(stdout, "\n Establishing a test connection ..."); + if (!opt_silent) + fprintf(stdout, "\n Establishing a test connection ..."); if (!(lmysql= mysql_init(NULL))) { myerror("mysql_init() failed"); @@ -4132,7 +4224,8 @@ static void test_stmt_close() myerror("connection failed"); exit(1); } - fprintf(stdout, " OK"); + if (!opt_silent) + fprintf(stdout, " OK"); /* set AUTOCOMMIT to ON*/ @@ -4169,7 +4262,8 @@ static void test_stmt_close() verify_param_count(stmt2, 1); rc= mysql_stmt_close(stmt1); - fprintf(stdout, "\n mysql_close_stmt(1) returned: %d", rc); + if (!opt_silent) + fprintf(stdout, "\n mysql_close_stmt(1) returned: %d", rc); DIE_UNLESS(rc == 0); /* @@ -4203,7 +4297,8 @@ static void test_stmt_close() verify_st_affected_rows(stmt_x, 1); rc= mysql_stmt_close(stmt_x); - fprintf(stdout, "\n mysql_close_stmt(x) returned: %d", rc); + if (!opt_silent) + fprintf(stdout, "\n mysql_close_stmt(x) returned: %d", rc); DIE_UNLESS( rc == 0); rc= mysql_query(mysql, "SELECT id FROM test_stmt_close"); @@ -4262,7 +4357,8 @@ static void test_set_variable() rc= mysql_stmt_fetch(stmt1); check_execute(stmt1, rc); - fprintf(stdout, "\n max_error_count(default): %d", get_count); + if (!opt_silent) + fprintf(stdout, "\n max_error_count(default): %d", get_count); def_count= get_count; DIE_UNLESS(strcmp(var, "max_error_count") == 0); @@ -4292,7 +4388,8 @@ static void test_set_variable() rc= mysql_stmt_fetch(stmt1); check_execute(stmt1, rc); - fprintf(stdout, "\n max_error_count : %d", get_count); + if (!opt_silent) + fprintf(stdout, "\n max_error_count : %d", get_count); DIE_UNLESS(get_count == set_count); rc= mysql_stmt_fetch(stmt1); @@ -4309,7 +4406,8 @@ static void test_set_variable() rc= mysql_stmt_fetch(stmt1); check_execute(stmt1, rc); - fprintf(stdout, "\n max_error_count(default): %d", get_count); + if (!opt_silent) + fprintf(stdout, "\n max_error_count(default): %d", get_count); DIE_UNLESS(get_count == set_count); rc= mysql_stmt_fetch(stmt1); @@ -4367,12 +4465,14 @@ static void test_insert_meta() mysql_field_seek(result, 0); field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col1"); + if (!opt_silent) + fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col1"); DIE_UNLESS(strcmp(field->name, "col1") == 0); field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col3"); + if (!opt_silent) + fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col3"); DIE_UNLESS(strcmp(field->name, "col3") == 0); field= mysql_fetch_field(result); @@ -4429,15 +4529,21 @@ static void test_update_meta() mysql_field_seek(result, 0); field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1"); - fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update"); + if (!opt_silent) + { + fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1"); + fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update"); + } DIE_UNLESS(strcmp(field->name, "col1") == 0); DIE_UNLESS(strcmp(field->table, "test_prep_update") == 0); field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col3"); - fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update"); + if (!opt_silent) + { + fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col3"); + fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update"); + } DIE_UNLESS(strcmp(field->name, "col3") == 0); DIE_UNLESS(strcmp(field->table, "test_prep_update") == 0); @@ -4493,15 +4599,21 @@ static void test_select_meta() mysql_field_seek(result, 0); field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1"); - fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select"); + if (!opt_silent) + { + fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1"); + fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select"); + } DIE_UNLESS(strcmp(field->name, "col1") == 0); DIE_UNLESS(strcmp(field->table, "test_prep_select") == 0); field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col2"); - fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select"); + if (!opt_silent) + { + fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col2"); + fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select"); + } DIE_UNLESS(strcmp(field->name, "col2") == 0); DIE_UNLESS(strcmp(field->table, "test_prep_select") == 0); @@ -4545,8 +4657,9 @@ static void test_func_fields() field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n table name: `%s` (expected: `%s`)", field->table, - "test_dateformat"); + if (!opt_silent) + fprintf(stdout, "\n table name: `%s` (expected: `%s`)", field->table, + "test_dateformat"); DIE_UNLESS(strcmp(field->table, "test_dateformat") == 0); field= mysql_fetch_field(result); @@ -4563,7 +4676,8 @@ static void test_func_fields() field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n table name: `%s` (expected: `%s`)", field->table, ""); + if (!opt_silent) + fprintf(stdout, "\n table name: `%s` (expected: `%s`)", field->table, ""); DIE_UNLESS(field->table[0] == '\0'); field= mysql_fetch_field(result); @@ -4580,8 +4694,11 @@ static void test_func_fields() field= mysql_fetch_field(result); mytest(field); - fprintf(stdout, "\n field name: `%s` (expected: `%s`)", field->name, "YEAR"); - fprintf(stdout, "\n field org name: `%s` (expected: `%s`)", field->org_name, ""); + if (!opt_silent) + { + printf("\n field name: `%s` (expected: `%s`)", field->name, "YEAR"); + printf("\n field org name: `%s` (expected: `%s`)", field->org_name, ""); + } DIE_UNLESS(strcmp(field->name, "YEAR") == 0); DIE_UNLESS(field->org_name[0] == '\0'); @@ -4658,8 +4775,11 @@ static void test_multi_stmt() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n int_data: %lu(%lu)", (ulong) id, length[0]); - fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]); + if (!opt_silent) + { + fprintf(stdout, "\n int_data: %lu(%lu)", (ulong) id, length[0]); + fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]); + } DIE_UNLESS(id == 10); DIE_UNLESS(strcmp(name, "mysql") == 0); @@ -4687,8 +4807,11 @@ static void test_multi_stmt() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n int_data: %lu(%lu)", (ulong) id, length[0]); - fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]); + if (!opt_silent) + { + fprintf(stdout, "\n int_data: %lu(%lu)", (ulong) id, length[0]); + fprintf(stdout, "\n str_data: %s(%lu)", name, length[1]); + } DIE_UNLESS(id == 10); DIE_UNLESS(strcmp(name, "updated") == 0); @@ -4762,12 +4885,14 @@ static void test_manual_sample() fprintf(stderr, "\n %s", mysql_error(mysql)); exit(1); } - fprintf(stdout, "\n prepare, insert successful"); + if (!opt_silent) + fprintf(stdout, "\n prepare, insert successful"); /* Get the parameter count from the statement */ param_count= mysql_stmt_param_count(stmt); - fprintf(stdout, "\n total parameters in insert: %d", param_count); + if (!opt_silent) + fprintf(stdout, "\n total parameters in insert: %d", param_count); if (param_count != 3) /* validate parameter count */ { fprintf(stderr, "\n invalid parameter count returned by MySQL"); @@ -4823,7 +4948,8 @@ static void test_manual_sample() /* Get the total rows affected */ affected_rows= mysql_stmt_affected_rows(stmt); - fprintf(stdout, "\n total affected rows: %lld", affected_rows); + if (!opt_silent) + fprintf(stdout, "\n total affected rows: %lld", affected_rows); if (affected_rows != 1) /* validate affected rows */ { fprintf(stderr, "\n invalid affected rows by MySQL"); @@ -4847,7 +4973,8 @@ static void test_manual_sample() /* Get the total rows affected */ affected_rows= mysql_stmt_affected_rows(stmt); - fprintf(stdout, "\n total affected rows: %lld", affected_rows); + if (!opt_silent) + fprintf(stdout, "\n total affected rows: %lld", affected_rows); if (affected_rows != 1) /* validate affected rows */ { fprintf(stderr, "\n invalid affected rows by MySQL"); @@ -4871,7 +4998,8 @@ static void test_manual_sample() fprintf(stderr, "\n %s", mysql_error(mysql)); exit(1); } - fprintf(stdout, "Success !!!"); + if (!opt_silent) + fprintf(stdout, "Success !!!"); } @@ -4993,13 +5121,14 @@ DROP TABLE IF EXISTS test_multi_tab"; for (count= 0 ; count < array_elements(rows) ; count++) { - fprintf(stdout, "\n Query %d: ", count); + if (!opt_silent) + fprintf(stdout, "\n Query %d: ", count); if ((result= mysql_store_result(mysql_local))) { (void) my_process_result_set(result); mysql_free_result(result); } - else + else if (!opt_silent) fprintf(stdout, "OK, %lld row(s) affected, %d warning(s)\n", mysql_affected_rows(mysql_local), mysql_warning_count(mysql_local)); @@ -5007,7 +5136,7 @@ DROP TABLE IF EXISTS test_multi_tab"; exp_value= (uint) mysql_affected_rows(mysql_local); if (rows[count] != exp_value) { - fprintf(stdout, "row %d had affected rows: %d, should be %d\n", + fprintf(stderr, "row %d had affected rows: %d, should be %d\n", count, exp_value, rows[count]); exit(1); } @@ -5083,7 +5212,7 @@ static void test_prepare_multi_statements() if (!(mysql_local= mysql_init(NULL))) { - fprintf(stdout, "\n mysql_init() failed"); + fprintf(stderr, "\n mysql_init() failed"); exit(1); } @@ -5091,7 +5220,7 @@ static void test_prepare_multi_statements() opt_password, current_db, opt_port, opt_unix_socket, CLIENT_MULTI_STATEMENTS))) { - fprintf(stdout, "\n connection failed(%s)", mysql_error(mysql_local)); + fprintf(stderr, "\n connection failed(%s)", mysql_error(mysql_local)); exit(1); } strmov(query, "select 1; select 'another value'"); @@ -5159,7 +5288,8 @@ static void test_store_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %ld, %s(%lu)", (long) nData, szData, length1); + if (!opt_silent) + fprintf(stdout, "\n row 1: %ld, %s(%lu)", (long) nData, szData, length1); DIE_UNLESS(nData == 10); DIE_UNLESS(strcmp(szData, "venu") == 0); DIE_UNLESS(length1 == 4); @@ -5167,7 +5297,8 @@ static void test_store_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 2: %ld, %s(%lu)", (long) nData, szData, length1); + if (!opt_silent) + fprintf(stdout, "\n row 2: %ld, %s(%lu)", (long) nData, szData, length1); DIE_UNLESS(nData == 20); DIE_UNLESS(strcmp(szData, "mysql") == 0); DIE_UNLESS(length1 == 5); @@ -5176,7 +5307,7 @@ static void test_store_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - if (is_null[0]) + if (!opt_silent && is_null[0]) fprintf(stdout, "\n row 3: NULL, %s(%lu)", szData, length1); DIE_UNLESS(is_null[0]); DIE_UNLESS(strcmp(szData, "monty") == 0); @@ -5194,7 +5325,8 @@ static void test_store_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %ld, %s(%lu)", (long) nData, szData, length1); + if (!opt_silent) + fprintf(stdout, "\n row 1: %ld, %s(%lu)", (long) nData, szData, length1); DIE_UNLESS(nData == 10); DIE_UNLESS(strcmp(szData, "venu") == 0); DIE_UNLESS(length1 == 4); @@ -5202,7 +5334,8 @@ static void test_store_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 2: %ld, %s(%lu)", (long) nData, szData, length1); + if (!opt_silent) + fprintf(stdout, "\n row 2: %ld, %s(%lu)", (long) nData, szData, length1); DIE_UNLESS(nData == 20); DIE_UNLESS(strcmp(szData, "mysql") == 0); DIE_UNLESS(length1 == 5); @@ -5211,7 +5344,7 @@ static void test_store_result() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - if (is_null[0]) + if (!opt_silent && is_null[0]) fprintf(stdout, "\n row 3: NULL, %s(%lu)", szData, length1); DIE_UNLESS(is_null[0]); DIE_UNLESS(strcmp(szData, "monty") == 0); @@ -5260,7 +5393,8 @@ static void test_store_result1() rc= 0; while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rc++; - fprintf(stdout, "\n total rows: %d", rc); + if (!opt_silent) + fprintf(stdout, "\n total rows: %d", rc); DIE_UNLESS(rc == 3); rc= mysql_stmt_execute(stmt); @@ -5272,7 +5406,8 @@ static void test_store_result1() rc= 0; while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rc++; - fprintf(stdout, "\n total rows: %d", rc); + if (!opt_silent) + fprintf(stdout, "\n total rows: %d", rc); DIE_UNLESS(rc == 3); mysql_stmt_close(stmt); @@ -5338,7 +5473,8 @@ static void test_store_result2() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %d", nData); + if (!opt_silent) + fprintf(stdout, "\n row 1: %d", nData); DIE_UNLESS(nData == 10); rc= mysql_stmt_fetch(stmt); @@ -5355,7 +5491,8 @@ static void test_store_result2() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %d", nData); + if (!opt_silent) + fprintf(stdout, "\n row 1: %d", nData); DIE_UNLESS(nData == 20); rc= mysql_stmt_fetch(stmt); @@ -5458,7 +5595,8 @@ static void test_subselect() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %d", id); + if (!opt_silent) + fprintf(stdout, "\n row 1: %d", id); DIE_UNLESS(id == 1); rc= mysql_stmt_fetch(stmt); @@ -5471,7 +5609,8 @@ static void test_subselect() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %d", id); + if (!opt_silent) + fprintf(stdout, "\n row 1: %d", id); DIE_UNLESS(id == 0); rc= mysql_stmt_fetch(stmt); @@ -5587,21 +5726,21 @@ static void test_bind_date_conv(uint row_count) rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n"); + if (!opt_silent) + fprintf(stdout, "\n"); for (i= 0; i < array_elements(bind); i++) { - fprintf(stdout, "\n"); - fprintf(stdout, " time[%d]: %02d-%02d-%02d %02d:%02d:%02d.%02lu", - i, tm[i].year, tm[i].month, tm[i].day, - tm[i].hour, tm[i].minute, tm[i].second, - tm[i].second_part); - + if (!opt_silent) + fprintf(stdout, "\ntime[%d]: %02d-%02d-%02d %02d:%02d:%02d.%02lu", + i, tm[i].year, tm[i].month, tm[i].day, + tm[i].hour, tm[i].minute, tm[i].second, + tm[i].second_part); DIE_UNLESS(tm[i].year == 0 || tm[i].year == year+count); DIE_UNLESS(tm[i].month == 0 || tm[i].month == month+count); DIE_UNLESS(tm[i].day == 0 || tm[i].day == day+count); DIE_UNLESS(tm[i].hour == 0 || tm[i].hour == hour+count); -#if 0 +#ifdef NOT_USED /* minute causes problems from date<->time, don't assert, instead validate separatly in another routine @@ -5856,7 +5995,8 @@ static void test_buffers() buffer[1]= 'X'; rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data: %s (%lu)", buffer, length); + if (!opt_silent) + fprintf(stdout, "\n data: %s (%lu)", buffer, length); DIE_UNLESS(buffer[0] == 'M'); DIE_UNLESS(buffer[1] == 'X'); DIE_UNLESS(length == 5); @@ -5867,7 +6007,8 @@ static void test_buffers() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data: %s (%lu)", buffer, length); + if (!opt_silent) + fprintf(stdout, "\n data: %s (%lu)", buffer, length); DIE_UNLESS(strncmp(buffer, "Database", 8) == 0); DIE_UNLESS(length == 8); @@ -5877,7 +6018,8 @@ static void test_buffers() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data: %s (%lu)", buffer, length); + if (!opt_silent) + fprintf(stdout, "\n data: %s (%lu)", buffer, length); DIE_UNLESS(strcmp(buffer, "Open-Source") == 0); DIE_UNLESS(length == 11); @@ -5887,7 +6029,8 @@ static void test_buffers() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data: %s (%lu)", buffer, length); + if (!opt_silent) + fprintf(stdout, "\n data: %s (%lu)", buffer, length); DIE_UNLESS(strncmp(buffer, "Popula", 6) == 0); DIE_UNLESS(length == 7); @@ -6018,7 +6161,8 @@ static void test_fetch_nobuffs() while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rc++; - fprintf(stdout, "\n total rows : %d", rc); + if (!opt_silent) + fprintf(stdout, "\n total rows : %d", rc); DIE_UNLESS(rc == 1); bind[0].buffer_type= MYSQL_TYPE_STRING; @@ -6041,12 +6185,16 @@ static void test_fetch_nobuffs() while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) { rc++; - fprintf(stdout, "\n CURRENT_DATABASE(): %s", str[0]); - fprintf(stdout, "\n CURRENT_USER() : %s", str[1]); - fprintf(stdout, "\n CURRENT_DATE() : %s", str[2]); - fprintf(stdout, "\n CURRENT_TIME() : %s", str[3]); + if (!opt_silent) + { + fprintf(stdout, "\n CURRENT_DATABASE(): %s", str[0]); + fprintf(stdout, "\n CURRENT_USER() : %s", str[1]); + fprintf(stdout, "\n CURRENT_DATE() : %s", str[2]); + fprintf(stdout, "\n CURRENT_TIME() : %s", str[3]); + } } - fprintf(stdout, "\n total rows : %d", rc); + if (!opt_silent) + fprintf(stdout, "\n total rows : %d", rc); DIE_UNLESS(rc == 1); mysql_stmt_close(stmt); @@ -6113,10 +6261,13 @@ static void test_ushort_bug() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n ushort : %d (%ld)", short_value, s_length); - fprintf(stdout, "\n ulong : %lu (%ld)", (ulong) long_value, l_length); - fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); - fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); + if (!opt_silent) + { + fprintf(stdout, "\n ushort : %d (%ld)", short_value, s_length); + fprintf(stdout, "\n ulong : %lu (%ld)", (ulong) long_value, l_length); + fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); + fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); + } DIE_UNLESS(short_value == 35999); DIE_UNLESS(s_length == 2); @@ -6197,10 +6348,13 @@ static void test_sshort_bug() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n sshort : %d (%ld)", short_value, s_length); - fprintf(stdout, "\n slong : %ld (%ld)", (long) long_value, l_length); - fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); - fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); + if (!opt_silent) + { + fprintf(stdout, "\n sshort : %d (%ld)", short_value, s_length); + fprintf(stdout, "\n slong : %ld (%ld)", (long) long_value, l_length); + fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); + fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); + } DIE_UNLESS(short_value == -5999); DIE_UNLESS(s_length == 2); @@ -6281,10 +6435,13 @@ static void test_stiny_bug() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n sshort : %d (%ld)", short_value, s_length); - fprintf(stdout, "\n slong : %ld (%ld)", (long) long_value, l_length); - fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); - fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); + if (!opt_silent) + { + fprintf(stdout, "\n sshort : %d (%ld)", short_value, s_length); + fprintf(stdout, "\n slong : %ld (%ld)", (long) long_value, l_length); + fprintf(stdout, "\n longlong : %lld (%ld)", longlong_value, ll_length); + fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length); + } DIE_UNLESS(short_value == -128); DIE_UNLESS(s_length == 2); @@ -6373,7 +6530,8 @@ static void test_field_misc() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n default table type: %s(%ld)", table_type, type_length); + if (!opt_silent) + fprintf(stdout, "\n default table type: %s(%ld)", table_type, type_length); rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == MYSQL_NO_DATA); @@ -6493,7 +6651,8 @@ static void test_set_option() rc= mysql_query(mysql, "INSERT INTO test_limit VALUES(10), (20), (30), (40)"); myquery(rc); - fprintf(stdout, "\n with SQL_SELECT_LIMIT= 2 (direct)"); + if (!opt_silent) + fprintf(stdout, "\n with SQL_SELECT_LIMIT= 2 (direct)"); rc= mysql_query(mysql, "SELECT * FROM test_limit"); myquery(rc); @@ -6505,7 +6664,8 @@ static void test_set_option() mysql_free_result(result); - fprintf(stdout, "\n with SQL_SELECT_LIMIT=2 (prepare)"); + if (!opt_silent) + fprintf(stdout, "\n with SQL_SELECT_LIMIT=2 (prepare)"); stmt= mysql_simple_prepare(mysql, "SELECT * FROM test_limit"); check_stmt(stmt); @@ -6518,7 +6678,8 @@ static void test_set_option() mysql_stmt_close(stmt); /* RESET the LIMIT the rows count to 0 */ - fprintf(stdout, "\n with SQL_SELECT_LIMIT=DEFAULT (prepare)"); + if (!opt_silent) + fprintf(stdout, "\n with SQL_SELECT_LIMIT=DEFAULT (prepare)"); rc= mysql_query(mysql, "SET OPTION SQL_SELECT_LIMIT=DEFAULT"); myquery(rc); @@ -6576,7 +6737,8 @@ static void test_prepare_grant() MYSQL *org_mysql= mysql, *lmysql; MYSQL_STMT *stmt; - fprintf(stdout, "\n Establishing a test connection ..."); + if (!opt_silent) + fprintf(stdout, "\n Establishing a test connection ..."); if (!(lmysql= mysql_init(NULL))) { myerror("mysql_init() failed"); @@ -6590,7 +6752,8 @@ static void test_prepare_grant() mysql_close(lmysql); exit(1); } - fprintf(stdout, " OK"); + if (!opt_silent) + fprintf(stdout, " OK"); mysql= lmysql; rc= mysql_query(mysql, "INSERT INTO test_grant VALUES(NULL)"); @@ -6677,14 +6840,16 @@ static void test_frm_bug() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data directory: %s", data_dir); + if (!opt_silent) + fprintf(stdout, "\n data directory: %s", data_dir); rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == MYSQL_NO_DATA); strxmov(test_frm, data_dir, "/", current_db, "/", "test_frm_bug.frm", NullS); - fprintf(stdout, "\n test_frm: %s", test_frm); + if (!opt_silent) + fprintf(stdout, "\n test_frm: %s", test_frm); if (!(test_file= my_fopen(test_frm, (int) (O_RDWR | O_CREAT), MYF(MY_WME)))) { @@ -6692,7 +6857,8 @@ static void test_frm_bug() fprintf(stdout, "\n test cancelled"); exit(1); } - fprintf(test_file, "this is a junk file for test"); + if (!opt_silent) + fprintf(test_file, "this is a junk file for test"); rc= mysql_query(mysql, "SHOW TABLE STATUS like 'test_frm_bug'"); myquery(rc); @@ -6708,7 +6874,8 @@ static void test_frm_bug() row= mysql_fetch_row(result); mytest(row); - fprintf(stdout, "\n Comment: %s", row[17]); + if (!opt_silent) + fprintf(stdout, "\n Comment: %s", row[17]); DIE_UNLESS(row[17] != 0); mysql_free_result(result); @@ -6771,7 +6938,8 @@ static void test_decimal_bug() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data: %s", data); + if (!opt_silent) + fprintf(stdout, "\n data: %s", data); DIE_UNLESS(strcmp(data, "8.00") == 0); rc= mysql_stmt_fetch(stmt); @@ -6788,7 +6956,8 @@ static void test_decimal_bug() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data: %s", data); + if (!opt_silent) + fprintf(stdout, "\n data: %s", data); DIE_UNLESS(strcmp(data, "5.61") == 0); rc= mysql_stmt_fetch(stmt); @@ -6812,7 +6981,8 @@ static void test_decimal_bug() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n data: %s", data); + if (!opt_silent) + fprintf(stdout, "\n data: %s", data); DIE_UNLESS(strcmp(data, "10.22") == 0); rc= mysql_stmt_fetch(stmt); @@ -6852,8 +7022,9 @@ static void test_explain_bug() result= mysql_stmt_result_metadata(stmt); mytest(result); - fprintf(stdout, "\n total fields in the result: %d", - mysql_num_fields(result)); + if (!opt_silent) + fprintf(stdout, "\n total fields in the result: %d", + mysql_num_fields(result)); DIE_UNLESS(6 == mysql_num_fields(result)); verify_prepare_field(result, 0, "Field", "", MYSQL_TYPE_VAR_STRING, @@ -6889,8 +7060,9 @@ static void test_explain_bug() result= mysql_stmt_result_metadata(stmt); mytest(result); - fprintf(stdout, "\n total fields in the result: %d", - mysql_num_fields(result)); + if (!opt_silent) + fprintf(stdout, "\n total fields in the result: %d", + mysql_num_fields(result)); DIE_UNLESS(10 == mysql_num_fields(result)); verify_prepare_field(result, 0, "id", "", MYSQL_TYPE_LONGLONG, @@ -6911,8 +7083,12 @@ static void test_explain_bug() verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_LEN, 0); - verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_LONGLONG, - "", "", "", 3, 0); + verify_prepare_field(result, 6, "key_len", "", + (mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_LONGLONG : MYSQL_TYPE_VAR_STRING), + "", "", "", + (mysql_get_server_version(mysql) <= 50000 ? 3 : 4096), + 0); verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_LEN*16, 0); @@ -6938,11 +7114,14 @@ static void test_explain_bug() static void check_errcode(const unsigned int err) { - if (mysql->server_version) - fprintf(stdout, "\n [MySQL-%s]", mysql->server_version); - else - fprintf(stdout, "\n [MySQL]"); - fprintf(stdout, "[%d] %s\n", mysql_errno(mysql), mysql_error(mysql)); + if (!opt_silent || mysql_errno(mysql) != err) + { + if (mysql->server_version) + fprintf(stdout, "\n [MySQL-%s]", mysql->server_version); + else + fprintf(stdout, "\n [MySQL]"); + fprintf(stdout, "[%d] %s\n", mysql_errno(mysql), mysql_error(mysql)); + } DIE_UNLESS(mysql_errno(mysql) == err); } @@ -6988,7 +7167,8 @@ static void test_drop_temp() { MYSQL *org_mysql= mysql, *lmysql; - fprintf(stdout, "\n Establishing a test connection ..."); + if (!opt_silent) + fprintf(stdout, "\n Establishing a test connection ..."); if (!(lmysql= mysql_init(NULL))) { myerror("mysql_init() failed"); @@ -7007,7 +7187,8 @@ static void test_drop_temp() mysql_close(lmysql); exit(1); } - fprintf(stdout, " OK"); + if (!opt_silent) + fprintf(stdout, " OK"); mysql= lmysql; rc= mysql_query(mysql, "INSERT INTO t1 VALUES(10, 'C')"); @@ -7076,14 +7257,16 @@ static void test_cuted_rows() myquery(rc); count= mysql_warning_count(mysql); - fprintf(stdout, "\n total warnings: %d", count); + if (!opt_silent) + fprintf(stdout, "\n total warnings: %d", count); DIE_UNLESS(count == 0); rc= mysql_query(mysql, "INSERT INTO t2 SELECT * FROM t1"); myquery(rc); count= mysql_warning_count(mysql); - fprintf(stdout, "\n total warnings: %d", count); + if (!opt_silent) + fprintf(stdout, "\n total warnings: %d", count); DIE_UNLESS(count == 2); rc= mysql_query(mysql, "SHOW WARNINGS"); @@ -7100,7 +7283,8 @@ static void test_cuted_rows() myquery(rc); count= mysql_warning_count(mysql); - fprintf(stdout, "\n total warnings: %d", count); + if (!opt_silent) + fprintf(stdout, "\n total warnings: %d", count); DIE_UNLESS(count == 2); rc= mysql_query(mysql, "SHOW WARNINGS"); @@ -7213,8 +7397,11 @@ static void test_logs() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n id : %d", id); - fprintf(stdout, "\n name : %s(%ld)", data, length); + if (!opt_silent) + { + fprintf(stdout, "\n id : %d", id); + fprintf(stdout, "\n name : %s(%ld)", data, length); + } DIE_UNLESS(id == 9876); DIE_UNLESS(length == 19); /* Due to VARCHAR(20) */ @@ -7223,7 +7410,8 @@ static void test_logs() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n name : %s(%ld)", data, length); + if (!opt_silent) + fprintf(stdout, "\n name : %s(%ld)", data, length); DIE_UNLESS(length == 1); DIE_UNLESS(strcmp(data, "'") == 0); @@ -7231,7 +7419,8 @@ static void test_logs() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n name : %s(%ld)", data, length); + if (!opt_silent) + fprintf(stdout, "\n name : %s(%ld)", data, length); DIE_UNLESS(length == 1); DIE_UNLESS(strcmp(data, "\"") == 0); @@ -7239,7 +7428,8 @@ static void test_logs() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n name : %s(%ld)", data, length); + if (!opt_silent) + fprintf(stdout, "\n name : %s(%ld)", data, length); DIE_UNLESS(length == 7); DIE_UNLESS(strcmp(data, "my\'sql\'") == 0); @@ -7247,7 +7437,8 @@ static void test_logs() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n name : %s(%ld)", data, length); + if (!opt_silent) + fprintf(stdout, "\n name : %s(%ld)", data, length); DIE_UNLESS(length == 7); /*DIE_UNLESS(strcmp(data, "my\"sql\"") == 0); */ @@ -7293,7 +7484,8 @@ static void test_nstmts() for (i= 0; i < total_stmts; i++) { - fprintf(stdout, "\r stmt: %d", i); + if (!opt_silent) + fprintf(stdout, "\r stmt: %d", i); strmov(query, "insert into test_nstmts values(?)"); stmt= mysql_simple_prepare(mysql, query); @@ -7320,7 +7512,8 @@ static void test_nstmts() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n total rows: %d", i); + if (!opt_silent) + fprintf(stdout, "\n total rows: %d", i); DIE_UNLESS( i == total_stmts); rc= mysql_stmt_fetch(stmt); @@ -7386,7 +7579,8 @@ static void test_fetch_seek() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 0: %ld, %s, %s", (long) c1, c2, c3); + if (!opt_silent) + fprintf(stdout, "\n row 0: %ld, %s, %s", (long) c1, c2, c3); row= mysql_stmt_row_tell(stmt); @@ -7395,21 +7589,24 @@ static void test_fetch_seek() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 2: %ld, %s, %s", (long) c1, c2, c3); + if (!opt_silent) + fprintf(stdout, "\n row 2: %ld, %s, %s", (long) c1, c2, c3); row= mysql_stmt_row_seek(stmt, row); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 2: %ld, %s, %s", (long) c1, c2, c3); + if (!opt_silent) + fprintf(stdout, "\n row 2: %ld, %s, %s", (long) c1, c2, c3); mysql_stmt_data_seek(stmt, 0); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 0: %ld, %s, %s", (long) c1, c2, c3); + if (!opt_silent) + fprintf(stdout, "\n row 0: %ld, %s, %s", (long) c1, c2, c3); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); @@ -7477,17 +7674,20 @@ static void test_fetch_offset() data[0]= '\0'; rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 1: %s (%ld)", data, length); + if (!opt_silent) + fprintf(stdout, "\n col 1: %s (%ld)", data, length); DIE_UNLESS(strncmp(data, "abcd", 4) == 0 && length == 10); rc= mysql_stmt_fetch_column(stmt, bind, 0, 5); check_execute(stmt, rc); - fprintf(stdout, "\n col 1: %s (%ld)", data, length); + if (!opt_silent) + fprintf(stdout, "\n col 1: %s (%ld)", data, length); DIE_UNLESS(strncmp(data, "fg", 2) == 0 && length == 10); rc= mysql_stmt_fetch_column(stmt, bind, 0, 9); check_execute(stmt, rc); - fprintf(stdout, "\n col 0: %s (%ld)", data, length); + if (!opt_silent) + fprintf(stdout, "\n col 0: %s (%ld)", data, length); DIE_UNLESS(strncmp(data, "j", 1) == 0 && length == 10); rc= mysql_stmt_fetch(stmt); @@ -7560,7 +7760,8 @@ static void test_fetch_column() rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 0: %d, %s", bc1, bc2); + if (!opt_silent) + fprintf(stdout, "\n row 0: %d, %s", bc1, bc2); c2[0]= '\0'; l2= 0; bind[0].buffer_type= MYSQL_TYPE_STRING; @@ -7571,13 +7772,15 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); + if (!opt_silent) + fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); DIE_UNLESS(strncmp(c2, "venu", 4) == 0 && l2 == 4); c2[0]= '\0'; l2= 0; rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); + if (!opt_silent) + fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); DIE_UNLESS(strcmp(c2, "venu") == 0 && l2 == 4); c1= 0; @@ -7589,13 +7792,15 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); + if (!opt_silent) + fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); DIE_UNLESS(c1 == 1 && l1 == 4); rc= mysql_stmt_fetch(stmt); check_execute(stmt, rc); - fprintf(stdout, "\n row 1: %d, %s", bc1, bc2); + if (!opt_silent) + fprintf(stdout, "\n row 1: %d, %s", bc1, bc2); c2[0]= '\0'; l2= 0; bind[0].buffer_type= MYSQL_TYPE_STRING; @@ -7606,13 +7811,15 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); + if (!opt_silent) + fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); DIE_UNLESS(strncmp(c2, "mysq", 4) == 0 && l2 == 5); c2[0]= '\0'; l2= 0; rc= mysql_stmt_fetch_column(stmt, bind, 1, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 1: %si(%ld)", c2, l2); + if (!opt_silent) + fprintf(stdout, "\n col 1: %si(%ld)", c2, l2); DIE_UNLESS(strcmp(c2, "mysql") == 0 && l2 == 5); c1= 0; @@ -7624,7 +7831,8 @@ static void test_fetch_column() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); + if (!opt_silent) + fprintf(stdout, "\n col 0: %d(%ld)", c1, l1); DIE_UNLESS(c1 == 2 && l1 == 4); rc= mysql_stmt_fetch(stmt); @@ -7678,7 +7886,6 @@ static void test_mem_overun() MYSQL_RES *field_res; int rc, i, length; - myheader("test_mem_overun"); /* @@ -7728,7 +7935,8 @@ static void test_mem_overun() field_res= mysql_stmt_result_metadata(stmt); mytest(field_res); - fprintf(stdout, "\n total fields : %d", mysql_num_fields(field_res)); + if (!opt_silent) + fprintf(stdout, "\n total fields : %d", mysql_num_fields(field_res)); DIE_UNLESS( 1000 == mysql_num_fields(field_res)); rc= mysql_stmt_store_result(stmt); @@ -7795,7 +8003,8 @@ static void test_free_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 0: %s(%ld)", c2, l2); + if (!opt_silent) + fprintf(stdout, "\n col 0: %s(%ld)", c2, l2); DIE_UNLESS(strncmp(c2, "1", 1) == 0 && l2 == 1); rc= mysql_stmt_fetch(stmt); @@ -7810,7 +8019,8 @@ static void test_free_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 0: %d(%ld)", c1, l2); + if (!opt_silent) + fprintf(stdout, "\n col 0: %d(%ld)", c1, l2); DIE_UNLESS(c1 == 2 && l2 == 4); rc= mysql_query(mysql, "drop table test_free_result"); @@ -7877,7 +8087,8 @@ static void test_free_store_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); + if (!opt_silent) + fprintf(stdout, "\n col 1: %s(%ld)", c2, l2); DIE_UNLESS(strncmp(c2, "1", 1) == 0 && l2 == 1); rc= mysql_stmt_fetch(stmt); @@ -7892,7 +8103,8 @@ static void test_free_store_result() rc= mysql_stmt_fetch_column(stmt, bind, 0, 0); check_execute(stmt, rc); - fprintf(stdout, "\n col 0: %d(%ld)", c1, l2); + if (!opt_silent) + fprintf(stdout, "\n col 0: %d(%ld)", c1, l2); DIE_UNLESS(c1 == 2 && l2 == 4); rc= mysql_stmt_free_result(stmt); @@ -7924,16 +8136,19 @@ static void test_sqlmode() /* PIPES_AS_CONCAT */ strcpy(query, "SET SQL_MODE= \"PIPES_AS_CONCAT\""); - fprintf(stdout, "\n With %s", query); + if (!opt_silent) + fprintf(stdout, "\n With %s", query); rc= mysql_query(mysql, query); myquery(rc); strcpy(query, "INSERT INTO test_piping VALUES(?||?)"); - fprintf(stdout, "\n query: %s", query); + if (!opt_silent) + fprintf(stdout, "\n query: %s", query); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); - fprintf(stdout, "\n total parameters: %ld", mysql_stmt_param_count(stmt)); + if (!opt_silent) + fprintf(stdout, "\n total parameters: %ld", mysql_stmt_param_count(stmt)); /* We need to bzero bind structure because mysql_stmt_bind_param checks all @@ -7963,21 +8178,25 @@ static void test_sqlmode() myquery(rc); strcpy(query, "SELECT connection_id ()"); - fprintf(stdout, "\n query: %s", query); + if (!opt_silent) + fprintf(stdout, "\n query: %s", query); stmt= mysql_simple_prepare(mysql, query); check_stmt_r(stmt); /* ANSI */ strcpy(query, "SET SQL_MODE= \"ANSI\""); - fprintf(stdout, "\n With %s", query); + if (!opt_silent) + fprintf(stdout, "\n With %s", query); rc= mysql_query(mysql, query); myquery(rc); strcpy(query, "INSERT INTO test_piping VALUES(?||?)"); - fprintf(stdout, "\n query: %s", query); + if (!opt_silent) + fprintf(stdout, "\n query: %s", query); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); - fprintf(stdout, "\n total parameters: %ld", mysql_stmt_param_count(stmt)); + if (!opt_silent) + fprintf(stdout, "\n total parameters: %ld", mysql_stmt_param_count(stmt)); rc= mysql_stmt_bind_param(stmt, bind); check_execute(stmt, rc); @@ -7991,7 +8210,8 @@ static void test_sqlmode() /* ANSI mode spaces ... */ strcpy(query, "SELECT connection_id ()"); - fprintf(stdout, "\n query: %s", query); + if (!opt_silent) + fprintf(stdout, "\n query: %s", query); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -8003,18 +8223,21 @@ static void test_sqlmode() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == MYSQL_NO_DATA); - fprintf(stdout, "\n returned 1 row\n"); + if (!opt_silent) + fprintf(stdout, "\n returned 1 row\n"); mysql_stmt_close(stmt); /* IGNORE SPACE MODE */ strcpy(query, "SET SQL_MODE= \"IGNORE_SPACE\""); - fprintf(stdout, "\n With %s", query); + if (!opt_silent) + fprintf(stdout, "\n With %s", query); rc= mysql_query(mysql, query); myquery(rc); strcpy(query, "SELECT connection_id ()"); - fprintf(stdout, "\n query: %s", query); + if (!opt_silent) + fprintf(stdout, "\n query: %s", query); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -8026,7 +8249,8 @@ static void test_sqlmode() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == MYSQL_NO_DATA); - fprintf(stdout, "\n returned 1 row"); + if (!opt_silent) + fprintf(stdout, "\n returned 1 row"); mysql_stmt_close(stmt); } @@ -8118,7 +8342,8 @@ static void test_ts() sprintf(query, "SELECT a, b, c FROM test_ts WHERE %c=?", name); - fprintf(stdout, "\n %s", query); + if (!opt_silent) + fprintf(stdout, "\n %s", query); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -8131,7 +8356,8 @@ static void test_ts() while (mysql_stmt_fetch(stmt) == 0) row_count++; - fprintf(stdout, "\n returned '%d' rows", row_count); + if (!opt_silent) + fprintf(stdout, "\n returned '%d' rows", row_count); DIE_UNLESS(row_count == 2); mysql_stmt_close(stmt); } @@ -8273,7 +8499,8 @@ static void test_bug1946() check_stmt(stmt); rc= mysql_real_query(mysql, query, strlen(query)); DIE_UNLESS(rc != 0); - fprintf(stdout, "Got error (as expected):\n"); + if (!opt_silent) + fprintf(stdout, "Got error (as expected):\n"); myerror(NULL); mysql_stmt_close(stmt); @@ -8291,19 +8518,23 @@ static void test_parse_error_and_bad_length() rc= mysql_query(mysql, "SHOW DATABAAAA"); DIE_UNLESS(rc); - fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); + if (!opt_silent) + fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); rc= mysql_real_query(mysql, "SHOW DATABASES", 100); DIE_UNLESS(rc); - fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); + if (!opt_silent) + fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); stmt= mysql_simple_prepare(mysql, "SHOW DATABAAAA"); DIE_UNLESS(!stmt); - fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); + if (!opt_silent) + fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql)); stmt= mysql_stmt_init(mysql); DIE_UNLESS(stmt); rc= mysql_stmt_prepare(stmt, "SHOW DATABASES", 100); DIE_UNLESS(rc != 0); - fprintf(stdout, "Got error (as expected): '%s'\n", mysql_stmt_error(stmt)); + if (!opt_silent) + fprintf(stdout, "Got error (as expected): '%s'\n", mysql_stmt_error(stmt)); mysql_stmt_close(stmt); } @@ -8324,7 +8555,8 @@ static void test_bug2247() myheader("test_bug2247"); - fprintf(stdout, "\nChecking if stmt_affected_rows is not affected by\n" + if (!opt_silent) + 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); @@ -8381,7 +8613,8 @@ static void test_bug2247() DIE_UNLESS(mysql_stmt_affected_rows(stmt) == exp_count); mysql_stmt_close(stmt); - fprintf(stdout, "OK"); + if (!opt_silent) + fprintf(stdout, "OK"); } @@ -8659,7 +8892,8 @@ static void test_bug3117() check_execute(stmt, rc); DIE_UNLESS(is_null == 0 && lii == 1); - fprintf(stdout, "\n\tLAST_INSERT_ID()= 1 ok\n"); + if (!opt_silent) + fprintf(stdout, "\n\tLAST_INSERT_ID()= 1 ok\n"); rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)"); myquery(rc); @@ -8671,7 +8905,8 @@ static void test_bug3117() check_execute(stmt, rc); DIE_UNLESS(is_null == 0 && lii == 2); - fprintf(stdout, "\tLAST_INSERT_ID()= 2 ok\n"); + if (!opt_silent) + fprintf(stdout, "\tLAST_INSERT_ID()= 2 ok\n"); mysql_stmt_close(stmt); @@ -8821,7 +9056,8 @@ static void test_create_drop() { rc= mysql_stmt_execute(stmt_create); check_execute(stmt_create, rc); - fprintf(stdout, "created %i\n", i); + if (!opt_silent) + fprintf(stdout, "created %i\n", i); rc= mysql_stmt_execute(stmt_select); check_execute(stmt_select, rc); @@ -8830,11 +9066,13 @@ static void test_create_drop() rc= mysql_stmt_execute(stmt_drop); check_execute(stmt_drop, rc); - fprintf(stdout, "droped %i\n", i); + if (!opt_silent) + fprintf(stdout, "droped %i\n", i); rc= mysql_stmt_execute(stmt_create_select); check_execute(stmt_create, rc); - fprintf(stdout, "created select %i\n", i); + if (!opt_silent) + fprintf(stdout, "created select %i\n", i); rc= mysql_stmt_execute(stmt_select); check_execute(stmt_select, rc); @@ -8843,7 +9081,8 @@ static void test_create_drop() rc= mysql_stmt_execute(stmt_drop); check_execute(stmt_drop, rc); - fprintf(stdout, "droped %i\n", i); + if (!opt_silent) + fprintf(stdout, "droped %i\n", i); } mysql_stmt_close(stmt_create); @@ -8874,25 +9113,29 @@ static void test_rename() rc= mysql_stmt_execute(stmt); check_execute_r(stmt, rc); - fprintf(stdout, "rename without t3\n"); + if (!opt_silent) + fprintf(stdout, "rename without t3\n"); rc= mysql_query(mysql, "create table t3 (a int)"); myquery(rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - fprintf(stdout, "rename with t3\n"); + if (!opt_silent) + fprintf(stdout, "rename with t3\n"); rc= mysql_stmt_execute(stmt); check_execute_r(stmt, rc); - fprintf(stdout, "rename renamed\n"); + if (!opt_silent) + fprintf(stdout, "rename renamed\n"); rc= mysql_query(mysql, "rename table t2 to t1, t4 to t3"); myquery(rc); rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - fprintf(stdout, "rename reverted\n"); + if (!opt_silent) + fprintf(stdout, "rename reverted\n"); mysql_stmt_close(stmt); @@ -8926,10 +9169,12 @@ static void test_do_set() { rc= mysql_stmt_execute(stmt_do); check_execute(stmt_do, rc); - fprintf(stdout, "do %i\n", i); + if (!opt_silent) + fprintf(stdout, "do %i\n", i); rc= mysql_stmt_execute(stmt_set); check_execute(stmt_set, rc); - fprintf(stdout, "set %i\n", i); + if (!opt_silent) + fprintf(stdout, "set %i\n", i); } mysql_stmt_close(stmt_do); @@ -8995,11 +9240,13 @@ static void test_multi() rc= mysql_stmt_execute(stmt_update); check_execute(stmt_update, rc); - fprintf(stdout, "update %ld\n", (long) param); + if (!opt_silent) + fprintf(stdout, "update %ld\n", (long) param); rc= mysql_stmt_execute(stmt_delete); check_execute(stmt_delete, rc); - fprintf(stdout, "delete %ld\n", (long) param); + if (!opt_silent) + fprintf(stdout, "delete %ld\n", (long) param); rc= mysql_stmt_execute(stmt_select1); check_execute(stmt_select1, rc); @@ -9055,7 +9302,8 @@ static void test_insert_select() { rc= mysql_stmt_execute(stmt_insert); check_execute(stmt_insert, rc); - fprintf(stdout, "insert %u\n", i); + if (!opt_silent) + fprintf(stdout, "insert %u\n", i); rc= mysql_stmt_execute(stmt_select); check_execute(stmt_select, rc); @@ -9915,7 +10163,8 @@ static void test_bug3796() mysql_stmt_bind_result(stmt, bind); rc= mysql_stmt_fetch(stmt); - printf("Concat result: '%s'\n", out_buff); + if (!opt_silent) + printf("Concat result: '%s'\n", out_buff); check_execute(stmt, rc); strcpy(canonical_buff, concat_arg0); strcat(canonical_buff, "ONE"); @@ -9927,7 +10176,8 @@ static void test_bug3796() strcpy(canonical_buff + strlen(concat_arg0), "TWO"); DIE_UNLESS(strlen(canonical_buff) == out_length && strncmp(out_buff, canonical_buff, out_length) == 0); - printf("Concat result: '%s'\n", out_buff); + if (!opt_silent) + printf("Concat result: '%s'\n", out_buff); rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == MYSQL_NO_DATA); @@ -10001,12 +10251,15 @@ static void test_bug4026() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == 0); - printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second, - time_out.second_part); - printf("%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month, - datetime_out.day, datetime_out.hour, - datetime_out.minute, datetime_out.second, - datetime_out.second_part); + if (!opt_silent) + { + printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second, + time_out.second_part); + printf("%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month, + datetime_out.day, datetime_out.hour, + datetime_out.minute, datetime_out.second, + datetime_out.second_part); + } DIE_UNLESS(memcmp(&time_in, &time_out, sizeof(time_in)) == 0); DIE_UNLESS(memcmp(&datetime_in, &datetime_out, sizeof(datetime_in)) == 0); mysql_stmt_close(stmt); @@ -10049,8 +10302,9 @@ static void test_bug4079() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc != 0 && rc != MYSQL_NO_DATA); - printf("Got error from mysql_stmt_fetch (as expected):\n%s\n", - mysql_stmt_error(stmt)); + if (!opt_silent) + printf("Got error from mysql_stmt_fetch (as expected):\n%s\n", + mysql_stmt_error(stmt)); /* buggy version of libmysql hanged up here */ mysql_stmt_close(stmt); } @@ -10144,13 +10398,16 @@ static void test_bug4030() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == 0); - printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second, - time_out.second_part); - printf("%d-%d-%d\n", date_out.year, date_out.month, date_out.day); - printf("%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month, - datetime_out.day, datetime_out.hour, - datetime_out.minute, datetime_out.second, - datetime_out.second_part); + if (!opt_silent) + { + printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second, + time_out.second_part); + printf("%d-%d-%d\n", date_out.year, date_out.month, date_out.day); + printf("%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month, + datetime_out.day, datetime_out.hour, + datetime_out.minute, datetime_out.second, + datetime_out.second_part); + } DIE_UNLESS(memcmp(&time_canonical, &time_out, sizeof(time_out)) == 0); DIE_UNLESS(memcmp(&date_canonical, &date_out, sizeof(date_out)) == 0); DIE_UNLESS(memcmp(&datetime_canonical, &datetime_out, sizeof(datetime_out)) == 0); @@ -10200,7 +10457,8 @@ static void test_bug5126() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == 0); DIE_UNLESS(c1 == 8386608 && c2 == 1); - printf("%ld, %ld\n", (long) c1, (long) c2); + if (!opt_silent) + printf("%ld, %ld\n", (long) c1, (long) c2); mysql_stmt_close(stmt); } @@ -10306,7 +10564,8 @@ static void test_bug5399() check_execute(*stmt, rc); mysql_stmt_bind_result(*stmt, bind); } - printf("%d statements prepared.\n", NUM_OF_USED_STMT); + if (!opt_silent) + printf("%d statements prepared.\n", NUM_OF_USED_STMT); for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt) { @@ -10478,15 +10737,17 @@ static void test_bug5194() rc= mysql_stmt_prepare(stmt, query, query_ptr - query); if (rc && nrows * COLUMN_COUNT > uint16_max) { - printf("Failed to prepare a statement with %d placeholders " - "(as expected).\n", nrows * COLUMN_COUNT); + if (!opt_silent) + printf("Failed to prepare a statement with %d placeholders " + "(as expected).\n", nrows * COLUMN_COUNT); break; } else check_execute(stmt, rc); - printf("Insert: query length= %d, row count= %d, param count= %lu\n", - strlen(query), nrows, mysql_stmt_param_count(stmt)); + if (!opt_silent) + printf("Insert: query length= %d, row count= %d, param count= %lu\n", + strlen(query), nrows, mysql_stmt_param_count(stmt)); /* bind the parameter array and execute the query */ rc= mysql_stmt_bind_param(stmt, bind); @@ -10522,7 +10783,10 @@ static void test_bug5315() rc= mysql_stmt_execute(stmt); DIE_UNLESS(rc != 0); if (rc) - printf("Got error (as expected):\n%s", mysql_stmt_error(stmt)); + { + if (!opt_silent) + printf("Got error (as expected):\n%s", mysql_stmt_error(stmt)); + } /* check that connection is OK */ mysql_stmt_close(stmt); stmt= mysql_stmt_init(mysql); @@ -10570,8 +10834,11 @@ static void test_bug6049() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == 0); - printf("Result from query: %s\n", row[0]); - printf("Result from prepared statement: %s\n", (char*) buffer); + if (!opt_silent) + { + printf("Result from query: %s\n", row[0]); + printf("Result from prepared statement: %s\n", (char*) buffer); + } DIE_UNLESS(strcmp(row[0], (char*) buffer) == 0); @@ -10616,8 +10883,11 @@ static void test_bug6058() rc= mysql_stmt_fetch(stmt); DIE_UNLESS(rc == 0); - printf("Result from query: %s\n", row[0]); - printf("Result from prepared statement: %s\n", buffer); + if (!opt_silent) + { + printf("Result from query: %s\n", row[0]); + printf("Result from prepared statement: %s\n", buffer); + } DIE_UNLESS(strcmp(row[0], buffer) == 0); @@ -10656,17 +10926,17 @@ static void test_bug6046() stmt_text= "DROP TABLE IF EXISTS t1"; rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); - stmt_text= "CREATE TABLE a1 (a int, b int)"; + stmt_text= "CREATE TABLE t1 (a int, b int)"; rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); - stmt_text= "INSERT INTO a1 VALUES (1,1),(2,2),(3,1),(4,2)"; + stmt_text= "INSERT INTO t1 VALUES (1,1),(2,2),(3,1),(4,2)"; rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); myquery(rc); stmt= mysql_stmt_init(mysql); - stmt_text= "SELECT a1.a FROM a1 NATURAL JOIN a1 as X1 " - "WHERE a1.b > ? ORDER BY a1.a"; + stmt_text= "SELECT t1.a FROM t1 NATURAL JOIN t1 as X1 " + "WHERE t1.b > ? ORDER BY t1.a"; rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); check_execute(stmt, rc); @@ -10772,22 +11042,25 @@ static void test_bug6096() /* Print out and check the metadata */ - printf(" ---------------------------------------------------------------\n"); - printf(" | Metadata \n"); - printf(" ---------------------------------------------------------------\n"); - printf(" | Query | Prepared statement \n"); - printf(" ---------------------------------------------------------------\n"); - printf(" field name | length | max_length | length | max_length \n"); - printf(" ---------------------------------------------------------------\n"); - - for (i= 0; i < query_field_count; ++i) + if (!opt_silent) { - MYSQL_FIELD *f1= &query_field_list[i], *f2= &stmt_field_list[i]; - printf(" %-11s | %9lu | %10lu | %9lu | %10lu \n", - f1->name, f1->length, f1->max_length, f2->length, f2->max_length); - DIE_UNLESS(f1->length == f2->length); + printf(" ------------------------------------------------------------\n"); + printf(" | Metadata \n"); + printf(" ------------------------------------------------------------\n"); + printf(" | Query | Prepared statement \n"); + printf(" ------------------------------------------------------------\n"); + printf(" field name | length | max_length | length | max_length\n"); + printf(" ------------------------------------------------------------\n"); + + for (i= 0; i < query_field_count; ++i) + { + MYSQL_FIELD *f1= &query_field_list[i], *f2= &stmt_field_list[i]; + printf(" %-11s | %9lu | %10lu | %9lu | %10lu \n", + f1->name, f1->length, f1->max_length, f2->length, f2->max_length); + DIE_UNLESS(f1->length == f2->length); + } + printf(" ---------------------------------------------------------------\n"); } - printf(" ---------------------------------------------------------------\n"); /* Bind and fetch the data */ @@ -10842,6 +11115,8 @@ static struct my_option client_test_long_options[] = #endif {"port", 'P', "Port number to use for connection", (char **) &opt_port, (char **) &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"silent", 's', "Be more silent", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, + 0}, {"socket", 'S', "Socket file to use for connection", (char **) &opt_unix_socket, (char **) &opt_unix_socket, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"testcase", 'c', "May disable some code when runs as mysql-test-run testcase.", @@ -10851,36 +11126,25 @@ static struct my_option client_test_long_options[] = { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; -static void client_test_print_version(void) -{ - fprintf(stdout, "%s Distrib %s, for %s (%s)\n\n", - my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); -} - static void usage(void) { - /* - * show the usage string when the user asks for this - */ + /* show the usage string when the user asks for this */ putc('\n', stdout); - puts("***********************************************************************\n"); - puts(" Test for client-server protocol 4.1"); - puts(" By Monty & Venu \n"); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software, "); - puts("and you are welcome to modify and redistribute it under the GPL license\n"); - puts(" Copyright (C) 1995-2003 MySQL AB "); - puts("-----------------------------------------------------------------------\n"); - client_test_print_version(); - fprintf(stdout, "Usage: %s [OPTIONS]\n\n", my_progname); - + printf("%s Ver %s Distrib %s, for %s (%s)\n", + my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); + puts("By Monty, Venu, Kent and others\n"); + printf("\ +Copyright (C) 2002-2004 MySQL AB\n\ +This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ +and you are welcome to modify and redistribute it under the GPL license\n"); + printf("Usage: %s [OPTIONS]\n", my_progname); my_print_help(client_test_long_options); print_defaults("my", client_test_load_default_groups); my_print_variables(client_test_long_options); - - puts("***********************************************************************\n"); } + static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) @@ -10905,6 +11169,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), else tty_password= 1; break; + case 's': + if (argument == disabled_my_option) + opt_silent= 0; + else + opt_silent++; + break; case '?': case 'I': /* Info */ usage(); @@ -10933,14 +11203,17 @@ static void get_options(int argc, char **argv) static void print_test_output() { - fprintf(stdout, "\n\n"); - fprintf(stdout, "All '%d' tests were successful (in '%d' iterations)", - test_count-1, opt_count); - fprintf(stdout, "\n Total execution time: %g SECS", total_time); - if (opt_count > 1) - fprintf(stdout, " (Avg: %g SECS)", total_time/opt_count); - - fprintf(stdout, "\n\n!!! SUCCESS !!!\n"); + if (opt_silent < 3) + { + fprintf(stdout, "\n\n"); + fprintf(stdout, "All '%d' tests were successful (in '%d' iterations)", + test_count-1, opt_count); + fprintf(stdout, "\n Total execution time: %g SECS", total_time); + if (opt_count > 1) + fprintf(stdout, " (Avg: %g SECS)", total_time/opt_count); + + fprintf(stdout, "\n\n!!! SUCCESS !!!\n"); + } } |