Commit 5fa224b6 authored by unknown's avatar unknown

Remove bind_length + Fix the client-test


tests/client_test.c:
  Fix the tests
include/mysql.h:
  Remove bind_length
libmysql/libmysql.c:
  Remove bind_length
parent 8823fa22
......@@ -481,7 +481,6 @@ typedef struct st_mysql_bind
unsigned long buffer_length; /* buffer length */
/* The following are for internal use. Set by mysql_bind_param */
unsigned long bind_length; /* Default length of data */
unsigned int param_number; /* For null count and error messages */
my_bool long_data_used; /* If used with mysql_send_long_data */
void (*store_param_func)(NET *net, struct st_mysql_bind *param);
......
......@@ -4058,7 +4058,7 @@ static void store_param_double(NET *net, MYSQL_BIND *param)
static void store_param_str(NET *net, MYSQL_BIND *param)
{
ulong length= *param->length;
ulong length= min(*param->length, param->buffer_length);
char *to= (char *) net_store_length((char *) net->write_pos, length);
memcpy(to, param->buffer, length);
net->write_pos= (uchar*) to+length;
......@@ -4107,7 +4107,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param)
{
/*
Param->length should ALWAYS point to the correct length for the type
Either to the length pointer given by the user or param->bind_length
Either to the length pointer given by the user or param->buffer_length
*/
if ((my_realloc_str(net, 9 + *param->length)))
DBUG_RETURN(1);
......@@ -4277,12 +4277,14 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
param++)
{
param->param_number= count++;
param->long_data_used= 0;
/*
If param->length is not given, change it to point to bind_length.
If param->length is not given, change it to point to buffer_length.
This way we can always use *param->length to get the length of data
*/
if (!param->length)
param->length= &param->bind_length;
param->length= &param->buffer_length;
/* If param->is_null is not set, then the value can never be NULL */
if (!param->is_null)
......@@ -4295,33 +4297,33 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
break;
case MYSQL_TYPE_TINY:
/* Force param->length as this is fixed for this type */
param->length= &param->bind_length;
param->bind_length= param->buffer_length= 1;
param->length= &param->buffer_length;
param->buffer_length= 1;
param->store_param_func= store_param_tinyint;
break;
case MYSQL_TYPE_SHORT:
param->length= &param->bind_length;
param->bind_length= param->buffer_length= 2;
param->length= &param->buffer_length;
param->buffer_length= 2;
param->store_param_func= store_param_short;
break;
case MYSQL_TYPE_LONG:
param->length= &param->bind_length;
param->bind_length= param->buffer_length= 4;
param->length= &param->buffer_length;
param->buffer_length= 4;
param->store_param_func= store_param_int32;
break;
case MYSQL_TYPE_LONGLONG:
param->length= &param->bind_length;
param->bind_length= param->buffer_length= 8;
param->length= &param->buffer_length;
param->buffer_length= 8;
param->store_param_func= store_param_int64;
break;
case MYSQL_TYPE_FLOAT:
param->length= &param->bind_length;
param->bind_length= param->buffer_length= 4;
param->length= &param->buffer_length;
param->buffer_length= 4;
param->store_param_func= store_param_float;
break;
case MYSQL_TYPE_DOUBLE:
param->length= &param->bind_length;
param->bind_length= param->buffer_length= 8;
param->length= &param->buffer_length;
param->buffer_length= 8;
param->store_param_func= store_param_double;
break;
case MYSQL_TYPE_TINY_BLOB:
......@@ -4330,7 +4332,6 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
param->bind_length= param->buffer_length;
param->store_param_func= store_param_str;
break;
default:
......@@ -4586,6 +4587,7 @@ static void send_data_str(MYSQL_BIND *param, char *value, uint length)
}
default:
*param->length= length;
length= min(length, param->buffer_length);
memcpy(buffer, value, length);
buffer[length]='\0';
}
......@@ -4804,9 +4806,10 @@ static void fetch_result_double(MYSQL_BIND *param, uchar **row)
static void fetch_result_str(MYSQL_BIND *param, uchar **row)
{
ulong length= net_field_length(row);
memcpy(param->buffer, (char *)*row, length);
*(param->buffer+length)= '\0';
*param->length= length;
ulong copy_length= min(length, param->buffer_length);
memcpy(param->buffer, (char *)*row, copy_length);
*(param->buffer+copy_length)= '\0';
*param->length= length; // return total length
*row+= length;
}
......@@ -4882,7 +4885,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_RETURN(1);
}
if (!param->length)
param->length= &param->bind_length;
param->length= &param->buffer_length;
*param->length= (long)get_binary_length(param->buffer_type);
}
stmt->res_buffers= 1;
......
......@@ -46,12 +46,28 @@ static my_bool tty_password=0;
static MYSQL *mysql=0;
static char query[255];
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;
#define myheader(str) { fprintf(stdout,"\n\n#######################\n"); \
fprintf(stdout,"%s",str); \
fprintf(stdout,"\n#######################\n"); \
}
#define myheader(str) \
{ \
fprintf(stdout,"\n\n#####################################\n"); \
fprintf(stdout,"%d of (%d/%d): %s",test_count++, iter_count,\
opt_count, str); \
fprintf(stdout," \n#####################################\n"); \
}
#define myheader_r(str) \
{ \
fprintf(stdout,"\n\n#####################################\n"); \
fprintf(stdout,"%s", str); \
fprintf(stdout," \n#####################################\n"); \
}
/*
TODO: un comment this in 4.1.1 when it supports mysql_param_result
and also enable all meta_param_result tests
*/
#ifndef mysql_param_result
#define mysql_param_result mysql_prepare_result
#endif
......@@ -143,7 +159,7 @@ static void client_connect()
{
int rc;
char buff[255];
myheader("client_connect");
myheader_r("client_connect");
if (!(mysql = mysql_init(NULL)))
{
......@@ -174,7 +190,7 @@ static void client_connect()
*********************************************************/
static void client_disconnect()
{
myheader("client_disconnect");
myheader_r("client_disconnect");
if (mysql)
{
......@@ -1570,10 +1586,10 @@ static void test_select()
/* string data */
nData=10;
strmov(szData,(char *)"venu");
strcpy(szData,(char *)"venu");
bind[1].buffer_type=FIELD_TYPE_STRING;
bind[1].buffer=szData;
bind[1].buffer_length= sizeof(szData); /* Max string lenth */
bind[1].buffer=(char *)&szData;
bind[1].buffer_length= 4;
bind[1].length= &length[1];
length[1]= 4;
bind[1].is_null=0;
......@@ -2106,6 +2122,7 @@ static void test_simple_delete()
bind[1].buffer= szData; /* string data */
bind[1].buffer_length=sizeof(szData);
bind[1].length= &length[1];
bind[1].is_null= 0;
length[1]= 5;
bind[0].buffer=(char *)&nData;
......@@ -2633,6 +2650,139 @@ static void test_bind_result_ext1()
mysql_stmt_close(stmt);
}
/*
Generalized fetch conversion routine for all basic types
*/
static void bind_fetch(int row_count)
{
MYSQL_STMT *stmt;
int rc, i, count= row_count;
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];
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_fetch VALUES(?,?,?,?,?,?,?)",100);
mystmt_init(stmt);
verify_param_count(stmt, 7);
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
bind[i].buffer= (char *) &data[i];
bind[i].is_null= 0;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
while (count--)
{
rc= 10+count;
for (i= 0; i < (int) array_elements(bind); i++)
{
data[i]= rc+i;
rc+= 12;
}
rc = mysql_execute(stmt);
mystmt(stmt, rc);
}
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
myassert(row_count == (int)
my_stmt_result("SELECT * FROM test_bind_fetch",50));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_fetch",50);
myquery(rc);
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];
}
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= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
bind[6].buffer= (char *)&s_data;
bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_stmt_store_result(stmt);
mystmt(stmt, rc);
while (row_count--)
{
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
fprintf(stdout, "\n");
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+row_count;
for (i=0; i < 4; i++)
{
myassert(data[i] == rc+i);
myassert(length[i] == bit);
bit<<= 1;
rc+= 12;
}
/* FLOAT */
rc+= i;
myassert((int)f_data == rc);
myassert(length[4] == 4);
/* DOUBLE */
rc+= 13;
myassert((int)d_data == rc);
myassert(length[5] == 8);
/* CHAR */
rc+= 13;
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", rc));
myassert(strcmp(s_data,buff)==0);
myassert(length[6] == (ulong) len);
}
}
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
mysql_stmt_close(stmt);
}
/********************************************************
* to test fetching of date, time and ts *
*********************************************************/
......@@ -2773,26 +2923,17 @@ static void test_fetch_date()
*********************************************************/
static void test_fetch_str()
{
MYSQL_STMT *stmt;
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];
int rc;
myheader("test_fetch_str");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_str");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_fetch");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_query(mysql,"CREATE TABLE test_bind_str(c1 char(10),\
rc = mysql_query(mysql,"CREATE TABLE test_bind_fetch(c1 char(10),\
c2 char(10),\
c3 char(20),\
c4 char(20),\
......@@ -2804,106 +2945,7 @@ static void test_fetch_str()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_str VALUES(?,?,?,?,?,?,?)",100);
myquery(rc);
verify_param_count(stmt, 7);
round= 0;
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
bind[i].buffer= &data[i];
bind[i].is_null= 0;
data[i]= round+i+1;
round= (round +10)*10;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
myassert(1 == my_stmt_result("SELECT * FROM test_bind_str",50));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_str",50);
myquery(rc);
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];
}
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= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
bind[6].buffer= (char *)&s_data;
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
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;
for (i=0; i < 4; i++)
{
myassert(data[i] == round+i+1);
myassert(length[i] == bit);
round= (round+10)*10;
bit<<= 1;
}
/* FLOAT */
myassert((int)f_data == round+1+i);
myassert(length[4] == 4);
/* DOUBLE */
round= (round+10)*10;
myassert((int)d_data == round+2+i);
myassert(length[5] == 8);
/* CHAR */
round= (round+10)*10;
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
mysql_stmt_close(stmt);
bind_fetch(3);
}
/********************************************************
......@@ -2911,26 +2953,17 @@ static void test_fetch_str()
*********************************************************/
static void test_fetch_long()
{
MYSQL_STMT *stmt;
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];
int rc;
myheader("test_fetch_long");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_fetch");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_query(mysql,"CREATE TABLE test_bind_long(c1 int unsigned,\
rc = mysql_query(mysql,"CREATE TABLE test_bind_fetch(c1 int unsigned,\
c2 int unsigned,\
c3 int,\
c4 int,\
......@@ -2942,680 +2975,134 @@ static void test_fetch_long()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_long VALUES(?,?,?,?,?,?,?)",100);
myquery(rc);
bind_fetch(4);
}
verify_param_count(stmt, 7);
round= 0;
for (i=0; i < 7; i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
bind[i].buffer= (char *) &data[i];
bind[i].is_null=0;
data[i]= round+i+1;
round= (round +10)*10;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
/********************************************************
* to test fetching of short to all types *
*********************************************************/
static void test_fetch_short()
{
int rc;
rc = mysql_execute(stmt);
mystmt(stmt, rc);
myheader("test_fetch_short");
rc = mysql_commit(mysql);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_fetch");
myquery(rc);
mysql_stmt_close(stmt);
myassert(1 == my_stmt_result("SELECT * FROM test_bind_long",50));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
rc = mysql_commit(mysql);
myquery(rc);
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= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
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);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
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;
for (i=0; i < 4; i++)
{
myassert(data[i] == round+i+1);
myassert(length[i] == bit);
round= (round+10)*10;
bit<<= 1;
}
/* FLOAT */
myassert((int)f_data == round+1+i);
myassert(length[4] == 4);
/* DOUBLE */
round= (round+10)*10;
myassert((int)d_data == round+2+i);
myassert(length[5] == 8);
/* CHAR */
round= (round+10)*10;
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
mysql_stmt_close(stmt);
}
/********************************************************
* to test fetching of short to all types *
*********************************************************/
static void test_fetch_short()
{
MYSQL_STMT *stmt;
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");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_query(mysql,"CREATE TABLE test_bind_long(c1 smallint unsigned,\
c2 smallint,\
c3 smallint unsigned,\
c4 smallint,\
c5 smallint,\
c6 smallint,\
c7 smallint unsigned)");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_long VALUES(?,?,?,?,?,?,?)",100);
myquery(rc);
verify_param_count(stmt, 7);
round= 0;
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
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;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
myassert(1 == my_stmt_result("SELECT * FROM test_bind_long",50));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
for (i=0; i < 7; 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= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
bind[6].buffer= (char *)&s_data;
bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
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;
for (i=0; i < 4; i++)
{
myassert(data[i] == round+i+1);
myassert(length[i] == bit);
round= (round+10)*2;
bit<<= 1;
}
/* FLOAT */
myassert((int)f_data == round+1+i);
myassert(length[4] == 4);
/* DOUBLE */
round= (round+10)*2;
myassert((int)d_data == round+2+i);
myassert(length[5] == 8);
/* CHAR */
round= (round+10)*2;
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
mysql_stmt_close(stmt);
}
/********************************************************
* to test fetching of tiny to all types *
*********************************************************/
static void test_fetch_tiny()
{
MYSQL_STMT *stmt;
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");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_query(mysql,"CREATE TABLE test_bind_long(c1 tinyint unsigned,\
c2 tinyint,\
c3 tinyint unsigned,\
c4 tinyint,\
c5 tinyint,\
c6 tinyint,\
c7 tinyint unsigned)");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_long VALUES(?,?,?,?,?,?,?)",100);
myquery(rc);
verify_param_count(stmt, 7);
rc= 10;
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
bind[i].buffer= (char *) &data[i];
bind[i].is_null= 0;
data[i]= rc+i;
rc+= 10;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
myassert(1 == my_stmt_result("SELECT * FROM test_bind_long",50));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
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];
}
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= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
bind[6].buffer= (char *)&s_data;
bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
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;
for (i=0; i < 4; i++)
{
myassert(data[i] == rc+i);
myassert(length[i] == bit);
bit<<= 1;
rc+= 10;
}
/* FLOAT */
rc+= i;
myassert((int)f_data == rc);
myassert(length[4] == 4);
/* DOUBLE */
rc+= 11;
myassert((int)d_data == rc);
myassert(length[5] == 8);
/* CHAR */
rc+= 11;
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", rc));
myassert(strcmp(s_data,buff)==0);
myassert(length[6] == (ulong) len);
}
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
mysql_stmt_close(stmt);
}
/********************************************************
* to test fetching of longlong to all types *
*********************************************************/
static void test_fetch_bigint()
{
MYSQL_STMT *stmt;
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");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_query(mysql,"CREATE TABLE test_bind_long(c1 bigint,\
c2 bigint,\
c3 bigint unsigned,\
c4 bigint unsigned,\
c5 bigint unsigned,\
c6 bigint unsigned,\
c7 bigint unsigned)");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_long VALUES(?,?,?,?,?,?,?)",100);
myquery(rc);
verify_param_count(stmt, 7);
round= 0;
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
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;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
myassert(1 == my_stmt_result("SELECT * FROM test_bind_long",50));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
for (i= 0; i < (int) array_elements(bind); 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;
bind[2].buffer_type= MYSQL_TYPE_LONG;
bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
bind[4].buffer_type= MYSQL_TYPE_FLOAT;
bind[4].buffer= (char *)&f_data;
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
bind[5].buffer= (char *)&d_data;
bind[6].buffer_type= MYSQL_TYPE_STRING;
bind[6].buffer= (char *)&s_data;
bind[6].buffer_length= sizeof(s_data);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
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;
for (i=0; i < 4; i++)
{
myassert(data[i] == round+i+1);
myassert(length[i] == bit);
round= (round+10)*10;
bit<<= 1;
}
/* FLOAT */
myassert((int)f_data == round+1+i);
myassert(length[4] == 4);
/* DOUBLE */
round= (round+10)*10;
myassert((int)d_data == round+2+i);
myassert(length[5] == 8);
/* CHAR */
round= (round+10)*10;
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
myassert(length[6] == (ulong) len);
}
rc = mysql_query(mysql,"CREATE TABLE test_bind_fetch(c1 smallint unsigned,\
c2 smallint,\
c3 smallint unsigned,\
c4 smallint,\
c5 smallint,\
c6 smallint,\
c7 smallint unsigned)");
myquery(rc);
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
bind_fetch(5);
}
/********************************************************
* to test fetching of float to all types *
* to test fetching of tiny to all types *
*********************************************************/
static void test_fetch_float()
static void test_fetch_tiny()
{
MYSQL_STMT *stmt;
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];
int rc;
myheader("test_fetch_float");
myheader("test_fetch_tiny");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_fetch");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_query(mysql,"CREATE TABLE test_bind_long(c1 float(3),\
c2 float,\
c3 float unsigned,\
c4 float,\
c5 float,\
c6 float,\
c7 float(10) unsigned)");
rc = mysql_query(mysql,"CREATE TABLE test_bind_fetch(c1 tinyint unsigned,\
c2 tinyint,\
c3 tinyint unsigned,\
c4 tinyint,\
c5 tinyint,\
c6 tinyint,\
c7 tinyint unsigned)");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_long VALUES(?,?,?,?,?,?,?)",100);
myquery(rc);
verify_param_count(stmt, 7);
round= 0;
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
bind[i].buffer= (char *)&data[i];
bind[i].is_null= 0;
data[i]= round+i+1;
round= (round +10)*2;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
bind_fetch(3);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
}
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
/********************************************************
* to test fetching of longlong to all types *
*********************************************************/
static void test_fetch_bigint()
{
int rc;
myassert(1 == my_stmt_result("SELECT * FROM test_bind_long",50));
myheader("test_fetch_bigint");
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_fetch");
myquery(rc);
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];
length[i]=0;
}
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= (char *)&f_data;
rc = mysql_commit(mysql);
myquery(rc);
bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
bind[5].buffer= (char *)&d_data;
rc = mysql_query(mysql,"CREATE TABLE test_bind_fetch(c1 bigint,\
c2 bigint,\
c3 bigint unsigned,\
c4 bigint unsigned,\
c5 bigint unsigned,\
c6 bigint unsigned,\
c7 bigint unsigned)");
myquery(rc);
bind[6].buffer_type= MYSQL_TYPE_STRING;
bind[6].buffer= (char *) &s_data;
bind[6].buffer_length= sizeof(s_data);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
bind_fetch(2);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
}
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
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]);
/********************************************************
* to test fetching of float to all types *
*********************************************************/
static void test_fetch_float()
{
int rc;
round= 0;
bit= 1;
myheader("test_fetch_float");
for (i=0; i < 4; i++)
{
myassert(data[i] == round+i+1);
myassert(length[i] == bit);
round= (round+10)*2;
bit<<= 1;
}
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_fetch");
myquery(rc);
/* FLOAT */
myassert((int)f_data == round+1+i);
myassert(length[4] == 4);
rc = mysql_commit(mysql);
myquery(rc);
/* DOUBLE */
round= (round+10)*2;
myassert((int)d_data == round+2+i);
myassert(length[5] == 8);
rc = mysql_query(mysql,"CREATE TABLE test_bind_fetch(c1 float(3),\
c2 float,\
c3 float unsigned,\
c4 float,\
c5 float,\
c6 float,\
c7 float(10) unsigned)");
myquery(rc);
/* CHAR */
round= (round+10)*2;
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", round+3+i));
myassert(strcmp(s_data,buff)==0);
myassert(length[6] == (ulong) len);
}
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
bind_fetch(2);
mysql_stmt_close(stmt);
}
/********************************************************
......@@ -3623,26 +3110,17 @@ static void test_fetch_float()
*********************************************************/
static void test_fetch_double()
{
MYSQL_STMT *stmt;
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];
int rc;
myheader("test_fetch_double");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_long");
rc = mysql_query(mysql,"DROP TABLE IF EXISTS test_bind_fetch");
myquery(rc);
rc = mysql_commit(mysql);
myquery(rc);
rc = mysql_query(mysql,"CREATE TABLE test_bind_long(c1 double(5,2),\
rc = mysql_query(mysql,"CREATE TABLE test_bind_fetch(c1 double(5,2),\
c2 double unsigned,\
c3 double unsigned,\
c4 double unsigned,\
......@@ -3654,106 +3132,8 @@ static void test_fetch_double()
rc = mysql_commit(mysql);
myquery(rc);
stmt = mysql_prepare(mysql,"INSERT INTO test_bind_long VALUES(?,?,?,?,?,?,?)",100);
myquery(rc);
verify_param_count(stmt, 7);
round= 0;
for (i= 0; i < (int) array_elements(bind); i++)
{
bind[i].buffer_type= MYSQL_TYPE_LONG;
bind[i].buffer= (char *)&data[i];
bind[i].is_null= 0;
data[i]= round+i+1;
round= (round +10)*10;
}
rc = mysql_bind_param(stmt, bind);
mystmt(stmt,rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_commit(mysql);
myquery(rc);
mysql_stmt_close(stmt);
myassert(1 == my_stmt_result("SELECT * FROM test_bind_long",50));
stmt = mysql_prepare(mysql,"SELECT * FROM test_bind_long",50);
myquery(rc);
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];
}
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_STRING;
bind[4].buffer= (char *)&s_data;
bind[4].buffer_length= sizeof(s_data);
bind[5].buffer_type= MYSQL_TYPE_FLOAT;
bind[5].buffer= (char *)&f_data;
bind[6].buffer_type= MYSQL_TYPE_DOUBLE;
bind[6].buffer= (char *)&d_data;
rc = mysql_bind_result(stmt, bind);
mystmt(stmt, rc);
rc = mysql_execute(stmt);
mystmt(stmt, rc);
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
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;
for (i=0; i < 4; i++)
{
myassert(data[i] == round+i+1);
myassert(length[i] == bit);
round= (round+10)*10;
bit<<= 1;
}
/* CHAR */
{
char buff[20];
long len= my_sprintf(buff, (buff, "%d", round+1+i));
myassert(strcmp(s_data,buff)==0);
myassert(length[4] == (ulong) len);
}
/* FLOAT */
round= (round+10)*10;
myassert((int)f_data == round+2+i);
myassert(length[5] == 4);
/* DOUBLE */
round= (round+10)*10;
myassert((int)d_data == round+3+i);
myassert(length[6] == 8);
rc = mysql_fetch(stmt);
myassert(rc == MYSQL_NO_DATA);
bind_fetch(3);
mysql_stmt_close(stmt);
}
/********************************************************
......@@ -3820,7 +3200,7 @@ static void test_prepare_ext()
/* insert by prepare - all integers */
strmov(query,(char *)"INSERT INTO test_prepare_ext(c1,c2,c3,c4,c5,c6) VALUES(?,?,?,?,?,?)");
stmt = mysql_prepare(mysql,query, strlen(query));
myquery(rc);
mystmt_init(stmt);
verify_param_count(stmt,6);
......@@ -4992,7 +4372,7 @@ static void test_store_result()
bind[0].buffer_type=FIELD_TYPE_LONG;
bind[0].buffer= (char*) &nData; /* integer data */
bind[0].length= &length;
bind[1].is_null= &is_null[1];
bind[0].is_null= &is_null[0];
length= 0;
bind[1].buffer_type=FIELD_TYPE_STRING;
......@@ -5035,11 +4415,11 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
if (is_null[1])
if (is_null[0])
fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
fprintf(stdout,"\n row 3: %ld,%s(%lu)", nData, szData, length1);
myassert(is_null[1]);
myassert(is_null[0]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
......@@ -5072,11 +4452,11 @@ static void test_store_result()
rc = mysql_fetch(stmt);
mystmt(stmt,rc);
if (is_null[1])
if (is_null[0])
fprintf(stdout,"\n row 3: NULL,%s(%lu)", szData, length1);
else
fprintf(stdout,"\n row 3: %ld,%s(%lu)", nData, szData, length1);
myassert(is_null[1]);
myassert(is_null[0]);
myassert(strcmp(szData,"monty")==0);
myassert(length1 == 5);
......@@ -5183,8 +4563,6 @@ static void test_store_result2()
rc = mysql_commit(mysql);
myquery(rc);
/* fetch */
bind[0].buffer_type=FIELD_TYPE_LONG;
bind[0].buffer= (char *) &nData; /* integer data */
bind[0].length= &length;
......@@ -5337,6 +4715,8 @@ static struct my_option myctest_long_options[] =
(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},
{"count", 't', "Number of times test to be executed", (char **) &opt_count,
(char **) &opt_count, 0, GET_UINT, 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}
};
......@@ -5369,6 +4749,8 @@ static void usage(void)
fprintf(stdout,"\
-u, --user=# User for login if not current user.\n");
#endif
fprintf(stdout,"\
-t, --count=... Execute the test count times.\n");
fprintf(stdout,"*********************************************************************\n");
}
......@@ -5404,7 +4786,6 @@ static const char *load_default_groups[]= { "client",0 };
static void get_options(int argc, char **argv)
{
int ho_error;
load_defaults("my",load_default_groups,&argc,&argv);
if ((ho_error=handle_options(&argc,&argv, myctest_long_options,
......@@ -5414,6 +4795,8 @@ static void get_options(int argc, char **argv)
/*free_defaults(argv);*/
if (tty_password)
opt_password=get_tty_password(NullS);
if (!opt_count)
opt_count= 1;
return;
}
......@@ -5427,7 +4810,11 @@ int main(int argc, char **argv)
client_connect(); /* connect to server */
for (iter_count=1; iter_count <= opt_count; iter_count++)
{
/* Start of tests */
test_count= 0;
test_multi_query();
test_select_show(); /* test show syntax */
test_prepare_alter(); /* change table schema in middle of prepare */
......@@ -5446,11 +4833,14 @@ int main(int argc, char **argv)
test_bind_result_ext1(); /* result bind test - extension */
test_select_direct(); /* direct select - protocol_simple debug */
test_select_prepare(); /* prepare select - protocol_prep debug */
test_select_direct(); /* direct select - protocol_simple debug */
test_select(); /* simple select test */
test_select_version(); /* select with variables */
test_set_variable(); /* set variable prepare */
#if NOT_USED
/*
Enable this tests from 4.1.1 when mysql_param_result() is
supported
*/
test_select_meta(); /* select param meta information */
test_update_meta(); /* update param meta information */
test_insert_meta(); /* insert param meta information */
......@@ -5460,7 +4850,8 @@ int main(int argc, char **argv)
test_long_data(); /* test for sending text data in chunks */
test_insert(); /* simple insert test - prepare */
test_set_variable(); /* prepare with set variables */
test_tran_innodb(); /* test for mysql_commit(), rollback() and autocommit() */
test_tran_innodb(); /* test for mysql_commit(), rollback() and
autocommit() */
test_select_show(); /* prepare - show test */
test_null(); /* test null data handling */
test_simple_update(); /* simple prepare - update */
......@@ -5508,6 +4899,7 @@ int main(int argc, char **argv)
test_subselect(); /* test subselect prepare */
test_multi_query(); /* test multi query exec */
/* End of tests */
}
client_disconnect(); /* disconnect from server */
fprintf(stdout,"\n\nSUCCESS !!!\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment