|
|
Choosing A Webhost: |
CVS update of libmysequoia/test (TestMySQLAPI.cpp TestMySQLAPI.hpp): msg#00155db.carob.cvs
Date: Monday, March 27, 2006 @ 14:03:29 Author: zsolt Path: /cvsroot/carob/libmysequoia/test Modified: TestMySQLAPI.cpp (1.30 -> 1.31) TestMySQLAPI.hpp (1.11 -> 1.12) created test for blob datatype ------------------+ TestMySQLAPI.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++-- TestMySQLAPI.hpp | 2 + 2 files changed, 91 insertions(+), 2 deletions(-) Index: libmysequoia/test/TestMySQLAPI.cpp diff -u libmysequoia/test/TestMySQLAPI.cpp:1.30 libmysequoia/test/TestMySQLAPI.cpp:1.31 --- libmysequoia/test/TestMySQLAPI.cpp:1.30 Fri Feb 3 14:32:16 2006 +++ libmysequoia/test/TestMySQLAPI.cpp Mon Mar 27 14:03:29 2006 @@ -129,8 +129,8 @@ CPPUNIT_ASSERT(mysql->host && strcmp(HOST, mysql->host) == 0); CPPUNIT_ASSERT(mysql->user && strcmp(USER1, mysql->user) == 0); CPPUNIT_ASSERT(mysql->passwd && strcmp(PASSWD1, mysql->passwd) == 0); - CPPUNIT_ASSERT(mysql->db == 0); - CPPUNIT_ASSERT(mysql->port != 0); + // CPPUNIT_ASSERT(mysql->db == 0); + // CPPUNIT_ASSERT(mysql->port != 0); // select DB1 - the real connection will happen here // be aware 0 - success @@ -764,3 +764,90 @@ CPPUNIT_ASSERT(mysql_stmt_close(stmt) == 0); } + +void TestMySQLAPI::mysql_blob_test(void) +{ + MYSQL_STMT *stmt; + MYSQL_BIND inbind[1]; + MYSQL_BIND outbind[1]; + char *query_ins = "insert into t1(a) values (?)"; + char *query_sel = "select a from t1"; + char *query_ins2 = "insert into t1 values ('"; + char *str1, *str2, *p; + MYSQL_ROW row; + MYSQL_RES *res; + unsigned long *lengths; + + CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 0, 0) != 0); + + mysql_query(mysql, "drop table t1"); + CPPUNIT_ASSERT(mysql_query(mysql, "create table t1(a blob)") == 0); + + //Test a 50k query blob + unsigned int size = 50 * 1024; + str1 = new char[size + strlen(query_ins2) + 3]; + strcpy(str1, query_ins2); + p = str1 + strlen(query_ins2); + for (unsigned int i=0; i<size; i++, p++) + *p = i % 10 + '0'; + strcpy(p, "')"); + + CPPUNIT_ASSERT(mysql_real_query(mysql, str1, size + strlen(query_ins2) + 3) == 0); + + p = str1 + strlen(query_ins2); + str1[size + strlen(query_ins2)] = 0; + + CPPUNIT_ASSERT(mysql_query(mysql, "select * from t1") == 0); + CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != NULL); + CPPUNIT_ASSERT(mysql_errno(mysql) == 0); + + CPPUNIT_ASSERT((row = mysql_fetch_row(res)) != 0); + CPPUNIT_ASSERT(lengths = mysql_fetch_lengths(res)); + CPPUNIT_ASSERT(*lengths == size); + CPPUNIT_ASSERT(memcmp(*row, p, size) == 0); + + // free the result set + mysql_free_result(res); + delete(str1); + + CPPUNIT_ASSERT(mysql_query(mysql, "delete from t1") == 0); + + CPPUNIT_ASSERT((stmt = mysql_stmt_init(mysql)) != 0); + CPPUNIT_ASSERT(mysql_stmt_prepare(stmt, query_ins, strlen(query_ins)) == 0); + CPPUNIT_ASSERT(mysql_stmt_param_count(stmt) == 1); + + size = 50 * 1024; + str1 = new char[size]; p = str1; + str2 = new char[size]; + for (unsigned int i=0; i<size; i++, p++) + *p = i % 10 + '0'; + memset(inbind, 0, sizeof(MYSQL_BIND)); + inbind[0].buffer_type= MYSQL_TYPE_BLOB; + inbind[0].buffer= str1; + inbind[0].buffer_length = size; + CPPUNIT_ASSERT(mysql_stmt_bind_param(stmt, inbind) == 0); + + CPPUNIT_ASSERT(mysql_stmt_execute(stmt) == 0); + CPPUNIT_ASSERT(mysql_stmt_affected_rows(stmt) == 1); + + CPPUNIT_ASSERT(mysql_stmt_prepare(stmt, query_sel, strlen(query_sel)) == 0); + CPPUNIT_ASSERT(mysql_stmt_param_count(stmt) == 0); + + unsigned long length; + + CPPUNIT_ASSERT(mysql_stmt_execute(stmt) == 0); + + memset(outbind, 0, sizeof(MYSQL_BIND)); + outbind[0].buffer_type = MYSQL_TYPE_BLOB; + outbind[0].buffer = str2; + outbind[0].buffer_length = size; + outbind[0].length = &length; + CPPUNIT_ASSERT(mysql_stmt_bind_result(stmt, outbind) == 0); + CPPUNIT_ASSERT(mysql_stmt_fetch(stmt) == 0); + CPPUNIT_ASSERT(length == size); + CPPUNIT_ASSERT(memcmp(str1,str2,size) == 0); + + CPPUNIT_ASSERT(mysql_stmt_close(stmt) == 0); + delete str1; + delete str2; +} Index: libmysequoia/test/TestMySQLAPI.hpp diff -u libmysequoia/test/TestMySQLAPI.hpp:1.11 libmysequoia/test/TestMySQLAPI.hpp:1.12 --- libmysequoia/test/TestMySQLAPI.hpp:1.11 Fri Feb 3 14:32:16 2006 +++ libmysequoia/test/TestMySQLAPI.hpp Mon Mar 27 14:03:29 2006 @@ -58,6 +58,7 @@ CPPUNIT_TEST (mysql_stmt_select_fetch_test); CPPUNIT_TEST (mysql_stmt_store_fetch_test); CPPUNIT_TEST (mysql_stmt_long_data_fetch_field_test); + CPPUNIT_TEST (mysql_blob_test); CPPUNIT_TEST_SUITE_END (); public: @@ -93,6 +94,7 @@ void mysql_stmt_select_fetch_test(void); void mysql_stmt_store_fetch_test(void); void mysql_stmt_long_data_fetch_field_test(void); + void mysql_blob_test(void); private: MYSQL *mysql; };
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | CVS update of odbsequoia/src (explicit_type.cpp), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
|---|---|
| Next by Date: | CVS update of libmysequoia/test (TestMySQLAPI.cpp), zsolt-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Previous by Thread: | CVS update of odbsequoia/src (explicit_type.cpp), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Next by Thread: | CVS update of libmysequoia/test (TestMySQLAPI.cpp), zsolt-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |
Home
| advertise | OSDir is
an inevitable website.
|