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> |
383.1.44
by Monty Taylor
Renamed drizzle.h to libdrizzle.h. |
21 |
#include "libdrizzle.h" |
1
by brian
clean slate |
22 |
#include "errmsg.h" |
23 |
#include <sys/stat.h> |
|
24 |
#include <signal.h> |
|
25 |
#include <time.h> |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
26 |
#ifdef HAVE_PWD_H
|
1
by brian
clean slate |
27 |
#include <pwd.h> |
28 |
#endif
|
|
94
by Brian Aker
DOS removal. DOS... hard to believe aye? |
29 |
|
1
by brian
clean slate |
30 |
#include <sys/socket.h> |
31 |
#include <netinet/in.h> |
|
32 |
#include <arpa/inet.h> |
|
33 |
#include <netdb.h> |
|
34 |
#ifdef HAVE_SELECT_H
|
|
35 |
#include <select.h> |
|
36 |
#endif
|
|
37 |
#ifdef HAVE_SYS_SELECT_H
|
|
38 |
#include <sys/select.h> |
|
39 |
#endif
|
|
94
by Brian Aker
DOS removal. DOS... hard to believe aye? |
40 |
|
1
by brian
clean slate |
41 |
#ifdef HAVE_POLL
|
42 |
#include <sys/poll.h> |
|
43 |
#endif
|
|
44 |
#ifdef HAVE_SYS_UN_H
|
|
45 |
#include <sys/un.h> |
|
46 |
#endif
|
|
47 |
#ifndef INADDR_NONE
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
48 |
#define INADDR_NONE -1
|
1
by brian
clean slate |
49 |
#endif
|
50 |
||
51 |
#include <sql_common.h> |
|
264.1.9
by Monty Taylor
Removed version.h (non-public header) from drizzle.h (public header) |
52 |
#include <drizzled/version.h> |
1
by brian
clean slate |
53 |
|
383.1.38
by Monty Taylor
Reworked drizzle_escape_string. |
54 |
/* Borrowed from libicu header */
|
55 |
||
56 |
#define U8_IS_SINGLE(c) (((c)&0x80)==0)
|
|
57 |
#define U8_LENGTH(c) \
|
|
58 |
((uint32_t)(c)<=0x7f ? 1 : \
|
|
59 |
((uint32_t)(c)<=0x7ff ? 2 : \
|
|
60 |
((uint32_t)(c)<=0xd7ff ? 3 : \
|
|
61 |
((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
|
|
62 |
((uint32_t)(c)<=0xffff ? 3 : 4)\
|
|
63 |
) \
|
|
64 |
) \
|
|
65 |
) \
|
|
66 |
)
|
|
67 |
||
68 |
||
1
by brian
clean slate |
69 |
#undef net_buffer_length
|
70 |
#undef max_allowed_packet
|
|
71 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
72 |
uint32_t net_buffer_length= 8192; |
73 |
uint32_t max_allowed_packet= 1024L*1024L*1024L; |
|
1
by brian
clean slate |
74 |
|
75 |
#include <errno.h> |
|
76 |
#define SOCKET_ERROR -1
|
|
77 |
||
78 |
/*
|
|
79 |
If allowed through some configuration, then this needs to
|
|
80 |
be changed
|
|
81 |
*/
|
|
82 |
#define MAX_LONG_DATA_LENGTH 8192
|
|
83 |
#define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG)
|
|
84 |
||
202.2.2
by Monty Taylor
Merged mysql_server_init into drizzle_create() |
85 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
86 |
static DRIZZLE_PARAMETERS drizzle_internal_parameters= |
1
by brian
clean slate |
87 |
{&max_allowed_packet, &net_buffer_length, 0}; |
88 |
||
287.3.6
by Monty Taylor
Eeek. Final cleanups. |
89 |
const DRIZZLE_PARAMETERS * drizzle_get_parameters(void) |
1
by brian
clean slate |
90 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
91 |
return &drizzle_internal_parameters; |
1
by brian
clean slate |
92 |
}
|
93 |
||
94 |
/*
|
|
95 |
Expand wildcard to a sql string
|
|
96 |
*/
|
|
97 |
||
98 |
static void |
|
99 |
append_wild(char *to, char *end, const char *wild) |
|
100 |
{
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
101 |
end-=5; /* Some extra */ |
1
by brian
clean slate |
102 |
if (wild && wild[0]) |
103 |
{
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
104 |
to= strcpy(to," like '"); |
105 |
to+= 7; /* strlen(" like '"); */ |
|
106 |
||
1
by brian
clean slate |
107 |
while (*wild && to < end) |
108 |
{
|
|
109 |
if (*wild == '\\' || *wild == '\'') |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
110 |
*to++='\\'; |
1
by brian
clean slate |
111 |
*to++= *wild++; |
112 |
}
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
113 |
if (*wild) /* Too small buffer */ |
114 |
*to++='%'; /* Nicer this way */ |
|
1
by brian
clean slate |
115 |
to[0]='\''; |
116 |
to[1]=0; |
|
117 |
}
|
|
118 |
}
|
|
119 |
||
120 |
/**************************************************************************
|
|
121 |
Change user and database
|
|
122 |
**************************************************************************/
|
|
123 |
||
236.3.6
by Andrey Hristov
read_change_user_result doesn't neet buffer and password. They were needed to handle 3.23 authentication, which is no more. |
124 |
int cli_read_change_user_result(DRIZZLE *drizzle) |
1
by brian
clean slate |
125 |
{
|
294
by Brian Aker
libdrizzle has ulong removed. |
126 |
uint32_t pkt_length; |
1
by brian
clean slate |
127 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
128 |
pkt_length= cli_safe_read(drizzle); |
1
by brian
clean slate |
129 |
|
130 |
if (pkt_length == packet_error) |
|
131 |
return 1; |
|
132 |
||
133 |
return 0; |
|
134 |
}
|
|
135 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
136 |
bool drizzle_change_user(DRIZZLE *drizzle, const char *user, |
261.1.2
by Brian Aker
Cleanup/removal of more of the dead protocols. |
137 |
const char *passwd, const char *db) |
1
by brian
clean slate |
138 |
{
|
139 |
char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2]; |
|
140 |
char *end= buff; |
|
141 |
int rc; |
|
142 |
||
143 |
/* Use an empty string instead of NULL. */
|
|
144 |
||
145 |
if (!user) |
|
146 |
user=""; |
|
147 |
if (!passwd) |
|
148 |
passwd=""; |
|
149 |
||
150 |
/* Store user into the buffer */
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
151 |
end= strncpy(end, user, USERNAME_LENGTH) + USERNAME_LENGTH + 1; |
1
by brian
clean slate |
152 |
|
153 |
/* write scrambled password according to server capabilities */
|
|
154 |
if (passwd[0]) |
|
155 |
{
|
|
156 |
{
|
|
157 |
*end++= SCRAMBLE_LENGTH; |
|
158 |
end+= SCRAMBLE_LENGTH; |
|
159 |
}
|
|
160 |
}
|
|
161 |
else
|
|
162 |
*end++= '\0'; /* empty password */ |
|
163 |
/* Add database if needed */
|
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
164 |
end= strncpy(end, db ? db : "", NAME_LEN) + NAME_LEN + 1; |
1
by brian
clean slate |
165 |
|
166 |
/* Add character set number. */
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
167 |
if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION) |
1
by brian
clean slate |
168 |
{
|
383.1.39
by Monty Taylor
Removed more CHARSET_INFO stuff from libdrizzle. |
169 |
int2store(end, (ushort) 45); // utf8mb4 number from mystrings/ctype-utf8.c |
1
by brian
clean slate |
170 |
end+= 2; |
171 |
}
|
|
172 |
||
173 |
/* Write authentication package */
|
|
294
by Brian Aker
libdrizzle has ulong removed. |
174 |
(void)simple_command(drizzle,COM_CHANGE_USER, (uchar*) buff, (uint32_t) (end-buff), 1); |
1
by brian
clean slate |
175 |
|
236.3.6
by Andrey Hristov
read_change_user_result doesn't neet buffer and password. They were needed to handle 3.23 authentication, which is no more. |
176 |
rc= (*drizzle->methods->read_change_user_result)(drizzle); |
1
by brian
clean slate |
177 |
|
178 |
if (rc == 0) |
|
179 |
{
|
|
180 |
/* Free old connect information */
|
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
181 |
if(drizzle->user) |
182 |
free(drizzle->user); |
|
183 |
if(drizzle->passwd) |
|
184 |
free(drizzle->passwd); |
|
185 |
if(drizzle->db) |
|
186 |
free(drizzle->db); |
|
1
by brian
clean slate |
187 |
|
188 |
/* alloc new connect information */
|
|
240.1.1
by Toru Maesaka
removed my_strdup and dead code from libdrizzle |
189 |
drizzle->user= strdup(user); |
190 |
drizzle->passwd= strdup(passwd); |
|
191 |
drizzle->db= db ? strdup(db) : 0; |
|
1
by brian
clean slate |
192 |
}
|
193 |
||
51.3.5
by Jay Pipes
Merged in from trunk. |
194 |
return(rc); |
1
by brian
clean slate |
195 |
}
|
196 |
||
197 |
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
|
|
198 |
struct passwd *getpwuid(uid_t); |
|
199 |
char* getlogin(void); |
|
200 |
#endif
|
|
201 |
||
202 |
/**************************************************************************
|
|
203 |
Do a query. If query returned rows, free old rows.
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
204 |
Read data by drizzle_store_result or by repeat call of drizzle_fetch_row
|
1
by brian
clean slate |
205 |
**************************************************************************/
|
206 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
207 |
int
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
208 |
drizzle_query(DRIZZLE *drizzle, const char *query) |
1
by brian
clean slate |
209 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
210 |
return drizzle_real_query(drizzle,query, (uint) strlen(query)); |
1
by brian
clean slate |
211 |
}
|
212 |
||
213 |
||
214 |
/**************************************************************************
|
|
215 |
Return next field of the query results
|
|
216 |
**************************************************************************/
|
|
217 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
218 |
DRIZZLE_FIELD * |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
219 |
drizzle_fetch_field(DRIZZLE_RES *result) |
1
by brian
clean slate |
220 |
{
|
221 |
if (result->current_field >= result->field_count) |
|
222 |
return(NULL); |
|
223 |
return &result->fields[result->current_field++]; |
|
224 |
}
|
|
225 |
||
226 |
||
227 |
/**************************************************************************
|
|
228 |
Move to a specific row and column
|
|
229 |
**************************************************************************/
|
|
230 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
231 |
void
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
232 |
drizzle_data_seek(DRIZZLE_RES *result, uint64_t row) |
1
by brian
clean slate |
233 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
234 |
DRIZZLE_ROWS *tmp=0; |
1
by brian
clean slate |
235 |
if (result->data) |
236 |
for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; |
|
237 |
result->current_row=0; |
|
238 |
result->data_cursor = tmp; |
|
239 |
}
|
|
240 |
||
241 |
||
242 |
/*************************************************************************
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
243 |
put the row or field cursor one a position one got from DRIZZLE_ROW_tell()
|
244 |
This doesn't restore any data. The next drizzle_fetch_row or
|
|
245 |
drizzle_fetch_field will return the next row or field after the last used
|
|
1
by brian
clean slate |
246 |
*************************************************************************/
|
247 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
248 |
DRIZZLE_ROW_OFFSET
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
249 |
drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET row) |
1
by brian
clean slate |
250 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
251 |
DRIZZLE_ROW_OFFSET return_value=result->data_cursor; |
1
by brian
clean slate |
252 |
result->current_row= 0; |
253 |
result->data_cursor= row; |
|
254 |
return return_value; |
|
255 |
}
|
|
256 |
||
257 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
258 |
DRIZZLE_FIELD_OFFSET
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
259 |
drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET field_offset) |
1
by brian
clean slate |
260 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
261 |
DRIZZLE_FIELD_OFFSET return_value=result->current_field; |
1
by brian
clean slate |
262 |
result->current_field=field_offset; |
263 |
return return_value; |
|
264 |
}
|
|
265 |
||
266 |
||
267 |
/*****************************************************************************
|
|
268 |
List all tables in a database
|
|
269 |
If wild is given then only the tables matching wild is returned
|
|
270 |
*****************************************************************************/
|
|
271 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
272 |
DRIZZLE_RES * |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
273 |
drizzle_list_tables(DRIZZLE *drizzle, const char *wild) |
1
by brian
clean slate |
274 |
{
|
275 |
char buff[255]; |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
276 |
char *ptr= strcpy(buff, "show tables"); |
277 |
ptr+= 11; /* strlen("show tables"); */ |
|
1
by brian
clean slate |
278 |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
279 |
append_wild(ptr,buff+sizeof(buff),wild); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
280 |
if (drizzle_query(drizzle,buff)) |
51.3.5
by Jay Pipes
Merged in from trunk. |
281 |
return(0); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
282 |
return (drizzle_store_result(drizzle)); |
1
by brian
clean slate |
283 |
}
|
284 |
||
285 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
286 |
DRIZZLE_FIELD *cli_list_fields(DRIZZLE *drizzle) |
1
by brian
clean slate |
287 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
288 |
DRIZZLE_DATA *query; |
264.2.4
by Andrey Hristov
Remove support for the old, pre-4.1, protocol |
289 |
if (!(query= cli_read_rows(drizzle,(DRIZZLE_FIELD*) 0, 8))) |
1
by brian
clean slate |
290 |
return NULL; |
291 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
292 |
drizzle->field_count= (uint) query->rows; |
383.1.40
by Monty Taylor
More mysys removal from libdrizzle. Got rid of MEM_ROOT related stuff. |
293 |
return unpack_fields(query, drizzle->field_count, 1); |
1
by brian
clean slate |
294 |
}
|
295 |
||
296 |
||
297 |
/**************************************************************************
|
|
298 |
List all fields in a table
|
|
299 |
If wild is given then only the fields matching wild is returned
|
|
300 |
Instead of this use query:
|
|
301 |
show fields in 'table' like "wild"
|
|
302 |
**************************************************************************/
|
|
303 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
304 |
DRIZZLE_RES * |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
305 |
drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild) |
1
by brian
clean slate |
306 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
307 |
DRIZZLE_RES *result; |
308 |
DRIZZLE_FIELD *fields; |
|
240.1.2
by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c |
309 |
char buff[257], *end; |
310 |
||
311 |
end= strncpy(buff, table, 128) + 128; |
|
312 |
end= strncpy(end+1, wild ? wild : "", 128) + 128; |
|
313 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
314 |
free_old_query(drizzle); |
315 |
if (simple_command(drizzle, COM_FIELD_LIST, (uchar*) buff, |
|
294
by Brian Aker
libdrizzle has ulong removed. |
316 |
(uint32_t) (end-buff), 1) || |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
317 |
!(fields= (*drizzle->methods->list_fields)(drizzle))) |
318 |
return(NULL); |
|
319 |
||
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
320 |
if (!(result = (DRIZZLE_RES *) malloc(sizeof(DRIZZLE_RES)))) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
321 |
return(NULL); |
322 |
||
266.3.2
by Andrew Garner
memory was not initialized for new results in drizzle_list_fields |
323 |
memset(result, 0, sizeof(DRIZZLE_RES)); |
324 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
325 |
result->methods= drizzle->methods; |
326 |
drizzle->fields=0; |
|
327 |
result->field_count = drizzle->field_count; |
|
1
by brian
clean slate |
328 |
result->fields= fields; |
329 |
result->eof=1; |
|
51.3.5
by Jay Pipes
Merged in from trunk. |
330 |
return(result); |
1
by brian
clean slate |
331 |
}
|
332 |
||
333 |
/* List all running processes (threads) in server */
|
|
334 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
335 |
DRIZZLE_RES * |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
336 |
drizzle_list_processes(DRIZZLE *drizzle) |
1
by brian
clean slate |
337 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
338 |
DRIZZLE_DATA *fields; |
1
by brian
clean slate |
339 |
uint field_count; |
340 |
uchar *pos; |
|
341 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
342 |
if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0)) |
51.3.5
by Jay Pipes
Merged in from trunk. |
343 |
return(0); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
344 |
free_old_query(drizzle); |
345 |
pos=(uchar*) drizzle->net.read_pos; |
|
1
by brian
clean slate |
346 |
field_count=(uint) net_field_length(&pos); |
264.2.4
by Andrey Hristov
Remove support for the old, pre-4.1, protocol |
347 |
if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0, 7))) |
51.3.5
by Jay Pipes
Merged in from trunk. |
348 |
return(NULL); |
383.1.40
by Monty Taylor
More mysys removal from libdrizzle. Got rid of MEM_ROOT related stuff. |
349 |
if (!(drizzle->fields=unpack_fields(fields, field_count, 0))) |
51.3.5
by Jay Pipes
Merged in from trunk. |
350 |
return(0); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
351 |
drizzle->status=DRIZZLE_STATUS_GET_RESULT; |
352 |
drizzle->field_count=field_count; |
|
353 |
return(drizzle_store_result(drizzle)); |
|
1
by brian
clean slate |
354 |
}
|
355 |
||
356 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
357 |
int
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
358 |
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level) |
1
by brian
clean slate |
359 |
{
|
360 |
uchar level[1]; |
|
361 |
level[0]= (uchar) shutdown_level; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
362 |
return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0)); |
1
by brian
clean slate |
363 |
}
|
364 |
||
365 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
366 |
int
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
367 |
drizzle_refresh(DRIZZLE *drizzle,uint options) |
1
by brian
clean slate |
368 |
{
|
369 |
uchar bits[1]; |
|
370 |
bits[0]= (uchar) options; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
371 |
return(simple_command(drizzle, COM_REFRESH, bits, 1, 0)); |
1
by brian
clean slate |
372 |
}
|
373 |
||
374 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
375 |
int32_t
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
376 |
drizzle_kill(DRIZZLE *drizzle, uint32_t pid) |
1
by brian
clean slate |
377 |
{
|
378 |
uchar buff[4]; |
|
379 |
int4store(buff,pid); |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
380 |
return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0)); |
1
by brian
clean slate |
381 |
}
|
382 |
||
383 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
384 |
int
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
385 |
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option) |
1
by brian
clean slate |
386 |
{
|
387 |
uchar buff[2]; |
|
388 |
int2store(buff, (uint) option); |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
389 |
return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0)); |
1
by brian
clean slate |
390 |
}
|
391 |
||
392 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
393 |
const char *cli_read_statistics(DRIZZLE *drizzle) |
1
by brian
clean slate |
394 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
395 |
drizzle->net.read_pos[drizzle->packet_length]=0; /* End of stat string */ |
396 |
if (!drizzle->net.read_pos[0]) |
|
1
by brian
clean slate |
397 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
398 |
set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate); |
399 |
return drizzle->net.last_error; |
|
1
by brian
clean slate |
400 |
}
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
401 |
return (char*) drizzle->net.read_pos; |
1
by brian
clean slate |
402 |
}
|
403 |
||
404 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
405 |
int
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
406 |
drizzle_ping(DRIZZLE *drizzle) |
1
by brian
clean slate |
407 |
{
|
408 |
int res; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
409 |
res= simple_command(drizzle,COM_PING,0,0,0); |
410 |
if (res == CR_SERVER_LOST && drizzle->reconnect) |
|
411 |
res= simple_command(drizzle,COM_PING,0,0,0); |
|
51.3.5
by Jay Pipes
Merged in from trunk. |
412 |
return(res); |
1
by brian
clean slate |
413 |
}
|
414 |
||
415 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
416 |
const char * |
236.3.5
by Andrey Hristov
Constify libdrizzle functions |
417 |
drizzle_get_server_info(const DRIZZLE *drizzle) |
1
by brian
clean slate |
418 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
419 |
return((char*) drizzle->server_version); |
1
by brian
clean slate |
420 |
}
|
421 |
||
422 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
423 |
const char * |
236.3.5
by Andrey Hristov
Constify libdrizzle functions |
424 |
drizzle_get_host_info(const DRIZZLE *drizzle) |
1
by brian
clean slate |
425 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
426 |
return(drizzle->host_info); |
1
by brian
clean slate |
427 |
}
|
428 |
||
429 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
430 |
uint
|
236.3.5
by Andrey Hristov
Constify libdrizzle functions |
431 |
drizzle_get_proto_info(const DRIZZLE *drizzle) |
1
by brian
clean slate |
432 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
433 |
return (drizzle->protocol_version); |
1
by brian
clean slate |
434 |
}
|
435 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
436 |
const char * |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
437 |
drizzle_get_client_info(void) |
1
by brian
clean slate |
438 |
{
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
439 |
return (char*) DRIZZLE_SERVER_VERSION; |
1
by brian
clean slate |
440 |
}
|
441 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
442 |
uint32_t drizzle_get_client_version(void) |
1
by brian
clean slate |
443 |
{
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
444 |
return DRIZZLE_VERSION_ID; |
1
by brian
clean slate |
445 |
}
|
446 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
447 |
bool drizzle_eof(const DRIZZLE_RES *res) |
1
by brian
clean slate |
448 |
{
|
449 |
return res->eof; |
|
450 |
}
|
|
451 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
452 |
const DRIZZLE_FIELD * drizzle_fetch_field_direct(const DRIZZLE_RES *res, unsigned int fieldnr) |
1
by brian
clean slate |
453 |
{
|
454 |
return &(res)->fields[fieldnr]; |
|
455 |
}
|
|
456 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
457 |
const DRIZZLE_FIELD * drizzle_fetch_fields(const DRIZZLE_RES *res) |
1
by brian
clean slate |
458 |
{
|
236.3.5
by Andrey Hristov
Constify libdrizzle functions |
459 |
return res->fields; |
1
by brian
clean slate |
460 |
}
|
461 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
462 |
DRIZZLE_ROW_OFFSET drizzle_row_tell(const DRIZZLE_RES *res) |
1
by brian
clean slate |
463 |
{
|
464 |
return res->data_cursor; |
|
465 |
}
|
|
466 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
467 |
DRIZZLE_FIELD_OFFSET drizzle_field_tell(const DRIZZLE_RES *res) |
1
by brian
clean slate |
468 |
{
|
236.3.5
by Andrey Hristov
Constify libdrizzle functions |
469 |
return res->current_field; |
1
by brian
clean slate |
470 |
}
|
471 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
472 |
/* DRIZZLE */
|
473 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
474 |
unsigned int drizzle_field_count(const DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
475 |
{
|
476 |
return drizzle->field_count; |
|
477 |
}
|
|
478 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
479 |
uint64_t drizzle_affected_rows(const DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
480 |
{
|
481 |
return drizzle->affected_rows; |
|
482 |
}
|
|
483 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
484 |
uint64_t drizzle_insert_id(const DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
485 |
{
|
486 |
return drizzle->insert_id; |
|
487 |
}
|
|
488 |
||
287.3.6
by Monty Taylor
Eeek. Final cleanups. |
489 |
const char * drizzle_sqlstate(const DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
490 |
{
|
491 |
return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate; |
|
492 |
}
|
|
493 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
494 |
uint32_t drizzle_warning_count(const DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
495 |
{
|
496 |
return drizzle->warning_count; |
|
497 |
}
|
|
498 |
||
287.3.6
by Monty Taylor
Eeek. Final cleanups. |
499 |
const char * drizzle_info(const DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
500 |
{
|
501 |
return drizzle->info; |
|
502 |
}
|
|
503 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
504 |
uint32_t drizzle_thread_id(const DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
505 |
{
|
236.3.5
by Andrey Hristov
Constify libdrizzle functions |
506 |
return drizzle->thread_id; |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
507 |
}
|
508 |
||
1
by brian
clean slate |
509 |
/****************************************************************************
|
510 |
Some support functions
|
|
511 |
****************************************************************************/
|
|
512 |
||
513 |
/*
|
|
514 |
Functions called my my_net_init() to set some application specific variables
|
|
515 |
*/
|
|
516 |
||
517 |
void my_net_local_init(NET *net) |
|
518 |
{
|
|
519 |
net->max_packet= (uint) net_buffer_length; |
|
520 |
my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT); |
|
521 |
my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT); |
|
522 |
net->retry_count= 1; |
|
523 |
net->max_packet_size= max(net_buffer_length, max_allowed_packet); |
|
524 |
}
|
|
525 |
||
526 |
/*
|
|
527 |
This function is used to create HEX string that you
|
|
528 |
can use in a SQL statement in of the either ways:
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
529 |
INSERT INTO blob_column VALUES (0xAABBCC); (any DRIZZLE version)
|
264.2.4
by Andrey Hristov
Remove support for the old, pre-4.1, protocol |
530 |
INSERT INTO blob_column VALUES (X'AABBCC');
|
1
by brian
clean slate |
531 |
|
532 |
The string in "from" is encoded to a HEX string.
|
|
533 |
The result is placed in "to" and a terminating null byte is appended.
|
|
534 |
|
|
535 |
The string pointed to by "from" must be "length" bytes long.
|
|
536 |
You must allocate the "to" buffer to be at least length*2+1 bytes long.
|
|
537 |
Each character needs two bytes, and you need room for the terminating
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
538 |
null byte. When drizzle_hex_string() returns, the contents of "to" will
|
1
by brian
clean slate |
539 |
be a null-terminated string. The return value is the length of the
|
383.1.38
by Monty Taylor
Reworked drizzle_escape_string. |
540 |
encoded string, not including the terminating null character. The return value does not contain any leading 0x or a leading X' and
|
1
by brian
clean slate |
541 |
trailing '. The caller must supply whichever of those is desired.
|
542 |
*/
|
|
543 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
544 |
uint32_t
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
545 |
drizzle_hex_string(char *to, const char *from, uint32_t length) |
1
by brian
clean slate |
546 |
{
|
547 |
char *to0= to; |
|
548 |
const char *end; |
|
549 |
||
550 |
for (end= from + length; from < end; from++) |
|
551 |
{
|
|
552 |
*to++= _dig_vec_upper[((unsigned char) *from) >> 4]; |
|
553 |
*to++= _dig_vec_upper[((unsigned char) *from) & 0x0F]; |
|
554 |
}
|
|
555 |
*to= '\0'; |
|
164
by Brian Aker
Commit cleanup of export types. |
556 |
return (uint32_t) (to-to0); |
1
by brian
clean slate |
557 |
}
|
558 |
||
559 |
/*
|
|
560 |
Add escape characters to a string (blob?) to make it suitable for a insert
|
|
561 |
to should at least have place for length*2+1 chars
|
|
562 |
Returns the length of the to string
|
|
563 |
*/
|
|
564 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
565 |
uint32_t
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
566 |
drizzle_escape_string(char *to,const char *from, uint32_t length) |
1
by brian
clean slate |
567 |
{
|
383.1.38
by Monty Taylor
Reworked drizzle_escape_string. |
568 |
const char *to_start= to; |
569 |
const char *end, *to_end=to_start + 2*length; |
|
570 |
bool overflow= false; |
|
571 |
for (end= from + length; from < end; from++) |
|
572 |
{
|
|
573 |
uint32_t tmp_length; |
|
574 |
char escape= 0; |
|
575 |
if (!U8_IS_SINGLE(*from)) |
|
576 |
{
|
|
577 |
tmp_length= U8_LENGTH(*from); |
|
578 |
if (to + tmp_length > to_end) |
|
579 |
{
|
|
580 |
overflow= true; |
|
581 |
break; |
|
582 |
}
|
|
583 |
while (tmp_length--) |
|
584 |
*to++= *from++; |
|
585 |
from--; |
|
586 |
continue; |
|
587 |
}
|
|
588 |
switch (*from) { |
|
589 |
case 0: /* Must be escaped for 'mysql' */ |
|
590 |
escape= '0'; |
|
591 |
break; |
|
592 |
case '\n': /* Must be escaped for logs */ |
|
593 |
escape= 'n'; |
|
594 |
break; |
|
595 |
case '\r': |
|
596 |
escape= 'r'; |
|
597 |
break; |
|
598 |
case '\\': |
|
599 |
escape= '\\'; |
|
600 |
break; |
|
601 |
case '\'': |
|
602 |
escape= '\''; |
|
603 |
break; |
|
604 |
case '"': /* Better safe than sorry */ |
|
605 |
escape= '"'; |
|
606 |
break; |
|
607 |
case '\032': /* This gives problems on Win32 */ |
|
608 |
escape= 'Z'; |
|
609 |
break; |
|
610 |
}
|
|
611 |
if (escape) |
|
612 |
{
|
|
613 |
if (to + 2 > to_end) |
|
614 |
{
|
|
615 |
overflow= true; |
|
616 |
break; |
|
617 |
}
|
|
618 |
*to++= '\\'; |
|
619 |
*to++= escape; |
|
620 |
}
|
|
621 |
else
|
|
622 |
{
|
|
623 |
if (to + 1 > to_end) |
|
624 |
{
|
|
625 |
overflow= true; |
|
626 |
break; |
|
627 |
}
|
|
628 |
*to++= *from; |
|
629 |
}
|
|
630 |
}
|
|
631 |
*to= 0; |
|
632 |
return overflow ? (size_t) -1 : (size_t) (to - to_start); |
|
1
by brian
clean slate |
633 |
}
|
634 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
635 |
int cli_unbuffered_fetch(DRIZZLE *drizzle, char **row) |
1
by brian
clean slate |
636 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
637 |
if (packet_error == cli_safe_read(drizzle)) |
1
by brian
clean slate |
638 |
return 1; |
639 |
||
236.3.3
by Andrey Hristov
Define a constant, instead of a magic number |
640 |
*row= ((drizzle->net.read_pos[0] == DRIZZLE_PROTOCOL_NO_MORE_DATA) ? NULL : |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
641 |
(char*) (drizzle->net.read_pos+1)); |
1
by brian
clean slate |
642 |
return 0; |
643 |
}
|
|
644 |
||
645 |
/********************************************************************
|
|
646 |
Transactional APIs
|
|
647 |
*********************************************************************/
|
|
648 |
||
649 |
/*
|
|
650 |
Commit the current transaction
|
|
651 |
*/
|
|
652 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
653 |
bool drizzle_commit(DRIZZLE *drizzle) |
1
by brian
clean slate |
654 |
{
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
655 |
return((bool) drizzle_real_query(drizzle, "commit", 6)); |
1
by brian
clean slate |
656 |
}
|
657 |
||
658 |
/*
|
|
659 |
Rollback the current transaction
|
|
660 |
*/
|
|
661 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
662 |
bool drizzle_rollback(DRIZZLE *drizzle) |
1
by brian
clean slate |
663 |
{
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
664 |
return((bool) drizzle_real_query(drizzle, "rollback", 8)); |
1
by brian
clean slate |
665 |
}
|
666 |
||
667 |
||
668 |
/*
|
|
669 |
Set autocommit to either true or false
|
|
670 |
*/
|
|
671 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
672 |
bool drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode) |
1
by brian
clean slate |
673 |
{
|
207.2.3
by Toru Maesaka
Merge from trunk and conflicts resolved |
674 |
return((bool) drizzle_real_query(drizzle, auto_mode ? |
1
by brian
clean slate |
675 |
"set autocommit=1":"set autocommit=0", |
676 |
16)); |
|
677 |
}
|
|
678 |
||
679 |
||
680 |
/********************************************************************
|
|
681 |
Multi query execution + SPs APIs
|
|
682 |
*********************************************************************/
|
|
683 |
||
684 |
/*
|
|
685 |
Returns true/false to indicate whether any more query results exist
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
686 |
to be read using drizzle_next_result()
|
1
by brian
clean slate |
687 |
*/
|
688 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
689 |
bool drizzle_more_results(const DRIZZLE *drizzle) |
1
by brian
clean slate |
690 |
{
|
236.3.3
by Andrey Hristov
Define a constant, instead of a magic number |
691 |
return (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) ? true:false; |
1
by brian
clean slate |
692 |
}
|
693 |
||
694 |
||
695 |
/*
|
|
696 |
Reads and returns the next query results
|
|
697 |
*/
|
|
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
698 |
int drizzle_next_result(DRIZZLE *drizzle) |
1
by brian
clean slate |
699 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
700 |
if (drizzle->status != DRIZZLE_STATUS_READY) |
1
by brian
clean slate |
701 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
702 |
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); |
51.3.5
by Jay Pipes
Merged in from trunk. |
703 |
return(1); |
1
by brian
clean slate |
704 |
}
|
705 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
706 |
net_clear_error(&drizzle->net); |
707 |
drizzle->affected_rows= ~(uint64_t) 0; |
|
708 |
||
709 |
if (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) |
|
710 |
return((*drizzle->methods->next_result)(drizzle)); |
|
711 |
||
712 |
return(-1); /* No more results */ |
|
713 |
}
|
|
714 |
||
715 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
716 |
DRIZZLE_RES * drizzle_use_result(DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
717 |
{
|
718 |
return (*drizzle->methods->use_result)(drizzle); |
|
719 |
}
|
|
720 |
||
287.3.3
by Monty Taylor
Removed STDCALL macros calls. |
721 |
bool drizzle_read_query_result(DRIZZLE *drizzle) |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
722 |
{
|
723 |
return (*drizzle->methods->read_query_result)(drizzle); |
|
1
by brian
clean slate |
724 |
}
|
725 |