diff --git a/src/modules/mysql/configure.in b/src/modules/mysql/configure.in index 7745ae4f02e0b0b25bb86e6f15e05456cb989f69..a86f7e46b7833d1616a2b5a685c4a3100cc583ae 100644 --- a/src/modules/mysql/configure.in +++ b/src/modules/mysql/configure.in @@ -1,5 +1,5 @@ # -# $Id: configure.in,v 1.11 1997/01/30 22:45:23 grubba Exp $ +# $Id: configure.in,v 1.12 1997/01/31 01:13:15 grubba Exp $ # # Configure script for the mysql-module # @@ -178,6 +178,8 @@ if test x$with_mysql = xyes; then MYSQL_LIBS="" else AC_DEFINE(HAVE_MYSQL) + + AC_CHECK_FUNCS(mysql_real_query mysql_fetch_lengths) fi fi else diff --git a/src/modules/mysql/doc/mysql b/src/modules/mysql/doc/mysql index 8732a8c99eda8be12557590c29448088364b893e..8e11cefe880f1606993e05bb220d75cabed3e657 100644 --- a/src/modules/mysql/doc/mysql +++ b/src/modules/mysql/doc/mysql @@ -360,3 +360,19 @@ SEE ALSO /precompiled/sql/mysql_result +============================================================================ +NAME + binary_data - inform if this version of mysql supports binary data + +SYNTAX + int mysql->binary_data(); + +DESCRIPTION + This function returns non-zero if binary data can be reliably stored + and retreived with this version of the mysql-module. + + Usually, there is no problem storing binary data in mysql-tables, + but data containing '\0' (NUL) couldn't be fetched with old + versions (prior to 3.20.5) of the mysql-library. + + diff --git a/src/modules/mysql/mysql.c b/src/modules/mysql/mysql.c index 44798c4ce754dc8d5d834bb222ca778845f87b10..16406ac205397f73997c9134d321c9e414484819 100644 --- a/src/modules/mysql/mysql.c +++ b/src/modules/mysql/mysql.c @@ -1,5 +1,5 @@ /* - * $Id: mysql.c,v 1.12 1997/01/30 23:45:22 grubba Exp $ + * $Id: mysql.c,v 1.13 1997/01/31 01:13:16 grubba Exp $ * * SQL database functionality for Pike * @@ -59,7 +59,7 @@ typedef struct dynamic_buffer_s dynamic_buffer; * Globals */ -RCSID("$Id: mysql.c,v 1.12 1997/01/30 23:45:22 grubba Exp $"); +RCSID("$Id: mysql.c,v 1.13 1997/01/31 01:13:16 grubba Exp $"); struct program *mysql_program = NULL; @@ -606,6 +606,19 @@ static void f_list_processes(INT32 args) push_object(clone(mysql_result_program, 1)); } +/* + * Support for binary data in tables + */ +static void f_binary_data(INT32 args) +{ + pop_n_elems(args); +#ifdef HAVE_MYSQL_FETCH_LENGTHS + push_int(1); +#else + push_int(0); +#endif /* HAVE_MYSQL_FETCH_LENGTHS */ +} + #endif /* HAVE_MYSQL */ /* @@ -661,6 +674,8 @@ void init_mysql_programs(void) add_function("list_fields", f_list_fields, "function(string, void|string:array(int|mapping(string:mixed)))", OPT_EXTERNAL_DEPEND); add_function("list_processes", f_list_processes, "function(void|string:object)", OPT_EXTERNAL_DEPEND); + add_function("binary_data", f_binary_data, "function(void:int)", OPT_TRY_OPTIMIZE); + set_init_callback(init_mysql_struct); set_exit_callback(exit_mysql_struct); diff --git a/src/modules/mysql/result.c b/src/modules/mysql/result.c index d2d52634c81a0361da6ca42b9fc6f796ec9ce39c..cba96d412d94a2fe4aeecdb1b8ff79a4c60735b9 100644 --- a/src/modules/mysql/result.c +++ b/src/modules/mysql/result.c @@ -1,5 +1,5 @@ /* - * $Id: result.c,v 1.11 1997/01/24 01:46:38 grubba Exp $ + * $Id: result.c,v 1.12 1997/01/31 01:13:17 grubba Exp $ * * mysql query result * @@ -62,7 +62,7 @@ typedef struct dynamic_buffer_s dynamic_buffer; * Globals */ -RCSID("$Id: result.c,v 1.11 1997/01/24 01:46:38 grubba Exp $"); +RCSID("$Id: result.c,v 1.12 1997/01/31 01:13:17 grubba Exp $"); struct program *mysql_result_program = NULL; @@ -315,6 +315,9 @@ static void f_fetch_row(INT32 args) { int num_fields = mysql_num_fields(PIKE_MYSQL_RES->result); MYSQL_ROW row = mysql_fetch_row(PIKE_MYSQL_RES->result); +#ifdef HAVE_MYSQL_FETCH_LENGTHS + int *row_lengths = mysql_fetch_lengths(PIKE_MYSQL_RES->result); +#endif /* HAVE_MYSQL_FETCH_LENGTHS */ pop_n_elems(args); @@ -335,7 +338,7 @@ static void f_fetch_row(INT32 args) case FIELD_TYPE_INT24: #if 0 /* This one will not always fit in an INT32 */ - case FIELD_TYPE_LONGLONG: + case FIELD_TYPE_LONGLONG: #endif /* 0 */ push_int(atoi(row[i])); break; @@ -346,12 +349,20 @@ static void f_fetch_row(INT32 args) push_float(atof(row[i])); break; default: +#ifdef HAVE_MYSQL_FETCH_LENGTHS + push_string(make_shared_binary_string(row[i], row_lengths[i])); +#else push_text(row[i]); +#endif /* HAVE_MYSQL_FETCH_LENGTHS */ break; } } else { /* Probably doesn't happen, but... */ +#ifdef HAVE_MYSQL_FETCH_LENGTHS + push_string(make_shared_binary_string(row[i], row_lengths[i])); +#else push_text(row[i]); +#endif /* HAVE_MYSQL_FETCH_LENGTHS */ } } else { /* NULL? */