206.3.1
by Patrick Galbraith
Most everything working with client rename |
1 |
/* Copyright (C) 2000-2004 DRIZZLE AB
|
1
by brian
clean slate |
2 |
|
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation.
|
|
6 |
||
7 |
There are special exceptions to the terms and conditions of the GPL as it
|
|
8 |
is applied to this software. View the full text of the exception in file
|
|
9 |
EXCEPTIONS-CLIENT in the directory of this software distribution.
|
|
10 |
||
11 |
This program is distributed in the hope that it will be useful,
|
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
GNU General Public License for more details.
|
|
15 |
||
16 |
You should have received a copy of the GNU General Public License
|
|
17 |
along with this program; if not, write to the Free Software
|
|
18 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
19 |
||
212.5.39
by Monty Taylor
Phew. Moved my_base and my_global. |
20 |
#include <drizzled/global.h> |
21 |
#include <mysys/my_sys.h> |
|
22 |
#include "my_time.h" |
|
1
by brian
clean slate |
23 |
#include <mysys_err.h> |
212.5.18
by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype. |
24 |
#include <mystrings/m_string.h> |
25 |
#include <mystrings/m_ctype.h> |
|
77.1.39
by Monty Taylor
More mysql->drizzle renaming. |
26 |
#include "drizzle.h" |
212.5.5
by Monty Taylor
Moved mysqld_err* -> drizzled_err* |
27 |
#include "drizzled_error.h" |
1
by brian
clean slate |
28 |
#include "errmsg.h" |
29 |
#include <violite.h> |
|
30 |
#include <sys/stat.h> |
|
31 |
#include <signal.h> |
|
32 |
#include <time.h> |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
33 |
#ifdef HAVE_PWD_H
|
1
by brian
clean slate |
34 |
#include <pwd.h> |
35 |
#endif
|
|
94
by Brian Aker
DOS removal. DOS... hard to believe aye? |
36 |
|
1
by brian
clean slate |
37 |
#include <sys/socket.h> |
38 |
#include <netinet/in.h> |
|
39 |
#include <arpa/inet.h> |
|
40 |
#include <netdb.h> |
|
41 |
#ifdef HAVE_SELECT_H
|
|
42 |
#include <select.h> |
|
43 |
#endif
|
|
44 |
#ifdef HAVE_SYS_SELECT_H
|
|
45 |
#include <sys/select.h> |
|
46 |
#endif
|
|
94
by Brian Aker
DOS removal. DOS... hard to believe aye? |
47 |
|
1
by brian
clean slate |
48 |
#ifdef HAVE_POLL
|
49 |
#include <sys/poll.h> |
|
50 |
#endif
|
|
51 |
#ifdef HAVE_SYS_UN_H
|
|
52 |
#include <sys/un.h> |
|
53 |
#endif
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
54 |
#include <my_pthread.h> /* because of signal() */ |
1
by brian
clean slate |
55 |
#ifndef INADDR_NONE
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
56 |
#define INADDR_NONE -1
|
1
by brian
clean slate |
57 |
#endif
|
58 |
||
59 |
#include <sql_common.h> |
|
60 |
#include "client_settings.h" |
|
61 |
||
62 |
#undef net_buffer_length
|
|
63 |
#undef max_allowed_packet
|
|
64 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
65 |
uint32_t net_buffer_length= 8192; |
66 |
uint32_t max_allowed_packet= 1024L*1024L*1024L; |
|
1
by brian
clean slate |
67 |
|
68 |
#include <errno.h> |
|
69 |
#define SOCKET_ERROR -1
|
|
70 |
||
71 |
/*
|
|
72 |
If allowed through some configuration, then this needs to
|
|
73 |
be changed
|
|
74 |
*/
|
|
75 |
#define MAX_LONG_DATA_LENGTH 8192
|
|
76 |
#define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG)
|
|
77 |
||
78 |
static void append_wild(char *to,char *end,const char *wild); |
|
79 |
||
202.2.2
by Monty Taylor
Merged mysql_server_init into drizzle_create() |
80 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
81 |
static DRIZZLE_PARAMETERS drizzle_internal_parameters= |
1
by brian
clean slate |
82 |
{&max_allowed_packet, &net_buffer_length, 0}; |
83 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
84 |
DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void) |
1
by brian
clean slate |
85 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
86 |
return &drizzle_internal_parameters; |
1
by brian
clean slate |
87 |
}
|
88 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
89 |
bool STDCALL drizzle_thread_init() |
1
by brian
clean slate |
90 |
{
|
91 |
return my_thread_init(); |
|
92 |
}
|
|
93 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
94 |
void STDCALL drizzle_thread_end() |
1
by brian
clean slate |
95 |
{
|
96 |
my_thread_end(); |
|
97 |
}
|
|
98 |
||
99 |
||
100 |
/*
|
|
101 |
Expand wildcard to a sql string
|
|
102 |
*/
|
|
103 |
||
104 |
static void |
|
105 |
append_wild(char *to, char *end, const char *wild) |
|
106 |
{
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
107 |
end-=5; /* Some extra */ |
1
by brian
clean slate |
108 |
if (wild && wild[0]) |
109 |
{
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
110 |
to= strcpy(to," like '"); |
111 |
to+= 7; /* strlen(" like '"); */ |
|
112 |
||
1
by brian
clean slate |
113 |
while (*wild && to < end) |
114 |
{
|
|
115 |
if (*wild == '\\' || *wild == '\'') |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
116 |
*to++='\\'; |
1
by brian
clean slate |
117 |
*to++= *wild++; |
118 |
}
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
119 |
if (*wild) /* Too small buffer */ |
120 |
*to++='%'; /* Nicer this way */ |
|
1
by brian
clean slate |
121 |
to[0]='\''; |
122 |
to[1]=0; |
|
123 |
}
|
|
124 |
}
|
|
125 |
||
126 |
/**************************************************************************
|
|
127 |
Ignore SIGPIPE handler
|
|
128 |
ARGSUSED
|
|
129 |
**************************************************************************/
|
|
130 |
||
131 |
sig_handler
|
|
132 |
my_pipe_sig_handler(int sig __attribute__((unused))) |
|
133 |
{
|
|
134 |
#ifdef DONT_REMEMBER_SIGNAL
|
|
135 |
(void) signal(SIGPIPE, my_pipe_sig_handler); |
|
136 |
#endif
|
|
137 |
}
|
|
138 |
||
139 |
||
140 |
/**************************************************************************
|
|
141 |
Connect to sql server
|
|
142 |
If host == 0 then use localhost
|
|
143 |
**************************************************************************/
|
|
144 |
||
145 |
#ifdef USE_OLD_FUNCTIONS
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
146 |
DRIZZLE * STDCALL |
147 |
drizzle_connect(DRIZZLE *drizzle,const char *host, |
|
148 |
const char *user, const char *passwd) |
|
1
by brian
clean slate |
149 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
150 |
DRIZZLE *res; |
151 |
drizzle=drizzle_init(drizzle); /* Make it thread safe */ |
|
1
by brian
clean slate |
152 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
153 |
if (!(res=drizzle_connect(drizzle,host,user,passwd,NullS,0,NullS,0))) |
1
by brian
clean slate |
154 |
{
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
155 |
if (drizzle->free_me && drizzle) |
156 |
free((uchar*) drizzle); |
|
1
by brian
clean slate |
157 |
}
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
158 |
drizzle->reconnect= 1; |
51.3.5
by Jay Pipes
Merged in from trunk. |
159 |
return(res); |
1
by brian
clean slate |
160 |
}
|
161 |
}
|
|
162 |
#endif
|
|
163 |
||
164 |
||
165 |
/**************************************************************************
|
|
166 |
Change user and database
|
|
167 |
**************************************************************************/
|
|
168 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
169 |
int cli_read_change_user_result(DRIZZLE *drizzle, char *buff, const char *passwd) |
1
by brian
clean slate |
170 |
{
|
77.1.107
by Monty Taylor
Fixed build warnings. |
171 |
(void)buff; |
172 |
(void)passwd; |
|
1
by brian
clean slate |
173 |
ulong pkt_length; |
174 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
175 |
pkt_length= cli_safe_read(drizzle); |
1
by brian
clean slate |
176 |
|
177 |
if (pkt_length == packet_error) |
|
178 |
return 1; |
|
179 |
||
180 |
return 0; |
|
181 |
}
|
|
182 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
183 |
bool STDCALL drizzle_change_user(DRIZZLE *drizzle, const char *user, |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
184 |
const char *passwd, const char *db) |
1
by brian
clean slate |
185 |
{
|
186 |
char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2]; |
|
187 |
char *end= buff; |
|
188 |
int rc; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
189 |
CHARSET_INFO *saved_cs= drizzle->charset; |
1
by brian
clean slate |
190 |
|
191 |
/* Get the connection-default character set. */
|
|
192 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
193 |
if (drizzle_init_character_set(drizzle)) |
1
by brian
clean slate |
194 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
195 |
drizzle->charset= saved_cs; |
51.3.5
by Jay Pipes
Merged in from trunk. |
196 |
return(true); |
1
by brian
clean slate |
197 |
}
|
198 |
||
199 |
/* Use an empty string instead of NULL. */
|
|
200 |
||
201 |
if (!user) |
|
202 |
user=""; |
|
203 |
if (!passwd) |
|
204 |
passwd=""; |
|
205 |
||
206 |
/* Store user into the buffer */
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
207 |
end= strncpy(end, user, USERNAME_LENGTH) + USERNAME_LENGTH + 1; |
1
by brian
clean slate |
208 |
|
209 |
/* write scrambled password according to server capabilities */
|
|
210 |
if (passwd[0]) |
|
211 |
{
|
|
212 |
{
|
|
213 |
*end++= SCRAMBLE_LENGTH; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
214 |
scramble(end, drizzle->scramble, passwd); |
1
by brian
clean slate |
215 |
end+= SCRAMBLE_LENGTH; |
216 |
}
|
|
217 |
}
|
|
218 |
else
|
|
219 |
*end++= '\0'; /* empty password */ |
|
220 |
/* Add database if needed */
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
221 |
end= strncpy(end, db ? db : "", NAME_LEN) + NAME_LEN + 1; |
1
by brian
clean slate |
222 |
|
223 |
/* Add character set number. */
|
|
224 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
225 |
if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION) |
1
by brian
clean slate |
226 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
227 |
int2store(end, (ushort) drizzle->charset->number); |
1
by brian
clean slate |
228 |
end+= 2; |
229 |
}
|
|
230 |
||
231 |
/* Write authentication package */
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
232 |
(void)simple_command(drizzle,COM_CHANGE_USER, (uchar*) buff, (ulong) (end-buff), 1); |
1
by brian
clean slate |
233 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
234 |
rc= (*drizzle->methods->read_change_user_result)(drizzle, buff, passwd); |
1
by brian
clean slate |
235 |
|
236 |
if (rc == 0) |
|
237 |
{
|
|
238 |
/* Free old connect information */
|
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
239 |
if(drizzle->user) |
240 |
free(drizzle->user); |
|
241 |
if(drizzle->passwd) |
|
242 |
free(drizzle->passwd); |
|
243 |
if(drizzle->db) |
|
244 |
free(drizzle->db); |
|
1
by brian
clean slate |
245 |
|
246 |
/* alloc new connect information */
|
|
240.1.1
by Toru Maesaka
removed my_strdup and dead code from libdrizzle |
247 |
drizzle->user= strdup(user); |
248 |
drizzle->passwd= strdup(passwd); |
|
249 |
drizzle->db= db ? strdup(db) : 0; |
|
1
by brian
clean slate |
250 |
}
|
251 |
else
|
|
252 |
{
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
253 |
drizzle->charset= saved_cs; |
1
by brian
clean slate |
254 |
}
|
255 |
||
51.3.5
by Jay Pipes
Merged in from trunk. |
256 |
return(rc); |
1
by brian
clean slate |
257 |
}
|
258 |
||
259 |
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
|
|
260 |
struct passwd *getpwuid(uid_t); |
|
261 |
char* getlogin(void); |
|
262 |
#endif
|
|
263 |
||
264 |
void read_user_name(char *name) |
|
265 |
{
|
|
266 |
if (geteuid() == 0) |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
267 |
strcpy(name,"root"); /* allow use of surun */ |
1
by brian
clean slate |
268 |
else
|
269 |
{
|
|
270 |
#ifdef HAVE_GETPWUID
|
|
271 |
struct passwd *skr; |
|
272 |
const char *str; |
|
273 |
if ((str=getlogin()) == NULL) |
|
274 |
{
|
|
275 |
if ((skr=getpwuid(geteuid())) != NULL) |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
276 |
str=skr->pw_name; |
1
by brian
clean slate |
277 |
else if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) && |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
278 |
!(str=getenv("LOGIN"))) |
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
279 |
str="UNKNOWN_USER"; |
1
by brian
clean slate |
280 |
}
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
281 |
strncpy(name,str,USERNAME_LENGTH); |
1
by brian
clean slate |
282 |
#elif HAVE_CUSERID
|
283 |
(void) cuserid(name); |
|
284 |
#else
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
285 |
strcpy(name,"UNKNOWN_USER"); |
1
by brian
clean slate |
286 |
#endif
|
287 |
}
|
|
51.3.5
by Jay Pipes
Merged in from trunk. |
288 |
return; |
1
by brian
clean slate |
289 |
}
|
290 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
291 |
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename) |
1
by brian
clean slate |
292 |
{
|
207.2.2
by Toru Maesaka
replaced my_bool in libdrizzle with C99 boolean |
293 |
bool result= true; |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
294 |
uint packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE); |
295 |
NET *net= &drizzle->net; |
|
1
by brian
clean slate |
296 |
int readcount; |
297 |
void *li_ptr; /* pass state to local_infile functions */ |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
298 |
char *buf; /* buffer to be filled by local_infile_read */ |
299 |
struct st_drizzle_options *options= &drizzle->options; |
|
1
by brian
clean slate |
300 |
|
301 |
/* check that we've got valid callback functions */
|
|
302 |
if (!(options->local_infile_init && |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
303 |
options->local_infile_read && |
304 |
options->local_infile_end && |
|
305 |
options->local_infile_error)) |
|
1
by brian
clean slate |
306 |
{
|
307 |
/* if any of the functions is invalid, set the default */
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
308 |
drizzle_set_local_infile_default(drizzle); |
1
by brian
clean slate |
309 |
}
|
310 |
||
311 |
/* copy filename into local memory and allocate read buffer */
|
|
207.2.1
by Toru Maesaka
replaced my_malloc/my_free with malloc(3)/free(3). NULL pointer checks also added |
312 |
if (!(buf=malloc(packet_length))) |
1
by brian
clean slate |
313 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
314 |
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate); |
51.3.5
by Jay Pipes
Merged in from trunk. |
315 |
return(1); |
1
by brian
clean slate |
316 |
}
|
317 |
||
318 |
/* initialize local infile (open file, usually) */
|
|
319 |
if ((*options->local_infile_init)(&li_ptr, net_filename, |
|
320 |
options->local_infile_userdata)) |
|
321 |
{
|
|
322 |
VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */ |
|
323 |
net_flush(net); |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
324 |
strcpy(net->sqlstate, unknown_sqlstate); |
1
by brian
clean slate |
325 |
net->last_errno= |
326 |
(*options->local_infile_error)(li_ptr, |
|
327 |
net->last_error, |
|
328 |
sizeof(net->last_error)-1); |
|
329 |
goto err; |
|
330 |
}
|
|
331 |
||
332 |
/* read blocks of data from local infile callback */
|
|
333 |
while ((readcount = |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
334 |
(*options->local_infile_read)(li_ptr, buf, |
335 |
packet_length)) > 0) |
|
1
by brian
clean slate |
336 |
{
|
337 |
if (my_net_write(net, (uchar*) buf, readcount)) |
|
338 |
{
|
|
339 |
goto err; |
|
340 |
}
|
|
341 |
}
|
|
342 |
||
343 |
/* Send empty packet to mark end of file */
|
|
344 |
if (my_net_write(net, (const uchar*) "", 0) || net_flush(net)) |
|
345 |
{
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
346 |
set_drizzle_error(drizzle, CR_SERVER_LOST, unknown_sqlstate); |
1
by brian
clean slate |
347 |
goto err; |
348 |
}
|
|
349 |
||
350 |
if (readcount < 0) |
|
351 |
{
|
|
352 |
net->last_errno= |
|
353 |
(*options->local_infile_error)(li_ptr, |
|
354 |
net->last_error, |
|
355 |
sizeof(net->last_error)-1); |
|
356 |
goto err; |
|
357 |
}
|
|
358 |
||
207.2.2
by Toru Maesaka
replaced my_bool in libdrizzle with C99 boolean |
359 |
result=false; /* Ok */ |
1
by brian
clean slate |
360 |
|
361 |
err: |
|
362 |
/* free up memory allocated with _init, usually */
|
|
363 |
(*options->local_infile_end)(li_ptr); |
|
207.2.1
by Toru Maesaka
replaced my_malloc/my_free with malloc(3)/free(3). NULL pointer checks also added |
364 |
if(buf) |
365 |
free(buf); |
|
51.3.5
by Jay Pipes
Merged in from trunk. |
366 |
return(result); |
1
by brian
clean slate |
367 |
}
|
368 |
||
369 |
||
370 |
/****************************************************************************
|
|
371 |
Default handlers for LOAD LOCAL INFILE
|
|
372 |
****************************************************************************/
|
|
373 |
||
374 |
typedef struct st_default_local_infile |
|
375 |
{
|
|
376 |
int fd; |
|
377 |
int error_num; |
|
378 |
const char *filename; |
|
379 |
char error_msg[LOCAL_INFILE_ERROR_LEN]; |
|
380 |
} default_local_infile_data; |
|
381 |
||
382 |
||
383 |
/*
|
|
384 |
Open file for LOAD LOCAL INFILE
|
|
385 |
||
386 |
SYNOPSIS
|
|
387 |
default_local_infile_init()
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
388 |
ptr Store pointer to internal data here
|
389 |
filename File name to open. This may be in unix format !
|
|
1
by brian
clean slate |
390 |
|
391 |
||
392 |
NOTES
|
|
393 |
Even if this function returns an error, the load data interface
|
|
394 |
guarantees that default_local_infile_end() is called.
|
|
395 |
||
396 |
RETURN
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
397 |
0 ok
|
398 |
1 error
|
|
1
by brian
clean slate |
399 |
*/
|
400 |
||
401 |
static int default_local_infile_init(void **ptr, const char *filename, |
|
402 |
void *userdata __attribute__ ((unused))) |
|
403 |
{
|
|
404 |
default_local_infile_data *data; |
|
405 |
char tmp_name[FN_REFLEN]; |
|
406 |
||
407 |
if (!(*ptr= data= ((default_local_infile_data *) |
|
207.2.1
by Toru Maesaka
replaced my_malloc/my_free with malloc(3)/free(3). NULL pointer checks also added |
408 |
malloc(sizeof(default_local_infile_data))))) |
1
by brian
clean slate |
409 |
return 1; /* out of memory */ |
410 |
||
411 |
data->error_msg[0]= 0; |
|
412 |
data->error_num= 0; |
|
413 |
data->filename= filename; |
|
414 |
||
415 |
fn_format(tmp_name, filename, "", "", MY_UNPACK_FILENAME); |
|
416 |
if ((data->fd = my_open(tmp_name, O_RDONLY, MYF(0))) < 0) |
|
417 |
{
|
|
418 |
data->error_num= my_errno; |
|
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
419 |
snprintf(data->error_msg, sizeof(data->error_msg)-1, |
420 |
EE(EE_FILENOTFOUND), tmp_name, data->error_num); |
|
1
by brian
clean slate |
421 |
return 1; |
422 |
}
|
|
423 |
return 0; /* ok */ |
|
424 |
}
|
|
425 |
||
426 |
||
427 |
/*
|
|
428 |
Read data for LOAD LOCAL INFILE
|
|
429 |
||
430 |
SYNOPSIS
|
|
431 |
default_local_infile_read()
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
432 |
ptr Points to handle allocated by _init
|
433 |
buf Read data here
|
|
434 |
buf_len Ammount of data to read
|
|
1
by brian
clean slate |
435 |
|
436 |
RETURN
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
437 |
> 0 number of bytes read
|
438 |
== 0 End of data
|
|
439 |
< 0 Error
|
|
1
by brian
clean slate |
440 |
*/
|
441 |
||
442 |
static int default_local_infile_read(void *ptr, char *buf, uint buf_len) |
|
443 |
{
|
|
444 |
int count; |
|
445 |
default_local_infile_data*data = (default_local_infile_data *) ptr; |
|
446 |
||
447 |
if ((count= (int) my_read(data->fd, (uchar *) buf, buf_len, MYF(0))) < 0) |
|
448 |
{
|
|
449 |
data->error_num= EE_READ; /* the errmsg for not entire file read */ |
|
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
450 |
snprintf(data->error_msg, sizeof(data->error_msg)-1, |
451 |
EE(EE_READ), |
|
452 |
data->filename, my_errno); |
|
1
by brian
clean slate |
453 |
}
|
454 |
return count; |
|
455 |
}
|
|
456 |
||
457 |
||
458 |
/*
|
|
459 |
Read data for LOAD LOCAL INFILE
|
|
460 |
||
461 |
SYNOPSIS
|
|
462 |
default_local_infile_end()
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
463 |
ptr Points to handle allocated by _init
|
464 |
May be NULL if _init failed!
|
|
1
by brian
clean slate |
465 |
|
466 |
RETURN
|
|
467 |
*/
|
|
468 |
||
469 |
static void default_local_infile_end(void *ptr) |
|
470 |
{
|
|
471 |
default_local_infile_data *data= (default_local_infile_data *) ptr; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
472 |
if (data) /* If not error on open */ |
1
by brian
clean slate |
473 |
{
|
474 |
if (data->fd >= 0) |
|
475 |
my_close(data->fd, MYF(MY_WME)); |
|
207.2.1
by Toru Maesaka
replaced my_malloc/my_free with malloc(3)/free(3). NULL pointer checks also added |
476 |
free(ptr); |
1
by brian
clean slate |
477 |
}
|
478 |
}
|
|
479 |
||
480 |
||
481 |
/*
|
|
482 |
Return error from LOAD LOCAL INFILE
|
|
483 |
||
484 |
SYNOPSIS
|
|
485 |
default_local_infile_end()
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
486 |
ptr Points to handle allocated by _init
|
487 |
May be NULL if _init failed!
|
|
488 |
error_msg Store error text here
|
|
489 |
error_msg_len Max lenght of error_msg
|
|
1
by brian
clean slate |
490 |
|
491 |
RETURN
|
|
492 |
error message number
|
|
493 |
*/
|
|
494 |
||
495 |
static int |
|
496 |
default_local_infile_error(void *ptr, char *error_msg, uint error_msg_len) |
|
497 |
{
|
|
498 |
default_local_infile_data *data = (default_local_infile_data *) ptr; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
499 |
if (data) /* If not error on open */ |
1
by brian
clean slate |
500 |
{
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
501 |
strncpy(error_msg, data->error_msg, error_msg_len); |
1
by brian
clean slate |
502 |
return data->error_num; |
503 |
}
|
|
504 |
/* This can only happen if we got error on malloc of handle */
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
505 |
strcpy(error_msg, ER(CR_OUT_OF_MEMORY)); |
1
by brian
clean slate |
506 |
return CR_OUT_OF_MEMORY; |
507 |
}
|
|
508 |
||
509 |
||
510 |
void
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
511 |
drizzle_set_local_infile_handler(DRIZZLE *drizzle, |
1
by brian
clean slate |
512 |
int (*local_infile_init)(void **, const char *, |
513 |
void *), |
|
514 |
int (*local_infile_read)(void *, char *, uint), |
|
515 |
void (*local_infile_end)(void *), |
|
516 |
int (*local_infile_error)(void *, char *, uint), |
|
517 |
void *userdata) |
|
518 |
{
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
519 |
drizzle->options.local_infile_init= local_infile_init; |
520 |
drizzle->options.local_infile_read= local_infile_read; |
|
521 |
drizzle->options.local_infile_end= local_infile_end; |
|
522 |
drizzle->options.local_infile_error= local_infile_error; |
|
523 |
drizzle->options.local_infile_userdata = userdata; |
|
1
by brian
clean slate |
524 |
}
|
525 |
||
526 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
527 |
void drizzle_set_local_infile_default(DRIZZLE *drizzle) |
1
by brian
clean slate |
528 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
529 |
drizzle->options.local_infile_init= default_local_infile_init; |
530 |
drizzle->options.local_infile_read= default_local_infile_read; |
|
531 |
drizzle->options.local_infile_end= default_local_infile_end; |
|
532 |
drizzle->options.local_infile_error= default_local_infile_error; |
|
1
by brian
clean slate |
533 |
}
|
534 |
||
535 |
||
536 |
/**************************************************************************
|
|
537 |
Do a query. If query returned rows, free old rows.
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
538 |
Read data by drizzle_store_result or by repeat call of drizzle_fetch_row
|
1
by brian
clean slate |
539 |
**************************************************************************/
|
540 |
||
541 |
int STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
542 |
drizzle_query(DRIZZLE *drizzle, const char *query) |
1
by brian
clean slate |
543 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
544 |
return drizzle_real_query(drizzle,query, (uint) strlen(query)); |
1
by brian
clean slate |
545 |
}
|
546 |
||
547 |
||
548 |
/**************************************************************************
|
|
549 |
Return next field of the query results
|
|
550 |
**************************************************************************/
|
|
551 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
552 |
DRIZZLE_FIELD * STDCALL |
553 |
drizzle_fetch_field(DRIZZLE_RES *result) |
|
1
by brian
clean slate |
554 |
{
|
555 |
if (result->current_field >= result->field_count) |
|
556 |
return(NULL); |
|
557 |
return &result->fields[result->current_field++]; |
|
558 |
}
|
|
559 |
||
560 |
||
561 |
/**************************************************************************
|
|
562 |
Move to a specific row and column
|
|
563 |
**************************************************************************/
|
|
564 |
||
565 |
void STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
566 |
drizzle_data_seek(DRIZZLE_RES *result, uint64_t row) |
1
by brian
clean slate |
567 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
568 |
DRIZZLE_ROWS *tmp=0; |
1
by brian
clean slate |
569 |
if (result->data) |
570 |
for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; |
|
571 |
result->current_row=0; |
|
572 |
result->data_cursor = tmp; |
|
573 |
}
|
|
574 |
||
575 |
||
576 |
/*************************************************************************
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
577 |
put the row or field cursor one a position one got from DRIZZLE_ROW_tell()
|
578 |
This doesn't restore any data. The next drizzle_fetch_row or
|
|
579 |
drizzle_fetch_field will return the next row or field after the last used
|
|
1
by brian
clean slate |
580 |
*************************************************************************/
|
581 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
582 |
DRIZZLE_ROW_OFFSET STDCALL |
583 |
drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET row) |
|
1
by brian
clean slate |
584 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
585 |
DRIZZLE_ROW_OFFSET return_value=result->data_cursor; |
1
by brian
clean slate |
586 |
result->current_row= 0; |
587 |
result->data_cursor= row; |
|
588 |
return return_value; |
|
589 |
}
|
|
590 |
||
591 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
592 |
DRIZZLE_FIELD_OFFSET STDCALL |
593 |
drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET field_offset) |
|
1
by brian
clean slate |
594 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
595 |
DRIZZLE_FIELD_OFFSET return_value=result->current_field; |
1
by brian
clean slate |
596 |
result->current_field=field_offset; |
597 |
return return_value; |
|
598 |
}
|
|
599 |
||
600 |
||
601 |
/*****************************************************************************
|
|
602 |
List all tables in a database
|
|
603 |
If wild is given then only the tables matching wild is returned
|
|
604 |
*****************************************************************************/
|
|
605 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
606 |
DRIZZLE_RES * STDCALL |
607 |
drizzle_list_tables(DRIZZLE *drizzle, const char *wild) |
|
1
by brian
clean slate |
608 |
{
|
609 |
char buff[255]; |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
610 |
char *ptr= strcpy(buff, "show tables"); |
611 |
ptr+= 11; /* strlen("show tables"); */ |
|
1
by brian
clean slate |
612 |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
613 |
append_wild(ptr,buff+sizeof(buff),wild); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
614 |
if (drizzle_query(drizzle,buff)) |
51.3.5
by Jay Pipes
Merged in from trunk. |
615 |
return(0); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
616 |
return (drizzle_store_result(drizzle)); |
1
by brian
clean slate |
617 |
}
|
618 |
||
619 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
620 |
DRIZZLE_FIELD *cli_list_fields(DRIZZLE *drizzle) |
1
by brian
clean slate |
621 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
622 |
DRIZZLE_DATA *query; |
623 |
if (!(query= cli_read_rows(drizzle,(DRIZZLE_FIELD*) 0, |
|
624 |
protocol_41(drizzle) ? 8 : 6))) |
|
1
by brian
clean slate |
625 |
return NULL; |
626 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
627 |
drizzle->field_count= (uint) query->rows; |
628 |
return unpack_fields(query,&drizzle->field_alloc, |
|
629 |
drizzle->field_count, 1, drizzle->server_capabilities); |
|
1
by brian
clean slate |
630 |
}
|
631 |
||
632 |
||
633 |
/**************************************************************************
|
|
634 |
List all fields in a table
|
|
635 |
If wild is given then only the fields matching wild is returned
|
|
636 |
Instead of this use query:
|
|
637 |
show fields in 'table' like "wild"
|
|
638 |
**************************************************************************/
|
|
639 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
640 |
DRIZZLE_RES * STDCALL |
641 |
drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild) |
|
1
by brian
clean slate |
642 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
643 |
DRIZZLE_RES *result; |
644 |
DRIZZLE_FIELD *fields; |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
645 |
char buff[257], *end; |
646 |
||
647 |
end= strncpy(buff, table, 128) + 128; |
|
648 |
end= strncpy(end+1, wild ? wild : "", 128) + 128; |
|
649 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
650 |
free_old_query(drizzle); |
651 |
if (simple_command(drizzle, COM_FIELD_LIST, (uchar*) buff, |
|
1
by brian
clean slate |
652 |
(ulong) (end-buff), 1) || |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
653 |
!(fields= (*drizzle->methods->list_fields)(drizzle))) |
654 |
return(NULL); |
|
655 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
656 |
if (!(result = (DRIZZLE_RES *) malloc(sizeof(DRIZZLE_RES)))) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
657 |
return(NULL); |
658 |
||
659 |
result->methods= drizzle->methods; |
|
660 |
result->field_alloc=drizzle->field_alloc; |
|
661 |
drizzle->fields=0; |
|
662 |
result->field_count = drizzle->field_count; |
|
1
by brian
clean slate |
663 |
result->fields= fields; |
664 |
result->eof=1; |
|
51.3.5
by Jay Pipes
Merged in from trunk. |
665 |
return(result); |
1
by brian
clean slate |
666 |
}
|
667 |
||
668 |
/* List all running processes (threads) in server */
|
|
669 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
670 |
DRIZZLE_RES * STDCALL |
671 |
drizzle_list_processes(DRIZZLE *drizzle) |
|
1
by brian
clean slate |
672 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
673 |
DRIZZLE_DATA *fields; |
1
by brian
clean slate |
674 |
uint field_count; |
675 |
uchar *pos; |
|
676 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
677 |
if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0)) |
51.3.5
by Jay Pipes
Merged in from trunk. |
678 |
return(0); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
679 |
free_old_query(drizzle); |
680 |
pos=(uchar*) drizzle->net.read_pos; |
|
1
by brian
clean slate |
681 |
field_count=(uint) net_field_length(&pos); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
682 |
if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0, |
683 |
protocol_41(drizzle) ? 7 : 5))) |
|
51.3.5
by Jay Pipes
Merged in from trunk. |
684 |
return(NULL); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
685 |
if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,field_count,0, |
686 |
drizzle->server_capabilities))) |
|
51.3.5
by Jay Pipes
Merged in from trunk. |
687 |
return(0); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
688 |
drizzle->status=DRIZZLE_STATUS_GET_RESULT; |
689 |
drizzle->field_count=field_count; |
|
690 |
return(drizzle_store_result(drizzle)); |
|
1
by brian
clean slate |
691 |
}
|
692 |
||
693 |
||
694 |
#ifdef USE_OLD_FUNCTIONS
|
|
695 |
int STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
696 |
drizzle_create_db(DRIZZLE *drizzle, const char *db) |
1
by brian
clean slate |
697 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
698 |
return(simple_command(drizzle,COM_CREATE_DB,db, (ulong) strlen(db),0)); |
1
by brian
clean slate |
699 |
}
|
700 |
||
701 |
||
702 |
int STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
703 |
drizzle_drop_db(DRIZZLE *drizzle, const char *db) |
1
by brian
clean slate |
704 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
705 |
return(simple_command(drizzle,COM_DROP_DB,db,(ulong) strlen(db),0)); |
1
by brian
clean slate |
706 |
}
|
707 |
#endif
|
|
708 |
||
709 |
||
710 |
int STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
711 |
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level) |
1
by brian
clean slate |
712 |
{
|
713 |
uchar level[1]; |
|
714 |
level[0]= (uchar) shutdown_level; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
715 |
return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0)); |
1
by brian
clean slate |
716 |
}
|
717 |
||
718 |
||
719 |
int STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
720 |
drizzle_refresh(DRIZZLE *drizzle,uint options) |
1
by brian
clean slate |
721 |
{
|
722 |
uchar bits[1]; |
|
723 |
bits[0]= (uchar) options; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
724 |
return(simple_command(drizzle, COM_REFRESH, bits, 1, 0)); |
1
by brian
clean slate |
725 |
}
|
726 |
||
727 |
||
164
by Brian Aker
Commit cleanup of export types. |
728 |
int32_t STDCALL |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
729 |
drizzle_kill(DRIZZLE *drizzle, uint32_t pid) |
1
by brian
clean slate |
730 |
{
|
731 |
uchar buff[4]; |
|
732 |
int4store(buff,pid); |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
733 |
return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0)); |
1
by brian
clean slate |
734 |
}
|
735 |
||
736 |
||
737 |
int STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
738 |
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option) |
1
by brian
clean slate |
739 |
{
|
740 |
uchar buff[2]; |
|
741 |
int2store(buff, (uint) option); |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
742 |
return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0)); |
1
by brian
clean slate |
743 |
}
|
744 |
||
745 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
746 |
const char *cli_read_statistics(DRIZZLE *drizzle) |
1
by brian
clean slate |
747 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
748 |
drizzle->net.read_pos[drizzle->packet_length]=0; /* End of stat string */ |
749 |
if (!drizzle->net.read_pos[0]) |
|
1
by brian
clean slate |
750 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
751 |
set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate); |
752 |
return drizzle->net.last_error; |
|
1
by brian
clean slate |
753 |
}
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
754 |
return (char*) drizzle->net.read_pos; |
1
by brian
clean slate |
755 |
}
|
756 |
||
757 |
||
758 |
const char * STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
759 |
drizzle_stat(DRIZZLE *drizzle) |
1
by brian
clean slate |
760 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
761 |
if (simple_command(drizzle,COM_STATISTICS,0,0,0)) |
762 |
return(drizzle->net.last_error); |
|
763 |
return((*drizzle->methods->read_statistics)(drizzle)); |
|
1
by brian
clean slate |
764 |
}
|
765 |
||
766 |
||
767 |
int STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
768 |
drizzle_ping(DRIZZLE *drizzle) |
1
by brian
clean slate |
769 |
{
|
770 |
int res; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
771 |
res= simple_command(drizzle,COM_PING,0,0,0); |
772 |
if (res == CR_SERVER_LOST && drizzle->reconnect) |
|
773 |
res= simple_command(drizzle,COM_PING,0,0,0); |
|
51.3.5
by Jay Pipes
Merged in from trunk. |
774 |
return(res); |
1
by brian
clean slate |
775 |
}
|
776 |
||
777 |
||
778 |
const char * STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
779 |
drizzle_get_server_info(DRIZZLE *drizzle) |
1
by brian
clean slate |
780 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
781 |
return((char*) drizzle->server_version); |
1
by brian
clean slate |
782 |
}
|
783 |
||
784 |
||
785 |
const char * STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
786 |
drizzle_get_host_info(DRIZZLE *drizzle) |
1
by brian
clean slate |
787 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
788 |
return(drizzle->host_info); |
1
by brian
clean slate |
789 |
}
|
790 |
||
791 |
||
792 |
uint STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
793 |
drizzle_get_proto_info(DRIZZLE *drizzle) |
1
by brian
clean slate |
794 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
795 |
return (drizzle->protocol_version); |
1
by brian
clean slate |
796 |
}
|
797 |
||
798 |
const char * STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
799 |
drizzle_get_client_info(void) |
1
by brian
clean slate |
800 |
{
|
801 |
return (char*) MYSQL_SERVER_VERSION; |
|
802 |
}
|
|
803 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
804 |
uint32_t STDCALL drizzle_get_client_version(void) |
1
by brian
clean slate |
805 |
{
|
806 |
return MYSQL_VERSION_ID; |
|
807 |
}
|
|
808 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
809 |
bool STDCALL drizzle_eof(DRIZZLE_RES *res) |
1
by brian
clean slate |
810 |
{
|
811 |
return res->eof; |
|
812 |
}
|
|
813 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
814 |
DRIZZLE_FIELD * STDCALL drizzle_fetch_field_direct(DRIZZLE_RES *res,uint fieldnr) |
1
by brian
clean slate |
815 |
{
|
816 |
return &(res)->fields[fieldnr]; |
|
817 |
}
|
|
818 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
819 |
DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(DRIZZLE_RES *res) |
1
by brian
clean slate |
820 |
{
|
821 |
return (res)->fields; |
|
822 |
}
|
|
823 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
824 |
DRIZZLE_ROW_OFFSET STDCALL DRIZZLE_ROW_tell(DRIZZLE_RES *res) |
1
by brian
clean slate |
825 |
{
|
826 |
return res->data_cursor; |
|
827 |
}
|
|
828 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
829 |
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(DRIZZLE_RES *res) |
1
by brian
clean slate |
830 |
{
|
831 |
return (res)->current_field; |
|
832 |
}
|
|
833 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
834 |
/* DRIZZLE */
|
835 |
||
836 |
unsigned int STDCALL drizzle_field_count(DRIZZLE *drizzle) |
|
837 |
{
|
|
838 |
return drizzle->field_count; |
|
839 |
}
|
|
840 |
||
841 |
uint64_t STDCALL drizzle_affected_rows(DRIZZLE *drizzle) |
|
842 |
{
|
|
843 |
return drizzle->affected_rows; |
|
844 |
}
|
|
845 |
||
846 |
uint64_t STDCALL drizzle_insert_id(DRIZZLE *drizzle) |
|
847 |
{
|
|
848 |
return drizzle->insert_id; |
|
849 |
}
|
|
850 |
||
851 |
const char *STDCALL drizzle_sqlstate(DRIZZLE *drizzle) |
|
852 |
{
|
|
853 |
return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate; |
|
854 |
}
|
|
855 |
||
856 |
uint32_t STDCALL drizzle_warning_count(DRIZZLE *drizzle) |
|
857 |
{
|
|
858 |
return drizzle->warning_count; |
|
859 |
}
|
|
860 |
||
861 |
const char *STDCALL drizzle_info(DRIZZLE *drizzle) |
|
862 |
{
|
|
863 |
return drizzle->info; |
|
864 |
}
|
|
865 |
||
866 |
uint32_t STDCALL drizzle_thread_id(DRIZZLE *drizzle) |
|
867 |
{
|
|
868 |
return (drizzle)->thread_id; |
|
869 |
}
|
|
870 |
||
871 |
const char * STDCALL drizzle_character_set_name(DRIZZLE *drizzle) |
|
872 |
{
|
|
873 |
return drizzle->charset->csname; |
|
874 |
}
|
|
875 |
||
876 |
void STDCALL drizzle_get_character_set_info(DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo) |
|
877 |
{
|
|
878 |
csinfo->number = drizzle->charset->number; |
|
879 |
csinfo->state = drizzle->charset->state; |
|
880 |
csinfo->csname = drizzle->charset->csname; |
|
881 |
csinfo->name = drizzle->charset->name; |
|
882 |
csinfo->comment = drizzle->charset->comment; |
|
883 |
csinfo->mbminlen = drizzle->charset->mbminlen; |
|
884 |
csinfo->mbmaxlen = drizzle->charset->mbmaxlen; |
|
885 |
||
886 |
if (drizzle->options.charset_dir) |
|
887 |
csinfo->dir = drizzle->options.charset_dir; |
|
1
by brian
clean slate |
888 |
else
|
889 |
csinfo->dir = charsets_dir; |
|
890 |
}
|
|
891 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
892 |
uint STDCALL drizzle_thread_safe(void) |
1
by brian
clean slate |
893 |
{
|
894 |
return 1; |
|
895 |
}
|
|
896 |
||
897 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
898 |
bool STDCALL drizzle_embedded(void) |
1
by brian
clean slate |
899 |
{
|
900 |
#ifdef EMBEDDED_LIBRARY
|
|
207.2.2
by Toru Maesaka
replaced my_bool in libdrizzle with C99 boolean |
901 |
return true; |
1
by brian
clean slate |
902 |
#else
|
207.2.2
by Toru Maesaka
replaced my_bool in libdrizzle with C99 boolean |
903 |
return false; |
1
by brian
clean slate |
904 |
#endif
|
905 |
}
|
|
906 |
||
907 |
/****************************************************************************
|
|
908 |
Some support functions
|
|
909 |
****************************************************************************/
|
|
910 |
||
911 |
/*
|
|
912 |
Functions called my my_net_init() to set some application specific variables
|
|
913 |
*/
|
|
914 |
||
915 |
void my_net_local_init(NET *net) |
|
916 |
{
|
|
917 |
net->max_packet= (uint) net_buffer_length; |
|
918 |
my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT); |
|
919 |
my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT); |
|
920 |
net->retry_count= 1; |
|
921 |
net->max_packet_size= max(net_buffer_length, max_allowed_packet); |
|
922 |
}
|
|
923 |
||
924 |
/*
|
|
925 |
This function is used to create HEX string that you
|
|
926 |
can use in a SQL statement in of the either ways:
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
927 |
INSERT INTO blob_column VALUES (0xAABBCC); (any DRIZZLE version)
|
1
by brian
clean slate |
928 |
INSERT INTO blob_column VALUES (X'AABBCC'); (4.1 and higher)
|
929 |
|
|
930 |
The string in "from" is encoded to a HEX string.
|
|
931 |
The result is placed in "to" and a terminating null byte is appended.
|
|
932 |
|
|
933 |
The string pointed to by "from" must be "length" bytes long.
|
|
934 |
You must allocate the "to" buffer to be at least length*2+1 bytes long.
|
|
935 |
Each character needs two bytes, and you need room for the terminating
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
936 |
null byte. When drizzle_hex_string() returns, the contents of "to" will
|
1
by brian
clean slate |
937 |
be a null-terminated string. The return value is the length of the
|
938 |
encoded string, not including the terminating null character.
|
|
939 |
||
940 |
The return value does not contain any leading 0x or a leading X' and
|
|
941 |
trailing '. The caller must supply whichever of those is desired.
|
|
942 |
*/
|
|
943 |
||
164
by Brian Aker
Commit cleanup of export types. |
944 |
uint32_t STDCALL |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
945 |
drizzle_hex_string(char *to, const char *from, uint32_t length) |
1
by brian
clean slate |
946 |
{
|
947 |
char *to0= to; |
|
948 |
const char *end; |
|
949 |
||
950 |
for (end= from + length; from < end; from++) |
|
951 |
{
|
|
952 |
*to++= _dig_vec_upper[((unsigned char) *from) >> 4]; |
|
953 |
*to++= _dig_vec_upper[((unsigned char) *from) & 0x0F]; |
|
954 |
}
|
|
955 |
*to= '\0'; |
|
164
by Brian Aker
Commit cleanup of export types. |
956 |
return (uint32_t) (to-to0); |
1
by brian
clean slate |
957 |
}
|
958 |
||
959 |
/*
|
|
960 |
Add escape characters to a string (blob?) to make it suitable for a insert
|
|
961 |
to should at least have place for length*2+1 chars
|
|
962 |
Returns the length of the to string
|
|
963 |
*/
|
|
964 |
||
164
by Brian Aker
Commit cleanup of export types. |
965 |
uint32_t STDCALL |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
966 |
drizzle_escape_string(char *to,const char *from, uint32_t length) |
1
by brian
clean slate |
967 |
{
|
968 |
return escape_string_for_mysql(default_charset_info, to, 0, from, length); |
|
969 |
}
|
|
970 |
||
164
by Brian Aker
Commit cleanup of export types. |
971 |
uint32_t STDCALL |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
972 |
drizzle_real_escape_string(DRIZZLE *drizzle, char *to,const char *from, |
973 |
uint32_t length) |
|
1
by brian
clean slate |
974 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
975 |
if (drizzle->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) |
976 |
return escape_quotes_for_mysql(drizzle->charset, to, 0, from, length); |
|
977 |
return escape_string_for_mysql(drizzle->charset, to, 0, from, length); |
|
1
by brian
clean slate |
978 |
}
|
979 |
||
980 |
void STDCALL |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
981 |
myodbc_remove_escape(DRIZZLE *drizzle,char *name) |
1
by brian
clean slate |
982 |
{
|
983 |
char *to; |
|
984 |
#ifdef USE_MB
|
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
985 |
bool use_mb_flag=use_mb(drizzle->charset); |
77.1.77
by Monty Taylor
A crapton more warning cleanups (I turned on more warnings) |
986 |
char *end=NULL; |
1
by brian
clean slate |
987 |
if (use_mb_flag) |
988 |
for (end=name; *end ; end++) ; |
|
989 |
#endif
|
|
990 |
||
991 |
for (to=name ; *name ; name++) |
|
992 |
{
|
|
993 |
#ifdef USE_MB
|
|
994 |
int l; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
995 |
if (use_mb_flag && (l = my_ismbchar( drizzle->charset, name , end ) ) ) |
1
by brian
clean slate |
996 |
{
|
997 |
while (l--) |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
998 |
*to++ = *name++; |
1
by brian
clean slate |
999 |
name--; |
1000 |
continue; |
|
1001 |
}
|
|
1002 |
#endif
|
|
1003 |
if (*name == '\\' && name[1]) |
|
1004 |
name++; |
|
1005 |
*to++= *name; |
|
1006 |
}
|
|
1007 |
*to=0; |
|
1008 |
}
|
|
1009 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1010 |
int cli_unbuffered_fetch(DRIZZLE *drizzle, char **row) |
1
by brian
clean slate |
1011 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1012 |
if (packet_error == cli_safe_read(drizzle)) |
1
by brian
clean slate |
1013 |
return 1; |
1014 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1015 |
*row= ((drizzle->net.read_pos[0] == 254) ? NULL : |
1016 |
(char*) (drizzle->net.read_pos+1)); |
|
1
by brian
clean slate |
1017 |
return 0; |
1018 |
}
|
|
1019 |
||
1020 |
/********************************************************************
|
|
1021 |
Transactional APIs
|
|
1022 |
*********************************************************************/
|
|
1023 |
||
1024 |
/*
|
|
1025 |
Commit the current transaction
|
|
1026 |
*/
|
|
1027 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1028 |
bool STDCALL drizzle_commit(DRIZZLE *drizzle) |
1
by brian
clean slate |
1029 |
{
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1030 |
return((bool) drizzle_real_query(drizzle, "commit", 6)); |
1
by brian
clean slate |
1031 |
}
|
1032 |
||
1033 |
/*
|
|
1034 |
Rollback the current transaction
|
|
1035 |
*/
|
|
1036 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1037 |
bool STDCALL drizzle_rollback(DRIZZLE *drizzle) |
1
by brian
clean slate |
1038 |
{
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1039 |
return((bool) drizzle_real_query(drizzle, "rollback", 8)); |
1
by brian
clean slate |
1040 |
}
|
1041 |
||
1042 |
||
1043 |
/*
|
|
1044 |
Set autocommit to either true or false
|
|
1045 |
*/
|
|
1046 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1047 |
bool STDCALL drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode) |
1
by brian
clean slate |
1048 |
{
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1049 |
return((bool) drizzle_real_query(drizzle, auto_mode ? |
1
by brian
clean slate |
1050 |
"set autocommit=1":"set autocommit=0", |
1051 |
16)); |
|
1052 |
}
|
|
1053 |
||
1054 |
||
1055 |
/********************************************************************
|
|
1056 |
Multi query execution + SPs APIs
|
|
1057 |
*********************************************************************/
|
|
1058 |
||
1059 |
/*
|
|
1060 |
Returns true/false to indicate whether any more query results exist
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1061 |
to be read using drizzle_next_result()
|
1
by brian
clean slate |
1062 |
*/
|
1063 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1064 |
bool STDCALL drizzle_more_results(DRIZZLE *drizzle) |
1
by brian
clean slate |
1065 |
{
|
207.2.2
by Toru Maesaka
replaced my_bool in libdrizzle with C99 boolean |
1066 |
bool res; |
1
by brian
clean slate |
1067 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1068 |
res= ((drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) ? 1: 0); |
51.3.5
by Jay Pipes
Merged in from trunk. |
1069 |
return(res); |
1
by brian
clean slate |
1070 |
}
|
1071 |
||
1072 |
||
1073 |
/*
|
|
1074 |
Reads and returns the next query results
|
|
1075 |
*/
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1076 |
int STDCALL drizzle_next_result(DRIZZLE *drizzle) |
1
by brian
clean slate |
1077 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1078 |
if (drizzle->status != DRIZZLE_STATUS_READY) |
1
by brian
clean slate |
1079 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1080 |
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); |
51.3.5
by Jay Pipes
Merged in from trunk. |
1081 |
return(1); |
1
by brian
clean slate |
1082 |
}
|
1083 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1084 |
net_clear_error(&drizzle->net); |
1085 |
drizzle->affected_rows= ~(uint64_t) 0; |
|
1086 |
||
1087 |
if (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) |
|
1088 |
return((*drizzle->methods->next_result)(drizzle)); |
|
1089 |
||
1090 |
return(-1); /* No more results */ |
|
1091 |
}
|
|
1092 |
||
1093 |
||
1094 |
DRIZZLE_RES * STDCALL drizzle_use_result(DRIZZLE *drizzle) |
|
1095 |
{
|
|
1096 |
return (*drizzle->methods->use_result)(drizzle); |
|
1097 |
}
|
|
1098 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
1099 |
bool STDCALL drizzle_read_query_result(DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
1100 |
{
|
1101 |
return (*drizzle->methods->read_query_result)(drizzle); |
|
1
by brian
clean slate |
1102 |
}
|
1103 |