105
99
static int wait_for_data(int fd, int32_t timeout);
106
100
int connect_with_timeout(int fd, const struct sockaddr *name, uint namelen, int32_t timeout);
108
/* Server error code and message */
109
unsigned int drizzle_server_last_errno;
110
char drizzle_server_last_error[DRIZZLE_ERRMSG_SIZE];
112
103
/****************************************************************************
113
104
A modified version of connect(). connect_with_timeout() allows you to specify
213
Set the internal error message to DRIZZLE handler
215
@param drizzle connection handle (client side)
216
@param errcode CR_ error code, passed to ER macro to get
218
@parma sqlstate SQL standard sqlstate
221
void set_drizzle_error(DRIZZLE *drizzle, int errcode, const char *sqlstate)
224
assert(drizzle != 0);
229
net->last_errno= errcode;
230
strcpy(net->last_error, ER(errcode));
231
strcpy(net->sqlstate, sqlstate);
235
drizzle_server_last_errno= errcode;
236
strcpy(drizzle_server_last_error, ER(errcode));
242
205
Clear possible error state of struct NET
251
214
strcpy(net->sqlstate, not_error_sqlstate);
255
Set an error message on the client.
257
@param drizzle connection handle
258
@param errcode CR_* errcode, for client errors
259
@param sqlstate SQL standard sql state, unknown_sqlstate for the
260
majority of client errors.
261
@param format error message template, in sprintf format
262
@param ... variable number of arguments
265
static void set_drizzle_extended_error(DRIZZLE *drizzle, int errcode,
266
const char *sqlstate,
267
const char *format, ...)
271
assert(drizzle != 0);
274
net->last_errno= errcode;
275
va_start(args, format);
276
vsnprintf(net->last_error, sizeof(net->last_error)-1,
279
strcpy(net->sqlstate, sqlstate);
284
218
/*****************************************************************************
285
219
Read a packet from server. Give error message if socket was down
406
340
if (net->last_errno == CR_NET_PACKET_TOO_LARGE)
408
set_drizzle_error(drizzle, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
342
drizzle_set_error(drizzle, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
345
drizzle_disconnect(drizzle);
412
346
if (drizzle_reconnect(drizzle) || stmt_skip)
414
348
if (net_write_command(net,(uchar) command, header, header_length,
415
349
arg, arg_length))
417
set_drizzle_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
351
drizzle_set_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
762
/****************************************************************************
763
Init DRIZZLE structure or allocate one
764
****************************************************************************/
767
drizzle_create(DRIZZLE *ptr)
770
if (!drizzle_client_init)
772
drizzle_client_init=true;
776
drizzle_port = DRIZZLE_PORT;
778
struct servent *serv_ptr;
782
if builder specifically requested a default port, use that
783
(even if it coincides with our factory default).
784
only if they didn't do we check /etc/services (and, failing
785
on that, fall back to the factory default of 4427).
786
either default can be overridden by the environment variable
787
DRIZZLE_TCP_PORT, which in turn can be overridden with command
791
#if DRIZZLE_PORT_DEFAULT == 0
792
if ((serv_ptr = getservbyname("drizzle", "tcp")))
793
drizzle_port = (uint) ntohs((ushort) serv_ptr->s_port);
795
if ((env = getenv("DRIZZLE_TCP_PORT")))
796
drizzle_port =(uint) atoi(env);
800
(void) signal(SIGPIPE, SIG_IGN);
806
ptr= (DRIZZLE *) malloc(sizeof(DRIZZLE));
810
set_drizzle_error(NULL, CR_OUT_OF_MEMORY, unknown_sqlstate);
813
memset(ptr, 0, sizeof(DRIZZLE));
818
memset(ptr, 0, sizeof(DRIZZLE));
821
ptr->options.connect_timeout= CONNECT_TIMEOUT;
822
strcpy(ptr->net.sqlstate, not_error_sqlstate);
825
Only enable LOAD DATA INFILE by default if configured with
826
--enable-local-infile
829
#if defined(ENABLED_LOCAL_INFILE) && !defined(DRIZZLE_SERVER)
830
ptr->options.client_flag|= CLIENT_LOCAL_FILES;
833
ptr->options.methods_to_use= DRIZZLE_OPT_GUESS_CONNECTION;
834
ptr->options.report_data_truncation= true; /* default */
837
By default we don't reconnect because it could silently corrupt data (after
838
reconnection you potentially lose table locks, user variables, session
839
variables (transactions but they are specifically dealt with in
840
drizzle_reconnect()).
841
This is a change: < 5.0.3 drizzle->reconnect was set to 1 by default.
842
How this change impacts existing apps:
843
- existing apps which relyed on the default will see a behaviour change;
844
they will have to set reconnect=1 after drizzle_connect().
845
- existing apps which explicitely asked for reconnection (the only way they
846
could do it was by setting drizzle.reconnect to 1 after drizzle_connect())
847
will not see a behaviour change.
848
- existing apps which explicitely asked for no reconnection
849
(drizzle.reconnect=0) will not see a behaviour change.
858
Free all memory and resources used by the client library
861
When calling this there should not be any other threads using
864
To make things simpler when used with windows dll's (which calls this
865
function automaticly), it's safe to call this function multiple times.
869
void drizzle_server_end()
871
if (!drizzle_client_init)
876
drizzle_client_init= org_my_init_done= 0;
881
681
Note that the drizzle argument must be initialized with drizzle_init()
882
682
before calling drizzle_connect !
1161
961
/* Write authentication package */
1162
962
if (my_net_write(net, (uchar*) buff, (size_t) (end-buff)) || net_flush(net))
1164
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
964
drizzle_set_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1165
965
ER(CR_SERVER_LOST_SEND_AUTH),