From f22517e4eca9b00049bb9cf9176c9d3489dfe94e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Jul 2003 00:13:22 -0700 Subject: [PATCH] Enable warnings by default for single value list inserts also when the client protocol is >= 4.1 tests/client_test.c: test for timestamp bug (BR #819) sql/sql_insert.cc: Enable warnings by default for single value list protocol mysql-test/t/warnings.test: Updated test for single value list insert warning mysql-test/r/warnings.result: Updated warnings results --- INSTALL-WIN-SOURCE | 2 +- mysql-test/r/warnings.result | 3 ++ mysql-test/t/warnings.test | 1 + sql/sql_insert.cc | 4 +- tests/client_test.c | 91 ++++++++++++++++++++++++++++++++++-- 5 files changed, 95 insertions(+), 6 deletions(-) diff --git a/INSTALL-WIN-SOURCE b/INSTALL-WIN-SOURCE index bce093633f5..78a8f0e5d5a 100755 --- a/INSTALL-WIN-SOURCE +++ b/INSTALL-WIN-SOURCE @@ -92,7 +92,7 @@ To build the latest Windows source package from the current BitKeeper source tree, use the following instructions. Please note that this procedure must be performed on a system running a Unix or Unix-like operating system. (The procedure -is know to work well on Linux, for example. +is know to work well on Linux), for example. - Clone the BitKeeper source tree for MySQL (version 4.1 or above, as desired). For more information how to clone diff --git a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result index d84c284d7b4..4e526d85d90 100644 --- a/mysql-test/r/warnings.result +++ b/mysql-test/r/warnings.result @@ -90,6 +90,9 @@ Warning 1263 Data truncated for column 'b' at row 2 Warning 1263 Data truncated for column 'b' at row 3 Warning 1261 Data truncated, NULL supplied to NOT NULL column 'a' at row 4 Warning 1263 Data truncated for column 'b' at row 4 +insert into t2(b) values('mysqlab'); +Warnings: +Warning 1263 Data truncated for column 'b' at row 1 drop table t1, t2; create table t1(a char(10)); alter table t1 add b char; diff --git a/mysql-test/t/warnings.test b/mysql-test/t/warnings.test index 6374fbf83ac..6991f9d9b2f 100644 --- a/mysql-test/t/warnings.test +++ b/mysql-test/t/warnings.test @@ -51,6 +51,7 @@ update t1 set c='mysql ab' where c='test'; update t1 set d=c; create table t2(a tinyint NOT NULL, b char(3)); insert into t2 select b,c from t1; +insert into t2(b) values('mysqlab'); drop table t1, t2; # diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 947205949f1..e2a7c517688 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -231,7 +231,9 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, info.update_fields=&update_fields; info.update_values=&update_values; // Don't count warnings for simple inserts - if (values_list.elements > 1 || (thd->options & OPTION_WARNINGS)) + if ((thd->client_capabilities & CLIENT_PROTOCOL_41) || + values_list.elements > 1 || + (thd->options & OPTION_WARNINGS)) thd->count_cuted_fields = 1; thd->cuted_fields = 0L; table->next_number_field=table->found_next_number_field; diff --git a/tests/client_test.c b/tests/client_test.c index 2741da1bbba..6ee7487ac45 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -176,7 +176,7 @@ static void client_connect() int rc; myheader_r("client_connect"); - fprintf(stdout, "\n Establishing a connection ..."); + fprintf(stdout, "\n Establishing a connection to '%s' ...", opt_host); if (!(mysql = mysql_init(NULL))) { @@ -3729,7 +3729,7 @@ static void test_stmt_close() fprintf(stdout, "\n Establishing a test connection ..."); if (!(lmysql = mysql_init(NULL))) { - myerror("mysql_init() failed"); + myerror("mysql_init() failed"); exit(0); } if (!(mysql_real_connect(lmysql,opt_host,opt_user, @@ -6071,7 +6071,7 @@ static void test_prepare_grant() fprintf(stdout, "\n Establishing a test connection ..."); if (!(lmysql = mysql_init(NULL))) { - myerror("mysql_init() failed"); + myerror("mysql_init() failed"); exit(0); } if (!(mysql_real_connect(lmysql,opt_host,"test_grant", @@ -6460,7 +6460,7 @@ static void test_drop_temp() fprintf(stdout, "\n Establishing a test connection ..."); if (!(lmysql = mysql_init(NULL))) { - myerror("mysql_init() failed"); + myerror("mysql_init() failed"); exit(0); } @@ -7160,6 +7160,11 @@ static void test_mem_overun() rc = mysql_real_query(mysql, buffer, length); myquery(rc); + + rc = mysql_query(mysql,"select * from t_mem_overun"); + myquery(rc); + + myassert(1 == my_process_result(mysql)); stmt = mysql_prepare(mysql, "select * from t_mem_overun",30); mystmt_init(stmt); @@ -7456,6 +7461,83 @@ static void test_sqlmode() mysql_stmt_close(stmt); } +/* + test for timestamp handling +*/ +static void test_ts() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + MYSQL_TIME ts; + char strts[30]; + long length; + int rc; + + myheader("test_ts"); + + rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_ts"); + myquery(rc); + + rc= mysql_query(mysql,"CREATE TABLE test_ts(a TIMESTAMP)"); + myquery(rc); + + rc = mysql_commit(mysql); + myquery(rc); + + stmt = mysql_prepare(mysql,"INSERT INTO test_ts VALUES(?),(?)",40); + mystmt_init(stmt); + + ts.year= 2003; + ts.month= 07; + ts.day= 12; + ts.hour= 21; + ts.minute= 07; + ts.second= 46; + length= (long)(strmov(strts,"2003-07-12 21:07:46") - strts); + + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= (char *)strts; + bind[0].buffer_length= sizeof(strts); + bind[0].is_null= 0; + bind[0].length= &length; + + bind[1].buffer_type= MYSQL_TYPE_TIMESTAMP; + bind[1].buffer= (char *)&ts; + bind[1].buffer_length= sizeof(ts); + bind[1].is_null= 0; + bind[1].length= 0; + + rc = mysql_bind_param(stmt, bind); + mystmt(stmt,rc); + + rc = mysql_execute(stmt); + mystmt(stmt,rc); + + mysql_stmt_close(stmt); + + verify_col_data("test_ts","a","2003-07-12 21:07:46"); + + stmt = mysql_prepare(mysql,"SELECT a FROM test_ts WHERE a >= ?",50); + mystmt_init(stmt); + + rc = mysql_bind_param(stmt, bind); + mystmt(stmt,rc); + + rc = mysql_execute(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + mystmt(stmt,rc); + + rc = mysql_fetch(stmt); + myassert(rc == MYSQL_NO_DATA); + + mysql_stmt_close(stmt); +} + /* Read and parse arguments and MySQL options from my.cnf @@ -7703,6 +7785,7 @@ int main(int argc, char **argv) test_fetch_offset(); /* to test mysql_fetch_column with offset */ test_fetch_column(); /* to test mysql_fetch_column */ test_sqlmode(); /* test for SQL_MODE */ + test_ts(); /* test for timestamp BR#819 */ end_time= time((time_t *)0); total_time+= difftime(end_time, start_time);