summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am16
-rw-r--r--tests/connect_test.c1
-rw-r--r--tests/deadlock_test.c1
-rw-r--r--tests/fork_big2.pl2
-rw-r--r--tests/grant.pl4
-rw-r--r--tests/insert_test.c1
-rw-r--r--tests/list_test.c1
-rwxr-xr-xtests/mail_to_db.pl54
-rw-r--r--tests/mysql_client_test.c3011
-rwxr-xr-xtests/pmail.pl283
-rw-r--r--tests/select_test.c1
-rw-r--r--tests/showdb_test.c1
-rw-r--r--tests/ssl_test.c1
-rw-r--r--tests/thread_test.c1
-rw-r--r--tests/udf_test3
-rw-r--r--tests/udf_test.res24
16 files changed, 3073 insertions, 332 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3c781b7e45b..131f8b1b625 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,6 +17,11 @@
## Process this file with automake to create Makefile.in
+if HAVE_YASSL
+ yassl_dummy_link_fix= $(top_srcdir)/extra/yassl/src/dummy.cpp
+else
+ yassl_dummy_link_fix=
+endif
EXTRA_DIST = auto_increment.res auto_increment.tst \
function.res function.tst lock_test.pl lock_test.res \
export.pl big_record.pl \
@@ -35,9 +40,12 @@ noinst_PROGRAMS = insert_test select_test thread_test
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
$(openssl_includes)
LIBS = @CLIENT_LIBS@
-LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysql/libmysqlclient.la
-mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS)
-mysql_client_test_SOURCES= mysql_client_test.c
+LDADD = @CLIENT_EXTRA_LDFLAGS@ \
+ $(top_builddir)/libmysql/libmysqlclient.la
+mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS)
+mysql_client_test_SOURCES= mysql_client_test.c $(yassl_dummy_link_fix)
+insert_test_SOURCES= insert_test.c $(yassl_dummy_link_fix)
+select_test_SOURCES= select_test.c $(yassl_dummy_link_fix)
insert_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
select_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
@@ -45,7 +53,7 @@ select_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
DEFS = -DUNDEF_THREADS_HACK
thread_test.o: thread_test.c
- $(COMPILE) -c @MT_INCLUDES@ $(INCLUDES) $<
+ $(COMPILE) -c $(INCLUDES) $<
# Don't update the files from bitkeeper
%::SCCS/s.%
diff --git a/tests/connect_test.c b/tests/connect_test.c
index fd81ad635ad..c68ade9f78f 100644
--- a/tests/connect_test.c
+++ b/tests/connect_test.c
@@ -46,6 +46,7 @@ int main(int argc, char **argv)
perror("");
exit(1);
}
+ sock->reconnect= 1;
if (mysql_select_db(sock,"test"))
{
diff --git a/tests/deadlock_test.c b/tests/deadlock_test.c
index 65a0df5c215..ab8158e0cd8 100644
--- a/tests/deadlock_test.c
+++ b/tests/deadlock_test.c
@@ -227,6 +227,7 @@ int main()
!mysql_real_connect(&sel, host, user, pass, db, 0,0,0 ) ||
!mysql_real_connect(&del_ins, host, user, pass, db, 0,0,0 ))
die("Error in mysql_real_connect(): %s", mysql_error(&lock));
+ lock.reconnect= sel.reconnect= del_ins.reconnect= 1;
permute(order, num_queries);
printf("count = %d\n", count);
diff --git a/tests/fork_big2.pl b/tests/fork_big2.pl
index a1c55ac4c11..567cfafa176 100644
--- a/tests/fork_big2.pl
+++ b/tests/fork_big2.pl
@@ -300,7 +300,7 @@ sub test_select
#
# Do big select count(distinct..) over the table
-#
+#
sub test_select_count
{
diff --git a/tests/grant.pl b/tests/grant.pl
index cd6a2eb80de..4f2bd1a61cb 100644
--- a/tests/grant.pl
+++ b/tests/grant.pl
@@ -201,7 +201,7 @@ safe_query("select * from mysql.db where user = '$opt_user'");
safe_query("grant CREATE,UPDATE,DROP on $opt_database.* to $user");
user_connect(0);
user_query("create table $opt_database.test2 (a int not null)");
-user_query("update test,test2 SET test.a=1 where 1");
+user_query("update test,test2 SET test.a=1 where 1",1);
user_query("update test,test2 SET test.a=test2.a where 1",1);
safe_query("grant SELECT on $opt_database.* to $user");
user_connect(0);
@@ -375,7 +375,7 @@ user_query("delete from $opt_database.test where a=2");
user_query("delete from $opt_database.test where A=2");
user_query("update test set b=5 where b>0");
user_query("update test set a=11 where b>5",1);
-user_query("update test,test2 SET test.b=5 where b>0");
+user_query("update test,test2 SET test.b=5 where b>0",1);
user_query("update test,test2 SET test.a=11 where b>0",1);
user_query("update test,test2 SET test.b=test2.a where b>0",1);
user_query("update test,test2 SET test.b=11 where test2.a>0",1);
diff --git a/tests/insert_test.c b/tests/insert_test.c
index 052c12bfdf0..2b659e9eecb 100644
--- a/tests/insert_test.c
+++ b/tests/insert_test.c
@@ -40,6 +40,7 @@ int main(int argc, char **argv)
perror("");
exit(1);
}
+ mysql.reconnect= 1;
num = atoi(argv[2]);
count = 0;
diff --git a/tests/list_test.c b/tests/list_test.c
index 06bf16d2751..1d50e703133 100644
--- a/tests/list_test.c
+++ b/tests/list_test.c
@@ -43,6 +43,7 @@ int main(int argc, char **argv)
perror("");
exit(1);
}
+ mysql.reconnect= 1;
if (mysql_select_db(sock,argv[1]) < 0)
{
diff --git a/tests/mail_to_db.pl b/tests/mail_to_db.pl
index dc40fb3ede6..5ceda392313 100755
--- a/tests/mail_to_db.pl
+++ b/tests/mail_to_db.pl
@@ -17,7 +17,7 @@ use DBI;
use Getopt::Long;
$| = 1;
-$VER = "2.6";
+$VER = "3.0";
$opt_help = 0;
$opt_version = 0;
@@ -26,7 +26,6 @@ $opt_host = undef();
$opt_port = undef();
$opt_socket = undef();
$opt_db = "mail";
-$opt_table = "mails";
$opt_user = undef();
$opt_password = undef();
$opt_max_mail_size = 65536;
@@ -97,7 +96,7 @@ sub main
print "the my.cnf file. This command is available from the latest MySQL\n";
print "distribution.\n";
}
- GetOptions("help","version","host=s","port=i","socket=s","db=s","table=s",
+ GetOptions("help","version","host=s","port=i","socket=s","db=s",
"user=s","password=s","max_mail_size=i","create","test",
"no_path","debug","stop_on_error","stdin")
|| die "Wrong option! See $progname --help\n";
@@ -123,7 +122,6 @@ sub main
|| die "Couldn't connect: $DBI::errstr\n";
die "You must specify the database; use --db=" if (!defined($opt_db));
- die "You must specify the table; use --table=" if (!defined($opt_table));
create_table($dbh) if ($opt_create);
@@ -218,9 +216,9 @@ sub main
print "Total number of mails:\t\t\t\t";
print $mail_inserted + $ignored;
print " (OK: ";
- print sprintf("%.1f", (($mail_inserted / ($mail_inserted+$ignored)) * 100));
+ print sprintf("%.1f", ($mail_inserted + $ignored) ? (($mail_inserted / ($mail_inserted+$ignored)) * 100) : 0.0);
print "% Ignored: ";
- print sprintf("%.1f", (($ignored / ($mail_inserted + $ignored)) * 100));
+ print sprintf("%.1f", ($mail_inserted + $ignored) ? (($ignored / ($mail_inserted + $ignored)) * 100) : 0);
print "%)\n";
print "################################ End Report ##################################\n";
exit(0);
@@ -232,13 +230,15 @@ sub main
sub create_table
{
- my ($dbh) = @_;
+ my ($dbh)= @_;
my ($sth, $query);
- $query = <<EOF;
-CREATE TABLE $opt_table
+ $query= <<EOF;
+CREATE TABLE my_mail
(
mail_id MEDIUMINT UNSIGNED NOT NULL auto_increment,
+ message_id VARCHAR(255),
+ in_reply_to VARCHAR(255),
date DATETIME NOT NULL,
time_zone VARCHAR(20),
mail_from VARCHAR(120) NOT NULL,
@@ -250,6 +250,8 @@ CREATE TABLE $opt_table
file VARCHAR(64) NOT NULL,
hash INTEGER NOT NULL,
KEY (mail_id),
+ KEY (message_id),
+ KEY (in_reply_to),
PRIMARY KEY (mail_from, date, hash))
TYPE=MyISAM COMMENT=''
EOF
@@ -277,7 +279,7 @@ sub process_mail_file
chop if (substr($_, -1, 1) eq "\r");
if ($type ne "message")
{
- if (/^Reply-To: (.*)/i)
+ if (/^Reply-To:\s*(.*)/i)
{
$type = "reply";
$values{$type} = $1;
@@ -302,14 +304,27 @@ sub process_mail_file
$type = "subject";
$values{$type} = $1;
}
+ elsif (/^Message-Id:\s*(.*)/i)
+ {
+ $type = "message_id";
+ s/^\s*(<.*>)\s*/$1/;
+ $values{$type} = $1;
+ }
+ elsif (/^In-Reply-To:\s*(.*)/i)
+ {
+ $type = "in_reply_to";
+ s/^\s*(<.*>)\s*/$1/;
+ $values{$type} = $1;
+ }
elsif (/^Date: (.*)/i)
{
date_parser($1, \%values, $file_name);
$type = "rubbish";
}
- elsif (/^[\w\W-]+:\s/)
+ # Catch those fields that we don't or can't handle (yet)
+ elsif (/^[\w\W-]+:/)
{
- $type = "rubbish";
+ $type = "rubbish";
}
elsif ($_ eq "")
{
@@ -319,6 +334,10 @@ sub process_mail_file
else
{
s/^\s*/ /;
+ if ($type eq 'message_id' || $type eq 'in_reply_to')
+ {
+ s/^\s*(<.*>)\s*/$1/;
+ }
$values{$type} .= $_;
}
}
@@ -421,8 +440,10 @@ sub update_table
goto restart; # Some mails may have duplicated messages
}
- $q = "INSERT INTO $opt_table (";
+ $q = "INSERT INTO my_mail (";
$q.= "mail_id,";
+ $q.= "message_id,";
+ $q.= "in_reply_to,";
$q.= "date,";
$q.= "time_zone,";
$q.= "mail_from,";
@@ -435,6 +456,12 @@ sub update_table
$q.= "hash";
$q.= ") VALUES (";
$q.= "NULL,";
+ $q.= (defined($values->{'message_id'}) ?
+ $dbh->quote($values->{'message_id'}) : "NULL");
+ $q.= ",";
+ $q.= (defined($values->{'in_reply_to'}) ?
+ $dbh->quote($values->{'in_reply_to'}) : "NULL");
+ $q.= ",";
$q.= "'" . $values->{'date'} . "',";
$q.= (defined($values->{'time_zone'}) ?
$dbh->quote($values->{'time_zone'}) : "NULL");
@@ -575,7 +602,6 @@ Options:
--port=# TCP/IP port to be used with connection.
--socket=... MySQL UNIX socket to be used with connection.
--db=... Database to be used.
---table=... Table name for mails.
--user=... Username for connecting.
--password=... Password for the user.
--stdin Read mails from stdin.
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index ffcf5b6f34d..84a32b52284 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -21,6 +21,12 @@
Main author: venu ( venu@mysql.com )
***************************************************************************/
+/*
+ XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST
+ DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH.
+*/
+
+
#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>
@@ -30,6 +36,7 @@
#define VER "2.1"
#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */
+#define MAX_KEY 64
#define MAX_SERVER_ARGS 64
/* set default options */
@@ -48,6 +55,7 @@ static char current_db[]= "client_test_db";
static unsigned int test_count= 0;
static unsigned int opt_count= 0;
static unsigned int iter_count= 0;
+static my_bool have_innodb= FALSE;
static const char *opt_basedir= "./";
@@ -64,7 +72,7 @@ static const char *embedded_server_groups[]= {
static time_t start_time, end_time;
static double total_time;
-const char *default_dbug_option= "d:t:o,/tmp/client_test.trace";
+const char *default_dbug_option= "d:t:o,/tmp/mysql_client_test.trace";
struct my_tests_st
{
@@ -213,6 +221,28 @@ static void print_st_error(MYSQL_STMT *stmt, const char *msg)
}
}
+/* Check if the connection has InnoDB tables */
+
+static my_bool check_have_innodb(MYSQL *conn)
+{
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ int rc;
+ my_bool result;
+
+ rc= mysql_query(conn, "show variables like 'have_innodb'");
+ myquery(rc);
+ res= mysql_use_result(conn);
+ DIE_UNLESS(res);
+
+ row= mysql_fetch_row(res);
+ DIE_UNLESS(row);
+
+ result= strcmp(row[1], "YES") == 0;
+ mysql_free_result(res);
+ return result;
+}
+
/*
This is to be what mysql_query() is for mysql_real_query(), for
@@ -234,7 +264,7 @@ mysql_simple_prepare(MYSQL *mysql, const char *query)
/* Connect to the server */
-static void client_connect()
+static void client_connect(ulong flag)
{
int rc;
myheader_r("client_connect");
@@ -252,7 +282,7 @@ static void client_connect()
if (!(mysql_real_connect(mysql, opt_host, opt_user,
opt_password, opt_db ? opt_db:"test", opt_port,
- opt_unix_socket, 0)))
+ opt_unix_socket, flag)))
{
opt_silent= 0;
myerror("connection failed");
@@ -260,6 +290,7 @@ static void client_connect()
fprintf(stdout, "\n Check the connection options using --help or -?\n");
exit(1);
}
+ mysql->reconnect= 1;
if (!opt_silent)
fprintf(stdout, " OK");
@@ -268,7 +299,12 @@ static void client_connect()
mysql_autocommit(mysql, TRUE);
if (!opt_silent)
+ {
+ fprintf(stdout, "\nConnected to MySQL server version: %s (%lu)\n",
+ mysql_get_server_info(mysql),
+ (ulong) mysql_get_server_version(mysql));
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);
@@ -277,6 +313,7 @@ static void client_connect()
strxmov(query, "USE ", current_db, NullS);
rc= mysql_query(mysql, query);
myquery(rc);
+ have_innodb= check_have_innodb(mysql);
if (!opt_silent)
fprintf(stdout, " OK");
@@ -533,16 +570,18 @@ int my_process_stmt_result(MYSQL_STMT *stmt)
buffer[i].buffer= (void *) data[i];
buffer[i].is_null= &is_null[i];
}
- my_print_result_metadata(result);
rc= mysql_stmt_bind_result(stmt, buffer);
check_execute(stmt, rc);
+ rc= 1;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*)&rc);
rc= mysql_stmt_store_result(stmt);
check_execute(stmt, rc);
+ my_print_result_metadata(result);
mysql_field_seek(result, 0);
- while (mysql_stmt_fetch(stmt) == 0)
+ while ((rc= mysql_stmt_fetch(stmt)) == 0)
{
if (!opt_silent)
{
@@ -575,6 +614,7 @@ int my_process_stmt_result(MYSQL_STMT *stmt)
}
row_count++;
}
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
if (!opt_silent)
{
if (row_count)
@@ -650,13 +690,20 @@ 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)
+#define verify_prepare_field(result,no,name,org_name,type,table,\
+ org_table,db,length,def) \
+ do_verify_prepare_field((result),(no),(name),(org_name),(type), \
+ (table),(org_table),(db),(length),(def), \
+ __FILE__, __LINE__)
+
+static void do_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,
+ const char *file, int line)
{
MYSQL_FIELD *field;
CHARSET_INFO *cs;
@@ -675,10 +722,12 @@ static void verify_prepare_field(MYSQL_RES *result,
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);
+ if (table)
+ fprintf(stdout, "\n table :`%s`\t(expected: `%s`)",
+ field->table, table);
+ if (org_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 :`%lu`\t(expected: `%lu`)",
field->length, length * cs->mbmaxlen);
@@ -698,16 +747,31 @@ static void verify_prepare_field(MYSQL_RES *result,
expect.
*/
if (cs->mbmaxlen == 1)
- DIE_UNLESS(field->type == type);
- DIE_UNLESS(strcmp(field->table, table) == 0);
- DIE_UNLESS(strcmp(field->org_table, org_table) == 0);
+ {
+ if (field->type != type)
+ {
+ fprintf(stderr,
+ "Expected field type: %d, got type: %d in file %s, line %d\n",
+ (int) type, (int) field->type, file, line);
+ DIE_UNLESS(field->type == type);
+ }
+ }
+ if (table)
+ DIE_UNLESS(strcmp(field->table, table) == 0);
+ if (org_table)
+ DIE_UNLESS(strcmp(field->org_table, org_table) == 0);
DIE_UNLESS(strcmp(field->db, db) == 0);
/*
Character set should be taken into account for multibyte encodings, such
as utf8. Field length is calculated as number of characters * maximum
number of bytes a character can occupy.
*/
- DIE_UNLESS(field->length == length * cs->mbmaxlen);
+ if (length && field->length != length * cs->mbmaxlen)
+ {
+ fprintf(stderr, "Expected field length: %d, got length: %d\n",
+ (int) (length * cs->mbmaxlen), (int) field->length);
+ DIE_UNLESS(field->length == length * cs->mbmaxlen);
+ }
if (def)
DIE_UNLESS(strcmp(field->def, def) == 0);
}
@@ -731,8 +795,8 @@ static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count)
{
ulonglong affected_rows= mysql_stmt_affected_rows(stmt);
if (!opt_silent)
- fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)",
- affected_rows, exp_count);
+ fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)",
+ (long) affected_rows, (long) exp_count);
DIE_UNLESS(affected_rows == exp_count);
}
@@ -743,8 +807,8 @@ static void verify_affected_rows(ulonglong exp_count)
{
ulonglong affected_rows= mysql_affected_rows(mysql);
if (!opt_silent)
- fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)",
- affected_rows, exp_count);
+ fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)",
+ (long) affected_rows, (long) exp_count);
DIE_UNLESS(affected_rows == exp_count);
}
@@ -763,6 +827,7 @@ static void verify_field_count(MYSQL_RES *result, uint exp_count)
/* Utility function to execute a query using prepare-execute */
+#ifndef EMBEDDED_LIBRARY
static void execute_prepare_query(const char *query, ulonglong exp_count)
{
MYSQL_STMT *stmt;
@@ -777,13 +842,13 @@ static void execute_prepare_query(const char *query, ulonglong exp_count)
affected_rows= mysql_stmt_affected_rows(stmt);
if (!opt_silent)
- fprintf(stdout, "\n total affected rows: `%lld` (expected: `%lld`)",
- affected_rows, exp_count);
+ fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)",
+ (long) affected_rows, (long) exp_count);
DIE_UNLESS(affected_rows == exp_count);
mysql_stmt_close(stmt);
}
-
+#endif
/* Store result processing */
@@ -826,6 +891,218 @@ static void client_use_result()
}
+/*
+ Accepts arbitrary number of queries and runs them against the database.
+ Used to fill tables for each test.
+*/
+
+void fill_tables(const char **query_list, unsigned query_count)
+{
+ int rc;
+ const char **query;
+ DBUG_ENTER("fill_tables");
+ for (query= query_list; query < query_list + query_count;
+ ++query)
+ {
+ rc= mysql_query(mysql, *query);
+ myquery(rc);
+ }
+ DBUG_VOID_RETURN;
+}
+
+/*
+ All state of fetch from one statement: statement handle, out buffers,
+ fetch position.
+ See fetch_n for for the only use case.
+*/
+
+enum { MAX_COLUMN_LENGTH= 255 };
+
+typedef struct st_stmt_fetch
+{
+ const char *query;
+ unsigned stmt_no;
+ MYSQL_STMT *handle;
+ my_bool is_open;
+ MYSQL_BIND *bind_array;
+ char **out_data;
+ unsigned long *out_data_length;
+ unsigned column_count;
+ unsigned row_count;
+} Stmt_fetch;
+
+
+/*
+ Create statement handle, prepare it with statement, execute and allocate
+ fetch buffers.
+*/
+
+void stmt_fetch_init(Stmt_fetch *fetch, unsigned stmt_no_arg,
+ const char *query_arg)
+{
+ unsigned long type= CURSOR_TYPE_READ_ONLY;
+ int rc;
+ unsigned i;
+ MYSQL_RES *metadata;
+ DBUG_ENTER("stmt_fetch_init");
+
+ /* Save query and statement number for error messages */
+ fetch->stmt_no= stmt_no_arg;
+ fetch->query= query_arg;
+
+ fetch->handle= mysql_stmt_init(mysql);
+
+ rc= mysql_stmt_prepare(fetch->handle, fetch->query, strlen(fetch->query));
+ check_execute(fetch->handle, rc);
+
+ /*
+ The attribute is sent to server on execute and asks to open read-only
+ for result set
+ */
+ mysql_stmt_attr_set(fetch->handle, STMT_ATTR_CURSOR_TYPE,
+ (const void*) &type);
+
+ rc= mysql_stmt_execute(fetch->handle);
+ check_execute(fetch->handle, rc);
+
+ /* Find out total number of columns in result set */
+ metadata= mysql_stmt_result_metadata(fetch->handle);
+ fetch->column_count= mysql_num_fields(metadata);
+ mysql_free_result(metadata);
+
+ /*
+ Now allocate bind handles and buffers for output data:
+ calloc memory to reduce number of MYSQL_BIND members we need to
+ set up.
+ */
+
+ fetch->bind_array= (MYSQL_BIND *) calloc(1, sizeof(MYSQL_BIND) *
+ fetch->column_count);
+ fetch->out_data= (char**) calloc(1, sizeof(char*) * fetch->column_count);
+ fetch->out_data_length= (ulong*) calloc(1, sizeof(ulong) *
+ fetch->column_count);
+ for (i= 0; i < fetch->column_count; ++i)
+ {
+ fetch->out_data[i]= (char*) calloc(1, MAX_COLUMN_LENGTH);
+ fetch->bind_array[i].buffer_type= MYSQL_TYPE_STRING;
+ fetch->bind_array[i].buffer= fetch->out_data[i];
+ fetch->bind_array[i].buffer_length= MAX_COLUMN_LENGTH;
+ fetch->bind_array[i].length= fetch->out_data_length + i;
+ }
+
+ mysql_stmt_bind_result(fetch->handle, fetch->bind_array);
+
+ fetch->row_count= 0;
+ fetch->is_open= TRUE;
+
+ /* Ready for reading rows */
+ DBUG_VOID_RETURN;
+}
+
+
+/* Fetch and print one row from cursor */
+
+int stmt_fetch_fetch_row(Stmt_fetch *fetch)
+{
+ int rc;
+ unsigned i;
+ DBUG_ENTER("stmt_fetch_fetch_row");
+
+ if ((rc= mysql_stmt_fetch(fetch->handle)) == 0)
+ {
+ ++fetch->row_count;
+ if (!opt_silent)
+ printf("Stmt %d fetched row %d:\n", fetch->stmt_no, fetch->row_count);
+ for (i= 0; i < fetch->column_count; ++i)
+ {
+ fetch->out_data[i][fetch->out_data_length[i]]= '\0';
+ if (!opt_silent)
+ printf("column %d: %s\n", i+1, fetch->out_data[i]);
+ }
+ }
+ else
+ fetch->is_open= FALSE;
+ DBUG_RETURN(rc);
+}
+
+
+void stmt_fetch_close(Stmt_fetch *fetch)
+{
+ unsigned i;
+ DBUG_ENTER("stmt_fetch_close");
+
+ for (i= 0; i < fetch->column_count; ++i)
+ free(fetch->out_data[i]);
+ free(fetch->out_data);
+ free(fetch->out_data_length);
+ free(fetch->bind_array);
+ mysql_stmt_close(fetch->handle);
+ DBUG_VOID_RETURN;
+}
+
+/*
+ For given array of queries, open query_count cursors and fetch
+ from them in simultaneous manner.
+ In case there was an error in one of the cursors, continue
+ reading from the rest.
+*/
+
+my_bool fetch_n(const char **query_list, unsigned query_count)
+{
+ unsigned open_statements= query_count;
+ int rc, error_count= 0;
+ Stmt_fetch *fetch_array= (Stmt_fetch*) calloc(1, sizeof(Stmt_fetch) *
+ query_count);
+ Stmt_fetch *fetch;
+ DBUG_ENTER("fetch_n");
+
+ for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch)
+ {
+ /* Init will exit(1) in case of error */
+ stmt_fetch_init(fetch, fetch - fetch_array,
+ query_list[fetch - fetch_array]);
+ }
+
+ while (open_statements)
+ {
+ for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch)
+ {
+ if (fetch->is_open && (rc= stmt_fetch_fetch_row(fetch)))
+ {
+ open_statements--;
+ /*
+ We try to fetch from the rest of the statements in case of
+ error
+ */
+ if (rc != MYSQL_NO_DATA)
+ {
+ fprintf(stderr,
+ "Got error reading rows from statement %d,\n"
+ "query is: %s,\n"
+ "error message: %s", (int) (fetch - fetch_array),
+ fetch->query,
+ mysql_stmt_error(fetch->handle));
+ error_count++;
+ }
+ }
+ }
+ }
+ if (error_count)
+ fprintf(stderr, "Fetch FAILED");
+ else
+ {
+ unsigned total_row_count= 0;
+ for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch)
+ total_row_count+= fetch->row_count;
+ if (!opt_silent)
+ printf("Success, total rows fetched: %d\n", total_row_count);
+ }
+ for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch)
+ stmt_fetch_close(fetch);
+ free(fetch_array);
+ DBUG_RETURN(error_count != 0);
+}
+
/* Separate thread query to test some cases */
static my_bool thread_query(char *query)
@@ -849,6 +1126,7 @@ static my_bool thread_query(char *query)
error= 1;
goto end;
}
+ l_mysql->reconnect= 1;
if (mysql_query(l_mysql, (char *)query))
{
fprintf(stderr, "Query failed (%s)\n", mysql_error(l_mysql));
@@ -1208,7 +1486,9 @@ static void test_prepare_field_result()
"t1", "test_prepare_field_result", current_db, 10, 0);
verify_prepare_field(result, 3, "ts_c", "ts_c", MYSQL_TYPE_TIMESTAMP,
"t1", "test_prepare_field_result", current_db, 19, 0);
- verify_prepare_field(result, 4, "char_c", "char_c", MYSQL_TYPE_VAR_STRING,
+ verify_prepare_field(result, 4, "char_c", "char_c",
+ (mysql_get_server_version(mysql) <= 50000 ?
+ MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING),
"t1", "test_prepare_field_result", current_db, 4, 0);
verify_field_count(result, 5);
@@ -1262,6 +1542,7 @@ static void test_prepare()
double double_data, o_double_data;
ulong length[7], len;
my_bool is_null[7];
+ char llbuf[22];
MYSQL_BIND bind[7];
myheader("test_prepare");
@@ -1376,11 +1657,11 @@ static void test_prepare()
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 big : %s (%lu)", llstr(big_data, llbuf),
+ length[4]);
fprintf(stdout, "\n\t float : %f (%lu)", real_data, length[5]);
fprintf(stdout, "\n\t double : %f (%lu)", double_data, length[6]);
@@ -1719,6 +2000,7 @@ static void test_fetch_null()
myquery(rc);
/* fetch */
+ bzero((char*) bind, sizeof(bind));
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
@@ -2028,7 +2310,7 @@ static void test_ps_conj_select()
check_execute(stmt, rc);
int_data= 1;
- strcpy(str_data, "hh");
+ strmov(str_data, "hh");
str_length= strlen(str_data);
rc= mysql_stmt_execute(stmt);
@@ -2072,7 +2354,9 @@ session_id char(9) NOT NULL, \
"(\"abj\", 1, 2, 3, 2003-08-30), "
"(\"abk\", 1, 2, 3, 2003-08-30), "
"(\"abl\", 1, 2, 3, 2003-08-30), "
- "(\"abq\", 1, 2, 3, 2003-08-30), "
+ "(\"abq\", 1, 2, 3, 2003-08-30) ");
+ myquery(rc);
+ rc= mysql_query(mysql, "INSERT INTO test_select VALUES "
"(\"abw\", 1, 2, 3, 2003-08-30), "
"(\"abe\", 1, 2, 3, 2003-08-30), "
"(\"abr\", 1, 2, 3, 2003-08-30), "
@@ -2787,11 +3071,13 @@ static void test_long_data_str1()
bind[0].buffer= (void *) &data; /* this buffer won't be altered */
bind[0].buffer_length= 16;
bind[0].length= &blob_length;
+ bind[0].error= &bind[0].error_value;
rc= mysql_stmt_bind_result(stmt, bind);
data[16]= 0;
rc= mysql_stmt_fetch(stmt);
- DIE_UNLESS(rc == 0);
+ DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
+ DIE_UNLESS(bind[0].error_value);
DIE_UNLESS(strlen(data) == 16);
DIE_UNLESS(blob_length == max_blob_length);
@@ -3128,7 +3414,7 @@ static void test_bind_result()
MYSQL_STMT *stmt;
int rc;
int nData;
- ulong length, length1;
+ ulong length1;
char szData[100];
MYSQL_BIND bind[2];
my_bool is_null[2];
@@ -3155,10 +3441,10 @@ static void test_bind_result()
/* fetch */
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (void *) &nData; /* integer data */
bind[0].is_null= &is_null[0];
- bind[0].length= 0;
bind[1].buffer_type= MYSQL_TYPE_STRING;
bind[1].buffer= szData; /* string data */
@@ -3193,7 +3479,6 @@ static void test_bind_result()
DIE_UNLESS(strcmp(szData, "MySQL") == 0);
DIE_UNLESS(length1 == 5);
- length= 99;
rc= mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
@@ -3227,7 +3512,7 @@ static void test_bind_result_ext()
MYSQL_BIND bind[8];
ulong length[8];
my_bool is_null[8];
-
+ char llbuf[22];
myheader("test_bind_result_ext");
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result");
@@ -3249,6 +3534,7 @@ static void test_bind_result_ext()
rc= mysql_commit(mysql);
myquery(rc);
+ bzero((char*) bind, sizeof(bind));
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].length= &length[i];
@@ -3300,7 +3586,7 @@ static void test_bind_result_ext()
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 (big) : %s", llstr(b_data, llbuf));
fprintf(stdout, "\n data (float) : %f", f_data);
fprintf(stdout, "\n data (double) : %f", d_data);
@@ -3367,37 +3653,46 @@ static void test_bind_result_ext1()
rc= mysql_commit(mysql);
myquery(rc);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (void *) t_data;
bind[0].buffer_length= sizeof(t_data);
+ bind[0].error= &bind[0].error_value;
bind[1].buffer_type= MYSQL_TYPE_FLOAT;
bind[1].buffer= (void *)&s_data;
bind[1].buffer_length= 0;
+ bind[1].error= &bind[1].error_value;
bind[2].buffer_type= MYSQL_TYPE_SHORT;
bind[2].buffer= (void *)&i_data;
bind[2].buffer_length= 0;
+ bind[2].error= &bind[2].error_value;
bind[3].buffer_type= MYSQL_TYPE_TINY;
bind[3].buffer= (void *)&b_data;
bind[3].buffer_length= 0;
+ bind[3].error= &bind[3].error_value;
bind[4].buffer_type= MYSQL_TYPE_LONG;
bind[4].buffer= (void *)&f_data;
bind[4].buffer_length= 0;
+ bind[4].error= &bind[4].error_value;
bind[5].buffer_type= MYSQL_TYPE_STRING;
bind[5].buffer= (void *)d_data;
bind[5].buffer_length= sizeof(d_data);
+ bind[5].error= &bind[5].error_value;
bind[6].buffer_type= MYSQL_TYPE_LONG;
bind[6].buffer= (void *)&bData;
bind[6].buffer_length= 0;
+ bind[6].error= &bind[6].error_value;
bind[7].buffer_type= MYSQL_TYPE_DOUBLE;
bind[7].buffer= (void *)&szData;
bind[7].buffer_length= 0;
+ bind[7].error= &bind[7].error_value;
for (i= 0; i < array_elements(bind); i++)
{
@@ -3415,7 +3710,8 @@ static void test_bind_result_ext1()
check_execute(stmt, rc);
rc= mysql_stmt_fetch(stmt);
- check_execute(stmt, rc);
+ printf("rc=%d\n", rc);
+ DIE_UNLESS(rc == 0);
if (!opt_silent)
{
@@ -3650,6 +3946,7 @@ static void test_fetch_date()
rc= mysql_commit(mysql);
myquery(rc);
+ bzero((char*) bind, sizeof(bind));
for (i= 0; i < array_elements(bind); i++)
{
bind[i].is_null= &is_null[i];
@@ -3931,40 +4228,40 @@ static void test_prepare_ext()
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext");
myquery(rc);
- sql= (char *)"CREATE TABLE test_prepare_ext\
- (\
- c1 tinyint, \
- c2 smallint, \
- c3 mediumint, \
- c4 int, \
- c5 integer, \
- c6 bigint, \
- c7 float, \
- c8 double, \
- c9 double precision, \
- c10 real, \
- c11 decimal(7, 4), \
- c12 numeric(8, 4), \
- c13 date, \
- c14 datetime, \
- c15 timestamp(14), \
- c16 time, \
- c17 year, \
- c18 bit, \
- c19 bool, \
- c20 char, \
- c21 char(10), \
- c22 varchar(30), \
- c23 tinyblob, \
- c24 tinytext, \
- c25 blob, \
- c26 text, \
- c27 mediumblob, \
- c28 mediumtext, \
- c29 longblob, \
- c30 longtext, \
- c31 enum('one', 'two', 'three'), \
- c32 set('monday', 'tuesday', 'wednesday'))";
+ sql= (char *)"CREATE TABLE test_prepare_ext"
+ "("
+ " c1 tinyint,"
+ " c2 smallint,"
+ " c3 mediumint,"
+ " c4 int,"
+ " c5 integer,"
+ " c6 bigint,"
+ " c7 float,"
+ " c8 double,"
+ " c9 double precision,"
+ " c10 real,"
+ " c11 decimal(7, 4),"
+ " c12 numeric(8, 4),"
+ " c13 date,"
+ " c14 datetime,"
+ " c15 timestamp(14),"
+ " c16 time,"
+ " c17 year,"
+ " c18 bit,"
+ " c19 bool,"
+ " c20 char,"
+ " c21 char(10),"
+ " c22 varchar(30),"
+ " c23 tinyblob,"
+ " c24 tinytext,"
+ " c25 blob,"
+ " c26 text,"
+ " c27 mediumblob,"
+ " c28 mediumtext,"
+ " c29 longblob,"
+ " c30 longtext,"
+ " c31 enum('one', 'two', 'three'),"
+ " c32 set('monday', 'tuesday', 'wednesday'))";
rc= mysql_query(mysql, sql);
myquery(rc);
@@ -4330,6 +4627,7 @@ static void test_stmt_close()
myerror("connection failed");
exit(1);
}
+ lmysql->reconnect= 1;
if (!opt_silent)
fprintf(stdout, " OK");
@@ -4451,8 +4749,6 @@ static void test_set_variable()
get_bind[1].buffer_type= MYSQL_TYPE_LONG;
get_bind[1].buffer= (void *)&get_count;
- get_bind[1].is_null= 0;
- get_bind[1].length= 0;
rc= mysql_stmt_execute(stmt1);
check_execute(stmt1, rc);
@@ -5056,7 +5352,7 @@ static void test_manual_sample()
affected_rows= mysql_stmt_affected_rows(stmt);
if (!opt_silent)
- fprintf(stdout, "\n total affected rows: %lld", affected_rows);
+ fprintf(stdout, "\n total affected rows: %ld", (ulong) affected_rows);
if (affected_rows != 1) /* validate affected rows */
{
fprintf(stderr, "\n invalid affected rows by MySQL");
@@ -5081,7 +5377,7 @@ static void test_manual_sample()
affected_rows= mysql_stmt_affected_rows(stmt);
if (!opt_silent)
- fprintf(stdout, "\n total affected rows: %lld", affected_rows);
+ fprintf(stdout, "\n total affected rows: %ld", (ulong) affected_rows);
if (affected_rows != 1) /* validate affected rows */
{
fprintf(stderr, "\n invalid affected rows by MySQL");
@@ -5116,7 +5412,6 @@ static void test_prepare_alter()
{
MYSQL_STMT *stmt;
int rc, id;
- long length;
MYSQL_BIND bind[1];
my_bool is_null;
@@ -5151,7 +5446,6 @@ static void test_prepare_alter()
check_execute(stmt, rc);
id= 30;
- length= 0;
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
@@ -5222,6 +5516,7 @@ DROP TABLE IF EXISTS test_multi_tab";
fprintf(stdout, "\n connection failed(%s)", mysql_error(mysql_local));
exit(1);
}
+ mysql_local->reconnect= 1;
rc= mysql_query(mysql_local, query);
myquery(rc);
@@ -5236,9 +5531,9 @@ DROP TABLE IF EXISTS test_multi_tab";
mysql_free_result(result);
}
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));
+ fprintf(stdout, "OK, %ld row(s) affected, %ld warning(s)\n",
+ (ulong) mysql_affected_rows(mysql_local),
+ (ulong) mysql_warning_count(mysql_local));
exp_value= (uint) mysql_affected_rows(mysql_local);
if (rows[count] != exp_value)
@@ -5330,6 +5625,7 @@ static void test_prepare_multi_statements()
fprintf(stderr, "\n connection failed(%s)", mysql_error(mysql_local));
exit(1);
}
+ mysql_local->reconnect= 1;
strmov(query, "select 1; select 'another value'");
stmt= mysql_simple_prepare(mysql_local, query);
check_stmt_r(stmt);
@@ -5367,6 +5663,7 @@ static void test_store_result()
myquery(rc);
/* fetch */
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (void *) &nData; /* integer data */
bind[0].length= &length;
@@ -5616,6 +5913,7 @@ static void test_subselect()
MYSQL_STMT *stmt;
int rc, id;
MYSQL_BIND bind[1];
+ DBUG_ENTER("test_subselect");
myheader("test_subselect");
@@ -5721,6 +6019,7 @@ static void test_subselect()
DIE_UNLESS(rc == MYSQL_NO_DATA);
mysql_stmt_close(stmt);
+ DBUG_VOID_RETURN;
}
@@ -5828,7 +6127,7 @@ static void test_bind_date_conv(uint row_count)
for (count= 0; count < row_count; count++)
{
rc= mysql_stmt_fetch(stmt);
- check_execute(stmt, rc);
+ DIE_UNLESS(rc == 0 || rc == MYSQL_DATA_TRUNCATED);
if (!opt_silent)
fprintf(stdout, "\n");
@@ -5844,14 +6143,8 @@ static void test_bind_date_conv(uint row_count)
DIE_UNLESS(tm[i].day == 0 || tm[i].day == day+count);
DIE_UNLESS(tm[i].hour == 0 || tm[i].hour == hour+count);
-#ifdef NOT_USED
- /*
- minute causes problems from date<->time, don't assert, instead
- validate separatly in another routine
- */
DIE_UNLESS(tm[i].minute == 0 || tm[i].minute == minute+count);
DIE_UNLESS(tm[i].second == 0 || tm[i].second == sec+count);
-#endif
DIE_UNLESS(tm[i].second_part == 0 ||
tm[i].second_part == second_part+count);
}
@@ -6082,13 +6375,15 @@ static void test_buffers()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- bzero(buffer, 20); /* Avoid overruns in printf() */
+ bzero(buffer, sizeof(buffer)); /* Avoid overruns in printf() */
+ bzero((char*) bind, sizeof(bind));
bind[0].length= &length;
bind[0].is_null= &is_null;
bind[0].buffer_length= 1;
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (void *)buffer;
+ bind[0].error= &bind[0].error_value;
rc= mysql_stmt_bind_result(stmt, bind);
check_execute(stmt, rc);
@@ -6098,7 +6393,8 @@ static void test_buffers()
buffer[1]= 'X';
rc= mysql_stmt_fetch(stmt);
- check_execute(stmt, rc);
+ DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
+ DIE_UNLESS(bind[0].error_value);
if (!opt_silent)
fprintf(stdout, "\n data: %s (%lu)", buffer, length);
DIE_UNLESS(buffer[0] == 'M');
@@ -6132,7 +6428,8 @@ static void test_buffers()
check_execute(stmt, rc);
rc= mysql_stmt_fetch(stmt);
- check_execute(stmt, rc);
+ DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
+ DIE_UNLESS(bind[0].error_value);
if (!opt_silent)
fprintf(stdout, "\n data: %s (%lu)", buffer, length);
DIE_UNLESS(strncmp(buffer, "Popula", 6) == 0);
@@ -6269,10 +6566,9 @@ static void test_fetch_nobuffs()
fprintf(stdout, "\n total rows : %d", rc);
DIE_UNLESS(rc == 1);
+ bzero((char*) bind, sizeof(MYSQL_BIND));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (void *)str[0];
- bind[0].is_null= 0;
- bind[0].length= 0;
bind[0].buffer_length= sizeof(str[0]);
bind[1]= bind[2]= bind[3]= bind[0];
bind[1].buffer= (void *)str[1];
@@ -6317,7 +6613,7 @@ static void test_ushort_bug()
ulonglong longlong_value;
int rc;
uchar tiny_value;
-
+ char llbuf[22];
myheader("test_ushort_bug");
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ushort");
@@ -6329,7 +6625,8 @@ static void test_ushort_bug()
d smallint unsigned)");
myquery(rc);
- rc= mysql_query(mysql, "INSERT INTO test_ushort VALUES(35999, 35999, 35999, 200)");
+ rc= mysql_query(mysql,
+ "INSERT INTO test_ushort VALUES(35999, 35999, 35999, 200)");
myquery(rc);
@@ -6339,24 +6636,23 @@ static void test_ushort_bug()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_SHORT;
bind[0].buffer= (void *)&short_value;
- bind[0].is_null= 0;
+ bind[0].is_unsigned= TRUE;
bind[0].length= &s_length;
bind[1].buffer_type= MYSQL_TYPE_LONG;
bind[1].buffer= (void *)&long_value;
- bind[1].is_null= 0;
bind[1].length= &l_length;
bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
bind[2].buffer= (void *)&longlong_value;
- bind[2].is_null= 0;
bind[2].length= &ll_length;
bind[3].buffer_type= MYSQL_TYPE_TINY;
bind[3].buffer= (void *)&tiny_value;
- bind[3].is_null= 0;
+ bind[3].is_unsigned= TRUE;
bind[3].length= &t_length;
rc= mysql_stmt_bind_result(stmt, bind);
@@ -6369,7 +6665,8 @@ static void test_ushort_bug()
{
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 longlong : %s (%ld)", llstr(longlong_value, llbuf),
+ ll_length);
fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length);
}
@@ -6404,6 +6701,7 @@ static void test_sshort_bug()
ulonglong longlong_value;
int rc;
uchar tiny_value;
+ char llbuf[22];
myheader("test_sshort_bug");
@@ -6426,24 +6724,22 @@ static void test_sshort_bug()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_SHORT;
bind[0].buffer= (void *)&short_value;
- bind[0].is_null= 0;
bind[0].length= &s_length;
bind[1].buffer_type= MYSQL_TYPE_LONG;
bind[1].buffer= (void *)&long_value;
- bind[1].is_null= 0;
bind[1].length= &l_length;
bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
bind[2].buffer= (void *)&longlong_value;
- bind[2].is_null= 0;
bind[2].length= &ll_length;
bind[3].buffer_type= MYSQL_TYPE_TINY;
bind[3].buffer= (void *)&tiny_value;
- bind[3].is_null= 0;
+ bind[3].is_unsigned= TRUE;
bind[3].length= &t_length;
rc= mysql_stmt_bind_result(stmt, bind);
@@ -6456,7 +6752,8 @@ static void test_sshort_bug()
{
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 longlong : %s (%ld)", llstr(longlong_value, llbuf),
+ ll_length);
fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length);
}
@@ -6491,6 +6788,7 @@ static void test_stiny_bug()
ulonglong longlong_value;
int rc;
uchar tiny_value;
+ char llbuf[22];
myheader("test_stiny_bug");
@@ -6513,24 +6811,21 @@ static void test_stiny_bug()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_SHORT;
bind[0].buffer= (void *)&short_value;
- bind[0].is_null= 0;
bind[0].length= &s_length;
bind[1].buffer_type= MYSQL_TYPE_LONG;
bind[1].buffer= (void *)&long_value;
- bind[1].is_null= 0;
bind[1].length= &l_length;
bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
bind[2].buffer= (void *)&longlong_value;
- bind[2].is_null= 0;
bind[2].length= &ll_length;
bind[3].buffer_type= MYSQL_TYPE_TINY;
bind[3].buffer= (void *)&tiny_value;
- bind[3].is_null= 0;
bind[3].length= &t_length;
rc= mysql_stmt_bind_result(stmt, bind);
@@ -6543,7 +6838,8 @@ static void test_stiny_bug()
{
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 longlong : %s (%ld)", llstr(longlong_value, llbuf),
+ ll_length);
fprintf(stdout, "\n tinyint : %d (%ld)", tiny_value, t_length);
}
@@ -6623,10 +6919,10 @@ static void test_field_misc()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= table_type;
bind[0].length= &type_length;
- bind[0].is_null= 0;
bind[0].buffer_length= NAME_LEN;
rc= mysql_stmt_bind_result(stmt, bind);
@@ -6656,7 +6952,8 @@ static void test_field_misc()
verify_prepare_field(result, 0,
"@@table_type", "", /* field and its org name */
- MYSQL_TYPE_STRING, /* field type */
+ mysql_get_server_version(mysql) <= 50000 ?
+ MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
"", "", /* table and its org name */
"", type_length, 0); /* db name, length */
@@ -6696,10 +6993,10 @@ static void test_field_misc()
DIE_UNLESS(1 == my_process_stmt_result(stmt));
verify_prepare_field(result, 0,
- "@@max_allowed_packet", "", /* field and its org name */
+ "@@max_allowed_packet", "", /* field and its org name */
MYSQL_TYPE_LONGLONG, /* field type */
"", "", /* table and its org name */
- "", 10, 0); /* db name, length */
+ "", 10, 0); /* db name, length */
mysql_free_result(result);
mysql_stmt_close(stmt);
@@ -6857,6 +7154,7 @@ static void test_prepare_grant()
mysql_close(lmysql);
exit(1);
}
+ lmysql->reconnect= 1;
if (!opt_silent)
fprintf(stdout, " OK");
@@ -6932,11 +7230,10 @@ static void test_frm_bug()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= data_dir;
bind[0].buffer_length= FN_REFLEN;
- bind[0].is_null= 0;
- bind[0].length= 0;
bind[1]= bind[0];
rc= mysql_stmt_bind_result(stmt, bind);
@@ -7023,7 +7320,7 @@ static void test_decimal_bug()
*/
bzero((char*) bind, sizeof(bind));
- bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer_type= MYSQL_TYPE_NEWDECIMAL;
bind[0].buffer= (void *)data;
bind[0].buffer_length= 25;
bind[0].is_null= &is_null;
@@ -7032,7 +7329,7 @@ static void test_decimal_bug()
rc= mysql_stmt_bind_param(stmt, bind);
check_execute(stmt, rc);
- strcpy(data, "8.0");
+ strmov(data, "8.0");
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
@@ -7050,7 +7347,7 @@ static void test_decimal_bug()
rc= mysql_stmt_fetch(stmt);
DIE_UNLESS(rc == MYSQL_NO_DATA);
- strcpy(data, "5.61");
+ strmov(data, "5.61");
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
@@ -7075,7 +7372,7 @@ static void test_decimal_bug()
rc= mysql_stmt_fetch(stmt);
DIE_UNLESS(rc == MYSQL_NO_DATA);
- strcpy(data, "10.22"); is_null= 0;
+ strmov(data, "10.22"); is_null= 0;
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
@@ -7132,23 +7429,33 @@ static void test_explain_bug()
mysql_num_fields(result));
DIE_UNLESS(6 == mysql_num_fields(result));
- verify_prepare_field(result, 0, "Field", "", MYSQL_TYPE_VAR_STRING,
- "", "", "", NAME_LEN, 0);
+ verify_prepare_field(result, 0, "Field", "COLUMN_NAME",
+ mysql_get_server_version(mysql) <= 50000 ?
+ MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
+ 0, 0, "", 64, 0);
- verify_prepare_field(result, 1, "Type", "", MYSQL_TYPE_VAR_STRING,
- "", "", "", 40, 0);
+ verify_prepare_field(result, 1, "Type", "COLUMN_TYPE", MYSQL_TYPE_BLOB,
+ 0, 0, "", 0, 0);
- verify_prepare_field(result, 2, "Null", "", MYSQL_TYPE_VAR_STRING,
- "", "", "", 1, 0);
+ verify_prepare_field(result, 2, "Null", "IS_NULLABLE",
+ mysql_get_server_version(mysql) <= 50000 ?
+ MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
+ 0, 0, "", 3, 0);
- verify_prepare_field(result, 3, "Key", "", MYSQL_TYPE_VAR_STRING,
- "", "", "", 3, 0);
+ verify_prepare_field(result, 3, "Key", "COLUMN_KEY",
+ mysql_get_server_version(mysql) <= 50000 ?
+ MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
+ 0, 0, "", 3, 0);
- verify_prepare_field(result, 4, "Default", "", MYSQL_TYPE_VAR_STRING,
- "", "", "", NAME_LEN, 0);
+ verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT",
+ mysql_get_server_version(mysql) <= 50000 ?
+ MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
+ 0, 0, "", 64, 0);
- verify_prepare_field(result, 5, "Extra", "", MYSQL_TYPE_VAR_STRING,
- "", "", "", 20, 0);
+ verify_prepare_field(result, 5, "Extra", "EXTRA",
+ mysql_get_server_version(mysql) <= 50000 ?
+ MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
+ 0, 0, "", 20, 0);
mysql_free_result(result);
mysql_stmt_close(stmt);
@@ -7182,26 +7489,30 @@ static void test_explain_bug()
verify_prepare_field(result, 3, "type", "", MYSQL_TYPE_VAR_STRING,
"", "", "", 10, 0);
- verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_BLOB,
- "", "", "", NAME_LEN*64, 0);
+ verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_VAR_STRING,
+ "", "", "", NAME_LEN*MAX_KEY, 0);
verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING,
"", "", "", NAME_LEN, 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);
+ if (mysql_get_server_version(mysql) <= 50000)
+ {
+ verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_LONGLONG, "",
+ "", "", 3, 0);
+ }
+ else
+ {
+ verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "",
+ "", "", NAME_LEN*MAX_KEY, 0);
+ }
- verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_BLOB,
+ verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING,
"", "", "", NAME_LEN*16, 0);
verify_prepare_field(result, 8, "rows", "", MYSQL_TYPE_LONGLONG,
"", "", "", 10, 0);
- verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_BLOB,
+ verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_VAR_STRING,
"", "", "", 255, 0);
mysql_free_result(result);
@@ -7292,6 +7603,7 @@ static void test_drop_temp()
mysql_close(lmysql);
exit(1);
}
+ lmysql->reconnect= 1;
if (!opt_silent)
fprintf(stdout, " OK");
@@ -7504,13 +7816,13 @@ static void test_logs()
if (!opt_silent)
{
- fprintf(stdout, "\n id : %d", id);
- fprintf(stdout, "\n name : %s(%ld)", data, length);
+ fprintf(stdout, "id : %d\n", id);
+ fprintf(stdout, "name : %s(%ld)\n", data, length);
}
DIE_UNLESS(id == 9876);
- DIE_UNLESS(length == 19); /* Due to VARCHAR(20) */
- DIE_UNLESS(strcmp(data, "MySQL - Open Source") == 0);
+ DIE_UNLESS(length == 19 || length == 20); /* Due to VARCHAR(20) */
+ DIE_UNLESS(is_prefix(data, "MySQL - Open Source") == 1);
rc= mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
@@ -7656,17 +7968,13 @@ static void test_fetch_seek()
stmt= mysql_simple_prepare(mysql, "select * from t1");
check_stmt(stmt);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (void *)&c1;
- bind[0].buffer_length= 0;
- bind[0].is_null= 0;
- bind[0].length= 0;
bind[1].buffer_type= MYSQL_TYPE_STRING;
bind[1].buffer= (void *)c2;
bind[1].buffer_length= sizeof(c2);
- bind[1].is_null= 0;
- bind[1].length= 0;
bind[2]= bind[1];
bind[2].buffer= (void *)c3;
@@ -7756,6 +8064,7 @@ static void test_fetch_offset()
stmt= mysql_simple_prepare(mysql, "select * from t1");
check_stmt(stmt);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (void *)data;
bind[0].buffer_length= 11;
@@ -7842,6 +8151,7 @@ static void test_fetch_column()
stmt= mysql_simple_prepare(mysql, "select * from t1 order by c2 desc");
check_stmt(stmt);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (void *)&bc1;
bind[0].buffer_length= 0;
@@ -8089,10 +8399,9 @@ static void test_free_result()
stmt= mysql_simple_prepare(mysql, "select * from test_free_result");
check_stmt(stmt);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (void *)&bc1;
- bind[0].buffer_length= 0;
- bind[0].is_null= 0;
bind[0].length= &bl1;
rc= mysql_stmt_execute(stmt);
@@ -8170,6 +8479,7 @@ static void test_free_store_result()
stmt= mysql_simple_prepare(mysql, "select * from test_free_result");
check_stmt(stmt);
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (void *)&bc1;
bind[0].buffer_length= 0;
@@ -8245,13 +8555,13 @@ static void test_sqlmode()
myquery(rc);
/* PIPES_AS_CONCAT */
- strcpy(query, "SET SQL_MODE= \"PIPES_AS_CONCAT\"");
+ strmov(query, "SET SQL_MODE= \"PIPES_AS_CONCAT\"");
if (!opt_silent)
fprintf(stdout, "\n With %s", query);
rc= mysql_query(mysql, query);
myquery(rc);
- strcpy(query, "INSERT INTO test_piping VALUES(?||?)");
+ strmov(query, "INSERT INTO test_piping VALUES(?||?)");
if (!opt_silent)
fprintf(stdout, "\n query: %s", query);
stmt= mysql_simple_prepare(mysql, query);
@@ -8277,7 +8587,7 @@ static void test_sqlmode()
rc= mysql_stmt_bind_param(stmt, bind);
check_execute(stmt, rc);
- strcpy(c1, "My"); strcpy(c2, "SQL");
+ strmov(c1, "My"); strmov(c2, "SQL");
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
@@ -8287,20 +8597,20 @@ static void test_sqlmode()
rc= mysql_query(mysql, "DELETE FROM test_piping");
myquery(rc);
- strcpy(query, "SELECT connection_id ()");
+ strmov(query, "SELECT connection_id ()");
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\"");
+ strmov(query, "SET SQL_MODE= \"ANSI\"");
if (!opt_silent)
fprintf(stdout, "\n With %s", query);
rc= mysql_query(mysql, query);
myquery(rc);
- strcpy(query, "INSERT INTO test_piping VALUES(?||?)");
+ strmov(query, "INSERT INTO test_piping VALUES(?||?)");
if (!opt_silent)
fprintf(stdout, "\n query: %s", query);
stmt= mysql_simple_prepare(mysql, query);
@@ -8311,7 +8621,7 @@ static void test_sqlmode()
rc= mysql_stmt_bind_param(stmt, bind);
check_execute(stmt, rc);
- strcpy(c1, "My"); strcpy(c2, "SQL");
+ strmov(c1, "My"); strmov(c2, "SQL");
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
@@ -8319,7 +8629,7 @@ static void test_sqlmode()
verify_col_data("test_piping", "name", "MySQL");
/* ANSI mode spaces ... */
- strcpy(query, "SELECT connection_id ()");
+ strmov(query, "SELECT connection_id ()");
if (!opt_silent)
fprintf(stdout, "\n query: %s", query);
stmt= mysql_simple_prepare(mysql, query);
@@ -8339,13 +8649,13 @@ static void test_sqlmode()
mysql_stmt_close(stmt);
/* IGNORE SPACE MODE */
- strcpy(query, "SET SQL_MODE= \"IGNORE_SPACE\"");
+ strmov(query, "SET SQL_MODE= \"IGNORE_SPACE\"");
if (!opt_silent)
fprintf(stdout, "\n With %s", query);
rc= mysql_query(mysql, query);
myquery(rc);
- strcpy(query, "SELECT connection_id ()");
+ strmov(query, "SELECT connection_id ()");
if (!opt_silent)
fprintf(stdout, "\n query: %s", query);
stmt= mysql_simple_prepare(mysql, query);
@@ -8560,10 +8870,6 @@ static void test_bug1500()
rc= my_process_stmt_result(stmt);
DIE_UNLESS(rc == 1);
- /*
- FIXME If we comment out next string server will crash too :(
- This is another manifestation of bug #1663
- */
mysql_stmt_close(stmt);
/* This should work too */
@@ -8734,7 +9040,7 @@ static void test_subqueries()
int rc, i;
const char *query= "SELECT (SELECT SUM(a+b) FROM t2 where t1.b=t2.b GROUP BY t1.a LIMIT 1) as scalar_s, exists (select 1 from t2 where t2.a/2=t1.a) as exists_s, a in (select a+3 from t2) as in_s, (a-1, b-1) in (select a, b from t2) as in_row_s FROM t1, (select a x, b y from t2) tt WHERE x=a";
- myheader("test_subquery");
+ myheader("test_subqueries");
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2");
myquery(rc);
@@ -8785,7 +9091,7 @@ static void test_distinct()
const char *query=
"SELECT 2+count(distinct b), group_concat(a) FROM t1 group by a";
- myheader("test_subquery");
+ myheader("test_distinct");
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
myquery(rc);
@@ -8854,7 +9160,7 @@ static void test_bug2248()
/* This too should not hang but should return proper error */
rc= mysql_stmt_fetch(stmt);
- DIE_UNLESS(rc == MYSQL_NO_DATA);
+ DIE_UNLESS(rc == 1);
/* This too should not hang but should not bark */
rc= mysql_stmt_store_result(stmt);
@@ -8863,7 +9169,7 @@ static void test_bug2248()
/* This should return proper error */
rc= mysql_stmt_fetch(stmt);
check_execute_r(stmt, rc);
- DIE_UNLESS(rc == MYSQL_NO_DATA);
+ DIE_UNLESS(rc == 1);
mysql_stmt_close(stmt);
@@ -9583,7 +9889,7 @@ static void test_bug3035()
{
MYSQL_STMT *stmt;
int rc;
- MYSQL_BIND bind_array[12];
+ MYSQL_BIND bind_array[12], *bind= bind_array, *bind_end= bind + 12;
int8 int8_val;
uint8 uint8_val;
int16 int16_val;
@@ -9634,7 +9940,10 @@ static void test_bug3035()
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
myquery(rc);
- bzero(bind_array, sizeof(bind_array));
+ bzero((char*) bind_array, sizeof(bind_array));
+
+ for (bind= bind_array; bind < bind_end; bind++)
+ bind->error= &bind->error_value;
bind_array[0].buffer_type= MYSQL_TYPE_TINY;
bind_array[0].buffer= (void *) &int8_val;
@@ -9742,7 +10051,15 @@ static void test_bug3035()
DIE_UNLESS(!strcmp(ulonglong_as_string, "0"));
rc= mysql_stmt_fetch(stmt);
- check_execute(stmt, rc);
+
+ if (!opt_silent)
+ {
+ printf("Truncation mask: ");
+ for (bind= bind_array; bind < bind_end; bind++)
+ printf("%d", (int) bind->error_value);
+ printf("\n");
+ }
+ DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED || rc == 0);
DIE_UNLESS(int8_val == int8_max);
DIE_UNLESS(uint8_val == uint8_max);
@@ -9832,7 +10149,7 @@ static void test_bug1664()
verify_param_count(stmt, 2);
- bzero(&bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (void *)str_data;
@@ -9996,7 +10313,7 @@ static void test_union_param()
my_bool my_null= FALSE;
myheader("test_union_param");
- strcpy(my_val, "abc");
+ strmov(my_val, "abc");
query= (char*)"select ? as my_col union distinct select ?";
stmt= mysql_simple_prepare(mysql, query);
@@ -10072,7 +10389,7 @@ static void test_ps_i18n()
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
myquery(rc);
- bzero(bind_array, sizeof(bind_array));
+ bzero((char*) bind_array, sizeof(bind_array));
bind_array[0].buffer_type= MYSQL_TYPE_STRING;
bind_array[0].buffer= (void *) koi8;
@@ -10256,7 +10573,7 @@ static void test_bug3796()
check_execute(stmt, rc);
/* Bind input buffers */
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= (void *) concat_arg0;
@@ -10278,14 +10595,14 @@ static void test_bug3796()
if (!opt_silent)
printf("Concat result: '%s'\n", out_buff);
check_execute(stmt, rc);
- strcpy(canonical_buff, concat_arg0);
+ strmov(canonical_buff, concat_arg0);
strcat(canonical_buff, "ONE");
DIE_UNLESS(strlen(canonical_buff) == out_length &&
strncmp(out_buff, canonical_buff, out_length) == 0);
rc= mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
- strcpy(canonical_buff + strlen(concat_arg0), "TWO");
+ strmov(canonical_buff + strlen(concat_arg0), "TWO");
DIE_UNLESS(strlen(canonical_buff) == out_length &&
strncmp(out_buff, canonical_buff, out_length) == 0);
if (!opt_silent)
@@ -10323,11 +10640,11 @@ static void test_bug4026()
check_execute(stmt, rc);
/* Bind input buffers */
- bzero(bind, sizeof(bind));
- bzero(&time_in, sizeof(time_in));
- bzero(&time_out, sizeof(time_out));
- bzero(&datetime_in, sizeof(datetime_in));
- bzero(&datetime_out, sizeof(datetime_out));
+ bzero((char*) bind, sizeof(bind));
+ bzero((char*) &time_in, sizeof(time_in));
+ bzero((char*) &time_out, sizeof(time_out));
+ bzero((char*) &datetime_in, sizeof(datetime_in));
+ bzero((char*) &datetime_out, sizeof(datetime_out));
bind[0].buffer_type= MYSQL_TYPE_TIME;
bind[0].buffer= (void *) &time_in;
@@ -10405,7 +10722,7 @@ static void test_bug4079()
check_execute(stmt, rc);
/* Bind input buffers */
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= (void *) &res;
@@ -10474,13 +10791,13 @@ static void test_bug4030()
check_execute(stmt, rc);
/* Bind output buffers */
- bzero(bind, sizeof(bind));
- bzero(&time_canonical, sizeof(time_canonical));
- bzero(&time_out, sizeof(time_out));
- bzero(&date_canonical, sizeof(date_canonical));
- bzero(&date_out, sizeof(date_out));
- bzero(&datetime_canonical, sizeof(datetime_canonical));
- bzero(&datetime_out, sizeof(datetime_out));
+ bzero((char*) bind, sizeof(bind));
+ bzero((char*) &time_canonical, sizeof(time_canonical));
+ bzero((char*) &time_out, sizeof(time_out));
+ bzero((char*) &date_canonical, sizeof(date_canonical));
+ bzero((char*) &date_out, sizeof(date_out));
+ bzero((char*) &datetime_canonical, sizeof(datetime_canonical));
+ bzero((char*) &datetime_out, sizeof(datetime_out));
bind[0].buffer_type= MYSQL_TYPE_TIME;
bind[0].buffer= (void *) &time_out;
@@ -10526,6 +10843,438 @@ static void test_bug4030()
mysql_stmt_close(stmt);
}
+static void test_view()
+{
+ MYSQL_STMT *stmt;
+ int rc, i;
+ MYSQL_BIND bind[1];
+ char str_data[50];
+ ulong length = 0L;
+ long is_null = 0L;
+ const char *query=
+ "SELECT COUNT(*) FROM v1 WHERE SERVERNAME=?";
+
+ myheader("test_view");
+
+ rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,t2,t3,v1");
+ myquery(rc);
+
+ rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,t1,t2,t3");
+ myquery(rc);
+ rc= mysql_query(mysql,"CREATE TABLE t1 ("
+ " SERVERGRP varchar(20) NOT NULL default '', "
+ " DBINSTANCE varchar(20) NOT NULL default '', "
+ " PRIMARY KEY (SERVERGRP)) "
+ " CHARSET=latin1 collate=latin1_bin");
+ myquery(rc);
+ rc= mysql_query(mysql,"CREATE TABLE t2 ("
+ " SERVERNAME varchar(20) NOT NULL, "
+ " SERVERGRP varchar(20) NOT NULL, "
+ " PRIMARY KEY (SERVERNAME)) "
+ " CHARSET=latin1 COLLATE latin1_bin");
+ myquery(rc);
+ rc= mysql_query(mysql,
+ "CREATE TABLE t3 ("
+ " SERVERGRP varchar(20) BINARY NOT NULL, "
+ " TABNAME varchar(30) NOT NULL, MAPSTATE char(1) NOT NULL, "
+ " ACTSTATE char(1) NOT NULL , "
+ " LOCAL_NAME varchar(30) NOT NULL, "
+ " CHG_DATE varchar(8) NOT NULL default '00000000', "
+ " CHG_TIME varchar(6) NOT NULL default '000000', "
+ " MXUSER varchar(12) NOT NULL default '', "
+ " PRIMARY KEY (SERVERGRP, TABNAME, MAPSTATE, ACTSTATE, "
+ " LOCAL_NAME)) CHARSET=latin1 COLLATE latin1_bin");
+ myquery(rc);
+ rc= mysql_query(mysql,"CREATE VIEW v1 AS select sql_no_cache"
+ " T0001.SERVERNAME AS SERVERNAME, T0003.TABNAME AS"
+ " TABNAME,T0003.LOCAL_NAME AS LOCAL_NAME,T0002.DBINSTANCE AS"
+ " DBINSTANCE from t2 T0001 join t1 T0002 join t3 T0003 where"
+ " ((T0002.SERVERGRP = T0001.SERVERGRP) and"
+ " (T0002.SERVERGRP = T0003.SERVERGRP)"
+ " and (T0003.MAPSTATE = _latin1'A') and"
+ " (T0003.ACTSTATE = _latin1' '))");
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, query, strlen(query));
+ check_execute(stmt, rc);
+
+ strmov(str_data, "TEST");
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= FIELD_TYPE_STRING;
+ bind[0].buffer= (char *)&str_data;
+ bind[0].buffer_length= 50;
+ bind[0].length= &length;
+ length= 4;
+ bind[0].is_null= (char*)&is_null;
+ rc= mysql_stmt_bind_param(stmt, bind);
+ check_execute(stmt,rc);
+
+ for (i= 0; i < 3; i++)
+ {
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ assert(1 == my_process_stmt_result(stmt));
+ }
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP TABLE t1,t2,t3");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW v1");
+ myquery(rc);
+}
+
+
+static void test_view_where()
+{
+ MYSQL_STMT *stmt;
+ int rc, i;
+ const char *query=
+ "select v1.c,v2.c from v1, v2";
+
+ myheader("test_view_where");
+
+ rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1,v2");
+ myquery(rc);
+
+ rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,v2,t1");
+ myquery(rc);
+ rc= mysql_query(mysql,"CREATE TABLE t1 (a int, b int)");
+ myquery(rc);
+ rc= mysql_query(mysql,"insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10)");
+ myquery(rc);
+ rc= mysql_query(mysql,"create view v1 (c) as select b from t1 where a<3");
+ myquery(rc);
+ rc= mysql_query(mysql,"create view v2 (c) as select b from t1 where a>=3");
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, query, strlen(query));
+ check_execute(stmt, rc);
+
+ for (i= 0; i < 3; i++)
+ {
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ assert(4 == my_process_stmt_result(stmt));
+ }
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW v1, v2");
+ myquery(rc);
+}
+
+
+static void test_view_2where()
+{
+ MYSQL_STMT *stmt;
+ int rc, i;
+ MYSQL_BIND bind[8];
+ char parms[8][100];
+ ulong length[8];
+ const char *query=
+ "select relid, report, handle, log_group, username, variant, type, "
+ "version, erfdat, erftime, erfname, aedat, aetime, aename, dependvars, "
+ "inactive from V_LTDX where mandt = ? and relid = ? and report = ? and "
+ "handle = ? and log_group = ? and username in ( ? , ? ) and type = ?";
+
+ myheader("test_view_2where");
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS LTDX");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW IF EXISTS V_LTDX");
+ myquery(rc);
+ rc= mysql_query(mysql,
+ "CREATE TABLE LTDX (MANDT char(3) NOT NULL default '000', "
+ " RELID char(2) NOT NULL, REPORT varchar(40) NOT NULL,"
+ " HANDLE varchar(4) NOT NULL, LOG_GROUP varchar(4) NOT NULL,"
+ " USERNAME varchar(12) NOT NULL,"
+ " VARIANT varchar(12) NOT NULL,"
+ " TYPE char(1) NOT NULL, SRTF2 int(11) NOT NULL,"
+ " VERSION varchar(6) NOT NULL default '000000',"
+ " ERFDAT varchar(8) NOT NULL default '00000000',"
+ " ERFTIME varchar(6) NOT NULL default '000000',"
+ " ERFNAME varchar(12) NOT NULL,"
+ " AEDAT varchar(8) NOT NULL default '00000000',"
+ " AETIME varchar(6) NOT NULL default '000000',"
+ " AENAME varchar(12) NOT NULL,"
+ " DEPENDVARS varchar(10) NOT NULL,"
+ " INACTIVE char(1) NOT NULL, CLUSTR smallint(6) NOT NULL,"
+ " CLUSTD blob,"
+ " PRIMARY KEY (MANDT, RELID, REPORT, HANDLE, LOG_GROUP, "
+ "USERNAME, VARIANT, TYPE, SRTF2))"
+ " CHARSET=latin1 COLLATE latin1_bin");
+ myquery(rc);
+ rc= mysql_query(mysql,
+ "CREATE VIEW V_LTDX AS select T0001.MANDT AS "
+ " MANDT,T0001.RELID AS RELID,T0001.REPORT AS "
+ " REPORT,T0001.HANDLE AS HANDLE,T0001.LOG_GROUP AS "
+ " LOG_GROUP,T0001.USERNAME AS USERNAME,T0001.VARIANT AS "
+ " VARIANT,T0001.TYPE AS TYPE,T0001.VERSION AS "
+ " VERSION,T0001.ERFDAT AS ERFDAT,T0001.ERFTIME AS "
+ " ERFTIME,T0001.ERFNAME AS ERFNAME,T0001.AEDAT AS "
+ " AEDAT,T0001.AETIME AS AETIME,T0001.AENAME AS "
+ " AENAME,T0001.DEPENDVARS AS DEPENDVARS,T0001.INACTIVE AS "
+ " INACTIVE from LTDX T0001 where (T0001.SRTF2 = 0)");
+ myquery(rc);
+ bzero((char*) bind, sizeof(bind));
+ for (i=0; i < 8; i++) {
+ strmov(parms[i], "1");
+ bind[i].buffer_type = MYSQL_TYPE_VAR_STRING;
+ bind[i].buffer = (char *)&parms[i];
+ bind[i].buffer_length = 100;
+ bind[i].is_null = 0;
+ bind[i].length = &length[i];
+ length[i] = 1;
+ }
+ 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);
+ assert(0 == my_process_stmt_result(stmt));
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP VIEW V_LTDX");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP TABLE LTDX");
+ myquery(rc);
+}
+
+
+static void test_view_star()
+{
+ MYSQL_STMT *stmt;
+ int rc, i;
+ MYSQL_BIND bind[8];
+ char parms[8][100];
+ ulong length[8];
+ const char *query= "SELECT * FROM vt1 WHERE a IN (?,?)";
+
+ myheader("test_view_star");
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, vt1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW IF EXISTS t1, vt1");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE TABLE t1 (a int)");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE VIEW vt1 AS SELECT a FROM t1");
+ myquery(rc);
+ bzero((char*) bind, sizeof(bind));
+ for (i= 0; i < 2; i++) {
+ sprintf((char *)&parms[i], "%d", i);
+ bind[i].buffer_type = MYSQL_TYPE_VAR_STRING;
+ bind[i].buffer = (char *)&parms[i];
+ bind[i].buffer_length = 100;
+ bind[i].is_null = 0;
+ bind[i].length = &length[i];
+ length[i] = 1;
+ }
+
+ 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);
+
+ for (i= 0; i < 3; i++)
+ {
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ assert(0 == my_process_stmt_result(stmt));
+ }
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW vt1");
+ myquery(rc);
+}
+
+
+static void test_view_insert()
+{
+ MYSQL_STMT *insert_stmt, *select_stmt;
+ int rc, i;
+ MYSQL_BIND bind[1];
+ int my_val = 0;
+ ulong my_length = 0L;
+ long my_null = 0L;
+ const char *query=
+ "insert into v1 values (?)";
+
+ myheader("test_view_insert");
+
+ rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1");
+ myquery(rc);
+ rc = mysql_query(mysql, "DROP VIEW IF EXISTS t1,v1");
+ myquery(rc);
+
+ rc= mysql_query(mysql,"create table t1 (a int, primary key (a))");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "create view v1 as select a from t1 where a>=1");
+ myquery(rc);
+
+ insert_stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(insert_stmt, query, strlen(query));
+ check_execute(insert_stmt, rc);
+ query= "select * from t1";
+ select_stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(select_stmt, query, strlen(query));
+ check_execute(select_stmt, rc);
+
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type = FIELD_TYPE_LONG;
+ bind[0].buffer = (char *)&my_val;
+ bind[0].length = &my_length;
+ bind[0].is_null = (char*)&my_null;
+ rc= mysql_stmt_bind_param(insert_stmt, bind);
+ check_execute(insert_stmt, rc);
+
+ for (i= 0; i < 3; i++)
+ {
+ my_val= i;
+
+ rc= mysql_stmt_execute(insert_stmt);
+ check_execute(insert_stmt, rc);
+
+ rc= mysql_stmt_execute(select_stmt);
+ check_execute(select_stmt, rc);
+ assert(i + 1 == (int) my_process_stmt_result(select_stmt));
+ }
+ mysql_stmt_close(insert_stmt);
+ mysql_stmt_close(select_stmt);
+
+ rc= mysql_query(mysql, "DROP VIEW v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+}
+
+
+static void test_left_join_view()
+{
+ MYSQL_STMT *stmt;
+ int rc, i;
+ const char *query=
+ "select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);";
+
+ myheader("test_left_join_view");
+
+ rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1");
+ myquery(rc);
+
+ rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,t1");
+ myquery(rc);
+ rc= mysql_query(mysql,"CREATE TABLE t1 (a int)");
+ myquery(rc);
+ rc= mysql_query(mysql,"insert into t1 values (1), (2), (3)");
+ myquery(rc);
+ rc= mysql_query(mysql,"create view v1 (x) as select a from t1 where a > 1");
+ myquery(rc);
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, query, strlen(query));
+ check_execute(stmt, rc);
+
+ for (i= 0; i < 3; i++)
+ {
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ assert(3 == my_process_stmt_result(stmt));
+ }
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP VIEW v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+}
+
+
+static void test_view_insert_fields()
+{
+ MYSQL_STMT *stmt;
+ char parm[11][1000];
+ ulong l[11];
+ int rc, i;
+ MYSQL_BIND bind[11];
+ const char *query= "INSERT INTO `v1` ( `K1C4` ,`K2C4` ,`K3C4` ,`K4N4` ,`F1C4` ,`F2I4` ,`F3N5` ,`F7F8` ,`F6N4` ,`F5C8` ,`F9D8` ) VALUES( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
+
+ myheader("test_view_insert_fields");
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW IF EXISTS t1, v1");
+ myquery(rc);
+ rc= mysql_query(mysql,
+ "CREATE TABLE t1 (K1C4 varchar(4) NOT NULL,"
+ "K2C4 varchar(4) NOT NULL, K3C4 varchar(4) NOT NULL,"
+ "K4N4 varchar(4) NOT NULL default '0000',"
+ "F1C4 varchar(4) NOT NULL, F2I4 int(11) NOT NULL,"
+ "F3N5 varchar(5) NOT NULL default '00000',"
+ "F4I4 int(11) NOT NULL default '0', F5C8 varchar(8) NOT NULL,"
+ "F6N4 varchar(4) NOT NULL default '0000',"
+ "F7F8 double NOT NULL default '0',"
+ "F8F8 double NOT NULL default '0',"
+ "F9D8 decimal(8,2) NOT NULL default '0.00',"
+ "PRIMARY KEY (K1C4,K2C4,K3C4,K4N4)) "
+ "CHARSET=latin1 COLLATE latin1_bin");
+ myquery(rc);
+ rc= mysql_query(mysql,
+ "CREATE VIEW v1 AS select sql_no_cache "
+ " K1C4 AS K1C4, K2C4 AS K2C4, K3C4 AS K3C4, K4N4 AS K4N4, "
+ " F1C4 AS F1C4, F2I4 AS F2I4, F3N5 AS F3N5,"
+ " F7F8 AS F7F8, F6N4 AS F6N4, F5C8 AS F5C8, F9D8 AS F9D8"
+ " from t1 T0001");
+
+ bzero((char*) bind, sizeof(bind));
+ for (i= 0; i < 11; i++)
+ {
+ l[i]= 20;
+ bind[i].buffer_type= MYSQL_TYPE_STRING;
+ bind[i].is_null= 0;
+ bind[i].buffer= (char *)&parm[i];
+
+ strmov(parm[i], "1");
+ bind[i].buffer_length= 2;
+ bind[i].length= &l[i];
+ }
+ 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);
+ mysql_stmt_close(stmt);
+
+ query= "select * from t1";
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, query, strlen(query));
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ assert(1 == my_process_stmt_result(stmt));
+
+ mysql_stmt_close(stmt);
+ rc= mysql_query(mysql, "DROP VIEW v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+
+}
static void test_bug5126()
{
@@ -10557,7 +11306,7 @@ static void test_bug5126()
check_execute(stmt, rc);
/* Bind output buffers */
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= &c1;
@@ -10603,8 +11352,8 @@ static void test_bug4231()
check_execute(stmt, rc);
/* Bind input buffers */
- bzero(bind, sizeof(bind));
- bzero(tm, sizeof(tm));
+ bzero((char*) bind, sizeof(bind));
+ bzero((char*) tm, sizeof(tm));
bind[0].buffer_type= MYSQL_TYPE_DATE;
bind[0].buffer= &tm[0];
@@ -10664,13 +11413,13 @@ static void test_bug5399()
myheader("test_bug5399");
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
bind[0].buffer= &no;
for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt)
{
- sprintf(buff, "select %d", stmt - stmt_list);
+ sprintf(buff, "select %d", (int) (stmt - stmt_list));
*stmt= mysql_stmt_init(mysql);
rc= mysql_stmt_prepare(*stmt, buff, strlen(buff));
check_execute(*stmt, rc);
@@ -10824,7 +11573,7 @@ static void test_bug5194()
param_str_length= strlen(param_str);
/* setup bind array */
- bzero(bind, MAX_PARAM_COUNT * sizeof(MYSQL_BIND));
+ bzero((char*) bind, MAX_PARAM_COUNT * sizeof(MYSQL_BIND));
for (i= 0; i < MAX_PARAM_COUNT; ++i)
{
bind[i].buffer_type= MYSQL_TYPE_FLOAT;
@@ -10865,7 +11614,7 @@ static void test_bug5194()
if (!opt_silent)
printf("Insert: query length= %d, row count= %d, param count= %lu\n",
- strlen(query), nrows, mysql_stmt_param_count(stmt));
+ (int) strlen(query), nrows, mysql_stmt_param_count(stmt));
/* bind the parameter array and execute the query */
rc= mysql_stmt_bind_param(stmt, bind);
@@ -10942,7 +11691,7 @@ static void test_bug6049()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[0].buffer = &buffer;
bind[0].buffer_length = sizeof(buffer);
@@ -10991,7 +11740,7 @@ static void test_bug6058()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[0].buffer = &buffer;
bind[0].buffer_length = sizeof(buffer);
@@ -11018,14 +11767,13 @@ static void test_bug6059()
{
MYSQL_STMT *stmt;
const char *stmt_text;
- int rc;
myheader("test_bug6059");
stmt_text= "SELECT 'foo' INTO OUTFILE 'x.3'";
stmt= mysql_stmt_init(mysql);
- rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ (void) mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
DIE_UNLESS(mysql_stmt_field_count(stmt) == 0);
mysql_stmt_close(stmt);
}
@@ -11060,7 +11808,7 @@ static void test_bug6046()
check_execute(stmt, rc);
b= 1;
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer= &b;
bind[0].buffer_type= MYSQL_TYPE_SHORT;
@@ -11077,6 +11825,62 @@ static void test_bug6046()
}
+
+static void test_basic_cursors()
+{
+ const char *basic_tables[]=
+ {
+ "DROP TABLE IF EXISTS t1, t2",
+
+ "CREATE TABLE t1 "
+ "(id INTEGER NOT NULL PRIMARY KEY, "
+ " name VARCHAR(20) NOT NULL)",
+
+ "INSERT INTO t1 (id, name) VALUES "
+ " (2, 'Ja'), (3, 'Ede'), "
+ " (4, 'Haag'), (5, 'Kabul'), "
+ " (6, 'Almere'), (7, 'Utrecht'), "
+ " (8, 'Qandahar'), (9, 'Amsterdam'), "
+ " (10, 'Amersfoort'), (11, 'Constantine')",
+
+ "CREATE TABLE t2 "
+ "(id INTEGER NOT NULL PRIMARY KEY, "
+ " name VARCHAR(20) NOT NULL)",
+
+ "INSERT INTO t2 (id, name) VALUES "
+ " (4, 'Guam'), (5, 'Aruba'), "
+ " (6, 'Angola'), (7, 'Albania'), "
+ " (8, 'Anguilla'), (9, 'Argentina'), "
+ " (10, 'Azerbaijan'), (11, 'Afghanistan'), "
+ " (12, 'Burkina Faso'), (13, 'Faroe Islands')"
+ };
+ const char *queries[]=
+ {
+ "SELECT * FROM t1",
+ "SELECT * FROM t2"
+ };
+
+ DBUG_ENTER("test_basic_cursors");
+ myheader("test_basic_cursors");
+
+ fill_tables(basic_tables, sizeof(basic_tables)/sizeof(*basic_tables));
+
+ fetch_n(queries, sizeof(queries)/sizeof(*queries));
+ DBUG_VOID_RETURN;
+}
+
+
+static void test_cursors_with_union()
+{
+ const char *queries[]=
+ {
+ "SELECT t1.name FROM t1 UNION SELECT t2.name FROM t2",
+ "SELECT t1.id FROM t1 WHERE t1.id < 5"
+ };
+ myheader("test_cursors_with_union");
+ fetch_n(queries, sizeof(queries)/sizeof(*queries));
+}
+
/*
Altough mysql_create_db(), mysql_rm_db() are deprecated since 4.0 they
should not crash server and should not hang in case of errors.
@@ -11115,6 +11919,7 @@ static void test_bug6096()
MYSQL_FIELD *query_field_list, *stmt_field_list;
ulong query_field_count, stmt_field_count;
int rc;
+ my_bool update_max_length= TRUE;
uint i;
myheader("test_bug6096");
@@ -11150,8 +11955,8 @@ static void test_bug6096()
check_execute(stmt, rc);
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- rc= 1;
- mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*)&rc);
+ mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH,
+ (void*) &update_max_length);
mysql_stmt_store_result(stmt);
stmt_metadata= mysql_stmt_result_metadata(stmt);
stmt_field_list= mysql_fetch_fields(stmt_metadata);
@@ -11182,7 +11987,7 @@ static void test_bug6096()
/* Bind and fetch the data */
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
for (i= 0; i < stmt_field_count; ++i)
{
bind[i].buffer_type= MYSQL_TYPE_STRING;
@@ -11237,7 +12042,7 @@ static void test_datetime_ranges()
check_stmt(stmt);
verify_param_count(stmt, 6);
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
for (i= 0; i < 6; i++)
{
bind[i].buffer_type= MYSQL_TYPE_DATETIME;
@@ -11326,7 +12131,7 @@ static void test_datetime_ranges()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- DIE_UNLESS(mysql_warning_count(mysql) != 2);
+ DIE_UNLESS(mysql_warning_count(mysql) == 2);
verify_col_data("t1", "day_ovfl", "838:59:59");
verify_col_data("t1", "day", "828:30:30");
@@ -11368,7 +12173,7 @@ static void test_bug4172()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= f;
bind[0].buffer_length= sizeof(f);
@@ -11435,7 +12240,7 @@ static void test_conversion()
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
check_execute(stmt, rc);
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
bind[0].buffer= buff;
bind[0].length= &length;
bind[0].buffer_type= MYSQL_TYPE_STRING;
@@ -11498,7 +12303,7 @@ static void test_rewind(void)
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
check_execute(stmt, rc);
- bzero(&bind,sizeof(MYSQL_BIND));
+ bzero((char*) &bind, sizeof(MYSQL_BIND));
bind.buffer_type= MYSQL_TYPE_LONG;
bind.buffer= (void *)&Data; /* this buffer won't be altered */
bind.length= &length;
@@ -11537,6 +12342,299 @@ static void test_rewind(void)
}
+static void test_truncation()
+{
+ MYSQL_STMT *stmt;
+ const char *stmt_text;
+ int rc;
+ uint bind_count;
+ MYSQL_BIND *bind_array, *bind;
+
+ myheader("test_truncation");
+
+ /* Prepare the test table */
+ rc= mysql_query(mysql, "drop table if exists t1");
+ myquery(rc);
+
+ stmt_text= "create table t1 ("
+ "i8 tinyint, ui8 tinyint unsigned, "
+ "i16 smallint, i16_1 smallint, "
+ "ui16 smallint unsigned, i32 int, i32_1 int, "
+ "d double, d_1 double, ch char(30), ch_1 char(30), "
+ "tx text, tx_1 text, ch_2 char(30) "
+ ")";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "insert into t1 VALUES ("
+ "-10, " /* i8 */
+ "200, " /* ui8 */
+ "32000, " /* i16 */
+ "-32767, " /* i16_1 */
+ "64000, " /* ui16 */
+ "1073741824, " /* i32 */
+ "1073741825, " /* i32_1 */
+ "123.456, " /* d */
+ "-12345678910, " /* d_1 */
+ "'111111111111111111111111111111',"/* ch */
+ "'abcdef', " /* ch_1 */
+ "'12345 ', " /* tx */
+ "'12345.67 ', " /* tx_1 */
+ "'12345.67abc'" /* ch_2 */
+ ")";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt_text= "select i8 c1, i8 c2, ui8 c3, i16_1 c4, ui16 c5, "
+ " i16 c6, ui16 c7, i32 c8, i32_1 c9, i32_1 c10, "
+ " d c11, d_1 c12, d_1 c13, ch c14, ch_1 c15, tx c16, "
+ " tx_1 c17, ch_2 c18 "
+ "from t1";
+
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ bind_count= (uint) mysql_stmt_field_count(stmt);
+
+ /*************** Fill in the bind structure and bind it **************/
+ bind_array= malloc(sizeof(MYSQL_BIND) * bind_count);
+ bzero((char*) bind_array, sizeof(MYSQL_BIND) * bind_count);
+ for (bind= bind_array; bind < bind_array + bind_count; bind++)
+ bind->error= &bind->error_value;
+ bind= bind_array;
+
+ bind->buffer= malloc(sizeof(uint8));
+ bind->buffer_type= MYSQL_TYPE_TINY;
+ bind->is_unsigned= TRUE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(uint32));
+ bind->buffer_type= MYSQL_TYPE_LONG;
+ bind->is_unsigned= TRUE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(int8));
+ bind->buffer_type= MYSQL_TYPE_TINY;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(uint16));
+ bind->buffer_type= MYSQL_TYPE_SHORT;
+ bind->is_unsigned= TRUE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(int16));
+ bind->buffer_type= MYSQL_TYPE_SHORT;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(uint16));
+ bind->buffer_type= MYSQL_TYPE_SHORT;
+ bind->is_unsigned= TRUE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(int8));
+ bind->buffer_type= MYSQL_TYPE_TINY;
+ bind->is_unsigned= TRUE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(float));
+ bind->buffer_type= MYSQL_TYPE_FLOAT;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(float));
+ bind->buffer_type= MYSQL_TYPE_FLOAT;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(double));
+ bind->buffer_type= MYSQL_TYPE_DOUBLE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(longlong));
+ bind->buffer_type= MYSQL_TYPE_LONGLONG;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(ulonglong));
+ bind->buffer_type= MYSQL_TYPE_LONGLONG;
+ bind->is_unsigned= TRUE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(longlong));
+ bind->buffer_type= MYSQL_TYPE_LONGLONG;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(longlong));
+ bind->buffer_type= MYSQL_TYPE_LONGLONG;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(longlong));
+ bind->buffer_type= MYSQL_TYPE_LONGLONG;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(longlong));
+ bind->buffer_type= MYSQL_TYPE_LONGLONG;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(double));
+ bind->buffer_type= MYSQL_TYPE_DOUBLE;
+
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ bind->buffer= malloc(sizeof(double));
+ bind->buffer_type= MYSQL_TYPE_DOUBLE;
+
+ rc= mysql_stmt_bind_result(stmt, bind_array);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
+
+ /*************** Verify truncation results ***************************/
+ bind= bind_array;
+
+ /* signed tiny -> tiny */
+ DIE_UNLESS(*bind->error && * (int8*) bind->buffer == -10);
+
+ /* signed tiny -> uint32 */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error && * (int32*) bind->buffer == -10);
+
+ /* unsigned tiny -> tiny */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error && * (uint8*) bind->buffer == 200);
+
+ /* short -> ushort */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error && * (int16*) bind->buffer == -32767);
+
+ /* ushort -> short */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error && * (uint16*) bind->buffer == 64000);
+
+ /* short -> ushort (no truncation, data is in the range of target type) */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(! *bind->error && * (uint16*) bind->buffer == 32000);
+
+ /* ushort -> utiny */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error && * (int8*) bind->buffer == 0);
+
+ /* int -> float: no truncation, the number is a power of two */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(! *bind->error && * (float*) bind->buffer == 1073741824);
+
+ /* int -> float: truncation, not enough bits in float */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error);
+
+ /* int -> double: no truncation */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(! *bind->error && * (double*) bind->buffer == 1073741825);
+
+ /* double -> longlong: fractional part is lost */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+
+ /* double -> ulonglong, negative fp number to unsigned integer */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ /* Value in the buffer is not defined: don't test it */
+ DIE_UNLESS(*bind->error);
+
+ /* double -> longlong, negative fp number to signed integer: no loss */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(! *bind->error && * (longlong*) bind->buffer == LL(-12345678910));
+
+ /* big numeric string -> number */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error);
+
+ /* junk string -> number */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(*bind->error && *(longlong*) bind->buffer == 0);
+
+ /* string with trailing spaces -> number */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(! *bind->error && *(longlong*) bind->buffer == 12345);
+
+ /* string with trailing spaces -> double */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ DIE_UNLESS(! *bind->error && *(double*) bind->buffer == 12345.67);
+
+ /* string with trailing junk -> double */
+ DIE_UNLESS(++bind < bind_array + bind_count);
+ /*
+ XXX: There must be a truncation error: but it's not the way the server
+ behaves, so let's leave it for now.
+ */
+ DIE_UNLESS(*(double*) bind->buffer == 12345.67);
+ /*
+ TODO: string -> double, double -> time, double -> string (truncation
+ errors are not supported here yet)
+ longlong -> time/date/datetime
+ date -> time, date -> timestamp, date -> number
+ time -> string, time -> date, time -> timestamp,
+ number -> date string -> date
+ */
+ /*************** Cleanup *********************************************/
+
+ mysql_stmt_close(stmt);
+
+ for (bind= bind_array; bind < bind_array + bind_count; bind++)
+ free(bind->buffer);
+ free(bind_array);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+static void test_truncation_option()
+{
+ MYSQL_STMT *stmt;
+ const char *stmt_text;
+ int rc;
+ uint8 buf;
+ my_bool option= 0;
+ my_bool error;
+ MYSQL_BIND bind;
+
+ myheader("test_truncation_option");
+
+ /* Prepare the test table */
+ stmt_text= "select -1";
+
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ bzero((char*) &bind, sizeof(MYSQL_BIND));
+
+ bind.buffer= (void*) &buf;
+ bind.buffer_type= MYSQL_TYPE_TINY;
+ bind.is_unsigned= TRUE;
+ bind.error= &error;
+
+ rc= mysql_stmt_bind_result(stmt, &bind);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
+ DIE_UNLESS(error);
+ rc= mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, (char*) &option);
+ myquery(rc);
+ /* need to rebind for the new setting to take effect */
+ rc= mysql_stmt_bind_result(stmt, &bind);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ /* The only change is rc - error pointers are still filled in */
+ DIE_UNLESS(error == 1);
+ /* restore back the defaults */
+ option= 1;
+ mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, (char*) &option);
+
+ mysql_stmt_close(stmt);
+}
+
+
/* Bug#6761 - mysql_list_fields doesn't work */
static void test_bug6761(void)
@@ -11581,7 +12679,7 @@ static void test_bug8330()
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
myquery(rc);
- bzero(bind, sizeof(bind));
+ bzero((char*) bind, sizeof(bind));
for (i=0; i < 2; i++)
{
stmt[i]= mysql_stmt_init(mysql);
@@ -11631,6 +12729,42 @@ static void test_bug7990()
}
+static void test_view_sp_list_fields()
+{
+ int rc;
+ MYSQL_RES *res;
+
+ myheader("test_view_sp_list_fields");
+
+ rc= mysql_query(mysql, "DROP FUNCTION IF EXISTS f1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS v1, t1, t2");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW IF EXISTS v1, t1, t2");
+ myquery(rc);
+ rc= mysql_query(mysql, "create function f1 () returns int return 5");
+ myquery(rc);
+ rc= mysql_query(mysql, "create table t1 (s1 char,s2 char)");
+ myquery(rc);
+ rc= mysql_query(mysql, "create table t2 (s1 int);");
+ myquery(rc);
+ rc= mysql_query(mysql, "create view v1 as select s2,sum(s1) - \
+count(s2) as vx from t1 group by s2 having sum(s1) - count(s2) < (select f1() \
+from t2);");
+ myquery(rc);
+ res= mysql_list_fields(mysql, "v1", NullS);
+ DIE_UNLESS(res != 0 && mysql_num_fields(res) != 0);
+ rc= mysql_query(mysql, "DROP FUNCTION f1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP TABLE t1, t2");
+ mysql_free_result(res);
+ myquery(rc);
+
+}
+
+
/*
Test mysql_real_escape_string() with gbk charset
@@ -11682,6 +12816,856 @@ static void test_bug8378()
}
+static void test_bug8722()
+{
+ MYSQL_STMT *stmt;
+ int rc;
+ const char *stmt_text;
+
+ myheader("test_bug8722");
+ /* Prepare test data */
+ stmt_text= "drop table if exists t1, v1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "CREATE TABLE t1 (c1 varchar(10), c2 varchar(10), c3 varchar(10),"
+ " c4 varchar(10), c5 varchar(10), c6 varchar(10),"
+ " c7 varchar(10), c8 varchar(10), c9 varchar(10),"
+ "c10 varchar(10))";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10)";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "CREATE VIEW v1 AS SELECT * FROM t1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ /* Note: if you uncomment following block everything works fine */
+/*
+ rc= mysql_query(mysql, "sellect * from v1");
+ myquery(rc);
+ mysql_free_result(mysql_store_result(mysql));
+*/
+
+ stmt= mysql_stmt_init(mysql);
+ stmt_text= "select * from v1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+ mysql_stmt_close(stmt);
+ stmt_text= "drop table if exists t1, v1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+}
+
+
+MYSQL_STMT *open_cursor(const char *query)
+{
+ int rc;
+ const ulong type= (ulong)CURSOR_TYPE_READ_ONLY;
+
+ MYSQL_STMT *stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, query, strlen(query));
+ check_execute(stmt, rc);
+
+ mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
+ return stmt;
+}
+
+
+static void test_bug8880()
+{
+ MYSQL_STMT *stmt_list[2], **stmt;
+ MYSQL_STMT **stmt_list_end= (MYSQL_STMT**) stmt_list + 2;
+ int rc;
+
+ myheader("test_bug8880");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (a int not null primary key, b int)");
+ rc= mysql_query(mysql, "insert into t1 values (1,1)");
+ myquery(rc); /* one check is enough */
+ /*
+ when inserting 2 rows everything works well
+ mysql_query(mysql, "INSERT INTO t1 VALUES (1,1),(2,2)");
+ */
+ for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
+ *stmt= open_cursor("select a from t1");
+ for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
+ {
+ rc= mysql_stmt_execute(*stmt);
+ check_execute(*stmt, rc);
+ }
+ for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
+ mysql_stmt_close(*stmt);
+}
+
+
+static void test_bug9159()
+{
+ MYSQL_STMT *stmt;
+ int rc;
+ const char *stmt_text= "select a, b from t1";
+ const unsigned long type= CURSOR_TYPE_READ_ONLY;
+
+ myheader("test_bug9159");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (a int not null primary key, b int)");
+ rc= mysql_query(mysql, "insert into t1 values (1,1)");
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+ mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void *)&type);
+
+ mysql_stmt_execute(stmt);
+ mysql_stmt_close(stmt);
+ rc= mysql_query(mysql, "drop table if exists t1");
+ myquery(rc);
+}
+
+
+/* Crash when opening a cursor to a query with DISTICNT and no key */
+
+static void test_bug9520()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[1];
+ char a[6];
+ ulong a_len;
+ int rc, row_count= 0;
+
+ myheader("test_bug9520");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (a char(5), b char(5), c char(5),"
+ " primary key (a, b, c))");
+ rc= mysql_query(mysql, "insert into t1 values ('x', 'y', 'z'), "
+ " ('a', 'b', 'c'), ('k', 'l', 'm')");
+ myquery(rc);
+
+ stmt= open_cursor("select distinct b from t1");
+
+ /*
+ Not crashes with:
+ stmt= open_cursor("select distinct a from t1");
+ */
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer= (char*) a;
+ bind[0].buffer_length= sizeof(a);
+ bind[0].length= &a_len;
+
+ mysql_stmt_bind_result(stmt, bind);
+
+ while (!(rc= mysql_stmt_fetch(stmt)))
+ row_count++;
+
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ printf("Fetched %d rows\n", row_count);
+ DBUG_ASSERT(row_count == 3);
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
+/*
+ We can't have more than one cursor open for a prepared statement.
+ Test re-executions of a PS with cursor; mysql_stmt_reset must close
+ the cursor attached to the statement, if there is one.
+*/
+
+static void test_bug9478()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[1];
+ char a[6];
+ ulong a_len;
+ int rc, i;
+ DBUG_ENTER("test_bug9478");
+
+ myheader("test_bug9478");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (id integer not null primary key, "
+ " name varchar(20) not null)");
+ rc= mysql_query(mysql, "insert into t1 (id, name) values "
+ " (1, 'aaa'), (2, 'bbb'), (3, 'ccc')");
+ myquery(rc);
+
+ stmt= open_cursor("select name from t1 where id=2");
+
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer= (char*) a;
+ bind[0].buffer_length= sizeof(a);
+ bind[0].length= &a_len;
+ mysql_stmt_bind_result(stmt, bind);
+
+ for (i= 0; i < 5; i++)
+ {
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ if (!opt_silent && i == 0)
+ printf("Fetched row: %s\n", a);
+
+ /*
+ The query above is a one-row result set. Therefore, there is no
+ cursor associated with it, as the server won't bother with opening
+ a cursor for a one-row result set. The first row was read from the
+ server in the fetch above. But there is eof packet pending in the
+ network. mysql_stmt_execute will flush the packet and successfully
+ execute the statement.
+ */
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ if (!opt_silent && i == 0)
+ printf("Fetched row: %s\n", a);
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ {
+ char buff[8];
+ /* Fill in the fethc packet */
+ int4store(buff, stmt->stmt_id);
+ buff[4]= 1; /* prefetch rows */
+ rc= ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH, buff,
+ sizeof(buff), 0,0,1) ||
+ (*mysql->methods->read_query_result)(mysql));
+ DIE_UNLESS(rc);
+ if (!opt_silent && i == 0)
+ printf("Got error (as expected): %s\n", mysql_error(mysql));
+ }
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ if (!opt_silent && i == 0)
+ printf("Fetched row: %s\n", a);
+
+ rc= mysql_stmt_reset(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc && mysql_stmt_errno(stmt));
+ if (!opt_silent && i == 0)
+ printf("Got error (as expected): %s\n", mysql_stmt_error(stmt));
+ }
+ rc= mysql_stmt_close(stmt);
+ DIE_UNLESS(rc == 0);
+
+ /* Test the case with a server side cursor */
+ stmt= open_cursor("select name from t1");
+
+ mysql_stmt_bind_result(stmt, bind);
+
+ for (i= 0; i < 5; i++)
+ {
+ DBUG_PRINT("loop",("i: %d", i));
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ if (!opt_silent && i == 0)
+ printf("Fetched row: %s\n", a);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ while (! (rc= mysql_stmt_fetch(stmt)))
+ {
+ if (!opt_silent && i == 0)
+ printf("Fetched row: %s\n", a);
+ }
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ if (!opt_silent && i == 0)
+ printf("Fetched row: %s\n", a);
+
+ rc= mysql_stmt_reset(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc && mysql_stmt_errno(stmt));
+ if (!opt_silent && i == 0)
+ printf("Got error (as expected): %s\n", mysql_stmt_error(stmt));
+ }
+
+ rc= mysql_stmt_close(stmt);
+ DIE_UNLESS(rc == 0);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+ DBUG_VOID_RETURN;
+}
+
+
+/*
+ Error message is returned for unsupported features.
+ Test also cursors with non-default PREFETCH_ROWS
+*/
+
+static void test_bug9643()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[1];
+ int32 a;
+ int rc;
+ const char *stmt_text;
+ int num_rows= 0;
+ ulong type;
+ ulong prefetch_rows= 5;
+
+ myheader("test_bug9643");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (id integer not null primary key)");
+ rc= mysql_query(mysql, "insert into t1 (id) values "
+ " (1), (2), (3), (4), (5), (6), (7), (8), (9)");
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+ /* Not implemented in 5.0 */
+ type= (ulong) CURSOR_TYPE_SCROLLABLE;
+ rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
+ DIE_UNLESS(rc);
+ if (! opt_silent)
+ printf("Got error (as expected): %s\n", mysql_stmt_error(stmt));
+
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS,
+ (void*) &prefetch_rows);
+ check_execute(stmt, rc);
+ stmt_text= "select * from t1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_LONG;
+ bind[0].buffer= (void*) &a;
+ bind[0].buffer_length= sizeof(a);
+ mysql_stmt_bind_result(stmt, bind);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ while ((rc= mysql_stmt_fetch(stmt)) == 0)
+ ++num_rows;
+ DIE_UNLESS(num_rows == 9);
+
+ rc= mysql_stmt_close(stmt);
+ DIE_UNLESS(rc == 0);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+/*
+ Bug#11111: fetch from view returns wrong data
+*/
+
+static void test_bug11111()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[2];
+ char buf[2][20];
+ ulong len[2];
+ int i;
+ int rc;
+ const char *query= "SELECT DISTINCT f1,ff2 FROM v1";
+
+ myheader("test_bug11111");
+
+ rc= mysql_query(mysql, "drop table if exists t1, t2, v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "drop view if exists t1, t2, v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "create table t1 (f1 int, f2 int)");
+ myquery(rc);
+ rc= mysql_query(mysql, "create table t2 (ff1 int, ff2 int)");
+ myquery(rc);
+ rc= mysql_query(mysql, "create view v1 as select * from t1, t2 where f1=ff1");
+ myquery(rc);
+ rc= mysql_query(mysql, "insert into t1 values (1,1), (2,2), (3,3)");
+ myquery(rc);
+ rc= mysql_query(mysql, "insert into t2 values (1,1), (2,2), (3,3)");
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+
+ mysql_stmt_prepare(stmt, query, strlen(query));
+ mysql_stmt_execute(stmt);
+
+ bzero((char*) bind, sizeof(bind));
+ for (i=0; i < 2; i++)
+ {
+ bind[i].buffer_type= MYSQL_TYPE_STRING;
+ bind[i].buffer= (gptr *)&buf[i];
+ bind[i].buffer_length= 20;
+ bind[i].length= &len[i];
+ }
+
+ rc= mysql_stmt_bind_result(stmt, bind);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ if (!opt_silent)
+ printf("return: %s", buf[1]);
+ DIE_UNLESS(!strcmp(buf[1],"1"));
+ mysql_stmt_close(stmt);
+ rc= mysql_query(mysql, "drop view v1");
+ myquery(rc);
+ rc= mysql_query(mysql, "drop table t1, t2");
+ myquery(rc);
+}
+
+/*
+ Check that proper cleanups are done for prepared statement when
+ fetching thorugh a cursor.
+*/
+
+static void test_bug10729()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[1];
+ char a[21];
+ int rc;
+ const char *stmt_text;
+ int i= 0;
+ const char *name_array[3]= { "aaa", "bbb", "ccc" };
+ ulong type;
+
+ myheader("test_bug10729");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (id integer not null primary key,"
+ "name VARCHAR(20) NOT NULL)");
+ rc= mysql_query(mysql, "insert into t1 (id, name) values "
+ "(1, 'aaa'), (2, 'bbb'), (3, 'ccc')");
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
+ check_execute(stmt, rc);
+ stmt_text= "select name from t1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer= (void*) a;
+ bind[0].buffer_length= sizeof(a);
+ mysql_stmt_bind_result(stmt, bind);
+
+ for (i= 0; i < 3; i++)
+ {
+ int row_no= 0;
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ while ((rc= mysql_stmt_fetch(stmt)) == 0)
+ {
+ DIE_UNLESS(strcmp(a, name_array[row_no]) == 0);
+ if (!opt_silent)
+ printf("%d: %s\n", row_no, a);
+ ++row_no;
+ }
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+ }
+ rc= mysql_stmt_close(stmt);
+ DIE_UNLESS(rc == 0);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
+/*
+ Check that mysql_next_result works properly in case when one of
+ the statements used in a multi-statement query is erroneous
+*/
+
+static void test_bug9992()
+{
+ MYSQL *mysql1;
+ MYSQL_RES* res ;
+ int rc;
+
+ myheader("test_bug9992");
+
+ if (!opt_silent)
+ printf("Establishing a connection with option CLIENT_MULTI_STATEMENTS..\n");
+
+ mysql1= mysql_init(NULL);
+
+ if (!mysql_real_connect(mysql1, opt_host, opt_user, opt_password,
+ opt_db ? opt_db : "test", opt_port, opt_unix_socket,
+ CLIENT_MULTI_STATEMENTS))
+ {
+ fprintf(stderr, "Failed to connect to the database\n");
+ DIE_UNLESS(0);
+ }
+
+
+ /* Sic: SHOW DATABASE is incorrect syntax. */
+ rc= mysql_query(mysql1, "SHOW TABLES; SHOW DATABASE; SELECT 1;");
+
+ if (rc)
+ {
+ fprintf(stderr, "[%d] %s\n", mysql_errno(mysql1), mysql_error(mysql1));
+ DIE_UNLESS(0);
+ }
+
+ if (!opt_silent)
+ printf("Testing mysql_store_result/mysql_next_result..\n");
+
+ res= mysql_store_result(mysql1);
+ DIE_UNLESS(res);
+ mysql_free_result(res);
+ rc= mysql_next_result(mysql1);
+ DIE_UNLESS(rc == 1); /* Got errors, as expected */
+
+ if (!opt_silent)
+ fprintf(stdout, "Got error, as expected:\n [%d] %s\n",
+ mysql_errno(mysql1), mysql_error(mysql1));
+
+ mysql_close(mysql1);
+}
+
+/* Bug#10736: cursors and subqueries, memroot management */
+
+static void test_bug10736()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[1];
+ char a[21];
+ int rc;
+ const char *stmt_text;
+ int i= 0;
+ ulong type;
+
+ myheader("test_bug10736");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (id integer not null primary key,"
+ "name VARCHAR(20) NOT NULL)");
+ rc= mysql_query(mysql, "insert into t1 (id, name) values "
+ "(1, 'aaa'), (2, 'bbb'), (3, 'ccc')");
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
+ check_execute(stmt, rc);
+ stmt_text= "select name from t1 where name=(select name from t1 where id=2)";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer= (void*) a;
+ bind[0].buffer_length= sizeof(a);
+ mysql_stmt_bind_result(stmt, bind);
+
+ for (i= 0; i < 3; i++)
+ {
+ int row_no= 0;
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ while ((rc= mysql_stmt_fetch(stmt)) == 0)
+ {
+ if (!opt_silent)
+ printf("%d: %s\n", row_no, a);
+ ++row_no;
+ }
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+ }
+ rc= mysql_stmt_close(stmt);
+ DIE_UNLESS(rc == 0);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+/* Bug#10794: cursors, packets out of order */
+
+static void test_bug10794()
+{
+ MYSQL_STMT *stmt, *stmt1;
+ MYSQL_BIND bind[2];
+ char a[21];
+ int id_val;
+ ulong a_len;
+ int rc;
+ const char *stmt_text;
+ int i= 0;
+ ulong type;
+
+ myheader("test_bug10794");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (id integer not null primary key,"
+ "name varchar(20) not null)");
+ stmt= mysql_stmt_init(mysql);
+ stmt_text= "insert into t1 (id, name) values (?, ?)";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_LONG;
+ bind[0].buffer= (void*) &id_val;
+ bind[1].buffer_type= MYSQL_TYPE_STRING;
+ bind[1].buffer= (void*) a;
+ bind[1].length= &a_len;
+ rc= mysql_stmt_bind_param(stmt, bind);
+ check_execute(stmt, rc);
+ for (i= 0; i < 42; i++)
+ {
+ id_val= (i+1)*10;
+ sprintf(a, "a%d", i);
+ a_len= strlen(a); /* safety against broken sprintf */
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ }
+ stmt_text= "select name from t1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+ stmt1= mysql_stmt_init(mysql);
+ mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+ bzero((char*) bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer= (void*) a;
+ bind[0].buffer_length= sizeof(a);
+ bind[0].length= &a_len;
+ rc= mysql_stmt_bind_result(stmt, bind);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+ if (!opt_silent)
+ printf("Fetched row from stmt: %s\n", a);
+ /* Don't optimize: an attribute of the original test case */
+ mysql_stmt_free_result(stmt);
+ mysql_stmt_reset(stmt);
+ stmt_text= "select name from t1 where id=10";
+ rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text));
+ check_execute(stmt1, rc);
+ rc= mysql_stmt_bind_result(stmt1, bind);
+ check_execute(stmt1, rc);
+ rc= mysql_stmt_execute(stmt1);
+ while (1)
+ {
+ rc= mysql_stmt_fetch(stmt1);
+ if (rc == MYSQL_NO_DATA)
+ {
+ if (!opt_silent)
+ printf("End of data in stmt1\n");
+ break;
+ }
+ check_execute(stmt1, rc);
+ if (!opt_silent)
+ printf("Fetched row from stmt1: %s\n", a);
+ }
+ mysql_stmt_close(stmt);
+ mysql_stmt_close(stmt1);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
+/* Bug#11172: cursors, crash on a fetch from a datetime column */
+
+static void test_bug11172()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind_in[1], bind_out[2];
+ MYSQL_TIME hired;
+ int rc;
+ const char *stmt_text;
+ int i= 0, id;
+ ulong type;
+
+ myheader("test_bug11172");
+
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (id integer not null primary key,"
+ "hired date not null)");
+ rc= mysql_query(mysql,
+ "insert into t1 (id, hired) values (1, '1933-08-24'), "
+ "(2, '1965-01-01'), (3, '1949-08-17'), (4, '1945-07-07'), "
+ "(5, '1941-05-15'), (6, '1978-09-15'), (7, '1936-03-28')");
+ myquery(rc);
+ stmt= mysql_stmt_init(mysql);
+ stmt_text= "SELECT id, hired FROM t1 WHERE hired=?";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+
+ bzero((char*) bind_in, sizeof(bind_in));
+ bzero((char*) bind_out, sizeof(bind_out));
+ bzero((char*) &hired, sizeof(hired));
+ hired.year= 1965;
+ hired.month= 1;
+ hired.day= 1;
+ bind_in[0].buffer_type= MYSQL_TYPE_DATE;
+ bind_in[0].buffer= (void*) &hired;
+ bind_in[0].buffer_length= sizeof(hired);
+ bind_out[0].buffer_type= MYSQL_TYPE_LONG;
+ bind_out[0].buffer= (void*) &id;
+ bind_out[1]= bind_in[0];
+
+ for (i= 0; i < 3; i++)
+ {
+ rc= mysql_stmt_bind_param(stmt, bind_in);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_bind_result(stmt, bind_out);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ while ((rc= mysql_stmt_fetch(stmt)) == 0)
+ {
+ if (!opt_silent)
+ printf("fetched data %d:%d-%d-%d\n", id,
+ hired.year, hired.month, hired.day);
+ }
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+ mysql_stmt_free_result(stmt) || mysql_stmt_reset(stmt);
+ }
+ mysql_stmt_close(stmt);
+ mysql_rollback(mysql);
+ mysql_rollback(mysql);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
+/* Bug#11656: cursors, crash on a fetch from a query with distinct. */
+
+static void test_bug11656()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[2];
+ int rc;
+ const char *stmt_text;
+ char buf[2][20];
+ int i= 0;
+ ulong type;
+
+ myheader("test_bug11656");
+
+ mysql_query(mysql, "drop table if exists t1");
+
+ rc= mysql_query(mysql, "create table t1 ("
+ "server varchar(40) not null, "
+ "test_kind varchar(1) not null, "
+ "test_id varchar(30) not null , "
+ "primary key (server,test_kind,test_id))");
+ myquery(rc);
+
+ stmt_text= "select distinct test_kind, test_id from t1 "
+ "where server in (?, ?)";
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+
+ bzero((char*) bind, sizeof(bind));
+ strmov(buf[0], "pcint502_MY2");
+ strmov(buf[1], "*");
+ for (i=0; i < 2; i++)
+ {
+ bind[i].buffer_type= MYSQL_TYPE_STRING;
+ bind[i].buffer= (gptr *)&buf[i];
+ bind[i].buffer_length= strlen(buf[i]);
+ }
+ mysql_stmt_bind_param(stmt, bind);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ mysql_stmt_close(stmt);
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
+/*
+ Check that the server signals when NO_BACKSLASH_ESCAPES mode is in effect,
+ and mysql_real_escape_string() does the right thing as a result.
+*/
+
+static void test_bug10214()
+{
+ int len;
+ char out[8];
+
+ myheader("test_bug10214");
+
+ DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES));
+
+ len= mysql_real_escape_string(mysql, out, "a'b\\c", 5);
+ DIE_UNLESS(memcmp(out, "a\\'b\\\\c", len) == 0);
+
+ mysql_query(mysql, "set sql_mode='NO_BACKSLASH_ESCAPES'");
+ DIE_UNLESS(mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES);
+
+ len= mysql_real_escape_string(mysql, out, "a'b\\c", 5);
+ DIE_UNLESS(memcmp(out, "a''b\\c", len) == 0);
+
+ mysql_query(mysql, "set sql_mode=''");
+}
+
+static void test_client_character_set()
+{
+ MY_CHARSET_INFO cs;
+ char *csname= (char*) "utf8";
+ char *csdefault= (char*)mysql_character_set_name(mysql);
+ int rc;
+
+ myheader("test_client_character_set");
+
+ rc= mysql_set_character_set(mysql, csname);
+ DIE_UNLESS(rc == 0);
+
+ mysql_get_character_set_info(mysql, &cs);
+ DIE_UNLESS(!strcmp(cs.csname, "utf8"));
+ DIE_UNLESS(!strcmp(cs.name, "utf8_general_ci"));
+ /* Restore the default character set */
+ rc= mysql_set_character_set(mysql, csdefault);
+ myquery(rc);
+}
+
/* Test correct max length for MEDIUMTEXT and LONGTEXT columns */
static void test_bug9735()
@@ -11708,6 +13692,7 @@ static void test_bug9735()
myquery(rc);
}
+
/* Bug#11183 "mysql_stmt_reset() doesn't reset information about error" */
static void test_bug11183()
@@ -11752,15 +13737,166 @@ static void test_bug11183()
myquery(rc);
}
+static void test_bug11037()
+{
+ MYSQL_STMT *stmt;
+ int rc;
+ const char *stmt_text;
+
+ myheader("test_bug11037");
+
+ mysql_query(mysql, "drop table if exists t1");
+
+ rc= mysql_query(mysql, "create table t1 (id int not null)");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "insert into t1 values (1)");
+ myquery(rc);
+
+ stmt_text= "select id FROM t1";
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+
+ /* expected error */
+ rc = mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==1);
+ if (!opt_silent)
+ fprintf(stdout, "Got error, as expected:\n [%d] %s\n",
+ mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==0);
+
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==MYSQL_NO_DATA);
+
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==MYSQL_NO_DATA);
+
+ mysql_stmt_close(stmt);
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+/* Bug#10760: cursors, crash in a fetch after rollback. */
+
+static void test_bug10760()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[1];
+ int rc;
+ const char *stmt_text;
+ char id_buf[20];
+ ulong id_len;
+ int i= 0;
+ ulong type;
+
+ myheader("test_bug10760");
+
+ mysql_query(mysql, "drop table if exists t1, t2");
+
+ /* create tables */
+ rc= mysql_query(mysql, "create table t1 (id integer not null primary key)"
+ " engine=MyISAM");
+ myquery(rc);
+ for (; i < 42; ++i)
+ {
+ char buf[100];
+ sprintf(buf, "insert into t1 (id) values (%d)", i+1);
+ rc= mysql_query(mysql, buf);
+ myquery(rc);
+ }
+ mysql_autocommit(mysql, FALSE);
+ /* create statement */
+ stmt= mysql_stmt_init(mysql);
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+
+ /*
+ 1: check that a deadlock within the same connection
+ is resolved and an error is returned. The deadlock is modelled
+ as follows:
+ con1: open cursor for select * from t1;
+ con1: insert into t1 (id) values (1)
+ */
+ stmt_text= "select id from t1 order by 1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_query(mysql, "update t1 set id=id+100");
+ DIE_UNLESS(rc);
+ if (!opt_silent)
+ printf("Got error (as expected): %s\n", mysql_error(mysql));
+ /*
+ 2: check that MyISAM tables used in cursors survive
+ COMMIT/ROLLBACK.
+ */
+ rc= mysql_rollback(mysql); /* should not close the cursor */
+ myquery(rc);
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+
+ /*
+ 3: check that cursors to InnoDB tables are closed (for now) by
+ COMMIT/ROLLBACK.
+ */
+ if (! have_innodb)
+ {
+ if (!opt_silent)
+ printf("Testing that cursors are closed at COMMIT/ROLLBACK requires "
+ "InnoDB.\n");
+ }
+ else
+ {
+ stmt_text= "select id from t1 order by 1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ rc= mysql_query(mysql, "alter table t1 engine=InnoDB");
+ myquery(rc);
+
+ bzero(bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+ bind[0].buffer= (void*) id_buf;
+ bind[0].buffer_length= sizeof(id_buf);
+ bind[0].length= &id_len;
+ check_execute(stmt, rc);
+ mysql_stmt_bind_result(stmt, bind);
+
+ rc= mysql_stmt_execute(stmt);
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == 0);
+ if (!opt_silent)
+ printf("Fetched row %s\n", id_buf);
+ rc= mysql_rollback(mysql); /* should close the cursor */
+ myquery(rc);
+#if 0
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc);
+ if (!opt_silent)
+ printf("Got error (as expected): %s\n", mysql_error(mysql));
+#endif
+ }
+
+ mysql_stmt_close(stmt);
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+ mysql_autocommit(mysql, TRUE); /* restore default */
+}
+
static void test_bug12001()
{
MYSQL *mysql_local;
MYSQL_RES *result;
const char *query= "DROP TABLE IF EXISTS test_table;"
- "CREATE TABLE test_table(id INT);"
- "INSERT INTO test_table VALUES(10);"
- "UPDATE test_table SET id=20 WHERE id=10;"
- "SELECT * FROM test_table;"
+ "CREATE TABLE test_table(id INT);"
+ "INSERT INTO test_table VALUES(10);"
+ "UPDATE test_table SET id=20 WHERE id=10;"
+ "SELECT * FROM test_table;"
"INSERT INTO non_existent_table VALUES(11);";
int rc, res;
@@ -11775,7 +13911,9 @@ static void test_bug12001()
/* Create connection that supports multi statements */
if (!mysql_real_connect(mysql_local, opt_host, opt_user,
opt_password, current_db, opt_port,
- opt_unix_socket, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS)) {
+ opt_unix_socket, CLIENT_MULTI_STATEMENTS |
+ CLIENT_MULTI_RESULTS))
+ {
fprintf(stdout, "\n mysql_real_connect() failed");
exit(1);
}
@@ -11783,12 +13921,16 @@ static void test_bug12001()
rc= mysql_query(mysql_local, query);
myquery(rc);
- do {
- if (mysql_field_count(mysql_local) && (result= mysql_use_result(mysql_local))) {
- mysql_free_result(result);
+ do
+ {
+ if (mysql_field_count(mysql_local) &&
+ (result= mysql_use_result(mysql_local)))
+ {
+ mysql_free_result(result);
}
- } while (!(res= mysql_next_result(mysql_local)));
-
+ }
+ while (!(res= mysql_next_result(mysql_local)));
+
rc= mysql_query(mysql_local, "DROP TABLE IF EXISTS test_table");
myquery(rc);
@@ -11796,6 +13938,382 @@ static void test_bug12001()
DIE_UNLESS(res==1);
}
+
+/* Bug#11909: wrong metadata if fetching from two cursors */
+
+static void test_bug11909()
+{
+ MYSQL_STMT *stmt1, *stmt2;
+ MYSQL_BIND bind[7];
+ int rc;
+ char firstname[20], midinit[20], lastname[20], workdept[20];
+ ulong firstname_len, midinit_len, lastname_len, workdept_len;
+ uint32 empno;
+ double salary;
+ float bonus;
+ const char *stmt_text;
+
+ myheader("test_bug11909");
+
+ stmt_text= "drop table if exists t1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt_text= "create table t1 ("
+ " empno int(11) not null, firstname varchar(20) not null,"
+ " midinit varchar(20) not null, lastname varchar(20) not null,"
+ " workdept varchar(6) not null, salary double not null,"
+ " bonus float not null, primary key (empno)"
+ ") default charset=latin1 collate=latin1_bin";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt_text= "insert into t1 values "
+ "(10, 'CHRISTINE', 'I', 'HAAS', 'A00', 52750, 1000), "
+ "(20, 'MICHAEL', 'L', 'THOMPSON', 'B01', 41250, 800),"
+ "(30, 'SALLY', 'A', 'KWAN', 'C01', 38250, 800),"
+ "(50, 'JOHN', 'B', 'GEYER', 'E01', 40175, 800), "
+ "(60, 'IRVING', 'F', 'STERN', 'D11', 32250, 500)";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ /* ****** Begin of trace ****** */
+
+ stmt1= open_cursor("SELECT empno, firstname, midinit, lastname,"
+ "workdept, salary, bonus FROM t1");
+
+ bzero(bind, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_LONG;
+ bind[0].buffer= (void*) &empno;
+
+ bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
+ bind[1].buffer= (void*) firstname;
+ bind[1].buffer_length= sizeof(firstname);
+ bind[1].length= &firstname_len;
+
+ bind[2].buffer_type= MYSQL_TYPE_VAR_STRING;
+ bind[2].buffer= (void*) midinit;
+ bind[2].buffer_length= sizeof(midinit);
+ bind[2].length= &midinit_len;
+
+ bind[3].buffer_type= MYSQL_TYPE_VAR_STRING;
+ bind[3].buffer= (void*) lastname;
+ bind[3].buffer_length= sizeof(lastname);
+ bind[3].length= &lastname_len;
+
+ bind[4].buffer_type= MYSQL_TYPE_VAR_STRING;
+ bind[4].buffer= (void*) workdept;
+ bind[4].buffer_length= sizeof(workdept);
+ bind[4].length= &workdept_len;
+
+ bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
+ bind[5].buffer= (void*) &salary;
+
+ bind[6].buffer_type= MYSQL_TYPE_FLOAT;
+ bind[6].buffer= (void*) &bonus;
+ rc= mysql_stmt_bind_result(stmt1, bind);
+ check_execute(stmt1, rc);
+
+ rc= mysql_stmt_execute(stmt1);
+ check_execute(stmt1, rc);
+
+ rc= mysql_stmt_fetch(stmt1);
+ DIE_UNLESS(rc == 0);
+ DIE_UNLESS(empno == 10);
+ DIE_UNLESS(strcmp(firstname, "CHRISTINE") == 0);
+ DIE_UNLESS(strcmp(midinit, "I") == 0);
+ DIE_UNLESS(strcmp(lastname, "HAAS") == 0);
+ DIE_UNLESS(strcmp(workdept, "A00") == 0);
+ DIE_UNLESS(salary == (double) 52750.0);
+ DIE_UNLESS(bonus == (float) 1000.0);
+
+ stmt2= open_cursor("SELECT empno, firstname FROM t1");
+ rc= mysql_stmt_bind_result(stmt2, bind);
+ check_execute(stmt2, rc);
+
+ rc= mysql_stmt_execute(stmt2);
+ check_execute(stmt2, rc);
+
+ rc= mysql_stmt_fetch(stmt2);
+ DIE_UNLESS(rc == 0);
+
+ DIE_UNLESS(empno == 10);
+ DIE_UNLESS(strcmp(firstname, "CHRISTINE") == 0);
+
+ rc= mysql_stmt_reset(stmt2);
+ check_execute(stmt2, rc);
+
+ /* ERROR: next statement should return 0 */
+
+ rc= mysql_stmt_fetch(stmt1);
+ DIE_UNLESS(rc == 0);
+
+ mysql_stmt_close(stmt1);
+ mysql_stmt_close(stmt2);
+ rc= mysql_rollback(mysql);
+ myquery(rc);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+/* Cursors: opening a cursor to a compilicated query with ORDER BY */
+
+static void test_bug11901()
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[2];
+ int rc;
+ char workdept[20];
+ ulong workdept_len;
+ uint32 empno;
+ const char *stmt_text;
+
+ myheader("test_bug11901");
+
+ stmt_text= "drop table if exists t1, t2";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt_text= "create table t1 ("
+ " empno int(11) not null, firstname varchar(20) not null,"
+ " midinit varchar(20) not null, lastname varchar(20) not null,"
+ " workdept varchar(6) not null, salary double not null,"
+ " bonus float not null, primary key (empno), "
+ " unique key (workdept, empno) "
+ ") default charset=latin1 collate=latin1_bin";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt_text= "insert into t1 values "
+ "(10, 'CHRISTINE', 'I', 'HAAS', 'A00', 52750, 1000),"
+ "(20, 'MICHAEL', 'L', 'THOMPSON', 'B01', 41250, 800), "
+ "(30, 'SALLY', 'A', 'KWAN', 'C01', 38250, 800), "
+ "(50, 'JOHN', 'B', 'GEYER', 'E01', 40175, 800), "
+ "(60, 'IRVING', 'F', 'STERN', 'D11', 32250, 500), "
+ "(70, 'EVA', 'D', 'PULASKI', 'D21', 36170, 700), "
+ "(90, 'EILEEN', 'W', 'HENDERSON', 'E11', 29750, 600), "
+ "(100, 'THEODORE', 'Q', 'SPENSER', 'E21', 26150, 500), "
+ "(110, 'VINCENZO', 'G', 'LUCCHESSI', 'A00', 46500, 900), "
+ "(120, 'SEAN', '', 'O\\'CONNELL', 'A00', 29250, 600), "
+ "(130, 'DOLORES', 'M', 'QUINTANA', 'C01', 23800, 500), "
+ "(140, 'HEATHER', 'A', 'NICHOLLS', 'C01', 28420, 600), "
+ "(150, 'BRUCE', '', 'ADAMSON', 'D11', 25280, 500), "
+ "(160, 'ELIZABETH', 'R', 'PIANKA', 'D11', 22250, 400), "
+ "(170, 'MASATOSHI', 'J', 'YOSHIMURA', 'D11', 24680, 500), "
+ "(180, 'MARILYN', 'S', 'SCOUTTEN', 'D11', 21340, 500), "
+ "(190, 'JAMES', 'H', 'WALKER', 'D11', 20450, 400), "
+ "(200, 'DAVID', '', 'BROWN', 'D11', 27740, 600), "
+ "(210, 'WILLIAM', 'T', 'JONES', 'D11', 18270, 400), "
+ "(220, 'JENNIFER', 'K', 'LUTZ', 'D11', 29840, 600), "
+ "(230, 'JAMES', 'J', 'JEFFERSON', 'D21', 22180, 400), "
+ "(240, 'SALVATORE', 'M', 'MARINO', 'D21', 28760, 600), "
+ "(250, 'DANIEL', 'S', 'SMITH', 'D21', 19180, 400), "
+ "(260, 'SYBIL', 'P', 'JOHNSON', 'D21', 17250, 300), "
+ "(270, 'MARIA', 'L', 'PEREZ', 'D21', 27380, 500), "
+ "(280, 'ETHEL', 'R', 'SCHNEIDER', 'E11', 26250, 500), "
+ "(290, 'JOHN', 'R', 'PARKER', 'E11', 15340, 300), "
+ "(300, 'PHILIP', 'X', 'SMITH', 'E11', 17750, 400), "
+ "(310, 'MAUDE', 'F', 'SETRIGHT', 'E11', 15900, 300), "
+ "(320, 'RAMLAL', 'V', 'MEHTA', 'E21', 19950, 400), "
+ "(330, 'WING', '', 'LEE', 'E21', 25370, 500), "
+ "(340, 'JASON', 'R', 'GOUNOT', 'E21', 23840, 500)";
+
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt_text= "create table t2 ("
+ " deptno varchar(6) not null, deptname varchar(20) not null,"
+ " mgrno int(11) not null, location varchar(20) not null,"
+ " admrdept varchar(6) not null, refcntd int(11) not null,"
+ " refcntu int(11) not null, primary key (deptno)"
+ ") default charset=latin1 collate=latin1_bin";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt_text= "insert into t2 values "
+ "('A00', 'SPIFFY COMPUTER SERV', 10, '', 'A00', 0, 0), "
+ "('B01', 'PLANNING', 20, '', 'A00', 0, 0), "
+ "('C01', 'INFORMATION CENTER', 30, '', 'A00', 0, 0), "
+ "('D01', 'DEVELOPMENT CENTER', 0, '', 'A00', 0, 0),"
+ "('D11', 'MANUFACTURING SYSTEM', 60, '', 'D01', 0, 0), "
+ "('D21', 'ADMINISTRATION SYSTE', 70, '', 'D01', 0, 0), "
+ "('E01', 'SUPPORT SERVICES', 50, '', 'A00', 0, 0), "
+ "('E11', 'OPERATIONS', 90, '', 'E01', 0, 0), "
+ "('E21', 'SOFTWARE SUPPORT', 100,'', 'E01', 0, 0)";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ /* ****** Begin of trace ****** */
+
+ stmt= open_cursor("select t1.empno, t1.workdept "
+ "from (t1 left join t2 on t2.deptno = t1.workdept) "
+ "where t2.deptno in "
+ " (select t2.deptno "
+ " from (t1 left join t2 on t2.deptno = t1.workdept) "
+ " where t1.empno = ?) "
+ "order by 1");
+ bzero(bind, sizeof(bind));
+
+ bind[0].buffer_type= MYSQL_TYPE_LONG;
+ bind[0].buffer= &empno;
+ rc= mysql_stmt_bind_param(stmt, bind);
+ check_execute(stmt, rc);
+
+ bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
+ bind[1].buffer= (void*) workdept;
+ bind[1].buffer_length= sizeof(workdept);
+ bind[1].length= &workdept_len;
+
+ rc= mysql_stmt_bind_result(stmt, bind);
+ check_execute(stmt, rc);
+
+ empno= 10;
+ /* ERROR: next statement causes a server crash */
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "drop table t1, t2");
+ myquery(rc);
+}
+
+/* Bug#11904: mysql_stmt_attr_set CURSOR_TYPE_READ_ONLY grouping wrong result */
+
+static void test_bug11904()
+{
+ MYSQL_STMT *stmt1;
+ int rc;
+ const char *stmt_text;
+ const ulong type= (ulong)CURSOR_TYPE_READ_ONLY;
+ MYSQL_BIND bind[2];
+ int country_id=0;
+ char row_data[11]= {0};
+
+ myheader("test_bug11904");
+
+ /* create tables */
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS bug11904b");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE TABLE bug11904b (id int, name char(10), primary key(id, name))");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "INSERT INTO bug11904b VALUES (1, 'sofia'), (1,'plovdiv'),"
+ " (1,'varna'), (2,'LA'), (2,'new york'), (3,'heidelberg'),"
+ " (3,'berlin'), (3, 'frankfurt')");
+
+ myquery(rc);
+ mysql_commit(mysql);
+ /* create statement */
+ stmt1= mysql_stmt_init(mysql);
+ mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+
+ stmt_text= "SELECT id, MIN(name) FROM bug11904b GROUP BY id";
+
+ rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text));
+ check_execute(stmt1, rc);
+
+ memset(bind, 0, sizeof(bind));
+ bind[0].buffer_type= MYSQL_TYPE_LONG;
+ bind[0].buffer=& country_id;
+ bind[0].buffer_length= 0;
+ bind[0].length= 0;
+
+ bind[1].buffer_type= MYSQL_TYPE_STRING;
+ bind[1].buffer=& row_data;
+ bind[1].buffer_length= sizeof(row_data) - 1;
+ bind[1].length= 0;
+
+ rc= mysql_stmt_bind_result(stmt1, bind);
+ check_execute(stmt1, rc);
+
+ rc= mysql_stmt_execute(stmt1);
+ check_execute(stmt1, rc);
+
+ rc= mysql_stmt_fetch(stmt1);
+ check_execute(stmt1, rc);
+ DIE_UNLESS(country_id == 1);
+ DIE_UNLESS(memcmp(row_data, "plovdiv", 7) == 0);
+
+ rc= mysql_stmt_fetch(stmt1);
+ check_execute(stmt1, rc);
+ DIE_UNLESS(country_id == 2);
+ DIE_UNLESS(memcmp(row_data, "LA", 2) == 0);
+
+ rc= mysql_stmt_fetch(stmt1);
+ check_execute(stmt1, rc);
+ DIE_UNLESS(country_id == 3);
+ DIE_UNLESS(memcmp(row_data, "berlin", 6) == 0);
+
+ rc= mysql_stmt_close(stmt1);
+ check_execute(stmt1, rc);
+
+ rc= mysql_query(mysql, "drop table bug11904b");
+ myquery(rc);
+}
+
+
+/* Bug#12243: multiple cursors, crash in a fetch after commit. */
+
+static void test_bug12243()
+{
+ MYSQL_STMT *stmt1, *stmt2;
+ int rc;
+ const char *stmt_text;
+ ulong type;
+
+ myheader("test_bug12243");
+
+ if (! have_innodb)
+ {
+ if (!opt_silent)
+ printf("This test requires InnoDB.\n");
+ return;
+ }
+
+ /* create tables */
+ mysql_query(mysql, "drop table if exists t1");
+ mysql_query(mysql, "create table t1 (a int) engine=InnoDB");
+ rc= mysql_query(mysql, "insert into t1 (a) values (1), (2)");
+ myquery(rc);
+ mysql_autocommit(mysql, FALSE);
+ /* create statement */
+ stmt1= mysql_stmt_init(mysql);
+ stmt2= mysql_stmt_init(mysql);
+ type= (ulong) CURSOR_TYPE_READ_ONLY;
+ mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+ mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, (const void*) &type);
+
+ stmt_text= "select a from t1";
+
+ rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text));
+ check_execute(stmt1, rc);
+ rc= mysql_stmt_execute(stmt1);
+ check_execute(stmt1, rc);
+ rc= mysql_stmt_fetch(stmt1);
+ check_execute(stmt1, rc);
+
+ rc= mysql_stmt_prepare(stmt2, stmt_text, strlen(stmt_text));
+ check_execute(stmt2, rc);
+ rc= mysql_stmt_execute(stmt2);
+ check_execute(stmt2, rc);
+ rc= mysql_stmt_fetch(stmt2);
+ check_execute(stmt2, rc);
+
+ rc= mysql_stmt_close(stmt1);
+ check_execute(stmt1, rc);
+ rc= mysql_commit(mysql);
+ myquery(rc);
+ rc= mysql_stmt_fetch(stmt2);
+ check_execute(stmt2, rc);
+
+ mysql_stmt_close(stmt2);
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+ mysql_autocommit(mysql, TRUE); /* restore default */
+}
+
/*
Bug#11718: query with function, join and order by returns wrong type
*/
@@ -11895,6 +14413,7 @@ and you are welcome to modify and redistribute it under the GPL license\n");
static struct my_tests_st my_tests[]= {
+ { "test_view_sp_list_fields", test_view_sp_list_fields},
{ "client_query", client_query },
{ "test_prepare_insert_update", test_prepare_insert_update},
#if NOT_YET_WORKING
@@ -12041,13 +14560,45 @@ static struct my_tests_st my_tests[]= {
{ "test_conversion", test_conversion },
{ "test_rewind", test_rewind },
{ "test_bug6761", test_bug6761 },
+ { "test_view", test_view },
+ { "test_view_where", test_view_where },
+ { "test_view_2where", test_view_2where },
+ { "test_view_star", test_view_star },
+ { "test_view_insert", test_view_insert },
+ { "test_left_join_view", test_left_join_view },
+ { "test_view_insert_fields", test_view_insert_fields },
+ { "test_basic_cursors", test_basic_cursors },
+ { "test_cursors_with_union", test_cursors_with_union },
+ { "test_truncation", test_truncation },
+ { "test_truncation_option", test_truncation_option },
+ { "test_client_character_set", test_client_character_set },
{ "test_bug8330", test_bug8330 },
{ "test_bug7990", test_bug7990 },
{ "test_bug8378", test_bug8378 },
+ { "test_bug8722", test_bug8722 },
+ { "test_bug8880", test_bug8880 },
+ { "test_bug9159", test_bug9159 },
+ { "test_bug9520", test_bug9520 },
+ { "test_bug9478", test_bug9478 },
+ { "test_bug9643", test_bug9643 },
+ { "test_bug10729", test_bug10729 },
+ { "test_bug11111", test_bug11111 },
+ { "test_bug9992", test_bug9992 },
+ { "test_bug10736", test_bug10736 },
+ { "test_bug10794", test_bug10794 },
+ { "test_bug11172", test_bug11172 },
+ { "test_bug11656", test_bug11656 },
+ { "test_bug10214", test_bug10214 },
{ "test_bug9735", test_bug9735 },
{ "test_bug11183", test_bug11183 },
+ { "test_bug11037", test_bug11037 },
+ { "test_bug10760", test_bug10760 },
{ "test_bug12001", test_bug12001 },
{ "test_bug11718", test_bug11718 },
+ { "test_bug11909", test_bug11909 },
+ { "test_bug11901", test_bug11901 },
+ { "test_bug11904", test_bug11904 },
+ { "test_bug12243", test_bug12243 },
{ 0, 0 }
};
@@ -12152,7 +14703,6 @@ static void print_test_output()
}
}
-
/***************************************************************************
main routine
***************************************************************************/
@@ -12174,7 +14724,7 @@ int main(int argc, char **argv)
(char**) embedded_server_groups))
DIE("Can't initialize MySQL server");
- client_connect(); /* connect to server */
+ client_connect(0); /* connect to server */
total_time= 0;
for (iter_count= 1; iter_count <= opt_count; iter_count++)
@@ -12182,7 +14732,6 @@ int main(int argc, char **argv)
/* Start of tests */
test_count= 1;
start_time= time((time_t *)0);
-
if (!argc)
{
for (fptr= my_tests; fptr->name; fptr++)
@@ -12212,11 +14761,6 @@ int main(int argc, char **argv)
}
}
- /*
- XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST
- DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH.
- */
-
end_time= time((time_t *)0);
total_time+= difftime(end_time, start_time);
@@ -12224,6 +14768,7 @@ int main(int argc, char **argv)
}
client_disconnect(); /* disconnect from server */
+
free_defaults(defaults_argv);
print_test_output();
diff --git a/tests/pmail.pl b/tests/pmail.pl
index c7f8d4ee368..02d5d60ac0f 100755
--- a/tests/pmail.pl
+++ b/tests/pmail.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w
#
# Prints mails to standard output
#
@@ -9,21 +9,25 @@
use DBI;
use Getopt::Long;
-$VER="1.5";
+$VER="2.0";
@fldnms= ("mail_from","mail_to","cc","date","time_zone","file","sbj","txt");
-$fields=8;
-@mail= (@from,@to,@cc,@date,@time_zone,@file,@sbj,@txt);
+my $fields= 0;
+my $base_q= "";
+my $mail_count= 0;
$opt_user= $opt_password= "";
$opt_socket= "/tmp/mysql.sock";
$opt_port= 3306;
$opt_db="mail";
-$opt_table="mails";
+$opt_table="my_mail";
$opt_help=$opt_count=0;
+$opt_thread= 0;
+$opt_host= "";
+$opt_message_id= 0;
GetOptions("help","count","port=i","db=s","table=s","host=s","password=s",
- "user=s","socket=s") || usage();
+ "user=s","socket=s", "thread","message_id") || usage();
if ($opt_host eq '')
{
@@ -39,81 +43,194 @@ if ($opt_help || !$ARGV[0])
#### Connect and parsing the query to MySQL
####
-$dbh= DBI->connect("DBI:mysql:$opt_db:$opt_host:port=$opt_port:mysql_socket=$opt_mysql_socket", $opt_user,$opt_password, { PrintError => 0})
+$dbh= DBI->connect("DBI:mysql:$opt_db:$opt_host:port=$opt_port:mysql_socket=$opt_socket", $opt_user,$opt_password, { PrintError => 0})
|| die $DBI::errstr;
-if ($opt_count)
-{
- count_mails();
-}
+main();
-$fields=0;
-$query = "select ";
-foreach $val (@fldnms)
+####
+#### main
+####
+
+sub main
{
- if (!$fields)
+ my ($row, $val, $q, $mail, $sth);
+
+ if ($opt_count)
{
- $query.= "$val";
+ count_mails();
}
- else
+
+ $base_q= "SELECT ";
+ foreach $val (@fldnms)
+ {
+ if (!$fields)
+ {
+ $base_q.= "$val";
+ }
+ else
+ {
+ $base_q.= ",$val";
+ }
+ $fields++;
+ }
+ $base_q.= ",message_id" if ($opt_thread || $opt_message_id);
+ $base_q.= " FROM $opt_table";
+ $q= " WHERE $ARGV[0]";
+
+ $sth= $dbh->prepare($base_q . $q);
+ if (!$sth->execute)
+ {
+ print "$DBI::errstr\n";
+ $sth->finish;
+ die;
+ }
+ for (; ($row= $sth->fetchrow_arrayref); $mail_count++)
{
- $query.= ",$val";
+ for ($i= 0; $i < $fields; $i++)
+ {
+ if ($opt_message_id)
+ {
+ $mail[$fields][$mail_count]= $row->[$fields];
+ $mail[$fields][$mail_count].= "\nNumber of Replies: " . get_nr_replies($row->[$fields]);
+ }
+ $mail[$i][$mail_count]= $row->[$i];
+ }
+ if ($opt_thread)
+ {
+ get_mail_by_message_id($row->[$fields], $mail);
+ }
}
- $fields++;
+ print_mails($mail);
}
-$query.= " from $opt_table where $ARGV[0] order by date desc";
####
-#### Send query and save result
+#### Function, which fetches mail by searching in-reply-to with
+#### a given message_id. Saves the value (mail) in mail variable.
+#### Returns the message id of the mail found and searches again
+#### and saves, until no more mails are found with that message_id.
####
-$sth= $dbh->prepare($query);
-if (!$sth->execute)
+sub get_mail_by_message_id
{
- print "$DBI::errstr\n";
- $sth->finish;
- die;
-}
-for ($i=0; ($row= $sth->fetchrow_arrayref); $i++)
-{
- for ($j=0; $j < $fields; $j++)
+ my ($message_id, $mail)= @_;
+ my ($q, $query, $i, $row, $sth);
+
+ $q= " WHERE in_reply_to = \"$message_id\"";
+ $query= $base_q . $q;
+ $sth= $dbh->prepare($query);
+ if (!$sth->execute)
+ {
+ print "QUERY: $query\n$DBI::errstr\n";
+ $sth->finish;
+ die;
+ }
+ while (($row= $sth->fetchrow_arrayref))
{
- $mail[$j][$i]= $row->[$j];
+ $mail_count++;
+ for ($i= 0; $i < $fields; $i++)
+ {
+ if ($opt_message_id)
+ {
+ $mail[$fields][$mail_count]= $row->[$fields];
+ $mail[$fields][$mail_count].= "\nNumber of Replies: " . get_nr_replies($row->[$fields]);
+ }
+ $mail[$i][$mail_count]= $row->[$i];
+ }
+ $new_message_id= $row->[$fields];
+ if (defined($new_message_id) && length($new_message_id))
+ {
+ get_mail_by_message_id($new_message_id, $mail);
+ }
}
+ return;
}
####
-#### Print to stderr
+#### Get number of replies for a given message_id
####
-for ($i=0; $mail[0][$i]; $i++)
+sub get_nr_replies
{
- print "#" x 33;
- print " " . ($i+1) . ". Mail ";
- print "#" x 33;
- print "\nFrom: $mail[0][$i]\n";
- print "To: $mail[1][$i]\n";
- print "Cc: $mail[2][$i]\n";
- print "Date: $mail[3][$i]\n";
- print "Timezone: $mail[4][$i]\n";
- print "File: $mail[5][$i]\n";
- print "Subject: $mail[6][$i]\n";
- print "Message:\n$mail[7][$i]\n";
-}
-print "#" x 20;
-print " Summary: ";
-if ($i == 1)
-{
- print "$i Mail ";
- print "matches the query ";
+ my ($message_id)= @_;
+ my ($sth, $sth2, $q, $row, $row2, $nr_replies);
+
+ $nr_replies= 0;
+ $q= "SELECT COUNT(*) FROM my_mail WHERE in_reply_to=\"$message_id\"";
+ $sth= $dbh->prepare($q);
+ if (!$sth->execute)
+ {
+ print "QUERY: $q\n$DBI::errstr\n";
+ $sth->finish;
+ die;
+ }
+ while (($row= $sth->fetchrow_arrayref))
+ {
+ if (($nr_replies= $row->[0]))
+ {
+ $q= "SELECT message_id FROM my_mail WHERE in_reply_to=\"$message_id\"";
+ $sth2= $dbh->prepare($q);
+ if (!$sth2->execute)
+ {
+ print "QUERY: $q\n$DBI::errstr\n";
+ $sth->finish;
+ die;
+ }
+ while (($row2= $sth2->fetchrow_arrayref))
+ {
+ # There may be several replies to the same mail. Also the
+ # replies to the 'parent' mail may contain several replies
+ # and so on. Thus we need to calculate it recursively.
+ $nr_replies+= get_nr_replies($row2->[0]);
+ }
+ }
+ return $nr_replies;
+ }
}
-else
+
+####
+#### Print mails
+####
+
+sub print_mails
{
- print "$i Mails ";
- print "match the query ";
-}
-print "#" x 20;
-print "\n";
+ my ($mail)= @_;
+ my ($i);
+
+ for ($i=0; $mail[0][$i]; $i++)
+ {
+ print "#" x 33;
+ print " " . ($i+1) . ". Mail ";
+ print "#" x 33;
+ print "\n";
+ if ($opt_message_id)
+ {
+ print "Msg ID: $mail[$fields][$i]\n";
+ }
+ print "From: $mail[0][$i]\n";
+ print "To: $mail[1][$i]\n";
+ print "Cc:" . (defined($mail[2][$i]) ? $mail[2][$i] : "") . "\n";
+ print "Date: $mail[3][$i]\n";
+ print "Timezone: $mail[4][$i]\n";
+ print "File: $mail[5][$i]\n";
+ print "Subject: $mail[6][$i]\n";
+ print "Message:\n$mail[7][$i]\n";
+ }
+ print "#" x 20;
+ print " Summary: ";
+ if ($i == 1)
+ {
+ print "$i Mail ";
+ print "matches the query ";
+ }
+ else
+ {
+ print "$i Mails ";
+ print "match the query ";
+ }
+ print "#" x 20;
+ print "\n";
+}
####
#### Count mails that matches the query, but don't show them
@@ -121,6 +238,8 @@ print "\n";
sub count_mails
{
+ my ($sth);
+
$sth= $dbh->prepare("select count(*) from $opt_table where $ARGV[0]");
if (!$sth->execute)
{
@@ -154,15 +273,21 @@ sub usage
Usage: pmail [options] "SQL where clause"
Options:
- --help show this help
- --count Shows how many mails matches the query, but not the mails.
- --db= database to use (Default: $opt_db)
- --table= table to use (Default: $opt_table)
- --host= Hostname which to connect (Default: $opt_host)
- --socket= Unix socket to be used for connection (Default: $opt_socket)
- --password= Password to use for mysql
- --user= User to be used for mysql connection, if not current user
- --port= mysql port to be used (Default: $opt_port)
+ --help show this help
+ --count Shows how many mails matches the query, but not the mails.
+ --db= database to use (Default: $opt_db)
+ --host= Hostname which to connect (Default: $opt_host)
+ --socket= Unix socket to be used for connection (Default: $opt_socket)
+ --password= Password to use for mysql
+ --user= User to be used for mysql connection, if not current user
+ --port= mysql port to be used (Default: $opt_port)
+ --thread Will search for possible replies to emails found by the search
+ criteria. Replies, if found, will be displayed right after the
+ original mail.
+ --message_id Display message_id on top of each mail. Useful when searching
+ email threads with --thread. On the second line is the number
+ of replies to the same thread, starting counting from that
+ mail (excluding possible parent mails).
"SQL where clause" is the end of the select clause,
where the condition is expressed. The result will
be the mail(s) that matches the condition and
@@ -176,18 +301,20 @@ sub usage
- Subject
- Message text
The field names that can be used in the where clause are:
- Field Type
- - mail_from varchar(120)
- - date datetime
- - sbj varchar(200)
- - txt mediumtext
- - cc text
- - mail_to text
- - time_zone varchar(6)
- - reply varchar(120)
- - file varchar(32)
- - hash int(11)
- An example of the pmail:
+ Field Type
+ - message_id varchar(255) # Use with --thread and --message_id
+ - in_reply_to varchar(255) # Internally used by --thread
+ - mail_from varchar(120)
+ - date datetime
+ - sbj varchar(200)
+ - txt mediumtext
+ - cc text
+ - mail_to text
+ - time_zone varchar(6)
+ - reply varchar(120)
+ - file varchar(32)
+ - hash int(11)
+ An example of pmail:
pmail "txt like '%libmysql.dll%' and sbj like '%delphi%'"
NOTE: the txt field is NOT case sensitive!
EOF
diff --git a/tests/select_test.c b/tests/select_test.c
index ee2a9192865..64c4fec5167 100644
--- a/tests/select_test.c
+++ b/tests/select_test.c
@@ -44,6 +44,7 @@ int main(int argc, char **argv)
perror("");
exit(1);
}
+ mysql.reconnect= 1;
count = 0;
num = atoi(argv[2]);
diff --git a/tests/showdb_test.c b/tests/showdb_test.c
index df2b3037c00..08229fc51ee 100644
--- a/tests/showdb_test.c
+++ b/tests/showdb_test.c
@@ -45,6 +45,7 @@ int main(int argc, char **argv)
perror("");
exit(1);
}
+ mysql.reconnect= 1;
count = 0;
num = atoi(argv[2]);
diff --git a/tests/ssl_test.c b/tests/ssl_test.c
index b18e493c267..85f490cb02e 100644
--- a/tests/ssl_test.c
+++ b/tests/ssl_test.c
@@ -51,6 +51,7 @@ int main(int argc, char **argv)
perror("");
exit(1);
}
+ mysql.reconnect= 1;
count = 0;
num = atoi(argv[2]);
while (count < num)
diff --git a/tests/thread_test.c b/tests/thread_test.c
index 06f335fe1a6..f8577857d0a 100644
--- a/tests/thread_test.c
+++ b/tests/thread_test.c
@@ -55,6 +55,7 @@ unsigned __stdcall test_thread(void *arg __attribute__((unused)))
perror("");
goto end;
}
+ mysql.reconnect= 1;
if (verbose) { putchar('*'); fflush(stdout); }
for (count=0 ; count < number_of_tests ; count++)
{
diff --git a/tests/udf_test b/tests/udf_test
index 4621a7b34a5..15ad640f984 100644
--- a/tests/udf_test
+++ b/tests/udf_test
@@ -9,6 +9,7 @@ CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "udf_example.so";
CREATE FUNCTION lookup RETURNS STRING SONAME "udf_example.so";
CREATE FUNCTION reverse_lookup RETURNS STRING SONAME "udf_example.so";
CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME "udf_example.so";
+CREATE FUNCTION myfunc_argument_name RETURNS STRING SONAME "udf_example.so";
select metaphon("hello");
select myfunc_double("hello","world");
@@ -20,6 +21,7 @@ create temporary table t1 (a int,b double);
insert into t1 values (1,5),(1,4),(2,8),(3,9),(4,11);
select avgcost(a,b) from t1;
select avgcost(a,b) from t1 group by a;
+select a, myfunc_argument_name(a), myfunc_argument_name(a as b) from t1;
drop table t1;
DROP FUNCTION metaphon;
@@ -28,3 +30,4 @@ DROP FUNCTION myfunc_int;
DROP FUNCTION lookup;
DROP FUNCTION reverse_lookup;
DROP FUNCTION avgcost;
+DROP FUNCTION myfunc_argument_name;
diff --git a/tests/udf_test.res b/tests/udf_test.res
index 66634e13616..de9e9969f3a 100644
--- a/tests/udf_test.res
+++ b/tests/udf_test.res
@@ -35,6 +35,12 @@ CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME "udf_example.so"
Query OK, 0 rows affected
--------------
+CREATE FUNCTION myfunc_argument_name RETURNS STRING SONAME "udf_example.so"
+--------------
+
+Query OK, 0 rows affected
+
+--------------
select metaphon("hello")
--------------
@@ -107,6 +113,18 @@ avgcost(a,b)
4 rows in set
--------------
+select a, myfunc_argument_name(a) from t1;
+--------------
+
+a myfunc_argument_name(a) myfunc_argument_name(a as b)
+1 a b
+1 a b
+2 a b
+3 a b
+4 a b
+5 rows in set
+
+--------------
drop table t1
--------------
@@ -148,4 +166,10 @@ DROP FUNCTION avgcost
Query OK, 0 rows affected
+--------------
+DROP FUNCTION myfunc_argument_name;
+--------------
+
+Query OK, 0 rows affected
+
Bye