I have a problem in the function dbi_result_get_binary_copy.
That function call the dbi_result_get_binary_copy_idx.
In the code dbi_result.c on line 1310 and 1311. The size variable
always is 0 or a low value and malloc allocates insufficient space in
pointer to newblob. The result is in line 1316 , memcpy not works like
expected.
And so I think that has a little bug in dbi_result_get_binary_copy_idx.
I have tested with modification in libdbi-drivers/tests/test_dbi.c
with the following patch to prove this bug. In my project I see this
bug too.
Thanks
PS: Version used 0.8.3-pre1 and mysql driver
--
-----------------------------------------------------------
João Henrique Freitas - joaohf_at_gmail.com
Campinas-SP-Brasil
BSD051283
LPI 1
http://joaohf.pbwiki.com
http://www.livejournal.com/users/joaohf/
--- test_dbi_cvs.c 2008-01-23 00:20:52.000000000 -0200
+++ test_dbi.c 2008-01-22 23:53:21.000000000 -0200
@@ -35,7 +35,9 @@
char string_to_quote[] = "Can \'we\' \"quote\" this properly?";
unsigned char binary_to_quote[] = {'A', 'B', '\0', 'C', '\'', 'D'};
+unsigned char binary_to_copy[] = "Test Teste 2";
size_t binary_to_quote_length = 6;
+size_t binary_to_copy_length = 12;
void init_tinfo(struct TABLEINFO* ptr_tinfo);
int init_db(struct CONNINFO* ptr_cinfo);
@@ -794,6 +796,7 @@
"the_empty_string VARCHAR(255),"
"the_null_string VARCHAR(255),"
"the_binary_string BLOB,"
+ "the_binary_copy BLOB,"
"the_datetime DATETIME,"
"the_datetime_tz DATETIME,"
"the_date DATE,"
@@ -1018,7 +1021,9 @@
char *driver_quoted_string = NULL;
char *conn_quoted_string = NULL;
unsigned char* quoted_binary = NULL;
+ unsigned char* binary_copied = NULL;
size_t quoted_binary_length;
+ size_t binary_copy_length;
const char *errmsg;
unsigned long long n_last_id;
unsigned long long n_next_id;
@@ -1027,6 +1032,7 @@
dbi_driver_quote_string_copy(dbi_conn_get_driver(conn), string_to_quote, &driver_quoted_string);
dbi_conn_quote_string_copy(conn, string_to_quote, &conn_quoted_string);
quoted_binary_length = dbi_conn_quote_binary_copy(conn, binary_to_quote, binary_to_quote_length, "ed_binary);
+ binary_copy_length = dbi_conn_quote_binary_copy(conn, binary_to_copy, binary_to_copy_length, &binary_copied);
if(!strcmp(ptr_cinfo->drivername, "msql")) {
snprintf(query, QUERY_LEN, "INSERT INTO test_datatypes VALUES ("
"-127,"
@@ -1172,6 +1178,7 @@
"the_empty_string,"
"the_null_string,"
"the_binary_string,"
+ "the_binary_copy,"
"the_datetime,"
"the_datetime_tz,"
"the_date,"
@@ -1192,11 +1199,12 @@
"'',"
"NULL,"
"%s,"
+ "%s,"
"'2001-12-31 23:59:59',"
"'2001-12-31 23:59:59 -10:00',"
"'2001-12-31',"
"'23:59:59',"
- "'23:59:59-10:00')", driver_quoted_string, conn_quoted_string, quoted_binary);
+ "'23:59:59-10:00')", driver_quoted_string, conn_quoted_string, quoted_binary, binary_copied);
}
if (driver_quoted_string) {
@@ -1266,6 +1274,7 @@
const char* the_empty_string;
const char* the_null_string;
const unsigned char* the_binary_string;
+ unsigned char* the_binary_copy;
time_t the_datetime;
time_t the_datetime_tz;
time_t the_date_dt;
@@ -1304,6 +1313,7 @@
unsigned int the_empty_string_length = 0;
unsigned int the_null_string_length = 0;
unsigned int the_binary_string_length = 0;
+ unsigned int the_binary_copy_length = 0;
dbi_error_flag errflag;
@@ -1409,6 +1419,12 @@
printf("the_null_string errflag=%s\n", errmsg);
}
+ the_binary_copy = dbi_result_get_binary_copy(result, "the_binary_copy");
+ errflag = dbi_conn_error(dbi_result_get_conn(result), &errmsg);
+ if (errflag) {
+ printf("the_binary_copy errflag=%s\n", errmsg);
+ }
+
printf("\tthis should cause a column type mismatch...\n");
dbi_result_get_string(result, "the_long");
errflag = dbi_conn_error(dbi_result_get_conn(result), &errmsg);
@@ -1484,12 +1500,17 @@
printf("the_empty_string_length errflag=%s\n", errmsg);
}
- the_binary_string_length = dbi_result_get_field_length(result, "the_binary_string");
+ the_binary_string_length = dbi_result_get_field_length(result, "the_binary_copy");
errflag = dbi_conn_error(dbi_result_get_conn(result), &errmsg);
if (errflag) {
- printf("the_binary_string_size errflag=%s\n", errmsg);
+ printf("the_binary_copy_size errflag=%s\n", errmsg);
}
+ the_binary_copy_length = dbi_result_get_field_length(result, "the_binary_string");
+ errflag = dbi_conn_error(dbi_result_get_conn(result), &errmsg);
+ if (errflag) {
+ printf("the_binary_string_size errflag=%s\n", errmsg);
+ }
if(!strcmp(ptr_cinfo->drivername, "msql")) {
the_date = dbi_result_get_string(result, "the_date");
@@ -1595,6 +1616,7 @@
"the_conn_string: in:\'%s\' out:\'%s\'<<\n"
"the_empty_string: out:\'%s\'<<\n"
"the_null_string: out:\'%s\'\n"
+ "the_binary_copy: out:\'%s\'\n"
"the_datetime: in:\'2001-12-31 23:59:59\' out:%d-%d-%d %d:%d:%d\n"
"the_datetime_tz: in:\'2001-12-31 23:59:59 -10:00\' out:%d-%d-%d %d:%d:%d\n"
"the_date: in:\'2001-12-31\' out:%d-%d-%d\n"
@@ -1603,7 +1625,7 @@
(signed int)the_char, (unsigned int)the_uchar, the_short, the_ushort,
the_long, the_ulong, the_longlong, the_ulonglong, the_float, the_double,
string_to_quote, the_driver_string, string_to_quote, the_conn_string,
- the_empty_string, the_null_string,
+ the_empty_string, the_null_string, the_binary_copy,
year_dt, mon_dt, day_dt, hour_dt, min_dt, sec_dt,
year_dt_tz, mon_dt_tz, day_dt_tz, hour_dt_tz, min_dt_tz, sec_dt_tz,
year, mon, day, hour, min, sec, hour_tz, min_tz, sec_tz);
@@ -1625,12 +1647,13 @@
printf("\n\nfield lengths:\n"
"the_driver_string_length %d\nthe_conn_string_length %d\n"
"the_empty_string_length %d\nthe_null_string_length %d\n"
- "the_binary_string_length %d\n\n",
+ "the_binary_string_length %d\nthe_binary_copy_length %d\n\n",
the_driver_string_length,
the_conn_string_length,
the_empty_string_length,
the_null_string_length,
- the_binary_string_length);
+ the_binary_string_length,
+ the_binary_copy_length);
} /* end while */
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libdbi-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libdbi-devel