From c5ed64a416d3c9c658a22c9b20c4d36d31408d7e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Jun 2006 04:10:27 +0300 Subject: [PATCH 1/4] Don't read ~/.my.cnf in mysqldump.test heap/hp_test1.c: Changed type from last commit mysql-test/mysql-test-run.sh: Fixed problem with running with --gdb and two masters Don't disable ndb becasue we run gdb mysql-test/t/mysqldump.test: Don't read ~/.my.cnf sql/ha_ndbcluster.cc: Portability fix --- heap/hp_test1.c | 2 +- mysql-test/mysql-test-run.sh | 20 +++++++------------- mysql-test/t/mysqldump.test | 2 +- sql/ha_ndbcluster.cc | 6 ++++-- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/heap/hp_test1.c b/heap/hp_test1.c index 1efa97842c7..703b39b1e2d 100644 --- a/heap/hp_test1.c +++ b/heap/hp_test1.c @@ -59,7 +59,7 @@ int main(int argc, char **argv) bzero((gptr) flags,sizeof(flags)); printf("- Creating heap-file\n"); - if (heap_create(filename,1,keyinfo,30,(ulong) flag*100000L,101L, + if (heap_create(filename,1,keyinfo,30,(ulong) flag*100000L,10L, &hp_create_info) || !(file= heap_open(filename, 2))) goto err; diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 93f741aecff..15c7470a74c 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -1252,16 +1252,16 @@ start_master() if [ x$DO_DDD = x1 ] then - $ECHO "set args $master_args" > $GDB_MASTER_INIT + $ECHO "set args $master_args" > $GDB_MASTER_INIT$1 manager_launch master ddd -display $DISPLAY --debugger \ - "gdb -x $GDB_MASTER_INIT" $MASTER_MYSQLD + "gdb -x $GDB_MASTER_INIT$1" $MASTER_MYSQLD elif [ x$DO_GDB = x1 ] then if [ x$MANUAL_GDB = x1 ] then - $ECHO "set args $master_args" > $GDB_MASTER_INIT + $ECHO "set args $master_args" > $GDB_MASTER_INIT$1 $ECHO "To start gdb for the master , type in another window:" - $ECHO "cd $CWD ; gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD" + $ECHO "cd $CWD ; gdb -x $GDB_MASTER_INIT$1 $MASTER_MYSQLD" wait_for_master=1500 else ( $ECHO set args $master_args; @@ -1273,9 +1273,9 @@ disa 1 end r EOF - fi ) > $GDB_MASTER_INIT + fi ) > $GDB_MASTER_INIT$1 manager_launch master $XTERM -display $DISPLAY \ - -title "Master" -e gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD + -title "Master" -e gdb -x $GDB_MASTER_INIT$1 $MASTER_MYSQLD fi else manager_launch master $MASTER_MYSQLD $master_args @@ -1810,13 +1810,7 @@ then mysql_install_db start_manager - -# Do not automagically start daemons if we are in gdb or running only one test -# case - if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ] - then - mysql_start - fi + mysql_start $ECHO "Loading Standard Test Databases" mysql_loadstd fi diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index eda89ff2dd3..e86635e24d0 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -652,7 +652,7 @@ drop table t1; # BUG#15328 Segmentation fault occured if my.cnf is invalid for escape sequence # ---exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQL_TEST_DIR/std_data/bug15328.cnf mysqldump +--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQL_TEST_DIR/std_data/bug15328.cnf mysqldump # BUG #19025 mysqldump doesn't correctly dump "auto_increment = [int]" diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 11fdd33fad9..1837b22cf42 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -2300,12 +2300,14 @@ void ha_ndbcluster::unpack_record(byte* buf) { // Table with hidden primary key int hidden_no= table->fields; + char buff[22]; const NDBTAB *tab= (const NDBTAB *) m_table; const NDBCOL *hidden_col= tab->getColumn(hidden_no); NdbRecAttr* rec= m_value[hidden_no].rec; DBUG_ASSERT(rec); - DBUG_PRINT("hidden", ("%d: %s \"%llu\"", hidden_no, - hidden_col->getName(), rec->u_64_value())); + DBUG_PRINT("hidden", ("%d: %s \"%s\"", hidden_no, + hidden_col->getName(), + llstr(rec->u_64_value(), buff))); } print_results(); #endif From 86155590380cc7a69e330ccf8ba7790475875a1a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Jun 2006 12:52:05 +0400 Subject: [PATCH 2/4] bug #20152: mysql_stmt_execute() overwrites parameter buffers When using a parameter bind MYSQL_TYPE_DATE in a prepared statement, the time part of the MYSQL_TIME buffer was written to zero in mysql_stmt_execute(). The param_store_date() function in libmysql.c worked directly on the provided buffer. Changed to use a copy of the buffer. libmysql/libmysql.c: fix for bug #20152 tests/mysql_client_test.c: added test for bug#20152 --- libmysql/libmysql.c | 7 +++--- tests/mysql_client_test.c | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 4b8f1c9da1f..80a7112eab2 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2409,10 +2409,9 @@ static void net_store_datetime(NET *net, MYSQL_TIME *tm) static void store_param_date(NET *net, MYSQL_BIND *param) { - MYSQL_TIME *tm= (MYSQL_TIME *) param->buffer; - tm->hour= tm->minute= tm->second= 0; - tm->second_part= 0; - net_store_datetime(net, tm); + MYSQL_TIME tm= *((MYSQL_TIME *) param->buffer); + tm.hour= tm.minute= tm.second= tm.second_part= 0; + net_store_datetime(net, &tm); } static void store_param_datetime(NET *net, MYSQL_BIND *param) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 3c54bf50c15..94034141d81 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -11855,6 +11855,58 @@ static void test_bug15613() mysql_stmt_close(stmt); } + +/* + Bug#20152: mysql_stmt_execute() writes to MYSQL_TYPE_DATE buffer + */ +static void test_bug20152() +{ + MYSQL_BIND bind[1]; + MYSQL_STMT *stmt; + MYSQL_TIME tm; + int rc; + const char *query= "INSERT INTO t1 (f1) VALUES (?)"; + + myheader("test_bug20152"); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_DATE; + bind[0].buffer= (void*)&tm; + + tm.year = 2006; + tm.month = 6; + tm.day = 18; + tm.hour = 14; + tm.minute = 9; + tm.second = 42; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + myquery(rc); + rc= mysql_query(mysql, "CREATE TABLE t1 (f1 DATE)"); + myquery(rc); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); + check_execute(stmt, rc); + rc= mysql_stmt_bind_param(stmt, bind); + check_execute(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + rc= mysql_stmt_close(stmt); + check_execute(stmt, rc); + rc= mysql_query(mysql, "DROP TABLE t1"); + myquery(rc); + + if (tm.hour == 14 && tm.minute == 9 && tm.second == 42) { + if (!opt_silent) + printf("OK!"); + } else { + printf("[14:09:42] != [%02d:%02d:%02d]\n", tm.hour, tm.minute, tm.second); + DIE_UNLESS(0==1); + } +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -12078,6 +12130,7 @@ static struct my_tests_st my_tests[]= { { "test_bug11718", test_bug11718 }, { "test_bug12925", test_bug12925 }, { "test_bug15613", test_bug15613 }, + { "test_bug20152", test_bug20152 }, { 0, 0 } }; From 437afbfda8ece60baa898b14fe8c01b3c00d8f09 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Jun 2006 16:25:07 +0200 Subject: [PATCH 3/4] adopted ndb handler code for tables without primary key and with unique index - added missing retrieval of hidden primary key --- sql/ha_ndbcluster.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 11fdd33fad9..e442d5991fa 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -1364,6 +1364,12 @@ int ha_ndbcluster::unique_index_read(const byte *key, m_value[i].ptr= NULL; } } + if (table->primary_key == MAX_KEY) + { + DBUG_PRINT("info", ("Getting hidden key")); + if (get_ndb_value(op, NULL, i, NULL)) + ERR_RETURN(op->getNdbError()); + } if (execute_no_commit_ie(this,trans) != 0) { From 66a59b10e9494b807c96f4ddb476d674f0295fd9 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Jun 2006 18:29:27 +0300 Subject: [PATCH 4/4] Reverted wrong bug fix (Bug#11228) mysql-test/r/key.result: Fixed result after removing wrong bug fix mysql-test/t/key.test: Added SHOW CREATE TABLE, which is the proper way to check for table definitions sql/table.cc: Reverted wrong bug fix. The intention with the original code was to show that MySQL treats the first given unique key as a primary key. Clients can use the marked primary key as a real primary key to validate row changes in case of conflicting updates. The ODBC driver (and other drivers) may also use this fact to optimize/check updates and handle conflicts. The marked key also shows what some engines, like InnoDB or NDB, will use as it's internal primary key. For checking if someone has declared a true PRIMARY KEY, one should use 'SHOW CREATE TABLE' --- mysql-test/r/key.result | 10 +++++++++- mysql-test/t/key.test | 1 + sql/table.cc | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/key.result b/mysql-test/r/key.result index 0bc241c0d19..75fc469460e 100644 --- a/mysql-test/r/key.result +++ b/mysql-test/r/key.result @@ -332,8 +332,16 @@ UNIQUE i1idx (i1), UNIQUE i2idx (i2)); desc t1; Field Type Null Key Default Extra -i1 int(11) UNI 0 +i1 int(11) PRI 0 i2 int(11) UNI 0 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i1` int(11) NOT NULL default '0', + `i2` int(11) NOT NULL default '0', + UNIQUE KEY `i1idx` (`i1`), + UNIQUE KEY `i2idx` (`i2`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 ( c1 int, diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index 796e36cb608..9aab8a13b06 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -330,6 +330,7 @@ create table t1 ( UNIQUE i1idx (i1), UNIQUE i2idx (i2)); desc t1; +show create table t1; drop table t1; # diff --git a/sql/table.cc b/sql/table.cc index 513f42665a6..8ac64ac198d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -567,6 +567,27 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, if (outparam->key_info[key].flags & HA_FULLTEXT) outparam->key_info[key].algorithm= HA_KEY_ALG_FULLTEXT; + if (primary_key >= MAX_KEY && (keyinfo->flags & HA_NOSAME)) + { + /* + If the UNIQUE key doesn't have NULL columns and is not a part key + declare this as a primary key. + */ + primary_key=key; + for (i=0 ; i < keyinfo->key_parts ;i++) + { + uint fieldnr= key_part[i].fieldnr; + if (!fieldnr || + outparam->field[fieldnr-1]->null_ptr || + outparam->field[fieldnr-1]->key_length() != + key_part[i].length) + { + primary_key=MAX_KEY; // Can't be used + break; + } + } + } + for (i=0 ; i < keyinfo->key_parts ; key_part++,i++) { if (new_field_pack_flag <= 1)