From 75ca739eb8d70c17d5b1d94191ae16969ad78e34 Mon Sep 17 00:00:00 2001 From: hoterran Date: Thu, 29 Aug 2013 22:30:16 +0800 Subject: [PATCH] add stmt test --- test/p20_stmt_fetch_and_cursor.c | 2 +- test/stmt/a.c | 8 + test/stmt/bak_p23.c | 63 ++++ test/stmt/p1.c | 293 ++++++++++++++++++ test/stmt/p10_use_db.c | 47 +++ test/stmt/p11_sqlcollect_size_too_big.c | 35 +++ test/stmt/p12_perf_test.c | 35 +++ test/stmt/p13_com_field_list.c | 33 ++ test/stmt/p14_local_file.c | 33 ++ test/stmt/p15_com_test.c | 50 +++ test/stmt/p16_long_preprare.c | 201 ++++++++++++ test/stmt/p17_mix_sql_prepare.c | 111 +++++++ test/stmt/p18_mix_prepare.c | 98 ++++++ test/stmt/p19_null_prepare.c | 61 ++++ test/stmt/p2.c | 59 ++++ test/stmt/p20_stmt_fetch_and_cursor.c | 148 +++++++++ test/stmt/p21_long_preprare_ok.c | 56 ++++ test/stmt/p22_blob.c | 78 +++++ test/stmt/p23_stmt_send_long_data.c | 63 ++++ test/stmt/p24_stmt_send_long_data2.c | 87 ++++++ test/stmt/p27_big_prepare_resultset.c | 56 ++++ test/stmt/p28_compress.c | 33 ++ test/stmt/p299_stmt_fetch.c | 113 +++++++ test/stmt/p29_stmt_fetch.c | 113 +++++++ test/stmt/p3.c | 60 ++++ test/stmt/p30_explain_error.c | 45 +++ test/stmt/p4.c | 44 +++ test/stmt/p5.c | 47 +++ test/stmt/p6.c | 118 +++++++ test/stmt/p7.c | 52 ++++ test/stmt/p8_multi_sql.c | 39 +++ .../p90_store_use_result_stmt_cursor_case.c | 151 +++++++++ test/stmt/p94_stmt_send_long_data.c | 98 ++++++ test/stmt/p95.c | 87 ++++++ test/stmt/p95_stmt_merge_order.c | 154 +++++++++ test/stmt/p96_stmt_merge.c | 154 +++++++++ test/stmt/p96_stmt_null.c | 75 +++++ test/stmt/p97_stmt_type.c | 156 ++++++++++ test/stmt/p98_drds.c | 104 +++++++ test/stmt/p98_stmt_mix.c | 109 +++++++ test/stmt/p99_stmt_normal.c | 118 +++++++ test/stmt/p9_long_field.c | 53 ++++ 42 files changed, 3539 insertions(+), 1 deletion(-) create mode 100644 test/stmt/a.c create mode 100644 test/stmt/bak_p23.c create mode 100644 test/stmt/p1.c create mode 100644 test/stmt/p10_use_db.c create mode 100644 test/stmt/p11_sqlcollect_size_too_big.c create mode 100644 test/stmt/p12_perf_test.c create mode 100644 test/stmt/p13_com_field_list.c create mode 100644 test/stmt/p14_local_file.c create mode 100644 test/stmt/p15_com_test.c create mode 100644 test/stmt/p16_long_preprare.c create mode 100644 test/stmt/p17_mix_sql_prepare.c create mode 100644 test/stmt/p18_mix_prepare.c create mode 100644 test/stmt/p19_null_prepare.c create mode 100644 test/stmt/p2.c create mode 100644 test/stmt/p20_stmt_fetch_and_cursor.c create mode 100644 test/stmt/p21_long_preprare_ok.c create mode 100644 test/stmt/p22_blob.c create mode 100644 test/stmt/p23_stmt_send_long_data.c create mode 100644 test/stmt/p24_stmt_send_long_data2.c create mode 100644 test/stmt/p27_big_prepare_resultset.c create mode 100644 test/stmt/p28_compress.c create mode 100644 test/stmt/p299_stmt_fetch.c create mode 100644 test/stmt/p29_stmt_fetch.c create mode 100644 test/stmt/p3.c create mode 100644 test/stmt/p30_explain_error.c create mode 100644 test/stmt/p4.c create mode 100644 test/stmt/p5.c create mode 100644 test/stmt/p6.c create mode 100644 test/stmt/p7.c create mode 100644 test/stmt/p8_multi_sql.c create mode 100644 test/stmt/p90_store_use_result_stmt_cursor_case.c create mode 100644 test/stmt/p94_stmt_send_long_data.c create mode 100644 test/stmt/p95.c create mode 100644 test/stmt/p95_stmt_merge_order.c create mode 100644 test/stmt/p96_stmt_merge.c create mode 100644 test/stmt/p96_stmt_null.c create mode 100644 test/stmt/p97_stmt_type.c create mode 100644 test/stmt/p98_drds.c create mode 100644 test/stmt/p98_stmt_mix.c create mode 100644 test/stmt/p99_stmt_normal.c create mode 100644 test/stmt/p9_long_field.c diff --git a/test/p20_stmt_fetch_and_cursor.c b/test/p20_stmt_fetch_and_cursor.c index 8521095..2a27323 100644 --- a/test/p20_stmt_fetch_and_cursor.c +++ b/test/p20_stmt_fetch_and_cursor.c @@ -141,7 +141,7 @@ int main (int argc, char *argv[]) { row_count = 0; while(!mysql_stmt_fetch(stmt)) { // here return resultset - printf("%d - %s\n", int_data, str_data); + printf("#####%d - %s\n", int_data, str_data); } mysql_stmt_close(stmt); diff --git a/test/stmt/a.c b/test/stmt/a.c new file mode 100644 index 0000000..265311b --- /dev/null +++ b/test/stmt/a.c @@ -0,0 +1,8 @@ +#include +#include + +int main() { + char *c = "abcdefg"; + printf("%3x\n", c); + return 0; +} diff --git a/test/stmt/bak_p23.c b/test/stmt/bak_p23.c new file mode 100644 index 0000000..9f407b8 --- /dev/null +++ b/test/stmt/bak_p23.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + // simple + char sql[100] = {}; + + sprintf(sql, "INSERT INTO blob_test(a, b) VALUE (1, 2)"); + + mysql_query(sock, sql); + + mysql_query(sock, "select * from blob_test"); + + result = mysql_store_result(mysql); + mysql_free_result(result); + + #define INSERT_QUERY "INSERT INTO blob_test(a, b) VALUES(?,?)" + + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + long length; + int int_data = 10; + char str[100]; + int ret; + + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, INSERT_QUERY, strlen(INSERT_QUERY)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_BLOB; + bind[1].buffer = (char*)&str; + bind[1].is_null= 0; + mysql_stmt_bind_param(stmt, bind); + + ret = mysql_stmt_send_long_data(stmt,1,"MySQL",5); + + ret = mysql_stmt_send_long_data(stmt,1," - The most popular Open Source database",40); + + mysql_stmt_execute(stmt); + + return 0; +} + diff --git a/test/stmt/p1.c b/test/stmt/p1.c new file mode 100644 index 0000000..80c7f58 --- /dev/null +++ b/test/stmt/p1.c @@ -0,0 +1,293 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* + +create table test1(byteCol tinyint, blobCol blob, dateCol date, decimalCol decimal, doubleCol double, floatCol float, intCol int, longCol bigint, nullCol int, shortcol smallint, medCol mediumint, stringCol varchar(300), timeCol time, timestampCol timestamp); + +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field + +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 VARCHAR(40), col21 varchar(40), col22 varchar(40), col3 SMALLINT, col4 TIMESTAMP, col5 datetime, col6 date, col7 time)" +#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2,col3, col4, col5, col6, col7, col21, col22) VALUES(?,?,?,?,?,?,?, ?, ?)" +#define INSERT_SAMPLE2 "INSERT INTO test_table(col1,col2,col3) VALUES(?,?,?)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + //mysql_real_connect(mysql, "127.0.0.1", "test", "test", "test", 3306, NULL, 0); + //mysql_real_connect(mysql, "10.1.170.196", "root", "root", "test", 3306, NULL, 0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[9]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE_TABLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + /* Prepare an INSERT query with 3 parameters */ + /* (the TIMESTAMP column is not named; the server */ + /* sets it to the current date and time) */ + stmt = mysql_stmt_init(mysql); + if (!stmt) + { + fprintf(stderr, " mysql_stmt_init(), out of memory\n"); + exit(0); + } + if (mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE))) + { + fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + fprintf(stdout, " prepare, INSERT successful\n"); + + /* Get the parameter count from the statement */ + param_count= mysql_stmt_param_count(stmt); + fprintf(stdout, " total parameters in INSERT: %d\n", param_count); + + /* Bind the data for all 3 parameters */ + + memset(bind, 0, sizeof(bind)); + + /* INTEGER PARAM */ + /* This is a number type, so there is no need to specify buffer_length */ + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + + /* STRING PARAM */ + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + //bind[1].buffer_length= STRING_SIZE; //最大长度, string not use this, 其它类型buffer_length 也没用 + bind[1].is_null= 0; + bind[1].length= &str_length; //实际大小, bind_ + + /* SMALLINT PARAM */ + bind[2].buffer_type= MYSQL_TYPE_SHORT; + bind[2].buffer= (char *)&small_data; + bind[2].is_null= &is_null; + + /* timestamp */ + + MYSQL_TIME t; + bind[3].buffer_type= MYSQL_TYPE_TIMESTAMP; + bind[3].buffer= (char*)&t; + bind[3].is_null= 0; + + bind[4].buffer_type= MYSQL_TYPE_DATETIME; + bind[4].buffer= (char*)&t; + bind[4].is_null= 0; + + bind[5].buffer_type= MYSQL_TYPE_DATE; + bind[5].buffer= (char*)&t; + bind[5].is_null= 0; + + bind[6].buffer_type= MYSQL_TYPE_TIME; + bind[6].buffer= (char*)&t; + bind[6].is_null= 0; + + bind[7].buffer_type= MYSQL_TYPE_STRING; + bind[7].buffer= (char *)str_data; + //bind[1].buffer_length= STRING_SIZE; //最大长度, string not use this, 其它类型buffer_length 也没用 + bind[7].is_null= 0; + bind[7].length= &str_length; //实际大小, bind_ + + bind[8].buffer_type= MYSQL_TYPE_NULL; + bind[8].buffer= (char *)str_data; + //bind[1].buffer_length= STRING_SIZE; //最大长度, string not use this, 其它类型buffer_length 也没用 + bind[8].is_null= 0; + bind[8].length= &str_length; //实际大小, bind_ + + /* Bind the buffers */ + if (mysql_stmt_bind_param(stmt, bind)) + { + fprintf(stderr, " mysql_stmt_bind_param() failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + /* Specify the data values for the first row -------------------------------------------------- */ + int_data= 10; /* integer */ + strncpy(str_data, "MySQL", STRING_SIZE); /* string */ + str_length= strlen(str_data); + + t.year= 2032; + t.month= 02; + t.day= 03; + + t.hour= 10; + t.minute= 45; + t.second= 20; + + /* INSERT SMALLINT data as NULL */ + is_null= 1; + + /* Execute the INSERT statement - 1*/ + if (mysql_stmt_execute(stmt)) + { + fprintf(stderr, " mysql_stmt_execute(), 1 failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + int_data= 333; /* integer */ + mysql_stmt_execute(stmt); + + /* Get the total number of affected rows */ + affected_rows= mysql_stmt_affected_rows(stmt); + fprintf(stdout, " total affected rows(insert 1): %lu\n", + (unsigned long) affected_rows); + + if (affected_rows != 1) /* validate affected rows */ + { + fprintf(stderr, " invalid affected rows by MySQL\n"); + exit(0); + } + + /* Specify data values for second row, then re-execute the statement ----------------------------------------*/ + int_data= 1000; + strncpy(str_data, "The most popular Open Source database", STRING_SIZE); + str_length= strlen(str_data); + small_data= 1000; /* smallint */ + is_null= 0; /* reset */ + + /* Execute the INSERT statement - 2*/ + if (mysql_stmt_execute(stmt)) + { + fprintf(stderr, " mysql_stmt_execute, 2 failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + /* Get the total rows affected */ + affected_rows= mysql_stmt_affected_rows(stmt); + fprintf(stdout, " total affected rows(insert 2): %lu\n", + (unsigned long) affected_rows); + + if (affected_rows != 1) /* validate affected rows */ + { + fprintf(stderr, " invalid affected rows by MySQL\n"); + exit(0); + } + + /* Specify data values for third row, then re-execute the statement */ + int_data= 1000; + strncpy(str_data, "The most popular Open Source database11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", STRING_SIZE); + str_length= strlen(str_data); + small_data= 10000; /* smallint */ + is_null= 0; /* reset */ + + /* Execute the INSERT statement - 2*/ + if (mysql_stmt_execute(stmt)) + { + fprintf(stderr, " mysql_stmt_execute, 2 failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + /* Get the total rows affected */ + affected_rows= mysql_stmt_affected_rows(stmt); + fprintf(stdout, " total affected rows(insert 2): %lu\n", + (unsigned long) affected_rows); + + if (affected_rows != 1) /* validate affected rows */ + { + fprintf(stderr, " invalid affected rows by MySQL\n"); + exit(0); + } + + //----------------------------- + + MYSQL_STMT *stmt2; + MYSQL_BIND bind2[3]; + + stmt2 = mysql_stmt_init(mysql); + + //here get stmt_id + mysql_stmt_prepare(stmt2, INSERT_SAMPLE2, strlen(INSERT_SAMPLE2)); + + memset(bind2, 0, sizeof(bind2)); + + /* INTEGER PARAM */ + /* This is a number type, so there is no need to specify buffer_length */ + bind2[0].buffer_type= MYSQL_TYPE_LONG; + bind2[0].buffer= (char *)&int_data; + bind2[0].is_null= 0; + + /* STRING PARAM */ + bind2[1].buffer_type= MYSQL_TYPE_STRING; + bind2[1].buffer= (char *)str_data; + //bind[1].buffer_length= STRING_SIZE; //最大长度, string not use this, 其它类型buffer_length 也没用 + bind2[1].is_null= 0; + bind2[1].length= &str_length; //实际大小, bind_ + + /* SMALLINT PARAM */ + bind2[2].buffer_type= MYSQL_TYPE_SHORT; + bind2[2].buffer= (char *)&small_data; + bind2[2].is_null= &is_null; + + /* Bind the buffers */ + mysql_stmt_bind_param(stmt2, bind2); + + /* Specify the data values for the first row -------------------------------------------------- */ + int_data= 999; /* integer */ + strncpy(str_data, "LALA", STRING_SIZE); /* string */ + str_length= strlen(str_data); + + t.year= 2017; + t.month= 02; + t.day= 03; + + t.hour= 10; + t.minute= 45; + t.second= 20; + + /* INSERT SMALLINT data as NULL */ + is_null= 1; + + /* Execute the INSERT statement - 1*/ + mysql_stmt_execute(stmt2); + + mysql_stmt_execute(stmt); + + /* Close the statement */ + mysql_stmt_close(stmt2); + + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p10_use_db.c b/test/stmt/p10_use_db.c new file mode 100644 index 0000000..2cf2860 --- /dev/null +++ b/test/stmt/p10_use_db.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + char *sql; + + int i; + + for(i = 0; i < 10000; i++) { + //1 + mysql_select_db(sock, "mysql"); + + //2 + sql = "use test"; + mysql_query(sock, sql); + + mysql_query(sock, "select * from n"); + + result = mysql_store_result(sock); + + mysql_free_result(result); + + //3 + mysql_select_db(sock, "information_schema"); + } + + mysql_close(mysql); + + return 0; +} diff --git a/test/stmt/p11_sqlcollect_size_too_big.c b/test/stmt/p11_sqlcollect_size_too_big.c new file mode 100644 index 0000000..738fdae --- /dev/null +++ b/test/stmt/p11_sqlcollect_size_too_big.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + char *sql = " select 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"; + + int i; + + for(i = 0; i < 10000; i++) { + mysql_query(sock, sql); + result = mysql_store_result(sock); + mysql_free_result(result); + } + + mysql_close(mysql); + + return 0; +} diff --git a/test/stmt/p12_perf_test.c b/test/stmt/p12_perf_test.c new file mode 100644 index 0000000..171c114 --- /dev/null +++ b/test/stmt/p12_perf_test.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + int i; + + char *sql = "select 111111111111111111111111111111111111111111111111111111111111111111111111111"; + + while(1) { + mysql_query(sock, sql); + result = mysql_store_result(sock); + mysql_free_result(result); + } + + mysql_close(mysql); + + return 0; +} diff --git a/test/stmt/p13_com_field_list.c b/test/stmt/p13_com_field_list.c new file mode 100644 index 0000000..a3e26ca --- /dev/null +++ b/test/stmt/p13_com_field_list.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + char *sql; + + int i; + + mysql_list_fields(mysql, "a1", ""); + + sleep(3); + + mysql_close(mysql); + + return 0; +} diff --git a/test/stmt/p14_local_file.c b/test/stmt/p14_local_file.c new file mode 100644 index 0000000..a3e26ca --- /dev/null +++ b/test/stmt/p14_local_file.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + char *sql; + + int i; + + mysql_list_fields(mysql, "a1", ""); + + sleep(3); + + mysql_close(mysql); + + return 0; +} diff --git a/test/stmt/p15_com_test.c b/test/stmt/p15_com_test.c new file mode 100644 index 0000000..e9ed667 --- /dev/null +++ b/test/stmt/p15_com_test.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + char *sql; + + int i; + + /*list dbs*/ + mysql_list_dbs(mysql, ""); + result = mysql_store_result(mysql); + mysql_free_result(result); + + /* COM_FERESH */ + mysql_refresh(mysql, REFRESH_TABLES); + + /* COM_PROCESS_INFO */ + mysql_list_processes(mysql); + result = mysql_store_result(mysql); + mysql_free_result(result); + + /* create db */ + //mysql_create_db(mysql, "new_test"); + + mysql_set_server_option(mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); + + mysql_change_user(mysql, "kkk", "kkk", "test"); + + sleep(3); + mysql_close(mysql); + + return 0; +} diff --git a/test/stmt/p16_long_preprare.c b/test/stmt/p16_long_preprare.c new file mode 100644 index 0000000..021955f --- /dev/null +++ b/test/stmt/p16_long_preprare.c @@ -0,0 +1,201 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* + +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field + +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 VARCHAR(1024), col21 varchar(40), col22 varchar(40), col3 SMALLINT, col4 TIMESTAMP, col5 datetime, col6 date, col7 time)" +#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2,col3, col4, col5, col6, col7, col21, col22) VALUES(?,?,?,?,?,?,?, ?, ?)" +#define INSERT_SAMPLE2 "INSERT INTO test_table(col1,col2,col3) VALUES(?,?,?)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[9]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE_TABLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + /* Prepare an INSERT query with 3 parameters */ + /* (the TIMESTAMP column is not named; the server */ + /* sets it to the current date and time) */ + stmt = mysql_stmt_init(mysql); + if (!stmt) + { + fprintf(stderr, " mysql_stmt_init(), out of memory\n"); + exit(0); + } + if (mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE))) + { + fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + fprintf(stdout, " prepare, INSERT successful\n"); + + /* Bind the data for all 3 parameters */ + + memset(bind, 0, sizeof(bind)); + + /* INTEGER PARAM */ + /* This is a number type, so there is no need to specify buffer_length */ + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + + /* STRING PARAM */ + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + //bind[1].buffer_length= STRING_SIZE; //最大长度, string not use this, 其它类型buffer_length 也没用 + bind[1].is_null= 0; + bind[1].length= &str_length; //实际大小, bind_ + + /* SMALLINT PARAM */ + bind[2].buffer_type= MYSQL_TYPE_SHORT; + bind[2].buffer= (char *)&small_data; + bind[2].is_null= &is_null; + + /* timestamp */ + + MYSQL_TIME t; + bind[3].buffer_type= MYSQL_TYPE_TIMESTAMP; + bind[3].buffer= (char*)&t; + bind[3].is_null= 0; + + bind[4].buffer_type= MYSQL_TYPE_DATETIME; + bind[4].buffer= (char*)&t; + bind[4].is_null= 0; + + bind[5].buffer_type= MYSQL_TYPE_DATE; + bind[5].buffer= (char*)&t; + bind[5].is_null= 0; + + bind[6].buffer_type= MYSQL_TYPE_TIME; + bind[6].buffer= (char*)&t; + bind[6].is_null= 0; + + bind[7].buffer_type= MYSQL_TYPE_STRING; + bind[7].buffer= (char *)str_data; + //bind[1].buffer_length= STRING_SIZE; //最大长度, string not use this, 其它类型buffer_length 也没用 + bind[7].is_null= 0; + bind[7].length= &str_length; //实际大小, bind_ + + bind[8].buffer_type= MYSQL_TYPE_NULL; + bind[8].buffer= (char *)str_data; + //bind[1].buffer_length= STRING_SIZE; //最大长度, string not use this, 其它类型buffer_length 也没用 + bind[8].is_null= 0; + bind[8].length= &str_length; //实际大小, bind_ + + /* Bind the buffers */ + if (mysql_stmt_bind_param(stmt, bind)) + { + fprintf(stderr, " mysql_stmt_bind_param() failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + /* Specify the data values for the first row -------------------------------------------------- */ + int_data= 10; /* integer */ + strncpy(str_data, "MySQL", STRING_SIZE); /* string */ + str_length= strlen(str_data); + + t.year= 2032; + t.month= 02; + t.day= 03; + + t.hour= 10; + t.minute= 45; + t.second= 20; + + /* INSERT SMALLINT data as NULL */ + is_null= 1; + + /* Execute the INSERT statement - 1*/ + if (mysql_stmt_execute(stmt)) + { + fprintf(stderr, " mysql_stmt_execute(), 1 failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + /* Get the total number of affected rows */ + affected_rows= mysql_stmt_affected_rows(stmt); + fprintf(stdout, " total affected rows(insert 1): %lu\n", + (unsigned long) affected_rows); + + if (affected_rows != 1) /* validate affected rows */ + { + fprintf(stderr, " invalid affected rows by MySQL\n"); + exit(0); + } + + /* Specify data values for second row, then re-execute the statement ----------------------------------------*/ + int_data= 1000; + /* 1024 too long */ + snprintf(str_data, STRING_SIZE, "%s", "The most popular Open S11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111ource database"); + + str_length= strlen(str_data); + small_data= 1000; /* smallint */ + is_null= 0; /* reset */ + + /* Execute the INSERT statement - 2*/ + if (mysql_stmt_execute(stmt)) + { + fprintf(stderr, " mysql_stmt_execute, 2 failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + /* Get the total rows affected */ + affected_rows= mysql_stmt_affected_rows(stmt); + fprintf(stdout, " total affected rows(insert 2): %lu\n", + (unsigned long) affected_rows); + + if (affected_rows != 1) /* validate affected rows */ + { + fprintf(stderr, " invalid affected rows by MySQL\n"); + exit(0); + } + + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p17_mix_sql_prepare.c b/test/stmt/p17_mix_sql_prepare.c new file mode 100644 index 0000000..77b011e --- /dev/null +++ b/test/stmt/p17_mix_sql_prepare.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* + +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field + +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 varchar(40))" +#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2) VALUES(?,?)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + mysql_query(mysql, DROP_SAMPLE_TABLE); + + mysql_query(mysql, CREATE_SAMPLE_TABLE); + + stmt = mysql_stmt_init(mysql); + + mysql_query(mysql, "select 1 from test_table"); // -------------------1 ok + result = mysql_store_result(mysql); + while(mysql_fetch_row(result)); + mysql_free_result(result); + + mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE)); + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].is_null= 0; + bind[1].length= &str_length; //实际大小, bind_ + mysql_stmt_bind_param(stmt, bind); + + int_data= 2; /* integer */ + strncpy(str_data, "MySQL", STRING_SIZE); /* string */ + str_length= strlen(str_data); + + mysql_stmt_execute(stmt); // --------------------------2 ok + + mysql_query(mysql, "select 3 from test_table"); // -------------------3 + result = mysql_store_result(mysql); + while(mysql_fetch_row(result)); + mysql_free_result(result); + + mysql_query(mysql, "select 4 from test_table"); // --------------------4 + result = mysql_store_result(mysql); + while(mysql_fetch_row(result)); + mysql_free_result(result); + + int_data= 5; /* integer */ + strncpy(str_data, "MySQL11111111", STRING_SIZE); /* string */ + str_length= strlen(str_data); + + mysql_stmt_execute(stmt); // failure for prepare sql cover by normal sql + + mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE)); + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].is_null= 0; + bind[1].length= &str_length; //实际大小, bind_ + mysql_stmt_bind_param(stmt, bind); + + int_data= 6; /* integer */ + strncpy(str_data, "MySQL11111111", STRING_SIZE); /* string */ + str_length= strlen(str_data); + + mysql_stmt_execute(stmt); // success + + mysql_query(mysql, "select 7 from test_table"); // success + + int_data= 8; + mysql_stmt_execute(stmt); //failure + + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p18_mix_prepare.c b/test/stmt/p18_mix_prepare.c new file mode 100644 index 0000000..3dcea82 --- /dev/null +++ b/test/stmt/p18_mix_prepare.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* + +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field + +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 varchar(40))" +#define INSERT_SAMPLE "INSERT INTO test_table(col1, col2) VALUES(?,?)" +#define INSERT_SAMPLE2 "INSERT INTO test_table(col1) VALUES(?)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE_TABLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + //1--- + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + + stmt = mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].is_null= 0; + bind[1].length= &str_length; //实际大小, bind_ + mysql_stmt_bind_param(stmt, bind); + + int_data= 10; /* integer */ + strncpy(str_data, "MySQL", STRING_SIZE); /* string */ + str_length= strlen(str_data); + mysql_stmt_execute(stmt); //success + + //2---------------- + MYSQL_STMT *stmt2; + MYSQL_BIND bind2[1]; + + stmt2 = mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt2, INSERT_SAMPLE2, strlen(INSERT_SAMPLE2)); + + memset(bind2, 0, sizeof(bind2)); + bind2[0].buffer_type= MYSQL_TYPE_LONG; + bind2[0].buffer= (char *)&int_data; + bind2[0].is_null= 0; + mysql_stmt_bind_param(stmt2, bind2); + + int_data= 999; + mysql_stmt_execute(stmt2); //success + mysql_stmt_execute(stmt); //failure + + mysql_stmt_close(stmt2); + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p19_null_prepare.c b/test/stmt/p19_null_prepare.c new file mode 100644 index 0000000..15742d8 --- /dev/null +++ b/test/stmt/p19_null_prepare.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* + +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field + +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 varchar(40))" +#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2) VALUES(?,?)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + mysql_query(mysql, DROP_SAMPLE_TABLE); + + mysql_query(mysql, CREATE_SAMPLE_TABLE); + + stmt = mysql_stmt_init(mysql); + + char *sql = "select * from test_table"; + + mysql_stmt_prepare(stmt, sql, strlen(sql)); + + mysql_stmt_execute(stmt); // --------------------------2 ok + + while(!mysql_stmt_fetch(stmt)) { // here return resultset + printf("%d - %s\n", int_data, str_data); + } + + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p2.c b/test/stmt/p2.c new file mode 100644 index 0000000..4913e92 --- /dev/null +++ b/test/stmt/p2.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define INSERT_SQL "insert into player_copy(id, name) values(?, ?)" + +void main(int argc, char **argv) +{ + MYSQL *mysql,*sock; + MYSQL_STMT *st; + MYSQL_BIND bind[2]; + + int param_count; + int int_data; + int i; + char str_data[3]; + unsigned long str_length; + my_bool is_null; + + mysql = mysql_init(NULL); + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + mysql_query(sock, "create table player_copy (id int, name varchar(20))"); + + st = mysql_stmt_init(mysql); + mysql_stmt_prepare(st, INSERT_SQL, 47); + param_count = mysql_stmt_param_count(st); + fprintf(stdout, " total parameters in INSERT: %d\n", param_count); + + for (i = 1; i < 1000; i ++) { + int_data = i; + str_data[0] = 'a'; + str_data[1] = 'b'; + str_data[2] = 'c'; + str_length = 3; + is_null = 0; + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= &int_data; + bind[0].is_null= &is_null; + + bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + bind[1].buffer= (char *)str_data; + bind[1].is_null= &is_null; + bind[1].length= &str_length; + + mysql_stmt_bind_param(st, bind); + mysql_stmt_execute(st); + } + + mysql_query(sock, "drop table player_copy"); +} diff --git a/test/stmt/p20_stmt_fetch_and_cursor.c b/test/stmt/p20_stmt_fetch_and_cursor.c new file mode 100644 index 0000000..2a27323 --- /dev/null +++ b/test/stmt/p20_stmt_fetch_and_cursor.c @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* + +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field + +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 varchar(40))" +#define INSERT_SAMPLE "INSERT INTO test_table(col1, col2) VALUES(?,?)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE_TABLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + //1--- + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + + stmt = mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].is_null= 0; + bind[1].length= &str_length; //实际大小, bind_ + mysql_stmt_bind_param(stmt, bind); + + int_data= 10; /* integer */ + strncpy(str_data, "MySQL", STRING_SIZE); /* string */ + str_length= strlen(str_data); + mysql_stmt_execute(stmt); //success + mysql_stmt_execute(stmt); //success + mysql_stmt_execute(stmt); //success + mysql_stmt_execute(stmt); //success + mysql_stmt_execute(stmt); //success + mysql_stmt_execute(stmt); //success + + mysql_stmt_close(stmt); + + // no cursor + stmt = mysql_stmt_init(mysql); + char *sql = "select 1 from test_table"; + unsigned long type = (unsigned long) CURSOR_TYPE_NO_CURSOR; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + mysql_stmt_prepare(stmt, sql, strlen(sql)); + mysql_stmt_execute(stmt); //success + mysql_stmt_close(stmt); + + // cursor read only + stmt = mysql_stmt_init(mysql); + sql = "select * from test_table"; + type = (unsigned long) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + mysql_stmt_prepare(stmt, sql, strlen(sql)); + mysql_stmt_execute(stmt); // not return resultset + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].buffer_length= STRING_SIZE; + mysql_stmt_bind_result(stmt, bind); + mysql_stmt_store_result(stmt); + + int row_count = 0; + while(!mysql_stmt_fetch(stmt)) { // here return resultset + printf("%d - %s\n", int_data, str_data); + } + + mysql_stmt_close(stmt); + + // set num + stmt = mysql_stmt_init(mysql); + sql = "select a.* from test_table a"; + type = (unsigned long) CURSOR_TYPE_READ_ONLY; + unsigned long prefetch_rows = 2; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, (void*) &prefetch_rows); + + mysql_stmt_prepare(stmt, sql, strlen(sql)); + mysql_stmt_execute(stmt); // not return resultset + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)str_data; + bind[1].buffer_length= STRING_SIZE; + mysql_stmt_bind_result(stmt, bind); + mysql_stmt_store_result(stmt); + + row_count = 0; + while(!mysql_stmt_fetch(stmt)) { // here return resultset + printf("#####%d - %s\n", int_data, str_data); + } + + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p21_long_preprare_ok.c b/test/stmt/p21_long_preprare_ok.c new file mode 100644 index 0000000..5c76a74 --- /dev/null +++ b/test/stmt/p21_long_preprare_ok.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include + +#include "c.h" + +#define STRING_SIZE 1024 + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS dd1dd;" + +#define CREATE_SAMPLE "create table dd1dd(a int,nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn text(1000), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb9 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb9 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz2 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz9 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz10 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbe text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbj text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbl text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbm text(1000));" + +#define select_SAMPLE2 " select * from dd1dd;" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + + MYSQL_STMT *stmt; + + stmt = mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt, select_SAMPLE2, strlen(select_SAMPLE2)); + + mysql_stmt_execute(stmt); + + sleep(3); + mysql_close(mysql); +} diff --git a/test/stmt/p22_blob.c b/test/stmt/p22_blob.c new file mode 100644 index 0000000..da67223 --- /dev/null +++ b/test/stmt/p22_blob.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + if (!(sock = CONN(CLIENT_MULTI_STATEMENTS))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + // simple + char sql[100] = {}; + + sprintf(sql, "INSERT INTO blob_test(a, b) VALUE (1, 2)"); + + mysql_query(sock, sql); + + mysql_query(sock, "select * from blob_test"); + + result = mysql_store_result(mysql); + mysql_free_result(result); + + //prepare + + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[1000]; + unsigned long str_length; + my_bool is_null; + + stmt = mysql_stmt_init(mysql); + + sprintf(sql, "INSERT INTO blob_test(a, b) VALUE (?, ?)"); + mysql_stmt_prepare(stmt, sql, strlen(sql)); + + memset(bind, 0, sizeof(bind)); + + /* INTEGER PARAM */ + /* This is a number type, so there is no need to specify buffer_length */ + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + + /* STRING PARAM */ + my_bool a = 1; + bind[1].buffer_type= MYSQL_TYPE_BLOB; + bind[1].buffer= (char *)str_data; + bind[1].is_null= &a; + bind[1].length= &str_length; //实际大小, bind_ + + mysql_stmt_bind_param(stmt, bind); + + /* Specify the data values for the first row -------------------------------------------------- */ + int_data= 10; /* integer */ + strncpy(str_data, "MySQL", 1000); /* string */ + str_length= strlen(str_data); + + mysql_stmt_execute(stmt); + + mysql_stmt_close(stmt); + + return 0; +} + diff --git a/test/stmt/p23_stmt_send_long_data.c b/test/stmt/p23_stmt_send_long_data.c new file mode 100644 index 0000000..9f407b8 --- /dev/null +++ b/test/stmt/p23_stmt_send_long_data.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + // simple + char sql[100] = {}; + + sprintf(sql, "INSERT INTO blob_test(a, b) VALUE (1, 2)"); + + mysql_query(sock, sql); + + mysql_query(sock, "select * from blob_test"); + + result = mysql_store_result(mysql); + mysql_free_result(result); + + #define INSERT_QUERY "INSERT INTO blob_test(a, b) VALUES(?,?)" + + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + long length; + int int_data = 10; + char str[100]; + int ret; + + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, INSERT_QUERY, strlen(INSERT_QUERY)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_BLOB; + bind[1].buffer = (char*)&str; + bind[1].is_null= 0; + mysql_stmt_bind_param(stmt, bind); + + ret = mysql_stmt_send_long_data(stmt,1,"MySQL",5); + + ret = mysql_stmt_send_long_data(stmt,1," - The most popular Open Source database",40); + + mysql_stmt_execute(stmt); + + return 0; +} + diff --git a/test/stmt/p24_stmt_send_long_data2.c b/test/stmt/p24_stmt_send_long_data2.c new file mode 100644 index 0000000..bd72d4f --- /dev/null +++ b/test/stmt/p24_stmt_send_long_data2.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + // simple + char sql[100] = {}; + + sprintf(sql, "INSERT INTO blob_test(a, b) VALUE (1, 2)"); + + mysql_query(sock, sql); + + mysql_query(sock, "select * from blob_test"); + + result = mysql_store_result(mysql); + mysql_free_result(result); + + #define INSERT_QUERY "INSERT INTO blob_test(a, b) VALUES(?,?)" + + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + long length; + int int_data = 10; + char str[100]; + int ret; + + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, INSERT_QUERY, strlen(INSERT_QUERY)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_BLOB; + bind[1].buffer = (char*)&str; + bind[1].is_null= 0; + mysql_stmt_bind_param(stmt, bind); + + ret = mysql_stmt_send_long_data(stmt,1,"fails",5); + + ret = mysql_stmt_send_long_data(stmt,1," - The most popular Open Source database",40); + + mysql_stmt_execute(stmt); + + mysql_stmt_close(stmt); + + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, INSERT_QUERY, strlen(INSERT_QUERY)); + + size_t s = sizeof(str); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + bind[1].buffer_type= MYSQL_TYPE_BLOB; + bind[1].buffer = (char*)&str; + bind[1].is_null= 0; + bind[1].length= (char*)&s; + mysql_stmt_bind_param(stmt, bind); + + snprintf(str, sizeof(str), "%s", "this success"); + + mysql_stmt_execute(stmt); + + mysql_stmt_close(stmt); + + return 0; +} + diff --git a/test/stmt/p27_big_prepare_resultset.c b/test/stmt/p27_big_prepare_resultset.c new file mode 100644 index 0000000..5c76a74 --- /dev/null +++ b/test/stmt/p27_big_prepare_resultset.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include + +#include "c.h" + +#define STRING_SIZE 1024 + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS dd1dd;" + +#define CREATE_SAMPLE "create table dd1dd(a int,nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn text(1000), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb9 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb9 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz2 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz9 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz10 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbe text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbj text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbl text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbm text(1000));" + +#define select_SAMPLE2 " select * from dd1dd;" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + + MYSQL_STMT *stmt; + + stmt = mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt, select_SAMPLE2, strlen(select_SAMPLE2)); + + mysql_stmt_execute(stmt); + + sleep(3); + mysql_close(mysql); +} diff --git a/test/stmt/p28_compress.c b/test/stmt/p28_compress.c new file mode 100644 index 0000000..77e7ccc --- /dev/null +++ b/test/stmt/p28_compress.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include + +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + /* add compress */ + mysql = mysql_init(NULL); + if (!(sock = CONN(CLIENT_COMPRESS))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + char *sql = "select 1"; + + mysql_query(sock, sql); + result= mysql_store_result(sock); + row = mysql_fetch_row(result); + + mysql_set_server_option(mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); + + return 0; +} + diff --git a/test/stmt/p299_stmt_fetch.c b/test/stmt/p299_stmt_fetch.c new file mode 100644 index 0000000..5377298 --- /dev/null +++ b/test/stmt/p299_stmt_fetch.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +#define SELECT_SAMPLE "SELECT c1 from a1" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_RES *prepare_meta_result; + MYSQL_TIME ts; + unsigned long length[1]; + int param_count, column_count, row_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + my_bool is_null[1]; + + // 1. no cursor + stmt = mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt, SELECT_SAMPLE, strlen(SELECT_SAMPLE)); + param_count= mysql_stmt_param_count(stmt); + //prepare_meta_result = mysql_stmt_result_metadata(stmt); + mysql_stmt_execute(stmt); + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + + mysql_stmt_bind_result(stmt, bind); + //mysql_stmt_store_result(stmt); + + while (!mysql_stmt_fetch(stmt)) { + printf("1 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + + // 2. cursor read only + stmt = mysql_stmt_init(mysql); + + unsigned long type = (unsigned long) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + + mysql_stmt_prepare(stmt, SELECT_SAMPLE, strlen(SELECT_SAMPLE)); + param_count= mysql_stmt_param_count(stmt); + //prepare_meta_result = mysql_stmt_result_metadata(stmt); + mysql_stmt_execute(stmt); + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + + mysql_stmt_bind_result(stmt, bind); + //mysql_stmt_store_result(stmt); // default 1 + + while (!mysql_stmt_fetch(stmt)) { + printf("1 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + // 3. set num + stmt = mysql_stmt_init(mysql); + + type = (unsigned long) CURSOR_TYPE_READ_ONLY; + unsigned long prefetch_rows = 2; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, (void*) &prefetch_rows); + + mysql_stmt_prepare(stmt, SELECT_SAMPLE, strlen(SELECT_SAMPLE)); + param_count= mysql_stmt_param_count(stmt); + //prepare_meta_result = mysql_stmt_result_metadata(stmt); + mysql_stmt_execute(stmt); + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + + mysql_stmt_bind_result(stmt, bind); + //mysql_stmt_store_result(stmt); + + while (!mysql_stmt_fetch(stmt)) { + printf("1 - %d \n", int_data); + } + + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p29_stmt_fetch.c b/test/stmt/p29_stmt_fetch.c new file mode 100644 index 0000000..be810f6 --- /dev/null +++ b/test/stmt/p29_stmt_fetch.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +#define SELECT_SAMPLE "SELECT c1 from a1" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_RES *prepare_meta_result; + MYSQL_TIME ts; + unsigned long length[1]; + int param_count, column_count, row_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + my_bool is_null[1]; + + // 1. no cursor + stmt = mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt, SELECT_SAMPLE, strlen(SELECT_SAMPLE)); + param_count= mysql_stmt_param_count(stmt); + //prepare_meta_result = mysql_stmt_result_metadata(stmt); + mysql_stmt_execute(stmt); + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + + mysql_stmt_bind_result(stmt, bind); + mysql_stmt_store_result(stmt); + + while (!mysql_stmt_fetch(stmt)) { + printf("1 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + + // 2. cursor read only + stmt = mysql_stmt_init(mysql); + + unsigned long type = (unsigned long) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + + mysql_stmt_prepare(stmt, SELECT_SAMPLE, strlen(SELECT_SAMPLE)); + param_count= mysql_stmt_param_count(stmt); + //prepare_meta_result = mysql_stmt_result_metadata(stmt); + mysql_stmt_execute(stmt); + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + + mysql_stmt_bind_result(stmt, bind); + mysql_stmt_store_result(stmt); + + while (!mysql_stmt_fetch(stmt)) { + printf("1 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + // 3. set num + stmt = mysql_stmt_init(mysql); + + type = (unsigned long) CURSOR_TYPE_READ_ONLY; + unsigned long prefetch_rows = 2; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, (void*) &prefetch_rows); + + mysql_stmt_prepare(stmt, SELECT_SAMPLE, strlen(SELECT_SAMPLE)); + param_count= mysql_stmt_param_count(stmt); + //prepare_meta_result = mysql_stmt_result_metadata(stmt); + mysql_stmt_execute(stmt); + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + + mysql_stmt_bind_result(stmt, bind); + mysql_stmt_store_result(stmt); + + while (!mysql_stmt_fetch(stmt)) { + printf("1 - %d \n", int_data); + } + + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p3.c b/test/stmt/p3.c new file mode 100644 index 0000000..cda8884 --- /dev/null +++ b/test/stmt/p3.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include "c.h" + +#define STRING_SIZE 1024 + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 VARCHAR(40))" +#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2) VALUES(1, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")" + +#define INSERT_SAMPLE2 "INSERT INTO test_table select * from test_table" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[7]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE_TABLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + int i = 0; + mysql_query(mysql, INSERT_SAMPLE); + for (; i < 16; i++) { + mysql_query(mysql, INSERT_SAMPLE2); + } + mysql_query(mysql, "select * from test_table"); + + /*last data will miss */ + +} diff --git a/test/stmt/p30_explain_error.c b/test/stmt/p30_explain_error.c new file mode 100644 index 0000000..31fdc18 --- /dev/null +++ b/test/stmt/p30_explain_error.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include "c.h" +#define STRING_SIZE 1024 + +#define SQL "explain select aaaa" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[7]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + int id = mysql_query(mysql, SQL); + + result = mysql_store_result(mysql); + + printf("%d %d\n", id, mysql_errno(mysql)); + + if (result) + while(mysql_fetch_row(result)) { + printf("ok\n"); + } + + mysql_close(mysql); +} diff --git a/test/stmt/p4.c b/test/stmt/p4.c new file mode 100644 index 0000000..455f62e --- /dev/null +++ b/test/stmt/p4.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include "c.h" +#define STRING_SIZE 1024 + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 VARCHAR(40))" +#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2) VALUES(1, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")" + +#define INSERT_SAMPLE2 "INSERT INTO test_table select * from test_table" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[7]; + my_ulonglong affected_rows; + int param_count; + short small_data; + int int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null; + + mysql_query(mysql, "select * from d limit 100000"); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_close(mysql); +} diff --git a/test/stmt/p5.c b/test/stmt/p5.c new file mode 100644 index 0000000..0d3a0e9 --- /dev/null +++ b/test/stmt/p5.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include + +#include "c.h" + +#define SQL "select user(), current_user()" + +void main(int argc, char **argv) +{ + MYSQL *mysql,*sock; + MYSQL_STMT *st; + char str[2][50]; + MYSQL_BIND my_bind[2]; + + int param_count; + int int_data; + int i; + char str_data[3]; + unsigned long str_length; + my_bool is_null; + + mysql = mysql_init(NULL); + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + st = mysql_stmt_init(mysql); + mysql_stmt_prepare(st, SQL, strlen(SQL)); + param_count = mysql_stmt_param_count(st); + + bzero((char*) my_bind, sizeof(MYSQL_BIND)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)str[0]; + my_bind[0].buffer_length= sizeof(str[0]); + my_bind[1]= my_bind[0]; + my_bind[1].buffer= (void *)str[1]; + + mysql_stmt_bind_param(st, my_bind); + mysql_stmt_execute(st); + + while (mysql_stmt_fetch(st) != MYSQL_NO_DATA); +} diff --git a/test/stmt/p6.c b/test/stmt/p6.c new file mode 100644 index 0000000..a7cd47f --- /dev/null +++ b/test/stmt/p6.c @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include "c.h" + +#define INSERT_SQL "insert into player_copy(id, name) values(?, ?)" + +void main(int argc, char **argv) +{ + MYSQL *mysql,*sock; + MYSQL_STMT *st; + int rc; + char *sql; + int nData= 1; + char tData= 1; + short sData= 10; + long bData= 20; + MYSQL_BIND my_bind[6]; + + mysql = mysql_init(NULL); + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + rc= mysql_query(sock, "DROP TABLE IF EXISTS test_prepare_ext"); + + sql= (char *)"CREATE TABLE test_prepare_ext" + "(" + " c1 tinyint," + " c2 smallint," + " c3 mediumint," + " c4 int," + " c5 integer," + " c6 bigint," + " c7 float," + " c8 double," + " c9 double precision," + " c10 real," + " c11 decimal(7, 4)," + " c12 numeric(8, 4)," + " c13 date," + " c14 datetime," + " c15 timestamp(14)," + " c16 time," + " c17 year," + " c18 bit," + " c19 bool," + " c20 char," + " c21 char(10)," + " c22 varchar(30)," + " c23 tinyblob," + " c24 tinytext," + " c25 blob," + " c26 text," + " c27 mediumblob," + " c28 mediumtext," + " c29 longblob," + " c30 longtext," + " c31 enum('one', 'two', 'three')," + " c32 set('monday', 'tuesday', 'wednesday'))"; + + rc= mysql_query(sock, sql); + + /* insert by prepare - all integers */ + char *query = (char *)"INSERT INTO test_prepare_ext(c1, c2, c3, c4, c5, c6) VALUES(?, ?, ?, ?, ?, ?)"; + st = mysql_stmt_init(mysql); + mysql_stmt_prepare(st, query, strlen(query)); + + /* Always bzero all members of bind parameter */ + bzero((char*) my_bind, sizeof(my_bind)); + + /*tinyint*/ + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&tData; + + /*smallint*/ + my_bind[1].buffer_type= MYSQL_TYPE_SHORT; + my_bind[1].buffer= (void *)&sData; + + /*mediumint*/ + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + my_bind[2].buffer= (void *)&nData; + + /*int*/ + my_bind[3].buffer_type= MYSQL_TYPE_LONG; + my_bind[3].buffer= (void *)&nData; + + /*integer*/ + my_bind[4].buffer_type= MYSQL_TYPE_LONG; + my_bind[4].buffer= (void *)&nData; + + /*bigint*/ + my_bind[5].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[5].buffer= (void *)&bData; + + rc= mysql_stmt_bind_param(st, my_bind); + + for (nData= 0; nData<10; nData++, tData++, sData++, bData++) + { + rc= mysql_stmt_execute(st); + } + + /* now fetch the results ..*/ + + query = "SELECT c1, c2, c3, c4, c5, c6 FROM test_prepare_ext"; + mysql_stmt_prepare(st, query, strlen(query)); + + /* get the result */ + rc= mysql_stmt_execute(st); + + mysql_stmt_close(st); + + mysql_close(sock); +} diff --git a/test/stmt/p7.c b/test/stmt/p7.c new file mode 100644 index 0000000..5df9b7f --- /dev/null +++ b/test/stmt/p7.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include "c.h" + +void main(int argc, char **argv) +{ + MYSQL *mysql,*sock; + MYSQL_STMT *st; + int rc; + char *sql; + int nData= 1; + char tData= 1; + short sData= 10; + long bData= 20; + MYSQL_BIND my_bind[1]; + + mysql = mysql_init(NULL); + if (!(sock = CONN(0))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + rc= mysql_query(sock, "DROP TABLE IF EXISTS a1"); + + sql= (char *)"CREATE TABLE a1(c1 int)"; + + rc= mysql_query(sock, sql); + + /* insert by prepare - all integers */ + char *query = (char *)"INSERT INTO a1(c1) VALUES(?)"; + st = mysql_stmt_init(mysql); + mysql_stmt_prepare(st, query, strlen(query)); + + /* Always bzero all members of bind parameter */ + bzero((char*) my_bind, sizeof(my_bind)); + + /*tinyint*/ + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&nData; + + rc= mysql_stmt_bind_param(st, my_bind); + + rc= mysql_stmt_execute(st); + + mysql_stmt_close(st); + + mysql_close(sock); +} diff --git a/test/stmt/p8_multi_sql.c b/test/stmt/p8_multi_sql.c new file mode 100644 index 0000000..dfabf3c --- /dev/null +++ b/test/stmt/p8_multi_sql.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + if (!(sock = CONN(CLIENT_MULTI_STATEMENTS))) { + fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(mysql)); + perror(""); + exit(1); + } + + char *sql = "select 1;select * from n"; + + mysql_query(sock, sql); + do + { + printf("total affected rows: %lld\n", mysql_affected_rows(sock)); + if (!(result= mysql_store_result(sock))) + { + printf("Got fatal error processing query\n"); + exit(1); + } + row = mysql_fetch_row(result); + printf("%s\n", row[0]); + mysql_free_result(result); + } while (!mysql_next_result(sock)); + + return 0; +} + diff --git a/test/stmt/p90_store_use_result_stmt_cursor_case.c b/test/stmt/p90_store_use_result_stmt_cursor_case.c new file mode 100644 index 0000000..7229baa --- /dev/null +++ b/test/stmt/p90_store_use_result_stmt_cursor_case.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[1]; + unsigned long length[1]; + int int_data; + + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + CONN(0); + + char *normalSql = "select intcol from test1 where intcol > 1"; + // 1. normal buffer + mysql_query(mysql, normalSql); + result = mysql_store_result(mysql); + while(row = mysql_fetch_row(result)) { + printf("1 - %d\n", atoi(row[0])); + } + mysql_free_result(result); + + // 2. normal unbuffer + mysql_query(mysql, normalSql); + result = mysql_use_result(mysql); + while(row = mysql_fetch_row(result)) { + printf("2 - %d\n", atoi(row[0])); + } + mysql_free_result(result); + + char *stmtSql = "select intcol from test1 where intcol > ?"; + + //3. stmt buffer + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + mysql_stmt_bind_param(stmt, bind); + + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONG; + bResult[0].buffer= (char *)&int_data; + mysql_stmt_bind_result(stmt, bResult); + + int_data= 1; + mysql_stmt_execute(stmt); + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("3 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + // 4. stmt unbuffer + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + mysql_stmt_bind_param(stmt, bind); + + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONG; + bResult[0].buffer= (char *)&int_data; + mysql_stmt_bind_result(stmt, bResult); + + int_data= 1; + mysql_stmt_execute(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("4 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + // 5. stmt server cursor default + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + unsigned long type = (unsigned long) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + mysql_stmt_bind_param(stmt, bind); + + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONG; + bResult[0].buffer= (char *)&int_data; + mysql_stmt_bind_result(stmt, bResult); + + int_data= 1; + mysql_stmt_execute(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("5 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + + // 6. stmt server cursor setting + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + type = (unsigned long) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + + unsigned long prefetch_rows = 2; + mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, (void*) &prefetch_rows); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (char *)&int_data; + mysql_stmt_bind_param(stmt, bind); + + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONG; + bResult[0].buffer= (char *)&int_data; + mysql_stmt_bind_result(stmt, bResult); + + int_data= 1; + mysql_stmt_execute(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("6 - %d \n", int_data); + } + + mysql_stmt_close(stmt); + + mysql_close(mysql); +} diff --git a/test/stmt/p94_stmt_send_long_data.c b/test/stmt/p94_stmt_send_long_data.c new file mode 100644 index 0000000..ee3c06d --- /dev/null +++ b/test/stmt/p94_stmt_send_long_data.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include "c.h" + +int main(int argc, char* argv[]) +{ + MYSQL *mysql,*sock; + MYSQL_ROW row; + MYSQL_RES *result; + + mysql = mysql_init(NULL); + CONN(0); + + // simple + #define QUERY "select longcol, bytecol from test1 where bytecol = ? and stringcol = ?" + + MYSQL_STMT *stmt; + MYSQL_BIND bind[2]; + long length; + char tiny_data ; + long long long_data; + char str[100]; + int ret; + + stmt = mysql_stmt_init(mysql); + + mysql_stmt_prepare(stmt, QUERY, strlen(QUERY)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_TINY; + bind[0].buffer= (char *)&tiny_data; + bind[0].is_null= 0; + + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)&str; + bind[1].is_null= 0; + bind[1].length = &length; + mysql_stmt_bind_param(stmt, bind); + + ret = mysql_stmt_send_long_data(stmt,1,"888888'888888888",strlen("88888'8888888888")); + + //ret = mysql_stmt_send_long_data(stmt,1," - The most popular Open Source database",40); + + MYSQL_BIND bResult[2]; + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&long_data; + + bResult[1].buffer_type= MYSQL_TYPE_TINY; + bResult[1].buffer= (char *)&tiny_data; + + mysql_stmt_bind_result(stmt, bResult); + + tiny_data = 1; + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + int ii = 0; + while(!mysql_stmt_fetch(stmt)) { + printf("1- %d[%lld, %d]\n", ii++, + long_data, tiny_data); + } + + tiny_data = 5; + snprintf(str, sizeof(str), "%s", "99\"9'9"); + length = strlen(str); + + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("2- %d[%lld, %d\n", ii++, + long_data, tiny_data); + } + + // two section + ret = mysql_stmt_send_long_data(stmt,1,"8888888888888",strlen("8888888888888")); + ret = mysql_stmt_send_long_data(stmt,1,"88",strlen("88")); + + tiny_data = 1; + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("3- %d[%lld, %d]\n", ii++, + long_data, tiny_data); + } + + // test reset is ok TODO + return 0; +} + diff --git a/test/stmt/p95.c b/test/stmt/p95.c new file mode 100644 index 0000000..8838556 --- /dev/null +++ b/test/stmt/p95.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS SMALL111" +#define CREATE_SAMPLE_TABLE "CREATE TABLE SMALL111(col1 bigint, col2 int, col21 varchar(40), col22 varchar(40), col3 SMALLINT, col4 TIMESTAMP, col5 datetime, col6 date, col7 time)" +#define INSERT_SAMPLE "INSERT INTO SMALL111(col1,col2,col3, col4, col5, col6, col7, col21, col22) VALUES(10,2,1,1,1,1,1,1,1)" +#define INSERT_SAMPLE1 "INSERT INTO SMALL111(col1,col2,col3, col4, col5, col6, col7, col21, col22) VALUES(2,2,1,1,1,1,1,1,1)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + //CONN(0); + mysql_real_connect(mysql, "10.250.7.14", "test", "test", "test", 3306, NULL, 0); + + //mysql_query(mysql, DROP_SAMPLE_TABLE); + //mysql_query(mysql, CREATE_SAMPLE_TABLE); + //mysql_query(mysql, INSERT_SAMPLE); + //mysql_query(mysql, INSERT_SAMPLE1); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[4]; + MYSQL_BIND bResult[4]; + unsigned long length[4]; + my_ulonglong affected_rows; + int param_count; + short small_data; + //long int_data; + char int_data[100] = ""; + char l2[100] = ""; + long long l1; + long long f1; + length[0] = sizeof(int_data); + length[2] = sizeof(l2); + my_bool is_null[1]; + + is_null[0] = 0; + stmt = mysql_stmt_init(mysql); + if (!stmt) + { + fprintf(stderr, " mysql_stmt_init(), out of memory\n"); + exit(0); + } + + #define SELECT_EXAMPLE "select bytecol, blobcol, datecol, decimalcol, doublecol, floatcol, intcol, longcol, null, shortcol, medcol, stringCol, timecol, timestampcol from test1" + + if (mysql_stmt_prepare(stmt, SELECT_EXAMPLE, strlen(SELECT_EXAMPLE))) + { + fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + fprintf(stdout, " prepare, INSERT successful\n"); + + if (mysql_stmt_execute(stmt)) + { + fprintf(stderr, " mysql_stmt_execute(), 1 failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + while(!mysql_stmt_fetch(stmt)) { + printf("[%s] [%lld] [%s] [%lld]\n", int_data, l1, l2, f1); + } + + mysql_stmt_reset(stmt); + mysql_stmt_close(stmt); + sleep(3); +} diff --git a/test/stmt/p95_stmt_merge_order.c b/test/stmt/p95_stmt_merge_order.c new file mode 100644 index 0000000..54c42c1 --- /dev/null +++ b/test/stmt/p95_stmt_merge_order.c @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[13]; + unsigned long length[3]; + + long long long_data; + char tiny_data; + char blob[1000]; + MYSQL_TIME date; + char decimal[1000]; + double d; + float f; + int i; + short s; + int m; + char str[1000]; + MYSQL_TIME time; + MYSQL_TIME timestamp; + // TODO datetime + // year type + + length[0] = sizeof(str); + length[1] = sizeof(str); + length[2] = sizeof(str); + + stmt = mysql_stmt_init(mysql); + + char *normalSql = "select * from test1"; + char *stmtSql = "select longcol, bytecol, blobcol, datecol, decimalcol, doublecol, floatcol, intcol, nullcol, shortcol, medcol, stringcol, timecol, timestampcol from test1 order by bytecol desc"; + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + /* Bind the data for all 3 parameters */ + +/* + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_TINY; + bind[0].buffer= (char *)&tiny_data; + bind[0].is_null= 0; + + mysql_stmt_bind_param(stmt, bind); + */ + /* + mysql_query(mysql, normalSql); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_free_result(result); + */ + /* --- */ + memset(bResult, 0, sizeof(bResult)); + + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&long_data; + + bResult[1].buffer_type= MYSQL_TYPE_TINY; + bResult[1].buffer= (char *)&tiny_data; + + bResult[2].buffer_type= MYSQL_TYPE_BLOB; + bResult[2].buffer= (char *)&blob; + bResult[2].buffer_length = length[0]; + + bResult[3].buffer_type= MYSQL_TYPE_DATE; + bResult[3].buffer= (char *)&date; + + bResult[4].buffer_type= MYSQL_TYPE_DECIMAL; + bResult[4].buffer= (char *)&decimal; + bResult[4].buffer_length= length[1]; + + bResult[5].buffer_type= MYSQL_TYPE_DOUBLE; + bResult[5].buffer= (char *)&d; + + bResult[6].buffer_type= MYSQL_TYPE_FLOAT; + bResult[6].buffer= (char *)&f; + + bResult[7].buffer_type= MYSQL_TYPE_LONG; + bResult[7].buffer= (char *)&i; + + bResult[8].buffer_type= MYSQL_TYPE_NULL; + + bResult[9].buffer_type= MYSQL_TYPE_SHORT; + bResult[9].buffer= (char *)&s; + + bResult[10].buffer_type= MYSQL_TYPE_INT24; + bResult[10].buffer= (char *)&m; + + bResult[11].buffer_type= MYSQL_TYPE_STRING; + bResult[11].buffer= (char *)&str; + bResult[11].buffer_length = length[2]; + + bResult[12].buffer_type= MYSQL_TYPE_TIME; + bResult[12].buffer= (char *)&time; + + bResult[13].buffer_type= MYSQL_TYPE_TIMESTAMP; + bResult[13].buffer= (char *)×tamp; + + mysql_stmt_bind_result(stmt, bResult); + + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + int ii = 0; + while(!mysql_stmt_fetch(stmt)) { + printf("%d[%lld, %d, %s, %lf, %f, %d, %hd, %d, %s]\n", ii++, + long_data, tiny_data, decimal, d, f, i, s, m, str); + } + + mysql_query(mysql, normalSql); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_free_result(result); + +/* + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("%d[%lld, %d, %s, %lf, %f, %d, %hd, %d, %s, %u, %u, %u, %u,%u,%u, %u, %u, %u, %u, %u, %u ]\n", ii++, + long_data, tiny_data, decimal, d, f, i, s, m, str, + date.year, date.month, date.day, time.hour, time.minute, time.second, + timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second); + } +*/ + mysql_stmt_reset(stmt); + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p96_stmt_merge.c b/test/stmt/p96_stmt_merge.c new file mode 100644 index 0000000..2ba6af1 --- /dev/null +++ b/test/stmt/p96_stmt_merge.c @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[13]; + unsigned long length[3]; + + long long long_data; + char tiny_data; + char blob[1000]; + MYSQL_TIME date; + char decimal[1000]; + double d; + float f; + int i; + short s; + int m; + char str[1000]; + MYSQL_TIME time; + MYSQL_TIME timestamp; + // TODO datetime + // year type + + length[0] = sizeof(str); + length[1] = sizeof(str); + length[2] = sizeof(str); + + stmt = mysql_stmt_init(mysql); + + char *normalSql = "select * from test1"; + char *stmtSql = "select longcol, bytecol, blobcol, datecol, decimalcol, doublecol, floatcol, intcol, nullcol, shortcol, medcol, stringcol, timecol, timestampcol from test1 "; + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + /* Bind the data for all 3 parameters */ + +/* + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_TINY; + bind[0].buffer= (char *)&tiny_data; + bind[0].is_null= 0; + + mysql_stmt_bind_param(stmt, bind); + */ + /* + mysql_query(mysql, normalSql); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_free_result(result); + */ + /* --- */ + memset(bResult, 0, sizeof(bResult)); + + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&long_data; + + bResult[1].buffer_type= MYSQL_TYPE_TINY; + bResult[1].buffer= (char *)&tiny_data; + + bResult[2].buffer_type= MYSQL_TYPE_BLOB; + bResult[2].buffer= (char *)&blob; + bResult[2].buffer_length = length[0]; + + bResult[3].buffer_type= MYSQL_TYPE_DATE; + bResult[3].buffer= (char *)&date; + + bResult[4].buffer_type= MYSQL_TYPE_DECIMAL; + bResult[4].buffer= (char *)&decimal; + bResult[4].buffer_length= length[1]; + + bResult[5].buffer_type= MYSQL_TYPE_DOUBLE; + bResult[5].buffer= (char *)&d; + + bResult[6].buffer_type= MYSQL_TYPE_FLOAT; + bResult[6].buffer= (char *)&f; + + bResult[7].buffer_type= MYSQL_TYPE_LONG; + bResult[7].buffer= (char *)&i; + + bResult[8].buffer_type= MYSQL_TYPE_NULL; + + bResult[9].buffer_type= MYSQL_TYPE_SHORT; + bResult[9].buffer= (char *)&s; + + bResult[10].buffer_type= MYSQL_TYPE_INT24; + bResult[10].buffer= (char *)&m; + + bResult[11].buffer_type= MYSQL_TYPE_STRING; + bResult[11].buffer= (char *)&str; + bResult[11].buffer_length = length[2]; + + bResult[12].buffer_type= MYSQL_TYPE_TIME; + bResult[12].buffer= (char *)&time; + + bResult[13].buffer_type= MYSQL_TYPE_TIMESTAMP; + bResult[13].buffer= (char *)×tamp; + + mysql_stmt_bind_result(stmt, bResult); + + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + int ii = 0; + while(!mysql_stmt_fetch(stmt)) { + printf("%d[%lld, %d, %s, %lf, %f, %d, %hd, %d, %s]\n", ii++, + long_data, tiny_data, decimal, d, f, i, s, m, str); + } + + mysql_query(mysql, normalSql); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_free_result(result); + +/* + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("%d[%lld, %d, %s, %lf, %f, %d, %hd, %d, %s, %u, %u, %u, %u,%u,%u, %u, %u, %u, %u, %u, %u ]\n", ii++, + long_data, tiny_data, decimal, d, f, i, s, m, str, + date.year, date.month, date.day, time.hour, time.minute, time.second, + timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second); + } +*/ + mysql_stmt_reset(stmt); + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p96_stmt_null.c b/test/stmt/p96_stmt_null.c new file mode 100644 index 0000000..9c0f498 --- /dev/null +++ b/test/stmt/p96_stmt_null.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field +*/ + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS SMALL111" +#define CREATE_SAMPLE_TABLE "CREATE TABLE SMALL111(col1 bigint, col2 int, col21 varchar(40), col22 varchar(40), col3 SMALLINT, col4 TIMESTAMP, col5 datetime, col6 date, col7 time)" +#define INSERT_SAMPLE "INSERT INTO SMALL111(col1,col2,col3, col4, col5, col6, col7, col21, col22) VALUES(10,2,1,1,1,1,1,1,1)" +#define INSERT_SAMPLE1 "INSERT INTO SMALL111(col1,col2,col3, col4, col5, col6, col7, col21, col22) VALUES(2,2,1,1,1,1,1,1,1)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + //CONN(0); + mysql_real_connect(mysql, "10.250.7.14", "test", "test", "test", 3306, NULL, 0); + + mysql_query(mysql, DROP_SAMPLE_TABLE); + mysql_query(mysql, CREATE_SAMPLE_TABLE); + mysql_query(mysql, INSERT_SAMPLE); + mysql_query(mysql, INSERT_SAMPLE1); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[1]; + unsigned long length[1]; + my_ulonglong affected_rows; + int param_count; + short small_data; + //long int_data; + char int_data[100] = "abc"; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null[1]; + + is_null[0] = 0; + stmt = mysql_stmt_init(mysql); + if (!stmt) + { + fprintf(stderr, " mysql_stmt_init(), out of memory\n"); + exit(0); + } + + #define SELECT_EXAMPLE "select '111'" + + mysql_query(mysql, SELECT_EXAMPLE); + + result = mysql_store_result(mysql); + while(mysql_fetch_row(result)); + + mysql_stmt_prepare(stmt, SELECT_EXAMPLE, strlen(SELECT_EXAMPLE)); + + mysql_stmt_execute(stmt); + +while(!mysql_stmt_fetch(stmt)) { + printf("aaaa\n"); +} + sleep(3); +} diff --git a/test/stmt/p97_stmt_type.c b/test/stmt/p97_stmt_type.c new file mode 100644 index 0000000..0c92f78 --- /dev/null +++ b/test/stmt/p97_stmt_type.c @@ -0,0 +1,156 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[13]; + unsigned long length[3]; + + long long long_data; + char tiny_data; + char blob[1000]; + MYSQL_TIME date; + char decimal[1000]; + double d; + float f; + int i; + short s; + int m; + char str[1000]; + MYSQL_TIME time; + MYSQL_TIME timestamp; + // TODO datetime + // year type + + length[0] = sizeof(str); + length[1] = sizeof(str); + length[2] = sizeof(str); + + stmt = mysql_stmt_init(mysql); + + char *normalSql = "select * from test1"; + char *stmtSql = "select longcol, bytecol, blobcol, datecol, decimalcol, doublecol, floatcol, intcol, nullcol, shortcol, medcol, stringcol, timecol, timestampcol from test1 where bytecol = ?"; + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + /* Bind the data for all 3 parameters */ + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_TINY; + bind[0].buffer= (char *)&tiny_data; + bind[0].is_null= 0; + + mysql_stmt_bind_param(stmt, bind); + + mysql_query(mysql, normalSql); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_free_result(result); + + /* --- */ + memset(bResult, 0, sizeof(bResult)); + + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&long_data; + + bResult[1].buffer_type= MYSQL_TYPE_TINY; + bResult[1].buffer= (char *)&tiny_data; + + bResult[2].buffer_type= MYSQL_TYPE_BLOB; + bResult[2].buffer= (char *)&blob; + bResult[2].buffer_length = length[0]; + + bResult[3].buffer_type= MYSQL_TYPE_DATE; + bResult[3].buffer= (char *)&date; + + bResult[4].buffer_type= MYSQL_TYPE_DECIMAL; + bResult[4].buffer= (char *)&decimal; + bResult[4].buffer_length= length[1]; + + bResult[5].buffer_type= MYSQL_TYPE_DOUBLE; + bResult[5].buffer= (char *)&d; + + bResult[6].buffer_type= MYSQL_TYPE_FLOAT; + bResult[6].buffer= (char *)&f; + + bResult[7].buffer_type= MYSQL_TYPE_LONG; + bResult[7].buffer= (char *)&i; + + bResult[8].buffer_type= MYSQL_TYPE_NULL; + + bResult[9].buffer_type= MYSQL_TYPE_SHORT; + bResult[9].buffer= (char *)&s; + + bResult[10].buffer_type= MYSQL_TYPE_INT24; + bResult[10].buffer= (char *)&m; + + bResult[11].buffer_type= MYSQL_TYPE_STRING; + bResult[11].buffer= (char *)&str; + bResult[11].buffer_length = length[2]; + + bResult[12].buffer_type= MYSQL_TYPE_TIME; + bResult[12].buffer= (char *)&time; + + bResult[13].buffer_type= MYSQL_TYPE_TIMESTAMP; + bResult[13].buffer= (char *)×tamp; + + mysql_stmt_bind_result(stmt, bResult); + + //singnode + tiny_data = 1; + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + int ii = 0; + while(!mysql_stmt_fetch(stmt)) { + printf("%d[%lld, %d, %s, %lf, %f, %d, %hd, %d, %s]\n", ii++, + long_data, tiny_data, decimal, d, f, i, s, m, str); + } + + mysql_query(mysql, normalSql); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_free_result(result); + + //singnode; + tiny_data = 2; + + mysql_stmt_execute(stmt); + + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("%d[%lld, %d, %s, %lf, %f, %d, %hd, %d, %s, %u, %u, %u, %u,%u,%u, %u, %u, %u, %u, %u, %u ]\n", ii++, + long_data, tiny_data, decimal, d, f, i, s, m, str, + date.year, date.month, date.day, time.hour, time.minute, time.second, + timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second); + } + + mysql_stmt_reset(stmt); + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p98_drds.c b/test/stmt/p98_drds.c new file mode 100644 index 0000000..7b4ffe4 --- /dev/null +++ b/test/stmt/p98_drds.c @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +/* +MYSQL_TYPE_TIMESTAMP TIMESTAMP field +MYSQL_TYPE_DATE DATE field +MYSQL_TYPE_TIME TIME field +MYSQL_TYPE_DATETIME DATETIME field +*/ + +//#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table" +//#define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT, col2 int, col21 varchar(40), col22 varchar(40), col3 SMALLINT, col4 TIMESTAMP, col5 datetime, col6 date, col7 time)" +//#define INSERT_SAMPLE "INSERT INTO test_table(col1,col2,col3, col4, col5, col6, col7, col21, col22) VALUES(1,2,1,1,1,1,1,1,1)" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[1]; + unsigned long length[1]; + my_ulonglong affected_rows; + int param_count; + short small_data; + long long int_data; + char str_data[STRING_SIZE]; + unsigned long str_length; + my_bool is_null[1]; + + is_null[0] = 0; + stmt = mysql_stmt_init(mysql); + if (!stmt) + { + fprintf(stderr, " mysql_stmt_init(), out of memory\n"); + exit(0); + } + + #define SELECT_EXAMPLE "select id from SMALL111 where id > ?" + + if (mysql_stmt_prepare(stmt, SELECT_EXAMPLE, strlen(SELECT_EXAMPLE))) + { + fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + fprintf(stdout, " prepare, INSERT successful\n"); + + /* Bind the data for all 3 parameters */ + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= &is_null[0]; + bind[0].length = &length[0]; + + /* Bind the buffers */ + if (mysql_stmt_bind_param(stmt, bind)) + { + fprintf(stderr, " mysql_stmt_bind_param() failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + int_data= 0x0000000000000001; + + if (mysql_stmt_execute(stmt)) + { + fprintf(stderr, " mysql_stmt_execute(), 1 failed\n"); + fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); + exit(0); + } + + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&int_data; + bResult[0].is_null= &is_null[0]; + bResult[0].length= &length[0]; + + mysql_stmt_bind_result(stmt, bResult); + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("%c-%lld\n", is_null[0], int_data); + } + + mysql_stmt_reset(stmt); + mysql_stmt_close(stmt); + sleep(3); +} diff --git a/test/stmt/p98_stmt_mix.c b/test/stmt/p98_stmt_mix.c new file mode 100644 index 0000000..0909243 --- /dev/null +++ b/test/stmt/p98_stmt_mix.c @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt, *stmt2; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[1]; + MYSQL_BIND bResult2[1]; + unsigned long length[1]; + my_ulonglong affected_rows; + short small_data; + long long long_data; + char int_data; + my_bool is_null; + + stmt = mysql_stmt_init(mysql); + stmt2 = mysql_stmt_init(mysql); + + char *normalSql = "select longcol from test1 where bytecol = 1"; + char *stmtSql = "select longcol from test1 where bytecol = ?"; + //1 + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_TINY; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + mysql_stmt_bind_param(stmt, bind); + //2 + mysql_stmt_prepare(stmt2, normalSql, strlen(normalSql)); + //3 + mysql_query(mysql, normalSql); + result = mysql_store_result(mysql); + while(mysql_fetch_row(result)); + mysql_free_result(result); + + //2 + memset(bResult2, 0, sizeof(bResult2)); + bResult2[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult2[0].buffer= (char *)&long_data; + bResult2[0].is_null= &is_null; + bResult2[0].length= &length[0]; + mysql_stmt_bind_result(stmt2, bResult2); + + //1 + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&long_data; + bResult[0].is_null= &is_null; + bResult[0].length= &length[0]; + mysql_stmt_bind_result(stmt, bResult); + + int_data= 1; + mysql_stmt_execute(stmt2); + mysql_stmt_store_result(stmt2); + + while(!mysql_stmt_fetch(stmt2)) { + printf("2[%lld]\n", long_data); + } + //must execute -> store->fetch over,then mysql is ready status + // other execute + mysql_stmt_execute(stmt); + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("1[%lld]\n", long_data); + } + + mysql_query(mysql, normalSql); + + result = mysql_store_result(mysql); + + while(mysql_fetch_row(result)); + + mysql_free_result(result); + + int_data= 1; + mysql_stmt_execute(stmt); + mysql_stmt_store_result(stmt); + while(!mysql_stmt_fetch(stmt)) { + printf("3[%lld]\n", long_data); + } + + mysql_stmt_execute(stmt2); + + mysql_stmt_store_result(stmt2); + + while(!mysql_stmt_fetch(stmt2)) { + printf("4[%lld]\n", long_data); + } + + mysql_stmt_reset(stmt); + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p99_stmt_normal.c b/test/stmt/p99_stmt_normal.c new file mode 100644 index 0000000..a4722ee --- /dev/null +++ b/test/stmt/p99_stmt_normal.c @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include + +#include "c.h" +#define STRING_SIZE 1024 + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_BIND bResult[1]; + unsigned long length[1]; + my_ulonglong affected_rows; + short small_data; + long long int_data; + char tiny_data; + my_bool is_null; + + stmt = mysql_stmt_init(mysql); + + // normal + // field > 0 and param > 0 + char *stmtSql = "select longcol from test1 where longcol > ?"; + + mysql_stmt_prepare(stmt, stmtSql, strlen(stmtSql)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONGLONG; + bind[0].buffer= (char *)&int_data; + bind[0].is_null= 0; + mysql_stmt_bind_param(stmt, bind); + + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&int_data; + bResult[0].is_null= &is_null; + bResult[0].length= &length[0]; + mysql_stmt_bind_result(stmt, bResult); + + int_data= 1; + mysql_stmt_execute(stmt); + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("1[%lld]\n", int_data); + } + + int_data= 100; + mysql_stmt_execute(stmt); + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("2[%lld]\n", int_data); + } + + int_data= 300; + mysql_stmt_execute(stmt); + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("3[%lld]\n", int_data); + } + + // param = 0 and field > 0 + char *stmtSql2 = "select longcol from test1 where longcol > 1 limit 15"; + + mysql_stmt_prepare(stmt, stmtSql2, strlen(stmtSql2)); + + memset(bResult, 0, sizeof(bResult)); + bResult[0].buffer_type= MYSQL_TYPE_LONGLONG; + bResult[0].buffer= (char *)&int_data; + bResult[0].is_null= &is_null; + bResult[0].length= &length[0]; + mysql_stmt_bind_result(stmt, bResult); + + mysql_stmt_execute(stmt); + mysql_stmt_store_result(stmt); + + while(!mysql_stmt_fetch(stmt)) { + printf("3[%lld]\n", int_data); + } + + // field = 0 and param > 0 + + char *stmtSql3 = "insert into test1(bytecol) values (?)"; + + mysql_stmt_prepare(stmt, stmtSql3, strlen(stmtSql3)); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_TINY; + bind[0].buffer= (char *)&tiny_data; + bind[0].is_null= 0; + mysql_stmt_bind_param(stmt, bind); + + tiny_data = 1; + mysql_stmt_execute(stmt); + + // param = 0 and field = 0 + char *stmtSql4 = "insert into test1(bytecol) values (10)"; + + mysql_stmt_prepare(stmt, stmtSql4, strlen(stmtSql4)); + mysql_stmt_execute(stmt); + + mysql_stmt_reset(stmt); + mysql_stmt_close(stmt); +} diff --git a/test/stmt/p9_long_field.c b/test/stmt/p9_long_field.c new file mode 100644 index 0000000..5d77086 --- /dev/null +++ b/test/stmt/p9_long_field.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +#include "c.h" + +#define STRING_SIZE 1024 + +#define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS dd1dd;" + +#define CREATE_SAMPLE "create table dd1dd(a int,nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn text(1000), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb9 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 text(1000),2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb9 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz1 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz2 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz3 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz4 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz5 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz6 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz7 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz8 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz9 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbz10 text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbd text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbe text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbj text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbl text(1000),bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbm text(1000));" + +#define select_SAMPLE2 " select * from dd1dd;" + +int main (int argc, char *argv[]) { + + MYSQL *mysql; + MYSQL_RES *result; + MYSQL_ROW row; + my_bool reconnect = 0; + mysql = mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + CONN(0); + + if (mysql_query(mysql, DROP_SAMPLE_TABLE)) + { + fprintf(stderr, " DROP TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + if (mysql_query(mysql, CREATE_SAMPLE)) + { + fprintf(stderr, " CREATE TABLE failed\n"); + fprintf(stderr, " %s\n", mysql_error(mysql)); + exit(0); + } + + + + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + mysql_query(mysql, "insert into dd1dd(a) values(1)"); + + mysql_query(mysql, select_SAMPLE2); + + sleep(3); + mysql_close(mysql); +}