summaryrefslogtreecommitdiff
path: root/tests/client_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/client_test.c')
-rw-r--r--tests/client_test.c1289
1 files changed, 676 insertions, 613 deletions
diff --git a/tests/client_test.c b/tests/client_test.c
index 35bd5f8639a..12a0275e0e0 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -1,56 +1,39 @@
-/***************************************************************************
- client_test.c - description
- -------------------------
- begin : Sun Feb 3 2002
- copyright : (C) MySQL AB 1995-2003, www.mysql.com
- author : venu ( venu@mysql.com )
- ***************************************************************************/
+/* Copyright (C) 2003 MySQL AB
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/***************************************************************************
- * *
- * This is a test sample to test the new features in MySQL client-server *
- * protocol *
- * *
- ***************************************************************************/
+ This is a test sample to test the new features in MySQL client-server
+ protocol
-#include <my_global.h>
+ Main author: venu ( venu@mysql.com )
-#if defined(__WIN__) || defined(_WIN32) || defined(_WIN64)
-#include <windows.h>
-#endif
+ NOTES:
+ - To be able to test which fields are used, we are not clearing
+ the MYSQL_BIND with bzero() but instead just clearing the fields that
+ are used by the API.
-/* standrad headers */
-#include <stdio.h>
-#include <string.h>
+***************************************************************************/
-/* mysql client headers */
+#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>
#include <my_getopt.h>
-
+#include <m_string.h>
#include <assert.h>
-#ifndef true
-#define true 1
-#endif
-
-#ifndef false
-#define false 0
-#endif
-
-#ifndef bzero
-#define bzero(A,B) memset(A,0,B)
-#endif
-
/* set default options */
static char *opt_db=0;
static char *opt_user=0;
@@ -69,8 +52,6 @@ static char current_db[]= "client_test_db";
fprintf(stdout,"\n#######################\n"); \
}
-#define init_bind(x) (bzero(x,sizeof(x)))
-
#ifndef mysql_param_result
#define mysql_param_result mysql_prepare_result
#endif
@@ -85,7 +66,7 @@ static void print_error(const char *msg)
fprintf(stderr,"\n [MySQL]");
fprintf(stderr,"[%d] %s\n",mysql_errno(mysql),mysql_error(mysql));
}
- else if(msg) fprintf(stderr, " [MySQL] %s\n", msg);
+ else if (msg) fprintf(stderr, " [MySQL] %s\n", msg);
}
static void print_st_error(MYSQL_STMT *stmt, const char *msg)
@@ -100,7 +81,7 @@ static void print_st_error(MYSQL_STMT *stmt, const char *msg)
fprintf(stderr,"[%d] %s\n",mysql_stmt_errno(stmt),
mysql_stmt_error(stmt));
}
- else if(msg) fprintf(stderr, " [MySQL] %s\n", msg);
+ else if (msg) fprintf(stderr, " [MySQL] %s\n", msg);
}
static void client_disconnect();
@@ -112,35 +93,35 @@ static void client_disconnect();
#define myquery(r) \
{ \
-if( r || r == -1) \
+if (r) \
myerror(NULL); \
myassert(r == 0); \
}
#define myquery_r(r) \
{ \
-if( r || r == -1) \
+if (r) \
myerror(NULL); \
myassert_r(r == 0); \
}
#define mystmt(stmt,r) \
{ \
-if( r || r == -1) \
+if (r) \
mysterror(stmt,NULL); \
myassert(r == 0);\
}
#define mystmt_r(stmt,r) \
{ \
-if( r || r == -1) \
+if (r) \
mysterror(stmt,NULL); \
myassert_r(r == 0);\
}
#define mystmt_init(stmt) \
{ \
-if( stmt == 0) \
+if ( stmt == 0) \
myerror(NULL); \
myassert(stmt != 0); \
}
@@ -150,8 +131,8 @@ myassert(stmt != 0); \
myassert(stmt == 0);\
}
-#define mytest(x) if(!x) {myerror(NULL);myassert(true);}
-#define mytest_r(x) if(x) {myerror(NULL);myassert(true);}
+#define mytest(x) if (!x) {myerror(NULL);myassert(TRUE);}
+#define mytest_r(x) if (x) {myerror(NULL);myassert(TRUE);}
#define PREPARE(A,B) mysql_prepare(A,B,strlen(B))
@@ -179,7 +160,7 @@ static void client_connect()
}
/* set AUTOCOMMIT to ON*/
- mysql_autocommit(mysql, true);
+ mysql_autocommit(mysql, TRUE);
sprintf(buff,"CREATE DATABASE IF NOT EXISTS %s", current_db);
rc = mysql_query(mysql, buff);
myquery(rc);
@@ -286,9 +267,9 @@ static void my_print_result_metadata(MYSQL_RES *result)
{
field = mysql_fetch_field(result);
j = strlen(field->name);
- if(j < field->max_length)
+ if (j < field->max_length)
j = field->max_length;
- if(j < 4 && !IS_NOT_NULL(field->flags))
+ if (j < 4 && !IS_NOT_NULL(field->flags))
j = 4;
field->max_length = j;
}
@@ -321,7 +302,7 @@ int my_process_result_set(MYSQL_RES *result)
my_print_result_metadata(result);
- while((row = mysql_fetch_row(result)) != NULL)
+ while ((row = mysql_fetch_row(result)) != NULL)
{
mysql_field_seek(result,0);
fputc('\t',stdout);
@@ -330,7 +311,7 @@ int my_process_result_set(MYSQL_RES *result)
for(i=0; i< mysql_num_fields(result); i++)
{
field = mysql_fetch_field(result);
- if(row[i] == NULL)
+ if (row[i] == NULL)
fprintf(stdout, " %-*s |", (int) field->max_length, "NULL");
else if (IS_NUM(field->type))
fprintf(stdout, " %*s |", (int) field->max_length, row[i]);
@@ -362,7 +343,8 @@ uint my_process_stmt_result(MYSQL_STMT *stmt)
MYSQL_FIELD *field;
MYSQL_RES *result;
char data[50][255];
- long length[50];
+ ulong length[50];
+ my_bool is_null[50];
int rc, i;
if (!(result= mysql_prepare_result(stmt)))
@@ -376,8 +358,9 @@ uint my_process_stmt_result(MYSQL_STMT *stmt)
{
buffer[i].buffer_type= MYSQL_TYPE_STRING;
buffer[i].buffer_length=50;
- buffer[i].length=(long *)&length[i];
- buffer[i].buffer=(gptr)data[i];
+ buffer[i].length=&length[i];
+ buffer[i].buffer=(char*) data[i];
+ buffer[i].is_null= &is_null[i];
}
my_print_result_metadata(result);
@@ -398,7 +381,7 @@ uint my_process_stmt_result(MYSQL_STMT *stmt)
for (i=0; i < field_count; i++)
{
field = mysql_fetch_field(result);
- if(length[i] == MYSQL_NULL_DATA)
+ if (is_null[i])
fprintf(stdout, " %-*s |", (int) field->max_length, "NULL");
else if (length[i] == 0)
data[i][0]='\0'; /* unmodified buffer */
@@ -571,7 +554,7 @@ static my_bool thread_query(char *query)
error= 0;
fprintf(stdout,"\n in thread_query(%s)", query);
- if(!(l_mysql = mysql_init(NULL)))
+ if (!(l_mysql = mysql_init(NULL)))
{
myerror("mysql_init() failed");
return 1;
@@ -645,7 +628,7 @@ static void test_tran_bdb()
myheader("test_tran_bdb");
/* set AUTOCOMMIT to OFF */
- rc = mysql_autocommit(mysql, false);
+ rc = mysql_autocommit(mysql, FALSE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS my_demo_transaction");
@@ -708,7 +691,7 @@ static void test_tran_bdb()
mytest_r(row);
mysql_free_result(result);
- mysql_autocommit(mysql,true);
+ mysql_autocommit(mysql,TRUE);
}
/********************************************************
@@ -723,7 +706,7 @@ static void test_tran_innodb()
myheader("test_tran_innodb");
/* set AUTOCOMMIT to OFF */
- rc = mysql_autocommit(mysql, false);
+ rc = mysql_autocommit(mysql, FALSE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS my_demo_transaction");
@@ -785,7 +768,7 @@ static void test_tran_innodb()
mytest_r(row);
mysql_free_result(result);
- mysql_autocommit(mysql,true);
+ mysql_autocommit(mysql,TRUE);
}
@@ -963,7 +946,7 @@ static void test_prepare_syntax()
static void test_prepare()
{
MYSQL_STMT *stmt;
- int rc;
+ int rc, i;
char query[200];
int int_data, o_int_data;
char str_data[50], data[50];
@@ -972,13 +955,13 @@ static void test_prepare()
longlong big_data, o_big_data;
float real_data, o_real_data;
double double_data, o_double_data;
- long length[7], len;
+ ulong length[7], len;
+ my_bool is_null[7];
MYSQL_BIND bind[7];
myheader("test_prepare");
- init_bind(bind);
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS my_prepare");
@@ -1002,26 +985,33 @@ static void test_prepare()
/* tinyint */
bind[0].buffer_type=FIELD_TYPE_TINY;
- bind[0].buffer= (gptr)&tiny_data;
+ bind[0].buffer= (char *)&tiny_data;
/* string */
bind[1].buffer_type=FIELD_TYPE_STRING;
- bind[1].buffer= (gptr)str_data;
- bind[1].length= &bind[1].buffer_length;
+ bind[1].buffer= (char *)str_data;
+ bind[1].buffer_length= 1000; /* Max string length */
/* integer */
bind[2].buffer_type=FIELD_TYPE_LONG;
- bind[2].buffer= (gptr)&int_data;
+ bind[2].buffer= (char *)&int_data;
/* short */
bind[3].buffer_type=FIELD_TYPE_SHORT;
- bind[3].buffer= (gptr)&small_data;
+ bind[3].buffer= (char *)&small_data;
/* bigint */
bind[4].buffer_type=FIELD_TYPE_LONGLONG;
- bind[4].buffer= (gptr)&big_data;
+ bind[4].buffer= (char *)&big_data;
/* float */
bind[5].buffer_type=FIELD_TYPE_FLOAT;
- bind[5].buffer= (gptr)&real_data;
+ bind[5].buffer= (char *)&real_data;
/* double */
bind[6].buffer_type=FIELD_TYPE_DOUBLE;
- bind[6].buffer= (gptr)&double_data;
+ bind[6].buffer= (char *)&double_data;
+
+ for (i= 0; i < (int) array_elements(bind); i++)
+ {
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
+ is_null[i]= 0;
+ }
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -1035,7 +1025,7 @@ static void test_prepare()
/* now, execute the prepared statement to insert 10 records.. */
for (tiny_data=0; tiny_data < 100; tiny_data++)
{
- bind[1].buffer_length = sprintf(str_data,"MySQL%d",int_data);
+ length[1]= my_sprintf(str_data,(str_data, "MySQL%d",int_data));
rc = mysql_execute(stmt);
mystmt(stmt, rc);
int_data += 25;
@@ -1057,9 +1047,6 @@ static void test_prepare()
stmt = mysql_prepare(mysql,"SELECT * FROM my_prepare",50);
mystmt_init(stmt);
- for (int_data= 0; int_data < 7; int_data++)
- bind[int_data].length= &length[int_data];
-
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -1076,22 +1063,23 @@ static void test_prepare()
/* now, execute the prepared statement to insert 10 records.. */
for (o_tiny_data=0; o_tiny_data < 100; o_tiny_data++)
{
- len = sprintf(data,"MySQL%d",o_int_data);
+ len = my_sprintf(data, (data, "MySQL%d",o_int_data));
rc = mysql_fetch(stmt);
mystmt(stmt, rc);
- fprintf(stdout, "\n tiny : %d (%ld)", tiny_data,length[0]);
- fprintf(stdout, "\n short : %d (%ld)", small_data,length[3]);
- fprintf(stdout, "\n int : %d (%ld)", int_data,length[2]);
- fprintf(stdout, "\n big : %lld (%ld)", big_data,length[4]);
+ fprintf(stdout, "\n tiny : %d (%lu)", tiny_data,length[0]);
+ fprintf(stdout, "\n short : %d (%lu)", small_data,length[3]);
+ fprintf(stdout, "\n int : %d (%lu)", int_data,length[2]);
+ fprintf(stdout, "\n big : %lld (%lu)", big_data,length[4]);
- fprintf(stdout, "\n float : %f (%ld)", real_data,length[5]);
- fprintf(stdout, "\n double : %f (%ld)", double_data,length[6]);
+ fprintf(stdout, "\n float : %f (%lu)", real_data,length[5]);
+ fprintf(stdout, "\n double : %f (%lu)", double_data,length[6]);
- fprintf(stdout, "\n str : %s (%ld)", str_data, length[1]);
+ fprintf(stdout, "\n str : %s (%lu)", str_data, length[1]);
myassert(tiny_data == o_tiny_data);
+ myassert(is_null[0] == 0);
myassert(length[0] == 1);
myassert(int_data == o_int_data);
@@ -1126,6 +1114,7 @@ static void test_prepare()
}
+
/********************************************************
* to test double comparision *
*********************************************************/
@@ -1137,11 +1126,11 @@ static void test_double_compare()
double double_data;
MYSQL_RES *result;
MYSQL_BIND bind[3];
+ ulong length[3];
myheader("test_double_compare");
- init_bind(bind);
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_double_compare");
@@ -1165,17 +1154,24 @@ static void test_double_compare()
/* tinyint */
bind[0].buffer_type=FIELD_TYPE_TINY;
- bind[0].buffer=(gptr)&tiny_data;
+ bind[0].buffer=(char *)&tiny_data;
+ bind[0].is_null= 0; /* Can never be null */
+
/* string->float */
bind[1].buffer_type=FIELD_TYPE_STRING;
- bind[1].buffer= (gptr)&real_data;
- bind[1].buffer_length=10;
+ bind[1].buffer= (char *)&real_data;
+ bind[1].buffer_length=sizeof(real_data);
+ bind[1].is_null= 0;
+ bind[1].length= &length[1];
+ length[1]= 10;
+
/* double */
bind[2].buffer_type=FIELD_TYPE_DOUBLE;
- bind[2].buffer= (gptr)&double_data;
+ bind[2].buffer= (char *)&double_data;
+ bind[2].is_null= 0;
tiny_data = 1;
- strcpy(real_data,"10.2");
+ strmov(real_data,"10.2");
double_data = 34.5;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -1204,6 +1200,7 @@ static void test_double_compare()
mysql_free_result(result);
}
+
/********************************************************
* to test simple null *
*********************************************************/
@@ -1214,10 +1211,10 @@ static void test_null()
int nData=1;
MYSQL_RES *result;
MYSQL_BIND bind[2];
+ my_bool is_null[2];
myheader("test_null");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_null");
myquery(rc);
@@ -1228,18 +1225,19 @@ static void test_null()
myquery(rc);
/* insert by prepare, wrong column name */
- strcpy(query,"INSERT INTO test_null(col3,col2) VALUES(?,?)");
+ strmov(query,"INSERT INTO test_null(col3,col2) VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init_r(stmt);
- strcpy(query,"INSERT INTO test_null(col1,col2) VALUES(?,?)");
+ strmov(query,"INSERT INTO test_null(col1,col2) VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
verify_param_count(stmt,2);
- bind[0].is_null=1;
- bind[0].buffer_type=MYSQL_TYPE_NULL;
+ bind[0].buffer_type=MYSQL_TYPE_LONG;
+ bind[0].is_null= &is_null[0];
+ is_null[0]= 1;
bind[1]=bind[0]; /* string data */
rc = mysql_bind_param(stmt,bind);
@@ -1278,12 +1276,13 @@ static void test_fetch_null()
MYSQL_STMT *stmt;
int rc;
const char query[100];
- int length[11], i, nData;
+ int i, nData;
MYSQL_BIND bind[11];
+ ulong length[11];
+ my_bool is_null[11];
myheader("test_fetch_null");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_fetch_null");
myquery(rc);
@@ -1309,15 +1308,15 @@ static void test_fetch_null()
myquery(rc);
/* fetch */
- for (i=0; i <= 10; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type=FIELD_TYPE_LONG;
- length[i]=99;
- bind[i].length= (long *)&length[i];
+ bind[i].is_null= &is_null[i];
+ bind[i].length= &length[i];
}
- bind[i-1].buffer=(gptr)&nData;
+ bind[i-1].buffer=(char *)&nData; /* Last column is not null */
- strcpy((char *)query , "SELECT * FROM test_fetch_null");
+ strmov((char *)query , "SELECT * FROM test_fetch_null");
myassert(3 == my_stmt_result(query,50));
@@ -1337,17 +1336,19 @@ static void test_fetch_null()
for (i=0; i < 10; i++)
{
fprintf(stdout, "\n data[%d] : %s", i,
- length[i] == MYSQL_NULL_DATA ? "NULL" : "NOT NULL");
- myassert(length[i] == MYSQL_NULL_DATA);
+ is_null[i] ? "NULL" : "NOT NULL");
+ myassert(is_null[i]);
}
fprintf(stdout, "\n data[%d]: %d", i, nData);
myassert(nData == 1000 || nData == 88 || nData == 389789);
+ myassert(is_null[i] == 0);
myassert(length[i] == 4);
}
myassert(rc == 3);
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple select *
*********************************************************/
@@ -1359,7 +1360,7 @@ static void test_select_version()
myheader("test_select_version");
- strcpy((char *)query , "SELECT @@version");
+ strmov((char *)query , "SELECT @@version");
stmt = PREPARE(mysql, query);
mystmt_init(stmt);
@@ -1384,7 +1385,7 @@ static void test_select_simple()
myheader("test_select_simple");
/* insert by prepare */
- strcpy((char *)query, "SHOW TABLES FROM mysql");
+ strmov((char *)query, "SHOW TABLES FROM mysql");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -1397,6 +1398,7 @@ static void test_select_simple()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple select to debug *
*********************************************************/
@@ -1407,7 +1409,7 @@ static void test_select_direct()
myheader("test_select_direct");
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_select");
@@ -1443,6 +1445,7 @@ static void test_select_direct()
mysql_free_result(result);
}
+
/********************************************************
* to test simple select with prepare *
*********************************************************/
@@ -1453,7 +1456,7 @@ static void test_select_prepare()
myheader("test_select_prepare");
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_select");
@@ -1515,6 +1518,7 @@ static void test_select_prepare()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple select *
*********************************************************/
@@ -1525,11 +1529,11 @@ static void test_select()
char szData[25];
int nData=1;
MYSQL_BIND bind[2];
+ ulong length[2];
myheader("test_select");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_select");
@@ -1558,7 +1562,7 @@ static void test_select()
rc = mysql_commit(mysql);
myquery(rc);
- strcpy(query,"SELECT * FROM test_select WHERE id=? AND name=?");
+ strmov(query,"SELECT * FROM test_select WHERE id=? AND name=?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -1566,12 +1570,17 @@ static void test_select()
/* string data */
nData=10;
- strcpy(szData,(char *)"venu");
+ strmov(szData,(char *)"venu");
bind[1].buffer_type=FIELD_TYPE_STRING;
bind[1].buffer=szData;
- bind[1].buffer_length=4;
- bind[0].buffer=(gptr)&nData;
+ bind[1].buffer_length= sizeof(szData); /* Max string lenth */
+ bind[1].length= &length[1];
+ length[1]= 4;
+ bind[1].is_null=0;
+
+ bind[0].buffer=(char *)&nData;
bind[0].buffer_type=FIELD_TYPE_LONG;
+ bind[0].is_null= 0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -1579,11 +1588,12 @@ static void test_select()
rc = mysql_execute(stmt);
mystmt(stmt, rc);
- myassert( 1 == my_process_stmt_result(stmt));
+ myassert(my_process_stmt_result(stmt) != 0);
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple select show *
*********************************************************/
@@ -1594,9 +1604,9 @@ static void test_select_show()
myheader("test_select_show");
- mysql_autocommit(mysql,true);
+ mysql_autocommit(mysql,TRUE);
- strcpy(query,"SELECT * FROM mysql.host");
+ strmov(query,"SELECT * FROM mysql.host");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -1610,6 +1620,7 @@ static void test_select_show()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple update *
*********************************************************/
@@ -1621,11 +1632,11 @@ static void test_simple_update()
int nData=1;
MYSQL_RES *result;
MYSQL_BIND bind[2];
+ ulong length[2];
myheader("test_simple_update");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_update");
@@ -1650,7 +1661,7 @@ static void test_simple_update()
myquery(rc);
/* insert by prepare */
- strcpy(query,"UPDATE test_update SET col2=? WHERE col1=?");
+ strmov(query,"UPDATE test_update SET col2=? WHERE col1=?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -1659,9 +1670,14 @@ static void test_simple_update()
nData=1;
bind[0].buffer_type=FIELD_TYPE_STRING;
bind[0].buffer=szData; /* string data */
- bind[0].buffer_length=sprintf(szData,"updated-data");
- bind[1].buffer=(gptr)&nData;
+ bind[0].buffer_length=sizeof(szData);
+ bind[0].length= &length[0];
+ bind[0].is_null= 0;
+ length[0]= my_sprintf(szData, (szData,"updated-data"));
+
+ bind[1].buffer=(char *) &nData;
bind[1].buffer_type=FIELD_TYPE_LONG;
+ bind[1].is_null= 0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -1697,15 +1713,12 @@ static void test_long_data()
MYSQL_STMT *stmt;
int rc, int_data;
char *data=NullS;
- long length;
MYSQL_RES *result;
MYSQL_BIND bind[3];
-
myheader("test_long_data");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_long_data");
@@ -1721,11 +1734,11 @@ static void test_long_data()
rc = mysql_commit(mysql);
myquery(rc);
- strcpy(query,"INSERT INTO test_long_data(col1,col2) VALUES(?)");
+ strmov(query,"INSERT INTO test_long_data(col1,col2) VALUES(?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init_r(stmt);
- strcpy(query,"INSERT INTO test_long_data(col1,col2,col3) VALUES(?,?,?)");
+ strmov(query,"INSERT INTO test_long_data(col1,col2,col3) VALUES(?,?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -1733,46 +1746,26 @@ static void test_long_data()
bind[0].buffer=(char *)&int_data;
bind[0].buffer_type=FIELD_TYPE_LONG;
-
- /* Non string or binary type, error */
- bind[1].buffer_type=FIELD_TYPE_LONG;
- bind[1].length=&length;
- length= MYSQL_LONG_DATA; /* specify long data suppy during run-time */
- rc = mysql_bind_param(stmt,bind);
- fprintf(stdout," mysql_bind_param() returned: %d\n",rc);
- mystmt_r(stmt, rc);
+ bind[0].is_null=0;
bind[1].buffer_type=FIELD_TYPE_STRING;
+ bind[1].is_null=0;
+ bind[1].buffer_length=0; /* Will not be used */
+ bind[1].length=0; /* Will not be used */
+
bind[2]=bind[1];
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
int_data= 999;
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
- data = (char *)"Micheal";
+ data = (char *)"Michael";
/* supply data in pieces */
- rc = mysql_send_long_data(stmt,1,data,7,0);
- mystmt(stmt, rc);
-
- /* try to execute mysql_execute() now, it should return
- MYSQL_NEED_DATA as the long data supply is not yet over
- */
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
- /* append data again ..*/
-
- /* Indicate end of data */
- data = (char *)" 'monty' Widenius";
- rc = mysql_send_long_data(stmt,1,data,17,1);
+ rc = mysql_send_long_data(stmt,1,data,strlen(data));
+ data = (char *)" 'Monty' Widenius";
+ rc = mysql_send_long_data(stmt,1,data,strlen(data));
mystmt(stmt, rc);
-
- rc = mysql_send_long_data(stmt,2,"Venu (venu@mysql.com)",4,1);
+ rc = mysql_send_long_data(stmt,2,"Venu (venu@mysql.com)",4);
mystmt(stmt, rc);
/* execute */
@@ -1795,10 +1788,11 @@ static void test_long_data()
mysql_free_result(result);
verify_col_data("test_long_data","col1","999");
- verify_col_data("test_long_data","col2","Micheal 'monty' Widenius");
+ verify_col_data("test_long_data","col2","Michael 'Monty' Widenius");
verify_col_data("test_long_data","col3","Venu");
}
+
/********************************************************
* to test long data (string) handling *
*********************************************************/
@@ -1810,12 +1804,11 @@ static void test_long_data_str()
long length, length1;
MYSQL_RES *result;
MYSQL_BIND bind[2];
-
+ my_bool is_null[2];
myheader("test_long_data_str");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_long_data_str");
@@ -1830,47 +1823,36 @@ static void test_long_data_str()
rc = mysql_commit(mysql);
myquery(rc);
- strcpy(query,"INSERT INTO test_long_data_str VALUES(?,?)");
+ strmov(query,"INSERT INTO test_long_data_str VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
verify_param_count(stmt,2);
- bind[0].buffer = (gptr)&length;
+ bind[0].buffer = (char *)&length;
bind[0].buffer_type = FIELD_TYPE_LONG;
+ bind[0].is_null= &is_null[0];
+ is_null[0]=0;
+ length= 0;
- bind[1].buffer=data; /* string data */
+ bind[1].buffer=data; /* string data */
bind[1].buffer_type=FIELD_TYPE_STRING;
bind[1].length= &length1;
- length1= MYSQL_LONG_DATA;
+ bind[1].buffer_length=0; /* Will not be used */
+ bind[1].is_null= &is_null[1];
+ is_null[1]=0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
- length = 10;
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
length = 40;
sprintf(data,"MySQL AB");
/* supply data in pieces */
for(i=0; i < 4; i++)
{
- rc = mysql_send_long_data(stmt,1,(char *)data,5,0);
+ rc = mysql_send_long_data(stmt,1,(char *)data,5);
mystmt(stmt, rc);
}
- /* try to execute mysql_execute() now, it should return
- MYSQL_NEED_DATA as the long data supply is not yet over
- */
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
- /* Indiate end of data supply */
- rc = mysql_send_long_data(stmt,1,0,0,1);
- mystmt(stmt, rc);
-
/* execute */
rc = mysql_execute(stmt);
fprintf(stdout," mysql_execute() returned %d\n",rc);
@@ -1913,11 +1895,9 @@ static void test_long_data_str1()
MYSQL_RES *result;
MYSQL_BIND bind[2];
-
myheader("test_long_data_str1");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_long_data_str");
@@ -1932,56 +1912,35 @@ static void test_long_data_str1()
rc = mysql_commit(mysql);
myquery(rc);
- strcpy(query,"INSERT INTO test_long_data_str VALUES(?,?)");
+ strmov(query,"INSERT INTO test_long_data_str VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
verify_param_count(stmt,2);
bind[0].buffer=data; /* string data */
+ bind[0].buffer_length= sizeof(data);
bind[0].length= &length1;
bind[0].buffer_type=FIELD_TYPE_STRING;
- length1= MYSQL_LONG_DATA;
+ bind[0].is_null= 0;
+ length1= 0;
bind[1] = bind[0];
bind[1].buffer_type=FIELD_TYPE_BLOB;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
-
- length = 10;
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
- length = sprintf(data,"MySQL AB");
+ length = my_sprintf(data, (data, "MySQL AB"));
/* supply data in pieces */
- for(i=0; i < 3; i++)
+ for (i=0; i < 3; i++)
{
- rc = mysql_send_long_data(stmt,0,data,length,0);
+ rc = mysql_send_long_data(stmt,0,data,length);
mystmt(stmt, rc);
- rc = mysql_send_long_data(stmt,1,data,2,0);
+ rc = mysql_send_long_data(stmt,1,data,2);
mystmt(stmt, rc);
}
- /* try to execute mysql_execute() now, it should return
- MYSQL_NEED_DATA as the long data supply is not yet over
- */
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
- /* Indiate end of data supply */
- rc = mysql_send_long_data(stmt,1,0,0,1);
- mystmt(stmt, rc);
-
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
- rc = mysql_send_long_data(stmt,0,0,0,1);
- mystmt(stmt, rc);
/* execute */
rc = mysql_execute(stmt);
@@ -2020,15 +1979,14 @@ static void test_long_data_bin()
MYSQL_STMT *stmt;
int rc;
char data[255];
- long length, length1;
+ long length;
MYSQL_RES *result;
MYSQL_BIND bind[2];
myheader("test_long_data_bin");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_long_data_bin");
@@ -2043,50 +2001,36 @@ static void test_long_data_bin()
rc = mysql_commit(mysql);
myquery(rc);
- strcpy(query,"INSERT INTO test_long_data_bin VALUES(?,?)");
+ strmov(query,"INSERT INTO test_long_data_bin VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
verify_param_count(stmt,2);
- bind[0].buffer = (gptr)&length;
+ bind[0].buffer = (char *)&length;
bind[0].buffer_type = FIELD_TYPE_LONG;
+ bind[0].is_null= 0;
+ length= 0;
- bind[1].buffer=data; /* string data */
+ bind[1].buffer=data; /* string data */
bind[1].buffer_type=FIELD_TYPE_LONG_BLOB;
- bind[1].length= &length1;
- length1= MYSQL_LONG_DATA;
+ bind[1].length= 0; /* Will not be used */
+ bind[1].is_null= 0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
length = 10;
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
-
sprintf(data,"MySQL AB");
/* supply data in pieces */
{
int i;
- for(i=0; i < 100; i++)
+ for (i=0; i < 100; i++)
{
- rc = mysql_send_long_data(stmt,1,(char *)data,4,0);
+ rc = mysql_send_long_data(stmt,1,(char *)data,4);
mystmt(stmt, rc);
}
-
- /* try to execute mysql_execute() now, it should return
- MYSQL_NEED_DATA as the long data supply is not yet over
- */
- rc = mysql_execute(stmt);
- fprintf(stdout," mysql_execute() returned %d\n",rc);
- myassert(rc == MYSQL_NEED_DATA);
}
-
- /* Indiate end of data supply */
- rc = mysql_send_long_data(stmt,1,0,0,1);
- mystmt(stmt, rc);
-
/* execute */
rc = mysql_execute(stmt);
fprintf(stdout," mysql_execute() returned %d\n",rc);
@@ -2121,12 +2065,11 @@ static void test_simple_delete()
int nData=1;
MYSQL_RES *result;
MYSQL_BIND bind[2];
-
+ ulong length[2];
myheader("test_simple_delete");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_simple_delete");
@@ -2151,19 +2094,23 @@ static void test_simple_delete()
myquery(rc);
/* insert by prepare */
- strcpy(query,"DELETE FROM test_simple_delete WHERE col1=? AND col2=? AND col3=100");
+ strmov(query,"DELETE FROM test_simple_delete WHERE col1=? AND col2=? AND col3=100");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
verify_param_count(stmt,2);
nData=1;
- strcpy(szData,"MySQL");
- bind[1].buffer_length = 5;
+ strmov(szData,"MySQL");
bind[1].buffer_type=FIELD_TYPE_STRING;
- bind[1].buffer=szData; /* string data */
- bind[0].buffer=(gptr)&nData;
+ bind[1].buffer= szData; /* string data */
+ bind[1].buffer_length=sizeof(szData);
+ bind[1].length= &length[1];
+ length[1]= 5;
+
+ bind[0].buffer=(char *)&nData;
bind[0].buffer_type=FIELD_TYPE_LONG;
+ bind[0].is_null= 0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -2203,12 +2150,11 @@ static void test_update()
int nData=1;
MYSQL_RES *result;
MYSQL_BIND bind[2];
-
+ ulong length[2];
myheader("test_update");
- init_bind(bind);
- rc = mysql_autocommit(mysql,true);
+ rc = mysql_autocommit(mysql,TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_update");
@@ -2224,7 +2170,7 @@ static void test_update()
rc = mysql_commit(mysql);
myquery(rc);
- strcpy(query,"INSERT INTO test_update(col2,col3) VALUES(?,?)");
+ strmov(query,"INSERT INTO test_update(col2,col3) VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -2233,9 +2179,14 @@ static void test_update()
/* string data */
bind[0].buffer_type=FIELD_TYPE_STRING;
bind[0].buffer=szData;
- bind[0].buffer_length=sprintf(szData,"inserted-data");
- bind[1].buffer=(gptr)&nData;
+ bind[0].buffer_length= sizeof(szData);
+ bind[0].length= &length[0];
+ length[0]= my_sprintf(szData, (szData, "inserted-data"));
+ bind[0].is_null= 0;
+
+ bind[1].buffer=(char *)&nData;
bind[1].buffer_type=FIELD_TYPE_LONG;
+ bind[1].is_null= 0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -2247,19 +2198,21 @@ static void test_update()
myassert(1 == mysql_affected_rows(mysql));
mysql_stmt_close(stmt);
- strcpy(query,"UPDATE test_update SET col2=? WHERE col3=?");
+ strmov(query,"UPDATE test_update SET col2=? WHERE col3=?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
verify_param_count(stmt,2);
nData=100;
-
bind[0].buffer_type=FIELD_TYPE_STRING;
bind[0].buffer=szData;
- bind[0].buffer_length=sprintf(szData,"updated-data");
- bind[1].buffer=(gptr)&nData;
+ bind[0].buffer_length= sizeof(szData);
+ bind[0].length= &length[0];
+ length[0]= my_sprintf(szData, (szData, "updated-data"));
+ bind[1].buffer=(char *)&nData;
bind[1].buffer_type=FIELD_TYPE_LONG;
+ bind[1].is_null= 0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -2309,7 +2262,7 @@ static void test_prepare_noparam()
/* insert by prepare */
- strcpy(query,"INSERT INTO my_prepare VALUES(10,'venu')");
+ strmov(query,"INSERT INTO my_prepare VALUES(10,'venu')");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -2344,14 +2297,15 @@ static void test_bind_result()
{
MYSQL_STMT *stmt;
int rc;
- const char query[100];
- int nData, length, length1;
+ char query[100];
+ int nData;
+ ulong length, length1;
char szData[100];
MYSQL_BIND bind[2];
+ my_bool is_null[2];
myheader("test_bind_result");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_result");
myquery(rc);
@@ -2379,14 +2333,17 @@ static void test_bind_result()
/* fetch */
bind[0].buffer_type=FIELD_TYPE_LONG;
- bind[0].buffer= (gptr) &nData; /* integer data */
- bind[0].length= (long *)&length;
+ bind[0].buffer= (char *) &nData; /* integer data */
+ bind[0].is_null= &is_null[0];
+ bind[0].length= 0;
+
bind[1].buffer_type=FIELD_TYPE_STRING;
bind[1].buffer=szData; /* string data */
bind[1].buffer_length=sizeof(szData);
- bind[1].length=(long *)&length1;
+ bind[1].length= &length1;
+ bind[1].is_null= &is_null[1];
- strcpy((char *)query , "SELECT * FROM test_bind_result");
+ strmov(query , "SELECT * FROM test_bind_result");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -2399,7 +2356,7 @@ static void test_bind_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout,"\n row 1: %d,%s(%d)",nData, szData, length1);
+ fprintf(stdout,"\n row 1: %d,%s(%lu)",nData, szData, length1);
myassert(nData == 10);
myassert(strcmp(szData,"venu")==0);
myassert(length1 == 4);
@@ -2407,7 +2364,7 @@ static void test_bind_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout,"\n row 2: %d,%s(%d)",nData, szData, length1);
+ fprintf(stdout,"\n row 2: %d,%s(%lu)",nData, szData, length1);
myassert(nData == 20);
myassert(strcmp(szData,"MySQL")==0);
myassert(length1 == 5);
@@ -2416,11 +2373,11 @@ static void test_bind_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- if (length == MYSQL_NULL_DATA)
- fprintf(stdout,"\n row 3: NULL,%s(%d)", szData, length1);
+ if (is_null[0])
+ fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
- fprintf(stdout,"\n row 3: %d,%s(%d)", nData, szData, length1);
- myassert(length == MYSQL_NULL_DATA);
+ fprintf(stdout,"\n row 3: %d,%s(%lu)", nData, szData, length1);
+ myassert(is_null[0]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
@@ -2437,7 +2394,7 @@ static void test_bind_result()
static void test_bind_result_ext()
{
MYSQL_STMT *stmt;
- int rc;
+ int rc, i;
const char query[100];
uchar t_data;
short s_data;
@@ -2446,12 +2403,13 @@ static void test_bind_result_ext()
float f_data;
double d_data;
char szData[20], bData[20];
- int szLength, bLength;
+ ulong szLength, bLength;
MYSQL_BIND bind[8];
+ long length[8];
+ my_bool is_null[8];
myheader("test_bind_result_ext");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_result");
myquery(rc);
@@ -2476,33 +2434,41 @@ static void test_bind_result_ext()
rc = mysql_commit(mysql);
myquery(rc);
+ for (i= 0; i < (int) array_elements(bind); i++)
+ {
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
+ }
+
bind[0].buffer_type=MYSQL_TYPE_TINY;
- bind[0].buffer=(gptr)&t_data;
+ bind[0].buffer=(char *)&t_data;
bind[1].buffer_type=MYSQL_TYPE_SHORT;
bind[2].buffer_type=MYSQL_TYPE_LONG;
bind[3].buffer_type=MYSQL_TYPE_LONGLONG;
- bind[1].buffer=(gptr)&s_data;
+ bind[1].buffer=(char *)&s_data;
- bind[2].buffer=(gptr)&i_data;
- bind[3].buffer=(gptr)&b_data;
+ bind[2].buffer=(char *)&i_data;
+ bind[3].buffer=(char *)&b_data;
bind[4].buffer_type=MYSQL_TYPE_FLOAT;
- bind[4].buffer=(gptr)&f_data;
+ bind[4].buffer=(char *)&f_data;
bind[5].buffer_type=MYSQL_TYPE_DOUBLE;
- bind[5].buffer=(gptr)&d_data;
+ bind[5].buffer=(char *)&d_data;
bind[6].buffer_type=MYSQL_TYPE_STRING;
- bind[6].buffer=(gptr)&szData;
- bind[6].length=(long *)&szLength;
+ bind[6].buffer= (char *)&szData;
+ bind[6].buffer_length= sizeof(szData);
+ bind[6].length= &szLength;
bind[7].buffer_type=MYSQL_TYPE_TINY_BLOB;
- bind[7].buffer=(gptr)&bData;
- bind[7].length=(long *)&bLength;
+ bind[7].buffer=(char *)&bData;
+ bind[7].length= &bLength;
+ bind[7].buffer_length= sizeof(bData);
- strcpy((char *)query , "SELECT * FROM test_bind_result");
+ strmov((char *)query , "SELECT * FROM test_bind_result");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -2523,8 +2489,8 @@ static void test_bind_result_ext()
fprintf(stdout, "\n data (float) : %f", f_data);
fprintf(stdout, "\n data (double) : %f", d_data);
- fprintf(stdout, "\n data (str) : %s(%d)", szData, szLength);
- fprintf(stdout, "\n data (bin) : %s(%d)", bData, bLength);
+ fprintf(stdout, "\n data (str) : %s(%lu)", szData, szLength);
+ fprintf(stdout, "\n data (bin) : %s(%lu)", bData, bLength);
myassert(t_data == 19);
@@ -2551,6 +2517,7 @@ static void test_bind_result_ext()
static void test_bind_result_ext1()
{
MYSQL_STMT *stmt;
+ uint i;
int rc;
const char query[100];
char t_data[20];
@@ -2559,14 +2526,13 @@ static void test_bind_result_ext1()
short b_data;
int f_data;
long bData;
- long length[11];
char d_data[20];
double szData;
MYSQL_BIND bind[8];
-
+ ulong length[8];
+ my_bool is_null[8];
myheader("test_bind_result_ext1");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_result");
myquery(rc);
@@ -2592,33 +2558,38 @@ static void test_bind_result_ext1()
myquery(rc);
bind[0].buffer_type=MYSQL_TYPE_STRING;
- bind[0].buffer=(gptr)t_data;
-
- for (rc=0; rc <= 7; rc++)
- bind[rc].length= &length[rc];
+ bind[0].buffer=(char *) t_data;
+ bind[0].buffer_length= sizeof(t_data);
+ bind[0].length= &length[0];
bind[1].buffer_type=MYSQL_TYPE_FLOAT;
- bind[1].buffer=(gptr)&s_data;
+ bind[1].buffer=(char *)&s_data;
bind[2].buffer_type=MYSQL_TYPE_SHORT;
- bind[2].buffer=(gptr)&i_data;
+ bind[2].buffer=(char *)&i_data;
bind[3].buffer_type=MYSQL_TYPE_TINY;
- bind[3].buffer=(gptr)&b_data;
+ bind[3].buffer=(char *)&b_data;
bind[4].buffer_type=MYSQL_TYPE_LONG;
- bind[4].buffer=(gptr)&f_data;
+ bind[4].buffer=(char *)&f_data;
bind[5].buffer_type=MYSQL_TYPE_STRING;
- bind[5].buffer=(gptr)d_data;
+ bind[5].buffer=(char *)d_data;
bind[6].buffer_type=MYSQL_TYPE_LONG;
- bind[6].buffer=(gptr)&bData;
+ bind[6].buffer=(char *)&bData;
bind[7].buffer_type=MYSQL_TYPE_DOUBLE;
- bind[7].buffer=(gptr)&szData;
+ bind[7].buffer=(char *)&szData;
- strcpy((char *)query , "SELECT * FROM test_bind_result");
+ for (i= 0; i < array_elements(bind); i++)
+ {
+ bind[i].is_null= &is_null[i];
+ bind[i].length= &length[i];
+ }
+
+ strmov((char *)query , "SELECT * FROM test_bind_result");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -2631,16 +2602,16 @@ static void test_bind_result_ext1()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n data (tiny) : %s(%ld)", t_data, length[0]);
- fprintf(stdout, "\n data (short) : %f(%ld)", s_data, length[1]);
- fprintf(stdout, "\n data (int) : %d(%ld)", i_data, length[2]);
- fprintf(stdout, "\n data (big) : %d(%ld)", b_data, length[3]);
+ fprintf(stdout, "\n data (tiny) : %s(%lu)", t_data, length[0]);
+ fprintf(stdout, "\n data (short) : %f(%lu)", s_data, length[1]);
+ fprintf(stdout, "\n data (int) : %d(%lu)", i_data, length[2]);
+ fprintf(stdout, "\n data (big) : %d(%lu)", b_data, length[3]);
- fprintf(stdout, "\n data (float) : %d(%ld)", f_data, length[4]);
- fprintf(stdout, "\n data (double) : %s(%ld)", d_data, length[5]);
+ fprintf(stdout, "\n data (float) : %d(%lu)", f_data, length[4]);
+ fprintf(stdout, "\n data (double) : %s(%lu)", d_data, length[5]);
- fprintf(stdout, "\n data (bin) : %ld(%ld)", bData, length[6]);
- fprintf(stdout, "\n data (str) : %g(%ld)", szData, length[7]);
+ fprintf(stdout, "\n data (bin) : %ld(%lu)", bData, length[6]);
+ fprintf(stdout, "\n data (str) : %g(%lu)", szData, length[7]);
myassert(strcmp(t_data,"120")==0);
myassert(i_data == 3999);
@@ -2668,16 +2639,17 @@ static void test_bind_result_ext1()
static void test_fetch_date()
{
MYSQL_STMT *stmt;
+ uint i;
int rc, year;
char date[25], time[25], ts[25], ts_4[15], ts_6[20], dt[20];
- int d_length, t_length, ts_length, ts4_length, ts6_length,
+ ulong d_length, t_length, ts_length, ts4_length, ts6_length,
dt_length, y_length;
-
- MYSQL_BIND bind[3];
+ MYSQL_BIND bind[8];
+ my_bool is_null[8];
+ ulong length[8];
myheader("test_fetch_date");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_result");
myquery(rc);
@@ -2706,33 +2678,45 @@ static void test_fetch_date()
rc = mysql_commit(mysql);
myquery(rc);
+ for (i= 0; i < array_elements(bind); i++)
+ {
+ bind[i].is_null= &is_null[i];
+ bind[i].length= &length[i];
+ }
+
bind[0].buffer_type=MYSQL_TYPE_STRING;
bind[1]=bind[2]=bind[0];
- bind[0].buffer=(gptr)&date;
- bind[0].length=(long *)&d_length;
+ bind[0].buffer=(char *)&date;
+ bind[0].buffer_length= sizeof(date);
+ bind[0].length= &d_length;
- bind[1].buffer=(gptr)&time;
- bind[1].length=(long *)&t_length;
+ bind[1].buffer=(char *)&time;
+ bind[1].buffer_length= sizeof(time);
+ bind[1].length= &t_length;
- bind[2].buffer=(gptr)&ts;
- bind[2].length=(long *)&ts_length;
+ bind[2].buffer=(char *)&ts;
+ bind[2].buffer_length= sizeof(ts);
+ bind[2].length= &ts_length;
bind[3].buffer_type=MYSQL_TYPE_LONG;
- bind[3].buffer=(gptr)&year;
- bind[3].length=(long *)&y_length;
+ bind[3].buffer=(char *)&year;
+ bind[3].length= &y_length;
bind[4].buffer_type=MYSQL_TYPE_STRING;
- bind[4].buffer=(gptr)&dt;
- bind[4].length=(long *)&dt_length;
+ bind[4].buffer=(char *)&dt;
+ bind[4].buffer_length= sizeof(dt);
+ bind[4].length= &dt_length;
bind[5].buffer_type=MYSQL_TYPE_STRING;
- bind[5].buffer=(gptr)&ts_4;
- bind[5].length=(long *)&ts4_length;
+ bind[5].buffer=(char *)&ts_4;
+ bind[5].buffer_length= sizeof(ts_4);
+ bind[5].length= &ts4_length;
bind[6].buffer_type=MYSQL_TYPE_STRING;
- bind[6].buffer=(gptr)&ts_6;
- bind[6].length=(long *)&ts6_length;
+ bind[6].buffer=(char *)&ts_6;
+ bind[6].buffer_length= sizeof(ts_6);
+ bind[6].length= &ts6_length;
myassert(1 == my_stmt_result("SELECT * FROM test_bind_result",50));
@@ -2749,13 +2733,13 @@ static void test_fetch_date()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n date : %s(%d)", date, d_length);
- fprintf(stdout, "\n time : %s(%d)", time, t_length);
- fprintf(stdout, "\n ts : %s(%d)", ts, ts_length);
- fprintf(stdout, "\n year : %d(%d)", year, y_length);
- fprintf(stdout, "\n dt : %s(%d)", dt, dt_length);
- fprintf(stdout, "\n ts(4) : %s(%d)", ts_4, ts4_length);
- fprintf(stdout, "\n ts(6) : %s(%d)", ts_6, ts6_length);
+ fprintf(stdout, "\n date : %s(%lu)", date, d_length);
+ fprintf(stdout, "\n time : %s(%lu)", time, t_length);
+ fprintf(stdout, "\n ts : %s(%lu)", ts, ts_length);
+ fprintf(stdout, "\n year : %d(%lu)", year, y_length);
+ fprintf(stdout, "\n dt : %s(%lu)", dt, dt_length);
+ fprintf(stdout, "\n ts(4) : %s(%lu)", ts_4, ts4_length);
+ fprintf(stdout, "\n ts(6) : %s(%lu)", ts_6, ts6_length);
myassert(strcmp(date,"2002-01-02")==0);
myassert(d_length == 10);
@@ -2790,16 +2774,18 @@ static void test_fetch_date()
static void test_fetch_str()
{
MYSQL_STMT *stmt;
- int rc, i, round, bit;
- long data[10], length[10];
+ int rc, i, round;
+ ulong bit;
+ long data[10];
float f_data;
double d_data;
char s_data[10];
+ ulong length[10];
MYSQL_BIND bind[7];
+ my_bool is_null[7];
myheader("test_fetch_str");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_str");
myquery(rc);
@@ -2824,10 +2810,11 @@ static void test_fetch_str()
verify_param_count(stmt, 7);
round= 0;
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
- bind[i].buffer= (void *)&data[i];
+ bind[i].buffer= &data[i];
+ bind[i].is_null= 0;
data[i]= round+i+1;
round= (round +10)*10;
}
@@ -2847,10 +2834,11 @@ static void test_fetch_str()
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_str",50);
myquery(rc);
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
- bind[i].buffer= (void *)&data[i];
- bind[i].length= (long *)&length[i];
+ bind[i].buffer= (char *) &data[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
}
bind[0].buffer_type= MYSQL_TYPE_TINY;
bind[1].buffer_type= MYSQL_TYPE_SHORT;
@@ -2858,13 +2846,13 @@ static void test_fetch_str()
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
bind[4].buffer_type= MYSQL_TYPE_FLOAT;
- bind[4].buffer= (void *)&f_data;
+ bind[4].buffer= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
- bind[5].buffer= (void *)&d_data;
+ bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
- bind[6].buffer= (void *)&s_data;
+ bind[6].buffer= (char *)&s_data;
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -2875,13 +2863,13 @@ static void test_fetch_str()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n tiny : %ld(%ld)", data[0], length[0]);
- fprintf(stdout, "\n short : %ld(%ld)", data[1], length[1]);
- fprintf(stdout, "\n int : %ld(%ld)", data[2], length[2]);
- fprintf(stdout, "\n longlong : %ld(%ld)", data[3], length[3]);
- fprintf(stdout, "\n float : %f(%ld)", f_data, length[4]);
- fprintf(stdout, "\n double : %g(%ld)", d_data, length[5]);
- fprintf(stdout, "\n char : %s(%ld)", s_data, length[6]);
+ fprintf(stdout, "\n tiny : %ld(%lu)", data[0], length[0]);
+ fprintf(stdout, "\n short : %ld(%lu)", data[1], length[1]);
+ fprintf(stdout, "\n int : %ld(%lu)", data[2], length[2]);
+ fprintf(stdout, "\n longlong : %ld(%lu)", data[3], length[3]);
+ fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]);
+ fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]);
+ fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]);
round= 0;
bit= 1;
@@ -2907,9 +2895,9 @@ static void test_fetch_str()
round= (round+10)*10;
{
char buff[20];
- int len= sprintf(buff,"%d", round+3+i);
+ long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
- myassert(length[6] == len);
+ myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
@@ -2924,16 +2912,18 @@ static void test_fetch_str()
static void test_fetch_long()
{
MYSQL_STMT *stmt;
- int rc, i, round, bit;
- long data[10], length[10];
+ int rc, i, round;
+ ulong bit;
+ long data[10];
float f_data;
double d_data;
char s_data[10];
+ ulong length[10];
MYSQL_BIND bind[7];
+ my_bool is_null[7];
myheader("test_fetch_long");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
@@ -2961,7 +2951,8 @@ static void test_fetch_long()
for (i=0; i < 7; i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
- bind[i].buffer= (void *)&data[i];
+ bind[i].buffer= (char *) &data[i];
+ bind[i].is_null=0;
data[i]= round+i+1;
round= (round +10)*10;
}
@@ -2981,24 +2972,27 @@ static void test_fetch_long()
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
- for (i=0; i < 7; i++)
- {
- bind[i].buffer= (void *)&data[i];
- bind[i].length= (long *)&length[i];
- }
bind[0].buffer_type= MYSQL_TYPE_TINY;
bind[1].buffer_type= MYSQL_TYPE_SHORT;
bind[2].buffer_type= MYSQL_TYPE_LONG;
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
bind[4].buffer_type= MYSQL_TYPE_FLOAT;
- bind[4].buffer= (void *)&f_data;
+ bind[4].buffer= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
- bind[5].buffer= (void *)&d_data;
+ bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
- bind[6].buffer= (void *)&s_data;
+ bind[6].buffer= (char *)&s_data;
+ bind[6].buffer_length= sizeof(s_data);
+
+ for (i= 0; i < (int) array_elements(bind); i++)
+ {
+ bind[i].buffer= (char*) &data[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
+ }
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -3009,13 +3003,13 @@ static void test_fetch_long()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n tiny : %ld(%ld)", data[0], length[0]);
- fprintf(stdout, "\n short : %ld(%ld)", data[1], length[1]);
- fprintf(stdout, "\n int : %ld(%ld)", data[2], length[2]);
- fprintf(stdout, "\n longlong : %ld(%ld)", data[3], length[3]);
- fprintf(stdout, "\n float : %f(%ld)", f_data, length[4]);
- fprintf(stdout, "\n double : %g(%ld)", d_data, length[5]);
- fprintf(stdout, "\n char : %s(%ld)", s_data, length[6]);
+ fprintf(stdout, "\n tiny : %ld(%lu)", data[0], length[0]);
+ fprintf(stdout, "\n short : %ld(%lu)", data[1], length[1]);
+ fprintf(stdout, "\n int : %ld(%lu)", data[2], length[2]);
+ fprintf(stdout, "\n longlong : %ld(%lu)", data[3], length[3]);
+ fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]);
+ fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]);
+ fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]);
round= 0;
bit= 1;
@@ -3041,9 +3035,9 @@ static void test_fetch_long()
round= (round+10)*10;
{
char buff[20];
- int len= sprintf(buff,"%d", round+3+i);
+ long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
- myassert(length[6] == len);
+ myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
@@ -3052,22 +3046,29 @@ static void test_fetch_long()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test fetching of short to all types *
*********************************************************/
static void test_fetch_short()
{
MYSQL_STMT *stmt;
- int rc, i, round, bit;
- long data[10], length[10];
+ int rc, i, round;
+ ulong bit;
+ long data[10];
+ char tiny_data;
+ short int short_data;
+ long long_data;
+ longlong longlong_data;
float f_data;
double d_data;
char s_data[10];
MYSQL_BIND bind[7];
+ ulong length[10];
+ my_bool is_null[7];
myheader("test_fetch_short");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
@@ -3092,10 +3093,12 @@ static void test_fetch_short()
verify_param_count(stmt, 7);
round= 0;
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
- bind[i].buffer= (void *)&data[i];
+ bind[i].buffer= (char *) &data[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= 0;
data[i]= round+i+1;
round= (round +10)*2;
}
@@ -3117,22 +3120,27 @@ static void test_fetch_short()
for (i=0; i < 7; i++)
{
- bind[i].buffer= (void *)&data[i];
- bind[i].length= (long *)&length[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
}
bind[0].buffer_type= MYSQL_TYPE_TINY;
+ bind[0].buffer= (char*) &tiny_data;
bind[1].buffer_type= MYSQL_TYPE_SHORT;
+ bind[1].buffer= (char*) &short_data;
bind[2].buffer_type= MYSQL_TYPE_LONG;
+ bind[1].buffer= (char*) &long_data;
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
+ bind[1].buffer= (char*) &longlong_data;
bind[4].buffer_type= MYSQL_TYPE_FLOAT;
- bind[4].buffer= (void *)&f_data;
+ bind[4].buffer= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
- bind[5].buffer= (void *)&d_data;
+ bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
- bind[6].buffer= (void *)&s_data;
+ bind[6].buffer= (char *)&s_data;
+ bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -3143,13 +3151,13 @@ static void test_fetch_short()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n tiny : %ld(%ld)", data[0], length[0]);
- fprintf(stdout, "\n short : %ld(%ld)", data[1], length[1]);
- fprintf(stdout, "\n int : %ld(%ld)", data[2], length[2]);
- fprintf(stdout, "\n longlong : %ld(%ld)", data[3], length[3]);
- fprintf(stdout, "\n float : %f(%ld)", f_data, length[4]);
- fprintf(stdout, "\n double : %g(%ld)", d_data, length[5]);
- fprintf(stdout, "\n char : %s(%ld)", s_data, length[6]);
+ fprintf(stdout, "\n tiny : %d(%lu)", tiny_data, length[0]);
+ fprintf(stdout, "\n short : %d(%lu)", short_data, length[1]);
+ fprintf(stdout, "\n int : %ld(%lu)", long_data, length[2]);
+ fprintf(stdout, "\n longlong : %ld(%lu)", (long) longlong_data, length[3]);
+ fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]);
+ fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]);
+ fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]);
round= 0;
bit= 1;
@@ -3175,9 +3183,9 @@ static void test_fetch_short()
round= (round+10)*2;
{
char buff[20];
- int len= sprintf(buff,"%d", round+3+i);
+ long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
- myassert(length[6] == len);
+ myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
@@ -3186,22 +3194,25 @@ static void test_fetch_short()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test fetching of tiny to all types *
*********************************************************/
static void test_fetch_tiny()
{
MYSQL_STMT *stmt;
- int rc, i, bit;
- long data[10], length[10];
+ int rc, i;
+ ulong bit;
+ long data[10];
+ ulong length[10];
float f_data;
double d_data;
char s_data[10];
MYSQL_BIND bind[7];
+ my_bool is_null[7];
myheader("test_fetch_tiny");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
@@ -3226,10 +3237,11 @@ static void test_fetch_tiny()
verify_param_count(stmt, 7);
rc= 10;
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
- bind[i].buffer= (void *)&data[i];
+ bind[i].buffer= (char *) &data[i];
+ bind[i].is_null= 0;
data[i]= rc+i;
rc+= 10;
}
@@ -3249,24 +3261,27 @@ static void test_fetch_tiny()
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
- bind[i].buffer= (void *)&data[i];
- bind[i].length= (long *)&length[i];
+ bind[i].buffer= (char *) &data[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
}
+
bind[0].buffer_type= MYSQL_TYPE_TINY;
bind[1].buffer_type= MYSQL_TYPE_SHORT;
bind[2].buffer_type= MYSQL_TYPE_LONG;
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
bind[4].buffer_type= MYSQL_TYPE_FLOAT;
- bind[4].buffer= (void *)&f_data;
+ bind[4].buffer= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
- bind[5].buffer= (void *)&d_data;
+ bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
- bind[6].buffer= (void *)&s_data;
+ bind[6].buffer= (char *)&s_data;
+ bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -3277,13 +3292,13 @@ static void test_fetch_tiny()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n tiny : %ld(%ld)", data[0], length[0]);
- fprintf(stdout, "\n short : %ld(%ld)", data[1], length[1]);
- fprintf(stdout, "\n int : %ld(%ld)", data[2], length[2]);
- fprintf(stdout, "\n longlong : %ld(%ld)", data[3], length[3]);
- fprintf(stdout, "\n float : %f(%ld)", f_data, length[4]);
- fprintf(stdout, "\n double : %g(%ld)", d_data, length[5]);
- fprintf(stdout, "\n char : %s(%ld)", s_data, length[6]);
+ fprintf(stdout, "\n tiny : %ld(%lu)", data[0], length[0]);
+ fprintf(stdout, "\n short : %ld(%lu)", data[1], length[1]);
+ fprintf(stdout, "\n int : %ld(%lu)", data[2], length[2]);
+ fprintf(stdout, "\n longlong : %ld(%lu)", data[3], length[3]);
+ fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]);
+ fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]);
+ fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]);
bit= 1;
rc= 10;
@@ -3309,9 +3324,9 @@ static void test_fetch_tiny()
rc+= 11;
{
char buff[20];
- int len= sprintf(buff,"%d", rc);
+ long len= my_sprintf(buff, (buff, "%d", rc));
myassert(strcmp(s_data,buff)==0);
- myassert(length[6] == len);
+ myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
@@ -3320,22 +3335,25 @@ static void test_fetch_tiny()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test fetching of longlong to all types *
*********************************************************/
static void test_fetch_bigint()
{
MYSQL_STMT *stmt;
- int rc, i, round, bit;
- long data[10], length[10];
+ int rc, i, round;
+ ulong bit;
+ long data[10];
float f_data;
double d_data;
char s_data[10];
MYSQL_BIND bind[7];
+ ulong length[7];
+ my_bool is_null[7];
myheader("test_fetch_bigint");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
@@ -3360,10 +3378,13 @@ static void test_fetch_bigint()
verify_param_count(stmt, 7);
round= 0;
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
- bind[i].buffer= (void *)&data[i];
+ bind[i].buffer= (char *)&data[i];
+ bind[i].is_null = &is_null[i];
+ bind[i].length= &length[i];
+ length[i]= 0;
data[i]= round+i+1;
round= (round +10)*10;
}
@@ -3383,10 +3404,11 @@ static void test_fetch_bigint()
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
- bind[i].buffer= (void *)&data[i];
- bind[i].length= (long *)&length[i];
+ bind[i].buffer= (char *)&data[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= 0;
}
bind[0].buffer_type= MYSQL_TYPE_TINY;
bind[1].buffer_type= MYSQL_TYPE_SHORT;
@@ -3394,13 +3416,14 @@ static void test_fetch_bigint()
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
bind[4].buffer_type= MYSQL_TYPE_FLOAT;
- bind[4].buffer= (void *)&f_data;
+ bind[4].buffer= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
- bind[5].buffer= (void *)&d_data;
+ bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
- bind[6].buffer= (void *)&s_data;
+ bind[6].buffer= (char *)&s_data;
+ bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -3411,13 +3434,13 @@ static void test_fetch_bigint()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n tiny : %ld(%ld)", data[0], length[0]);
- fprintf(stdout, "\n short : %ld(%ld)", data[1], length[1]);
- fprintf(stdout, "\n int : %ld(%ld)", data[2], length[2]);
- fprintf(stdout, "\n longlong : %ld(%ld)", data[3], length[3]);
- fprintf(stdout, "\n float : %f(%ld)", f_data, length[4]);
- fprintf(stdout, "\n double : %g(%ld)", d_data, length[5]);
- fprintf(stdout, "\n char : %s(%ld)", s_data, length[6]);
+ fprintf(stdout, "\n tiny : %ld(%lu)", data[0], length[0]);
+ fprintf(stdout, "\n short : %ld(%lu)", data[1], length[1]);
+ fprintf(stdout, "\n int : %ld(%lu)", data[2], length[2]);
+ fprintf(stdout, "\n longlong : %ld(%lu)", data[3], length[3]);
+ fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]);
+ fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]);
+ fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]);
round= 0;
bit= 1;
@@ -3443,9 +3466,9 @@ static void test_fetch_bigint()
round= (round+10)*10;
{
char buff[20];
- int len= sprintf(buff,"%d", round+3+i);
+ long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
- myassert(length[6] == len);
+ myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
@@ -3454,22 +3477,25 @@ static void test_fetch_bigint()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test fetching of float to all types *
*********************************************************/
static void test_fetch_float()
{
MYSQL_STMT *stmt;
- int rc, i, round, bit;
- long data[10], length[10];
+ int rc, i, round;
+ ulong bit;
+ long data[10];
float f_data;
double d_data;
char s_data[10];
MYSQL_BIND bind[7];
+ ulong length[10];
+ my_bool is_null[7];
myheader("test_fetch_float");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
@@ -3494,10 +3520,11 @@ static void test_fetch_float()
verify_param_count(stmt, 7);
round= 0;
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
- bind[i].buffer= (void *)&data[i];
+ bind[i].buffer= (char *)&data[i];
+ bind[i].is_null= 0;
data[i]= round+i+1;
round= (round +10)*2;
}
@@ -3517,10 +3544,12 @@ static void test_fetch_float()
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
- bind[i].buffer= (void *)&data[i];
- bind[i].length= (long *)&length[i];
+ bind[i].buffer= (char *)&data[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
+ length[i]=0;
}
bind[0].buffer_type= MYSQL_TYPE_TINY;
bind[1].buffer_type= MYSQL_TYPE_SHORT;
@@ -3528,13 +3557,14 @@ static void test_fetch_float()
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
bind[4].buffer_type= MYSQL_TYPE_FLOAT;
- bind[4].buffer= (void *)&f_data;
+ bind[4].buffer= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
- bind[5].buffer= (void *)&d_data;
+ bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
- bind[6].buffer= (void *)&s_data;
+ bind[6].buffer= (char *) &s_data;
+ bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -3545,13 +3575,13 @@ static void test_fetch_float()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n tiny : %ld(%ld)", data[0], length[0]);
- fprintf(stdout, "\n short : %ld(%ld)", data[1], length[1]);
- fprintf(stdout, "\n int : %ld(%ld)", data[2], length[2]);
- fprintf(stdout, "\n longlong : %ld(%ld)", data[3], length[3]);
- fprintf(stdout, "\n float : %f(%ld)", f_data, length[4]);
- fprintf(stdout, "\n double : %g(%ld)", d_data, length[5]);
- fprintf(stdout, "\n char : %s(%ld)", s_data, length[6]);
+ fprintf(stdout, "\n tiny : %ld(%lu)", data[0], length[0]);
+ fprintf(stdout, "\n short : %ld(%lu)", data[1], length[1]);
+ fprintf(stdout, "\n int : %ld(%lu)", data[2], length[2]);
+ fprintf(stdout, "\n longlong : %ld(%lu)", data[3], length[3]);
+ fprintf(stdout, "\n float : %f(%lu)", f_data, length[4]);
+ fprintf(stdout, "\n double : %g(%lu)", d_data, length[5]);
+ fprintf(stdout, "\n char : %s(%lu)", s_data, length[6]);
round= 0;
bit= 1;
@@ -3577,9 +3607,9 @@ static void test_fetch_float()
round= (round+10)*2;
{
char buff[20];
- int len= sprintf(buff,"%d", round+3+i);
+ long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
- myassert(length[6] == len);
+ myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
@@ -3594,16 +3624,18 @@ static void test_fetch_float()
static void test_fetch_double()
{
MYSQL_STMT *stmt;
- int rc, i, round, bit;
- long data[10], length[10];
+ int rc, i, round;
+ ulong bit;
+ long data[10];
float f_data;
double d_data;
char s_data[10];
MYSQL_BIND bind[7];
+ my_bool is_null[7];
+ ulong length[7];
myheader("test_fetch_double");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
@@ -3628,10 +3660,11 @@ static void test_fetch_double()
verify_param_count(stmt, 7);
round= 0;
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
- bind[i].buffer= (void *)&data[i];
+ bind[i].buffer= (char *)&data[i];
+ bind[i].is_null= 0;
data[i]= round+i+1;
round= (round +10)*10;
}
@@ -3651,10 +3684,11 @@ static void test_fetch_double()
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
- for (i=0; i < 7; i++)
+ for (i= 0; i < (int) array_elements(bind); i++)
{
- bind[i].buffer= (void *)&data[i];
- bind[i].length= (long *)&length[i];
+ bind[i].buffer= (char *)&data[i];
+ bind[i].length= &length[i];
+ bind[i].is_null= &is_null[i];
}
bind[0].buffer_type= MYSQL_TYPE_TINY;
bind[1].buffer_type= MYSQL_TYPE_SHORT;
@@ -3662,13 +3696,14 @@ static void test_fetch_double()
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
bind[4].buffer_type= MYSQL_TYPE_STRING;
- bind[4].buffer= (void *)&s_data;
+ bind[4].buffer= (char *)&s_data;
+ bind[4].buffer_length= sizeof(s_data);
bind[5].buffer_type= MYSQL_TYPE_FLOAT;
- bind[5].buffer= (void *)&f_data;
+ bind[5].buffer= (char *)&f_data;
bind[6].buffer_type= MYSQL_TYPE_DOUBLE;
- bind[6].buffer= (void *)&d_data;
+ bind[6].buffer= (char *)&d_data;
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
@@ -3679,13 +3714,13 @@ static void test_fetch_double()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout, "\n tiny : %ld(%ld)", data[0], length[0]);
- fprintf(stdout, "\n short : %ld(%ld)", data[1], length[1]);
- fprintf(stdout, "\n int : %ld(%ld)", data[2], length[2]);
- fprintf(stdout, "\n longlong : %ld(%ld)", data[3], length[3]);
- fprintf(stdout, "\n float : %f(%ld)", f_data, length[5]);
- fprintf(stdout, "\n double : %g(%ld)", d_data, length[6]);
- fprintf(stdout, "\n char : %s(%ld)", s_data, length[4]);
+ fprintf(stdout, "\n tiny : %ld(%lu)", data[0], length[0]);
+ fprintf(stdout, "\n short : %ld(%lu)", data[1], length[1]);
+ fprintf(stdout, "\n int : %ld(%lu)", data[2], length[2]);
+ fprintf(stdout, "\n longlong : %ld(%lu)", data[3], length[3]);
+ fprintf(stdout, "\n float : %f(%lu)", f_data, length[5]);
+ fprintf(stdout, "\n double : %g(%lu)", d_data, length[6]);
+ fprintf(stdout, "\n char : %s(%lu)", s_data, length[4]);
round= 0;
bit= 1;
@@ -3700,9 +3735,9 @@ static void test_fetch_double()
/* CHAR */
{
char buff[20];
- int len= sprintf(buff,"%d", round+1+i);
+ long len= my_sprintf(buff, (buff, "%d", round+1+i));
myassert(strcmp(s_data,buff)==0);
- myassert(length[4] == len);
+ myassert(length[4] == (ulong) len);
}
/* FLOAT */
@@ -3727,6 +3762,7 @@ static void test_fetch_double()
static void test_prepare_ext()
{
MYSQL_STMT *stmt;
+ uint i;
int rc;
char *sql;
int nData=1;
@@ -3734,12 +3770,9 @@ static void test_prepare_ext()
char tData=1;
short sData=10;
longlong bData=20;
- MYSQL_BIND bind_int[6];
-
+ MYSQL_BIND bind[6];
myheader("test_prepare_ext");
- init_bind(bind_int);
-
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_prepare_ext");
myquery(rc);
@@ -3785,37 +3818,40 @@ static void test_prepare_ext()
myquery(rc);
/* insert by prepare - all integers */
- strcpy(query,(char *)"INSERT INTO test_prepare_ext(c1,c2,c3,c4,c5,c6) VALUES(?,?,?,?,?,?)");
+ strmov(query,(char *)"INSERT INTO test_prepare_ext(c1,c2,c3,c4,c5,c6) VALUES(?,?,?,?,?,?)");
stmt = mysql_prepare(mysql,query, strlen(query));
myquery(rc);
verify_param_count(stmt,6);
/*tinyint*/
- bind_int[0].buffer_type=FIELD_TYPE_TINY;
- bind_int[0].buffer= (void *)&tData;
+ bind[0].buffer_type=FIELD_TYPE_TINY;
+ bind[0].buffer= (char *)&tData;
/*smallint*/
- bind_int[1].buffer_type=FIELD_TYPE_SHORT;
- bind_int[1].buffer= (void *)&sData;
+ bind[1].buffer_type=FIELD_TYPE_SHORT;
+ bind[1].buffer= (char *)&sData;
/*mediumint*/
- bind_int[2].buffer_type=FIELD_TYPE_LONG;
- bind_int[2].buffer= (void *)&nData;
+ bind[2].buffer_type=FIELD_TYPE_LONG;
+ bind[2].buffer= (char *)&nData;
/*int*/
- bind_int[3].buffer_type=FIELD_TYPE_LONG;
- bind_int[3].buffer= (void *)&nData;
+ bind[3].buffer_type=FIELD_TYPE_LONG;
+ bind[3].buffer= (char *)&nData;
/*integer*/
- bind_int[4].buffer_type=FIELD_TYPE_LONG;
- bind_int[4].buffer= (void *)&nData;
+ bind[4].buffer_type=FIELD_TYPE_LONG;
+ bind[4].buffer= (char *)&nData;
/*bigint*/
- bind_int[5].buffer_type=FIELD_TYPE_LONGLONG;
- bind_int[5].buffer= (void *)&bData;
+ bind[5].buffer_type=FIELD_TYPE_LONGLONG;
+ bind[5].buffer= (char *)&bData;
- rc = mysql_bind_param(stmt,bind_int);
+ for (i= 0; i < array_elements(bind); i++)
+ bind[i].is_null=0;
+
+ rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
/*
@@ -3846,7 +3882,6 @@ static void test_prepare_ext()
-
/********************************************************
* to test real and alias names *
*********************************************************/
@@ -3876,7 +3911,7 @@ static void test_field_names()
rc = mysql_commit(mysql);
myquery(rc);
- /* with table name included with true column name */
+ /* with table name included with TRUE column name */
rc = mysql_query(mysql,"SELECT id as 'id-alias' FROM test_field_names1");
myquery(rc);
@@ -3886,7 +3921,7 @@ static void test_field_names()
myassert(0 == my_process_result_set(result));
mysql_free_result(result);
- /* with table name included with true column name */
+ /* with table name included with TRUE column name */
rc = mysql_query(mysql,"SELECT t1.id as 'id-alias',test_field_names2.name FROM test_field_names1 t1,test_field_names2");
myquery(rc);
@@ -3945,16 +3980,17 @@ static void test_errors()
static void test_insert()
{
MYSQL_STMT *stmt;
- int rc, length;
+ int rc;
char query[200];
char str_data[50];
char tiny_data;
MYSQL_RES *result;
MYSQL_BIND bind[2];
+ ulong length[2];
myheader("test_insert");
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_prep_insert");
@@ -3969,7 +4005,7 @@ static void test_insert()
/* insert by prepare */
bzero(bind, sizeof(bind));
- strcpy(query,"INSERT INTO test_prep_insert VALUES(?,?)");
+ strmov(query,"INSERT INTO test_prep_insert VALUES(?,?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -3977,11 +4013,14 @@ static void test_insert()
/* tinyint */
bind[0].buffer_type=FIELD_TYPE_TINY;
- bind[0].buffer=(gptr)&tiny_data;
+ bind[0].buffer=(char *)&tiny_data;
+ bind[0].is_null= 0;
+
/* string */
bind[1].buffer_type=FIELD_TYPE_STRING;
bind[1].buffer=str_data;
- bind[1].length=(long *)&length;
+ bind[1].buffer_length=sizeof(str_data);;
+ bind[1].is_null= 0;
rc = mysql_bind_param(stmt,bind);
mystmt(stmt, rc);
@@ -3989,7 +4028,7 @@ static void test_insert()
/* now, execute the prepared statement to insert 10 records.. */
for (tiny_data=0; tiny_data < 3; tiny_data++)
{
- length = sprintf(str_data,"MySQL%d",tiny_data);
+ length[1] = my_sprintf(str_data, (str_data, "MySQL%d",tiny_data));
rc = mysql_execute(stmt);
mystmt(stmt, rc);
}
@@ -4025,7 +4064,7 @@ static void test_prepare_resultset()
myheader("test_prepare_resultset");
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_prepare_resultset");
@@ -4038,7 +4077,7 @@ static void test_prepare_resultset()
name varchar(50),extra double)");
myquery(rc);
- strcpy(query,"SELECT * FROM test_prepare_resultset");
+ strmov(query,"SELECT * FROM test_prepare_resultset");
stmt = PREPARE(mysql, query);
mystmt_init(stmt);
@@ -4082,7 +4121,7 @@ static void test_field_flags()
rc = mysql_commit(mysql);
myquery(rc);
- /* with table name included with true column name */
+ /* with table name included with TRUE column name */
rc = mysql_query(mysql,"SELECT * FROM test_field_flags");
myquery(rc);
@@ -4096,15 +4135,15 @@ static void test_field_flags()
{
field = mysql_fetch_field(result);
fprintf(stdout,"\n field:%d",i);
- if(field->flags & NOT_NULL_FLAG)
+ if (field->flags & NOT_NULL_FLAG)
fprintf(stdout,"\n NOT_NULL_FLAG");
- if(field->flags & PRI_KEY_FLAG)
+ if (field->flags & PRI_KEY_FLAG)
fprintf(stdout,"\n PRI_KEY_FLAG");
- if(field->flags & UNIQUE_KEY_FLAG)
+ if (field->flags & UNIQUE_KEY_FLAG)
fprintf(stdout,"\n UNIQUE_KEY_FLAG");
- if(field->flags & MULTIPLE_KEY_FLAG)
+ if (field->flags & MULTIPLE_KEY_FLAG)
fprintf(stdout,"\n MULTIPLE_KEY_FLAG");
- if(field->flags & AUTO_INCREMENT_FLAG)
+ if (field->flags & AUTO_INCREMENT_FLAG)
fprintf(stdout,"\n AUTO_INCREMENT_FLAG");
}
@@ -4118,7 +4157,7 @@ static void test_stmt_close()
{
MYSQL *lmysql;
MYSQL_STMT *stmt1, *stmt2, *stmt3, *stmt_x;
- MYSQL_BIND param[1];
+ MYSQL_BIND bind[1];
MYSQL_RES *result;
char query[100];
unsigned int count;
@@ -4126,8 +4165,7 @@ static void test_stmt_close()
myheader("test_stmt_close");
- init_bind(param);
- if(!(lmysql = mysql_init(NULL)))
+ if (!(lmysql = mysql_init(NULL)))
{
myerror("mysql_init() failed");
exit(0);
@@ -4140,32 +4178,32 @@ static void test_stmt_close()
exit(0);
}
if (opt_db)
- strcpy(current_db,opt_db);
+ strmov(current_db,opt_db);
/* set AUTOCOMMIT to ON*/
- mysql_autocommit(lmysql, true);
+ mysql_autocommit(lmysql, TRUE);
mysql_query(lmysql,"DROP TABLE IF EXISTS test_stmt_close");
mysql_query(lmysql,"CREATE TABLE test_stmt_close(id int)");
- strcpy(query,"ALTER TABLE test_stmt_close ADD name varchar(20)");
+ strmov(query,"ALTER TABLE test_stmt_close ADD name varchar(20)");
stmt1= PREPARE(lmysql, query);
mystmt_init(stmt1);
count= mysql_param_count(stmt1);
fprintf(stdout,"\n total params in alter: %d", count);
myassert(count == 0);
- strcpy(query,"INSERT INTO test_stmt_close(id) VALUES(?)");
+ strmov(query,"INSERT INTO test_stmt_close(id) VALUES(?)");
stmt_x= PREPARE(mysql, query);
mystmt_init(stmt_x);
count= mysql_param_count(stmt_x);
fprintf(stdout,"\n total params in insert: %d", count);
myassert(count == 1);
- strcpy(query,"UPDATE test_stmt_close SET id=? WHERE id=?");
+ strmov(query,"UPDATE test_stmt_close SET id=? WHERE id=?");
stmt3= PREPARE(lmysql, query);
mystmt_init(stmt3);
count= mysql_param_count(stmt3);
fprintf(stdout,"\n total params in update: %d", count);
myassert(count == 2);
- strcpy(query,"SELECT * FROM test_stmt_close WHERE id=?");
+ strmov(query,"SELECT * FROM test_stmt_close WHERE id=?");
stmt2= PREPARE(lmysql, query);
mystmt_init(stmt2);
count= mysql_param_count(stmt2);
@@ -4186,9 +4224,11 @@ static void test_stmt_close()
#endif
count= 100;
- param[0].buffer=(gptr)&count;
- param[0].buffer_type=MYSQL_TYPE_LONG;
- rc = mysql_bind_param(stmt_x, param);
+ bind[0].buffer=(char *)&count;
+ bind[0].buffer_type=MYSQL_TYPE_LONG;
+ bind[0].is_null=0;
+
+ rc = mysql_bind_param(stmt_x, bind);
mystmt(stmt_x, rc);
rc = mysql_execute(stmt_x);
mystmt(stmt_x, rc);
@@ -4212,6 +4252,7 @@ static void test_stmt_close()
mysql_free_result(result);
}
+
/********************************************************
* To test simple set-variable prepare *
*********************************************************/
@@ -4226,10 +4267,10 @@ static void test_set_variable()
myheader("test_set_variable");
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
- strcpy(query,"SET GLOBAL delayed_insert_limit=?");
+ strmov(query,"SET GLOBAL delayed_insert_limit=?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4238,10 +4279,10 @@ static void test_set_variable()
result= mysql_param_result(stmt);
mytest_r(result);
- init_bind(bind);
bind[0].buffer_type= MYSQL_TYPE_LONG;
- bind[0].buffer=(gptr)&select_limit;
+ bind[0].buffer=(char *)&select_limit;
+ bind[0].is_null=0;
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
@@ -4251,13 +4292,13 @@ static void test_set_variable()
mysql_store_result(mysql);
- strcpy(query,"show variables like 'delayed_insert_limit'");
+ strmov(query,"show variables like 'delayed_insert_limit'");
rc = mysql_query(mysql,query);
myquery(rc);
verify_col_data(NullS, NullS, "88");
-#if TO_BE_FIXED
+#ifdef TO_BE_FIXED
select_limit= 100;/* reset to default */
rc= mysql_execute(stmt);
@@ -4273,6 +4314,9 @@ static void test_set_variable()
#endif
mysql_stmt_close(stmt);
}
+
+
+
#if NOT_USED
/* Insert meta info .. */
static void test_insert_meta()
@@ -4285,7 +4329,7 @@ static void test_insert_meta()
myheader("test_insert_meta");
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_prep_insert");
@@ -4298,7 +4342,7 @@ static void test_insert_meta()
col2 varchar(50), col3 varchar(30))");
myquery(rc);
- strcpy(query,"INSERT INTO test_prep_insert VALUES(10,'venu1','test')");
+ strmov(query,"INSERT INTO test_prep_insert VALUES(10,'venu1','test')");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4307,7 +4351,7 @@ static void test_insert_meta()
result= mysql_param_result(stmt);
mytest_r(result);
- strcpy(query,"INSERT INTO test_prep_insert VALUES(?,'venu',?)");
+ strmov(query,"INSERT INTO test_prep_insert VALUES(?,'venu',?)");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4347,7 +4391,7 @@ static void test_update_meta()
myheader("test_update_meta");
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_prep_update");
@@ -4360,7 +4404,7 @@ static void test_update_meta()
col2 varchar(50), col3 varchar(30))");
myquery(rc);
- strcpy(query,"UPDATE test_prep_update SET col1=10, col2='venu1' WHERE col3='test'");
+ strmov(query,"UPDATE test_prep_update SET col1=10, col2='venu1' WHERE col3='test'");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4369,7 +4413,7 @@ static void test_update_meta()
result= mysql_param_result(stmt);
mytest_r(result);
- strcpy(query,"UPDATE test_prep_update SET col1=?, col2='venu' WHERE col3=?");
+ strmov(query,"UPDATE test_prep_update SET col1=?, col2='venu' WHERE col3=?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4413,7 +4457,7 @@ static void test_select_meta()
myheader("test_select_meta");
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_prep_select");
@@ -4426,7 +4470,7 @@ static void test_select_meta()
col2 varchar(50), col3 varchar(30))");
myquery(rc);
- strcpy(query,"SELECT * FROM test_prep_select WHERE col1=10");
+ strmov(query,"SELECT * FROM test_prep_select WHERE col1=10");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4435,7 +4479,7 @@ static void test_select_meta()
result= mysql_param_result(stmt);
mytest_r(result);
- strcpy(query,"SELECT col1, col3 from test_prep_select WHERE col1=? AND col3='test' AND col2= ?");
+ strmov(query,"SELECT col1, col3 from test_prep_select WHERE col1=? AND col3='test' AND col2= ?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4469,6 +4513,7 @@ n
}
#endif
+
/* Test FUNCTION field info / DATE_FORMAT() table_name . */
static void test_func_fields()
{
@@ -4478,7 +4523,7 @@ static void test_func_fields()
myheader("test_func_fields");
- rc = mysql_autocommit(mysql, true);
+ rc = mysql_autocommit(mysql, TRUE);
myquery(rc);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_dateformat");
@@ -4548,16 +4593,17 @@ static void test_func_fields()
mysql_free_result(result);
}
+
/* Multiple stmts .. */
static void test_multi_stmt()
{
#if TO_BE_FIXED_IN_SERVER
MYSQL_STMT *stmt, *stmt1;
int rc, id;
- long length;
char name[50]={0};
MYSQL_BIND bind[2];
-
+ ulong length[2];
+ my_bool is_null[2];
myheader("test_multi_stmt");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_multi_table");
@@ -4574,14 +4620,15 @@ static void test_multi_stmt()
verify_param_count(stmt,1);
- init_bind(bind);
-
- bind[0].buffer_type = MYSQL_TYPE_SHORT;
- bind[0].buffer = (void *)&id;
+ bind[0].buffer_type= MYSQL_TYPE_SHORT;
+ bind[0].buffer= (char *)&id;
+ bind[0].is_null= &is_null[0];
bind[1].buffer_type = MYSQL_TYPE_STRING;
- bind[1].buffer = (void *)&name;
- bind[1].length = &length;;
+ bind[1].buffer = (char *)&name;
+ bind[1].length = &length[1];
+ bind[1].is_null= &is_null[0];
+
rc = mysql_bind_param(stmt, bind);
mystmt(stmt, rc);
@@ -4598,7 +4645,7 @@ static void test_multi_stmt()
mystmt(stmt, rc);
fprintf(stdout, "\n int_data: %d", id);
- fprintf(stdout, "\n str_data: %s(%d)", name, length);
+ fprintf(stdout, "\n str_data: %s(%lu)", name, length);
myassert(id == 10);
myassert(strcmp(name,"mysql")==0);
@@ -4635,19 +4682,20 @@ static void test_multi_stmt()
#endif
}
+
/********************************************************
* to test simple sample - manual *
*********************************************************/
static void test_manual_sample()
{
unsigned int param_count;
- MYSQL_BIND bind[3];
MYSQL_STMT *stmt;
short small_data;
- int int_data;
+ int int_data, i;
char str_data[50], query[255];
- long length;
ulonglong affected_rows;
+ MYSQL_BIND bind[3];
+ my_bool is_null[3];
myheader("test_manual_sample");
@@ -4673,8 +4721,8 @@ static void test_manual_sample()
}
/* Prepare a insert query with 3 parameters */
- strcpy(query, "INSERT INTO test_table(col1,col2,col3) values(?,?,?)");
- if(!(stmt = mysql_prepare(mysql,query,strlen(query))))
+ strmov(query, "INSERT INTO test_table(col1,col2,col3) values(?,?,?)");
+ if (!(stmt = mysql_prepare(mysql,query,strlen(query))))
{
fprintf(stderr, "\n prepare, insert failed");
fprintf(stderr, "\n %s", mysql_error(mysql));
@@ -4697,17 +4745,22 @@ static void test_manual_sample()
/* INTEGER PART */
memset(bind,0,sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG;
- bind[0].buffer= (void *)&int_data;
-
+ bind[0].buffer= (char *)&int_data;
+
/* STRING PART */
bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
- bind[1].buffer= (void *)str_data;
+ bind[1].buffer= (char *)str_data;
bind[1].buffer_length= sizeof(str_data);
/* SMALLINT PART */
bind[2].buffer_type= MYSQL_TYPE_SHORT;
- bind[2].buffer= (void *)&small_data;
- bind[2].length= (long *)&length;
+ bind[2].buffer= (char *)&small_data;
+
+ for (i= 0; i < (int) array_elements(bind); i++)
+ {
+ bind[i].is_null= &is_null[i];
+ is_null[i]=0;
+ }
/* Bind the buffers */
if (mysql_bind_param(stmt, bind))
@@ -4719,9 +4772,9 @@ static void test_manual_sample()
/* Specify the data */
int_data= 10; /* integer */
- strcpy(str_data,"MySQL"); /* string */
+ strmov(str_data,"MySQL"); /* string */
/* INSERT SMALLINT data as NULL */
- length= MYSQL_NULL_DATA;
+ is_null[2]= 1;
/* Execute the insert statement - 1*/
if (mysql_execute(stmt))
@@ -4743,9 +4796,9 @@ static void test_manual_sample()
/* Re-execute the insert, by changing the values */
int_data= 1000;
- strcpy(str_data,"The most popular open source database");
+ strmov(str_data,"The most popular open source database");
small_data= 1000; /* smallint */
- length= 0;
+ is_null[2]= 0;
/* Execute the insert statement - 2*/
if (mysql_execute(stmt))
@@ -4784,6 +4837,7 @@ static void test_manual_sample()
fprintf(stdout, "Success !!!");
}
+
/********************************************************
* to test alter table scenario in the middle of prepare *
*********************************************************/
@@ -4793,6 +4847,7 @@ static void test_prepare_alter()
int rc, id;
long length;
MYSQL_BIND bind[1];
+ my_bool is_null;
myheader("test_prepare_alter");
@@ -4810,11 +4865,9 @@ static void test_prepare_alter()
verify_param_count(stmt,1);
- init_bind(bind);
-
bind[0].buffer_type= MYSQL_TYPE_SHORT;
- bind[0].length= (long *)&length;
- bind[0].buffer= (void *)&id;
+ bind[0].buffer= (char *)&id;
+ bind[0].is_null= &is_null;
rc = mysql_bind_param(stmt, bind);
mystmt(stmt, rc);
@@ -4826,7 +4879,7 @@ static void test_prepare_alter()
if (thread_query((char *)"ALTER TABLE test_prep_alter change id id_new varchar(20)"))
exit(0);
- length = MYSQL_NULL_DATA;
+ is_null=1;
rc = mysql_execute(stmt);
mystmt(stmt, rc);
@@ -4862,7 +4915,7 @@ static void test_multi_query()
rc = mysql_query(mysql, query); /* syntax error */
myquery_r(rc);
- if(!(l_mysql = mysql_init(NULL)))
+ if (!(l_mysql = mysql_init(NULL)))
{
fprintf(stdout,"\n mysql_init() failed");
exit(1);
@@ -4881,7 +4934,7 @@ static void test_multi_query()
myquery(rc);
count= 0;
- while(mysql_more_results(mysql) && count < sizeof(rows)/sizeof(uint))
+ while (mysql_more_results(mysql) && count < sizeof(rows)/sizeof(uint))
{
fprintf(stdout,"\n query %d", count);
if ((rc= mysql_next_result(mysql)))
@@ -4897,6 +4950,7 @@ static void test_multi_query()
mysql= org_mysql;
}
+
/********************************************************
* to test simple bind store result *
*********************************************************/
@@ -4905,13 +4959,14 @@ static void test_store_result()
MYSQL_STMT *stmt;
int rc;
const char query[100];
- int nData, length, length1;
+ long nData;
char szData[100];
MYSQL_BIND bind[2];
+ ulong length, length1;
+ my_bool is_null[2];
myheader("test_store_result");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_store_result");
myquery(rc);
@@ -4934,16 +4989,20 @@ static void test_store_result()
myquery(rc);
/* fetch */
-
bind[0].buffer_type=FIELD_TYPE_LONG;
- bind[0].buffer= (gptr) &nData; /* integer data */
- bind[0].length= (long *)&length;
+ bind[0].buffer= (char*) &nData; /* integer data */
+ bind[0].length= &length;
+ bind[1].is_null= &is_null[1];
+
+ length= 0;
bind[1].buffer_type=FIELD_TYPE_STRING;
bind[1].buffer=szData; /* string data */
bind[1].buffer_length=sizeof(szData);
- bind[1].length=(long *)&length1;
+ bind[1].length= &length1;
+ bind[1].is_null= &is_null[1];
+ length1= 0;
- strcpy((char *)query , "SELECT * FROM test_store_result");
+ strmov((char *)query , "SELECT * FROM test_store_result");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -4959,7 +5018,7 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout,"\n row 1: %d,%s(%d)",nData, szData, length1);
+ fprintf(stdout,"\n row 1: %ld,%s(%lu)", nData, szData, length1);
myassert(nData == 10);
myassert(strcmp(szData,"venu")==0);
myassert(length1 == 4);
@@ -4967,7 +5026,7 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout,"\n row 2: %d,%s(%d)",nData, szData, length1);
+ fprintf(stdout,"\n row 2: %ld,%s(%lu)",nData, szData, length1);
myassert(nData == 20);
myassert(strcmp(szData,"mysql")==0);
myassert(length1 == 5);
@@ -4976,11 +5035,11 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- if (length == MYSQL_NULL_DATA)
- fprintf(stdout,"\n row 3: NULL,%s(%d)", szData, length1);
+ if (is_null[1])
+ fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
- fprintf(stdout,"\n row 3: %d,%s(%d)", nData, szData, length1);
- myassert(length == MYSQL_NULL_DATA);
+ fprintf(stdout,"\n row 3: %ld,%s(%lu)", nData, szData, length1);
+ myassert(is_null[1]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
@@ -4996,7 +5055,7 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout,"\n row 1: %d,%s(%d)",nData, szData, length1);
+ fprintf(stdout,"\n row 1: %ld,%s(%lu)",nData, szData, length1);
myassert(nData == 10);
myassert(strcmp(szData,"venu")==0);
myassert(length1 == 4);
@@ -5004,7 +5063,7 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout,"\n row 2: %d,%s(%d)",nData, szData, length1);
+ fprintf(stdout,"\n row 2: %ld,%s(%lu)",nData, szData, length1);
myassert(nData == 20);
myassert(strcmp(szData,"mysql")==0);
myassert(length1 == 5);
@@ -5013,11 +5072,11 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- if (length == MYSQL_NULL_DATA)
- fprintf(stdout,"\n row 3: NULL,%s(%d)", szData, length1);
+ if (is_null[1])
+ fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
- fprintf(stdout,"\n row 3: %d,%s(%d)", nData, szData, length1);
- myassert(length == MYSQL_NULL_DATA);
+ fprintf(stdout,"\n row 3: %ld,%s(%lu)", nData, szData, length1);
+ myassert(is_null[1]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
@@ -5027,6 +5086,7 @@ static void test_store_result()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple bind store result *
*********************************************************/
@@ -5088,6 +5148,7 @@ static void test_store_result1()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple bind store result *
*********************************************************/
@@ -5101,7 +5162,6 @@ static void test_store_result2()
myheader("test_store_result2");
- init_bind(bind);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_store_result");
myquery(rc);
@@ -5126,10 +5186,12 @@ static void test_store_result2()
/* fetch */
bind[0].buffer_type=FIELD_TYPE_LONG;
- bind[0].buffer= (gptr) &nData; /* integer data */
+ bind[0].buffer= (char *) &nData; /* integer data */
bind[0].length= &length;
+ bind[0].is_null= 0;
+ length= 0;
- strcpy((char *)query , "SELECT col1 FROM test_store_result where col1= ?");
+ strmov((char *)query , "SELECT col1 FROM test_store_result where col1= ?");
stmt = mysql_prepare(mysql, query, strlen(query));
mystmt_init(stmt);
@@ -5176,6 +5238,7 @@ static void test_store_result2()
mysql_stmt_close(stmt);
}
+
/********************************************************
* to test simple subselect prepare *
*********************************************************/
@@ -5185,13 +5248,11 @@ static void test_subselect()
MYSQL_STMT *stmt;
int rc;
int id;
- long length;
+ ulong length;
MYSQL_BIND bind[1];
myheader("test_subselect");
- init_bind(bind);
-
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_sub1");
myquery(rc);
@@ -5222,10 +5283,12 @@ static void test_subselect()
/* fetch */
bind[0].buffer_type=FIELD_TYPE_LONG;
- bind[0].buffer= (gptr) &id;
+ bind[0].buffer= (char *) &id;
bind[0].length= &length;
+ bind[0],is_null= 0;
+ length=0;
- strcpy((char *)query , "SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=?)");
+ strmov((char *)query , "SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=?)");
myassert(1 == my_stmt_result("SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=8)",100));
myassert(1 == my_stmt_result("SELECT ROW(1,7) IN (select id, id1 from test_sub2 WHERE id1=7)",100));
stmt = mysql_prepare(mysql, query, strlen(query));
@@ -5244,7 +5307,7 @@ static void test_subselect()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
- fprintf(stdout,"\n row 1: %d(%ld)",id, length);
+ fprintf(stdout,"\n row 1: %d(%lu)",id, length);
myassert(id == 1);
rc = mysql_fetch(stmt);
@@ -5259,21 +5322,21 @@ static struct my_option myctest_long_options[] =
{
{"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0},
- {"database", 'D', "Database to use", (gptr*) &opt_db, (gptr*) &opt_db,
+ {"database", 'D', "Database to use", (char **) &opt_db, (char **) &opt_db,
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"host", 'h', "Connect to host", (gptr*) &opt_host, (gptr*) &opt_host, 0, GET_STR_ALLOC,
+ {"host", 'h', "Connect to host", (char **) &opt_host, (char **) &opt_host, 0, GET_STR_ALLOC,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given it's asked from the tty.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DONT_ALLOW_USER_CHANGE
- {"user", 'u', "User for login if not current user", (gptr*) &opt_user,
- (gptr*) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"user", 'u', "User for login if not current user", (char **) &opt_user,
+ (char **) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
- {"port", 'P', "Port number to use for connection", (gptr*) &opt_port,
- (gptr*) &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"socket", 'S', "Socket file to use for connection", (gptr*) &opt_unix_socket,
- (gptr*) &opt_unix_socket, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"port", 'P', "Port number to use for connection", (char **) &opt_port,
+ (char **) &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"socket", 'S', "Socket file to use for connection", (char **) &opt_unix_socket,
+ (char **) &opt_unix_socket, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};