summaryrefslogtreecommitdiff
path: root/libmysql/libmysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmysql/libmysql.c')
-rw-r--r--libmysql/libmysql.c113
1 files changed, 67 insertions, 46 deletions
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 771278c1dbb..e380ceb2d19 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -58,11 +58,20 @@
#endif
#include <sql_common.h>
+#include "client_settings.h"
-ulong net_buffer_length=8192;
-ulong max_allowed_packet= 1024L*1024L*1024L;
-ulong net_read_timeout= NET_READ_TIMEOUT;
-ulong net_write_timeout= NET_WRITE_TIMEOUT;
+#ifdef EMBEDDED_LIBRARY
+#ifdef net_flush
+#undef net_flush
+#endif
+
+my_bool net_flush(NET *net);
+
+#endif
+
+
+uint mysql_port=0;
+my_string mysql_unix_port=0;
#if defined(MSDOS) || defined(__WIN__)
/* socket_errno is defined in my_global.h for all platforms */
@@ -85,19 +94,6 @@ static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
const char *from, ulong length);
my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list);
-/*
- Initialize the MySQL library
-
- SYNOPSIS
- mysql_once_init()
-
- NOTES
- Can't be static on NetWare
- This function is called by mysql_init() and indirectly called
- by mysql_real_query(), so one should never have to call this from an
- outside program.
-*/
-
static my_bool mysql_client_init= 0;
static my_bool org_my_init_done= 0;
@@ -145,7 +141,6 @@ void mysql_once_init(void)
#endif
}
-
int STDCALL mysql_server_init(int argc __attribute__((unused)),
char **argv __attribute__((unused)),
char **groups __attribute__((unused)))
@@ -162,6 +157,7 @@ void STDCALL mysql_server_end()
else
mysql_thread_end();
}
+#endif /*EMBEDDED_LIBRARY*/
my_bool STDCALL mysql_thread_init()
{
@@ -183,17 +179,6 @@ void STDCALL mysql_thread_end()
Let the user specify that we don't want SIGPIPE; This doesn't however work
with threaded applications as we can have multiple read in progress.
*/
-
-#if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD)
-#define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0
-#define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler)
-#define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler);
-#else
-#define init_sigpipe_variables
-#define set_sigpipe(mysql)
-#define reset_sigpipe(mysql)
-#endif
-
static MYSQL* spawn_init(MYSQL* parent, const char* host,
unsigned int port,
const char* user,
@@ -856,6 +841,53 @@ STDCALL mysql_add_slave(MYSQL* mysql, const char* host,
return 0;
}
+/**************************************************************************
+ Alloc struct for use with unbuffered reads. Data is fetched by domand
+ when calling to mysql_fetch_row.
+ mysql_data_seek is a noop.
+
+ No other queries may be specified with the same MYSQL handle.
+ There shouldn't be much processing per row because mysql server shouldn't
+ have to wait for the client (and will not wait more than 30 sec/packet).
+**************************************************************************/
+
+MYSQL_RES * STDCALL CLI_MYSQL_USE_RESULT(MYSQL *mysql)
+{
+ MYSQL_RES *result;
+ DBUG_ENTER("mysql_use_result");
+
+ mysql = mysql->last_used_con;
+
+ if (!mysql->fields)
+ DBUG_RETURN(0);
+ if (mysql->status != MYSQL_STATUS_GET_RESULT)
+ {
+ strmov(mysql->net.sqlstate, unknown_sqlstate);
+ strmov(mysql->net.last_error,
+ ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
+ DBUG_RETURN(0);
+ }
+ if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
+ sizeof(ulong)*mysql->field_count,
+ MYF(MY_WME | MY_ZEROFILL))))
+ DBUG_RETURN(0);
+ result->lengths=(ulong*) (result+1);
+ if (!(result->row=(MYSQL_ROW)
+ my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME))))
+ { /* Ptrs: to one row */
+ my_free((gptr) result,MYF(0));
+ DBUG_RETURN(0);
+ }
+ result->fields= mysql->fields;
+ result->field_alloc= mysql->field_alloc;
+ result->field_count= mysql->field_count;
+ result->current_field=0;
+ result->handle= mysql;
+ result->current_row= 0;
+ mysql->fields=0; /* fields is now in result */
+ mysql->status=MYSQL_STATUS_USE_RESULT;
+ DBUG_RETURN(result); /* Data is read to be fetched */
+}
/**************************************************************************
Return next field of the query results
@@ -1249,19 +1281,6 @@ uint STDCALL mysql_thread_safe(void)
****************************************************************************/
/*
- Functions called my my_net_init() to set some application specific variables
-*/
-
-void my_net_local_init(NET *net)
-{
- net->max_packet= (uint) net_buffer_length;
- net->read_timeout= (uint) net_read_timeout;
- net->write_timeout=(uint) net_write_timeout;
- net->retry_count= 1;
- net->max_packet_size= max(net_buffer_length, max_allowed_packet);
-}
-
-/*
Add escape characters to a string (blob?) to make it suitable for a insert
to should at least have place for length*2+1 chars
Returns the length of the to string
@@ -1994,8 +2013,9 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
mysql->last_used_con= mysql;
int4store(buff, stmt->stmt_id); /* Send stmt id to server */
- if (advanced_command(mysql, COM_EXECUTE, buff, MYSQL_STMT_HEADER, packet,
- length, 1) ||
+ if ((*mysql->methods->advanced_command)(mysql, COM_EXECUTE, buff,
+ MYSQL_STMT_HEADER, packet,
+ length, 1) ||
mysql_read_query_result(mysql))
{
set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
@@ -2287,8 +2307,9 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number,
Note that we don't get any ok packet from the server in this case
This is intentional to save bandwidth.
*/
- if (advanced_command(mysql, COM_LONG_DATA, extra_data,
- MYSQL_LONG_DATA_HEADER, data, length, 1))
+ if ((*mysql->methods->advanced_command)(mysql, COM_LONG_DATA, extra_data,
+ MYSQL_LONG_DATA_HEADER, data,
+ length, 1))
{
set_stmt_errmsg(stmt, mysql->net.last_error,
mysql->net.last_errno, mysql->net.sqlstate);