00001 /* 00002 * Copyright (c) 2009 Thierry FOURNIER 00003 * 00004 * This file is part of MySAC. 00005 * 00006 * MySAC is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License 00009 * 00010 * MySAC is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with MySAC. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 /** @file */ 00020 00021 #ifndef __MYSAC_H__ 00022 #define __MYSAC_H__ 00023 00024 #include <stdlib.h> 00025 #include <stdarg.h> 00026 #include <time.h> 00027 #include <errno.h> 00028 #include <string.h> 00029 #include <sys/time.h> 00030 #include <mysql/errmsg.h> 00031 #include <mysql/mysql.h> 00032 00033 /* def imported from: linux-2.6.24/include/linux/stddef.h */ 00034 #define mysac_offset_of(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 00035 00036 /** 00037 * container_of - cast a member of a structure out to the containing structure 00038 * 00039 * def imported from: linux-2.6.24/include/linux/kernel.h 00040 * 00041 * @param ptr the pointer to the member. 00042 * @param type the type of the container struct this is embedded in. 00043 * @param member the name of the member within the struct. 00044 * 00045 */ 00046 #define mysac_container_of(ptr, type, member) ({ \ 00047 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 00048 (type *)( (char *)__mptr - mysac_offset_of(type,member) );}) 00049 00050 /** 00051 * Simple doubly linked list implementation. 00052 * 00053 * def imported from: linux-2.6.24/include/linux/list.h 00054 * 00055 * Some of the internal functions ("__xxx") are useful when 00056 * manipulating whole lists rather than single entries, as 00057 * sometimes we already know the next/prev entries and we can 00058 * generate better code by using them directly rather than 00059 * using the generic single-entry routines. 00060 */ 00061 struct mysac_list_head { 00062 struct mysac_list_head *next, *prev; 00063 }; 00064 00065 /** 00066 * list_entry - get the struct for this entry 00067 * 00068 * def imported from: linux-2.6.24/include/linux/list.h 00069 * 00070 * @param ptr: the &struct list_head pointer. 00071 * @param type: the type of the struct this is embedded in. 00072 * @param member: the name of the list_struct within the struct. 00073 */ 00074 #define mysac_list_entry(ptr, type, member) \ 00075 mysac_container_of(ptr, type, member) 00076 00077 /** 00078 * list_first_entry - get the first element from a list 00079 * 00080 * def imported from: linux-2.6.24/include/linux/list.h 00081 * @param ptr the list head to take the element from. 00082 * @param type the type of the struct this is embedded in. 00083 * @param member the name of the list_struct within the struct. 00084 * 00085 * Note, that list is expected to be not empty. 00086 */ 00087 #define mysac_list_first_entry(ptr, type, member) \ 00088 mysac_list_entry((ptr)->next, type, member) 00089 00090 #define mysac_list_next_entry(ptr, type, member) \ 00091 mysac_list_first_entry(ptr, type, member); 00092 00093 enum my_query_st { 00094 MYSAC_START, 00095 00096 MYSAC_CONN_CHECK, 00097 MYSAC_READ_GREATINGS, 00098 MYSAC_SEND_AUTH_1, 00099 MYSAC_RECV_AUTH_1, 00100 MYSAC_SEND_AUTH_2, 00101 00102 MYSAC_SEND_QUERY, 00103 MYSAC_RECV_QUERY_COLNUM, 00104 MYSAC_RECV_QUERY_COLDESC1, 00105 MYSAC_RECV_QUERY_COLDESC2, 00106 MYSAC_RECV_QUERY_EOF1, 00107 MYSAC_RECV_QUERY_EOF2, 00108 MYSAC_RECV_QUERY_DATA, 00109 00110 MYSAC_SEND_INIT_DB, 00111 MYSAC_RECV_INIT_DB, 00112 00113 MYSAC_SEND_STMT_QUERY, 00114 MYSAC_RECV_STMT_QUERY, 00115 00116 MYSAC_SEND_STMT_EXECUTE, 00117 MYSAC_RECV_STMT_EXECUTE, 00118 00119 MYSAC_READ_NUM, 00120 MYSAC_READ_HEADER, 00121 MYSAC_READ_LINE 00122 }; 00123 00124 #define MYSAC_COL_MAX_LEN 50 00125 #define MYSAC_COL_MAX_NUN 100 00126 00127 /* errors */ 00128 enum { 00129 MYERR_PROTOCOL_ERROR = 1, 00130 MYERR_BUFFER_OVERSIZE, 00131 MYERR_PACKET_CORRUPT, 00132 MYERR_WANT_READ, 00133 MYERR_WANT_WRITE, 00134 MYERR_UNKNOWN_ERROR, 00135 MYERR_MYSQL_ERROR, 00136 MYERR_SERVER_LOST, 00137 MYERR_BAD_PORT, 00138 MYERR_BAD_STATE, 00139 MYERR_RESOLV_HOST, 00140 MYERR_SYSTEM, 00141 MYERR_CANT_CONNECT, 00142 MYERR_BUFFER_TOO_SMALL, 00143 MYERR_UNEXPECT_R_STATE, 00144 MYERR_STRFIELD_CORRUPT, 00145 MYERR_BINFIELD_CORRUPT, 00146 MYERR_BAD_LCB, 00147 MYERR_LEN_OVER_BUFFER, 00148 MYERR_CONVLONG, 00149 MYERR_CONVLONGLONG, 00150 MYERR_CONVFLOAT, 00151 MYERR_CONVDOUBLE, 00152 MYERR_CONVTIME, 00153 MYERR_CONVTIMESTAMP, 00154 MYERR_CONVDATE 00155 }; 00156 00157 extern const char *mysac_type[]; 00158 extern const char *mysac_errors[]; 00159 00160 /** 00161 * This is union containing all c type matching mysql types 00162 */ 00163 typedef union { 00164 signed char stiny; /* MYSQL_TYPE_TINY TINYINT */ 00165 unsigned char utiny; /* MYSQL_TYPE_TINY TINYINT */ 00166 unsigned char mbool; /* MYSQL_TYPE_TINY TINYINT */ 00167 short ssmall; /* MYSQL_TYPE_SHORT SMALLINT */ 00168 unsigned short small; /* MYSQL_TYPE_SHORT SMALLINT */ 00169 int sint; /* MYSQL_TYPE_LONG INT */ 00170 unsigned int uint; /* MYSQL_TYPE_LONG INT */ 00171 long long sbigint; /* MYSQL_TYPE_LONGLONG BIGINT */ 00172 unsigned long long ubigint; /* MYSQL_TYPE_LONGLONG BIGINT */ 00173 float mfloat; /* MYSQL_TYPE_FLOAT FLOAT */ 00174 double mdouble; /* MYSQL_TYPE_DOUBLE DOUBLE */ 00175 struct timeval tv; /* MYSQL_TYPE_TIME TIME */ 00176 struct tm *tm; /* MYSQL_TYPE_DATE DATE 00177 MYSQL_TYPE_DATETIME DATETIME 00178 MYSQL_TYPE_TIMESTAMP TIMESTAMP */ 00179 char *string; /* MYSQL_TYPE_STRING TEXT,CHAR,VARCHAR */ 00180 char *blob; /* MYSQL_TYPE_BLOB BLOB,BINARY,VARBINARY */ 00181 void *ptr; /* generic pointer */ 00182 } MYSAC_ROW; 00183 00184 /** 00185 * This is chained element. contain pointer to each elements of one row 00186 */ 00187 typedef struct { 00188 struct mysac_list_head link; 00189 unsigned long *lengths; 00190 MYSAC_ROW *data; 00191 } MYSAC_ROWS; 00192 00193 /** 00194 * This contain the complete result of one request 00195 */ 00196 typedef struct { 00197 char *buffer; 00198 int buffer_len; 00199 int nb_cols; 00200 int nb_lines; 00201 int nb_time; 00202 int extend_bloc_size; 00203 int max_len; 00204 int do_free; 00205 MYSQL_FIELD *cols; 00206 struct mysac_list_head data; 00207 MYSAC_ROWS *cr; 00208 } MYSAC_RES; 00209 00210 /** 00211 * This contain list of values for statement binding 00212 */ 00213 typedef struct mysac_bind { 00214 enum enum_field_types type; 00215 void *value; 00216 int value_len; 00217 char is_null; 00218 } MYSAC_BIND; 00219 00220 /** 00221 * This contain the necessary for one mysql connection 00222 */ 00223 typedef struct mysac { 00224 int len; 00225 char *read; 00226 int read_len; 00227 char *send; 00228 int readst; 00229 00230 unsigned int packet_length; 00231 unsigned int packet_number; 00232 00233 /* mysac */ 00234 char free_it; 00235 int fd; 00236 int (*call_it)(/* MYSAC * */ struct mysac *); 00237 00238 /*defconnect */ 00239 unsigned int protocol; 00240 char *version; 00241 unsigned int threadid; 00242 char salt[SCRAMBLE_LENGTH + 1]; 00243 unsigned int options; 00244 unsigned int charset; 00245 unsigned int status; 00246 unsigned long affected_rows; 00247 unsigned int warnings; 00248 unsigned int errorcode; 00249 unsigned long insert_id; 00250 char *mysql_code; 00251 char *mysql_error; 00252 char eof; 00253 00254 /* user */ 00255 const char *addr; 00256 const char *login; 00257 const char *password; 00258 const char *database; 00259 const char *query; 00260 unsigned int flags; 00261 00262 /* query */ 00263 enum my_query_st qst; 00264 int read_id; 00265 MYSAC_RES *res; 00266 unsigned long *stmt_id; 00267 00268 /* the buffer */ 00269 unsigned int bufsize; 00270 char *buf; 00271 00272 /* special stmt */ 00273 int nb_cols; /* number of columns in response */ 00274 int nb_plhold; /* number of placeholders in request */ 00275 } MYSAC; 00276 00277 /** 00278 * Allocates and initializes a MYSQL object. 00279 * If mysql is a NULL pointer, the function allocates, initializes, and 00280 * returns a new object. Otherwise, the object is initialized and the address 00281 * of the object is returned. If mysql_init() allocates a new object, it is 00282 * freed when mysql_close() is called to close the connection. 00283 * 00284 * @param buffsize is the size of the buffer 00285 * 00286 * @return An initialized MYSAC* handle. NULL if there was insufficient memory 00287 * to allocate a new object. 00288 */ 00289 MYSAC *mysac_new(int buffsize); 00290 00291 /** 00292 * Initializes a MYSQL object. 00293 * If mysql is a NULL pointer, the function allocates, initializes, and 00294 * returns a new object. Otherwise, the object is initialized and the address 00295 * of the object is returned. If mysql_init() allocates a new object, it is 00296 * freed when mysql_close() is called to close the connection. 00297 * 00298 * @param mysac Should be the address of an existing MYSAC structure. 00299 * @param buffer is ptr on the pre-allocated buffer 00300 * @param buffsize is the size of the buffer 00301 */ 00302 void mysac_init(MYSAC *mysac, char *buffer, unsigned int buffsize); 00303 00304 /** 00305 * mysac_connect() attempts to establish a connection to a MySQL database engine 00306 * running on host. mysql_real_connect() must complete successfully before you 00307 * can execute any other API functions that require a valid MYSQL connection 00308 * handle structure. 00309 * 00310 * @param mysac The first parameter should be the address of an existing MYSQL 00311 * structure. Before calling mysql_real_connect() you must call 00312 * mysql_init() to initialize the MYSQL structure. You can change a lot 00313 * of connect options with the mysql_options() call. 00314 * 00315 * @param my_addr like "<ipv4>:<port>" "<ipv6>:<port>", "socket_unix_file" or 00316 * NULL. If NULL, bind is set to socket 0 00317 * 00318 * @param user The user parameter contains the user's MySQL login ID. If user 00319 * is NULL or the empty string "", the current user is assumed. 00320 * 00321 * @param passwd The passwd parameter contains the password for user. If passwd 00322 * is NULL, only entries in the user table for the user that have a blank 00323 * (empty) password field are checked for a match. 00324 * 00325 * @param db is the database name. If db is not NULL, the connection sets the 00326 * default database to this value. 00327 * 00328 * @param client_flag The value of client_flag is usually 0, but can be set to a 00329 * combination of the following flags to enable certain features: 00330 * 00331 * Flag Name Flag Description 00332 * CLIENT_COMPRESS Use compression protocol. 00333 * CLIENT_FOUND_ROWS Return the number of found (matched) rows, 00334 * not the number of changed rows. 00335 * CLIENT_IGNORE_SPACE Allow spaces after function names. Makes all 00336 * functions names reserved words. 00337 */ 00338 void mysac_setup(MYSAC *mysac, const char *my_addr, const char *user, 00339 const char *passwd, const char *db, 00340 unsigned long client_flag); 00341 00342 /** 00343 * Run network connexion and mysql authentication 00344 * 00345 * @param mysac Should be the address of an existing MYSQL structure. 00346 * 00347 * @return 00348 * MYERR_WANT_READ : want read socket 00349 * MYERR_WANT_WRITE : want write socket 00350 * CR_CONN_HOST_ERROR : Failed to connect to the MySQL server. 00351 * CR_CONNECTION_ERROR : Failed to connect to the local MySQL server. 00352 * CR_IPSOCK_ERROR : Failed to create an IP socket. 00353 * CR_OUT_OF_MEMORY : Out of memory. 00354 * CR_SOCKET_CREATE_ERROR : Failed to create a Unix socket. 00355 * CR_UNKNOWN_HOST : Failed to find the IP address for the hostname. 00356 * CR_VERSION_ERROR : A protocol mismatch resulted from attempting to 00357 * connect to a server with a client library that 00358 * uses a different protocol version. 00359 * CR_SERVER_LOST : If connect_timeout > 0 and it took longer than 00360 * connect_timeout seconds to connect to the server 00361 * or if the server died while executing the 00362 * init-command. 00363 */ 00364 int mysac_connect(MYSAC *mysac); 00365 00366 /** 00367 * Closes a previously opened connection. mysql_close() also deallocates the 00368 * connection handle pointed to by mysql if the handle was allocated 00369 * automatically by mysql_init() or mysql_connect(). 00370 * 00371 * @param mysac Should be the address of an existing MYSQL structure. 00372 */ 00373 void mysac_close(MYSAC *mysac); 00374 00375 /** 00376 * This function return the mysql filedescriptor used for connection 00377 * to the mysql server 00378 * 00379 * @param mysac Should be the address of an existing MYSAC structure. 00380 * 00381 * @return mysql filedescriptor 00382 */ 00383 int mysac_get_fd(MYSAC *mysac); 00384 00385 /** 00386 * this function call the io function associated with the current 00387 * command. (mysac_send_database, mysac_send_query and mysac_connect) 00388 * 00389 * @param mysac Should be the address of an existing MYSAC structure. 00390 * 00391 * @return 0 is ok, or all errors associated with functions 00392 * mysac_send_database, mysac_send_query and mysac_connect or 00393 * MYERR_BAD_STATE : the function does nothing to do (is an error) 00394 */ 00395 int mysac_io(MYSAC *mysac); 00396 00397 /** 00398 * Build use database message 00399 * 00400 * @param mysac Should be the address of an existing MYSQL structure. 00401 * @param database is the database name 00402 */ 00403 int mysac_set_database(MYSAC *mysac, const char *database); 00404 00405 /** 00406 * This send use database command 00407 * 00408 * @param mysac Should be the address of an existing MYSQL structure. 00409 * 00410 * @return 00411 * 0 => ok 00412 * MYSAC_WANT_READ 00413 * MYSAC_WANT_WRITE 00414 * ... 00415 */ 00416 int mysac_send_database(MYSAC *mysac); 00417 00418 /** 00419 * Initialize MYSAC_RES structur 00420 * This function can not allocate memory, just use your buffer. 00421 * 00422 * @param buffer this buffer must contain all the sql response. 00423 * this size is: 00424 * sizeof(MYSAC_RES) + 00425 * ( sizeof(MYSQL_FIELD) * nb_field ) + 00426 * ( different fields names ) 00427 * 00428 * and for each row: 00429 * sizeof(MYSAC_ROWS) + 00430 * ( sizeof(MYSAC_ROW) * nb_field ) + 00431 * ( sizeof(unsigned long) * nb_field ) + 00432 * ( sizeof(struct tm) for differents date fields of the request ) + 00433 * ( differents strings returned by the request ) + 00434 * 00435 * @param len is the len of the buffer 00436 * 00437 * @return MYSAC_RES. this function cannot be fail 00438 */ 00439 MYSAC_RES *mysac_init_res(char *buffer, int len); 00440 00441 /** 00442 * Create new MYSAC_RES structur 00443 * This function allocate memory 00444 * 00445 * WARNING: If extend is set, you must use the function mysac_get_res 00446 * for retrieving the resource pointer after each call att 00447 * mysac_send_query. 00448 * 00449 * @param chunk_size is the size allocated for the bloc 00450 * @param extend if is true, the block is extended if the initial 00451 * memory does not enough. the extension size is the size 00452 * of chunk_size 00453 */ 00454 MYSAC_RES *mysac_new_res(int chunk_size, int extend); 00455 00456 /** 00457 * Destroy MYSAC_RES structur 00458 * This function free memory 00459 */ 00460 void mysac_free_res(MYSAC_RES *r); 00461 00462 /** 00463 * Initialize query 00464 * 00465 * @param mysac Should be the address of an existing MYSAC structur. 00466 * @param res Should be the address of an existing MYSAC_RES structur. 00467 * @param fmt is the output format with the printf style 00468 * 00469 * @return 0: ok, -1 nok 00470 */ 00471 int mysac_set_query(MYSAC *mysac, MYSAC_RES *res, const char *fmt, ...); 00472 00473 /** 00474 * Initialize query 00475 * 00476 * @param mysac Should be the address of an existing MYSAC structur. 00477 * @param res Should be the address of an existing MYSAC_RES structur. 00478 * @param fmt is the output format with the printf style 00479 * @param ap is the argument list on format vprintf 00480 * 00481 * @return 0: ok, -1 nok 00482 */ 00483 int mysac_v_set_query(MYSAC *mysac, MYSAC_RES *res, const char *fmt, va_list ap); 00484 00485 /** 00486 * Initialize query 00487 * 00488 * @param mysac Should be the address of an existing MYSAC structur. 00489 * @param res Should be the address of an existing MYSAC_RES structur. 00490 * @param query is a string (terminated by \0) containing the query 00491 * 00492 * @return 0: ok, -1 nok 00493 */ 00494 int mysac_s_set_query(MYSAC *mysac, MYSAC_RES *res, const char *query); 00495 00496 /** 00497 * Initialize query 00498 * 00499 * @param mysac Should be the address of an existing MYSAC structur. 00500 * @param res Should be the address of an existing MYSAC_RES structur. 00501 * @param query is a string containing the query 00502 * @param len is the len of the query 00503 * 00504 * @return 0: ok, -1 nok 00505 */ 00506 int mysac_b_set_query(MYSAC *mysac, MYSAC_RES *res, const char *query, int len); 00507 00508 /** 00509 * This function return the mysql response pointer 00510 * 00511 * @param mysac Should be the address of an existing MYSAC structure. 00512 * 00513 * @return mysql response pointer 00514 */ 00515 MYSAC_RES *mysac_get_res(MYSAC *mysac); 00516 00517 /** 00518 * Send sql query command 00519 * 00520 * @param mysac Should be the address of an existing MYSAC structur. 00521 * 00522 * @return 00523 * 0 => ok 00524 * MYSAC_WANT_READ 00525 * MYSAC_WANT_WRITE 00526 * ... 00527 */ 00528 int mysac_send_query(MYSAC *mysac); 00529 00530 /** 00531 * Prepare statement 00532 * 00533 * @param mysac Should be the address of an existing MYSAC structur. 00534 * @param stmt_id is the receiver of the statement id 00535 * @param fmt is the output format with the printf style 00536 * 00537 * @return 0: ok, -1 nok 00538 */ 00539 int mysac_set_stmt_prepare(MYSAC *mysac, unsigned long *stmt_id, const char *fmt, ...); 00540 00541 /** 00542 * Prepare statement 00543 * 00544 * @param mysac Should be the address of an existing MYSAC structur. 00545 * @param stmt_id is the receiver of the statement id 00546 * @param fmt is the output format with the printf style 00547 * @param ap is the argument list on format vprintf 00548 * 00549 * @return 0: ok, -1 nok 00550 */ 00551 int mysac_v_set_stmt_prepare(MYSAC *mysac, unsigned long *stmt_id, const char *fmt, va_list ap); 00552 00553 /** 00554 * Prepare statement 00555 * 00556 * @param mysac Should be the address of an existing MYSAC structur. 00557 * @param stmt_id is the receiver of the statement id 00558 * @param query is a string (terminated by \0) containing the query 00559 * 00560 * @return 0: ok, -1 nok 00561 */ 00562 int mysac_s_set_stmt_prepare(MYSAC *mysac, unsigned long *stmt_id, const char *request); 00563 00564 /** 00565 * Prepare statement 00566 * 00567 * @param mysac Should be the address of an existing MYSAC structur. 00568 * @param stmt_id is the receiver of the statement id 00569 * @param request is a string containing the query 00570 * @param len is the len of the query 00571 * 00572 * @return 0: ok, -1 nok 00573 */ 00574 int mysac_b_set_stmt_prepare(MYSAC *mysac, unsigned long *stmt_id, const char *request, int len); 00575 00576 /** 00577 * Send sql query command 00578 * 00579 * @param mysac Should be the address of an existing MYSAC structur. 00580 * @param stmt_id is pointer for storing the statement id 00581 * 00582 * @return 00583 * 0 => ok 00584 * MYSAC_WANT_READ 00585 * MYSAC_WANT_WRITE 00586 * ... 00587 */ 00588 int mysac_send_stmt_prepare(MYSAC *mysac); 00589 00590 /** 00591 * Execute statement 00592 * 00593 * @param mysac Should be the address of an existing MYSAC structur. 00594 * @param res Should be the address of an existing MYSAC_RES structur. 00595 * @param stmt_id the statement id 00596 * @param values is array of values send for the request 00597 * @param nb is number of values 00598 * 00599 * @return 0: ok, -1 nok 00600 */ 00601 int mysac_set_stmt_execute(MYSAC *mysac, MYSAC_RES *res, unsigned long stmt_id, 00602 MYSAC_BIND *values, int nb); 00603 00604 /** 00605 * send stmt execute command 00606 * 00607 * @param mysac Should be the address of an existing MYSQL structure. 00608 * 00609 * @return 00610 */ 00611 int mysac_send_stmt_execute(MYSAC *mysac); 00612 00613 /** 00614 * After executing a statement with mysql_query() returns the number of rows 00615 * changed (for UPDATE), deleted (for DELETE), orinserted (for INSERT). For 00616 * SELECT statements, mysql_affected_rows() works like mysql_num_rows(). 00617 * 00618 * @param mysac Should be the address of an existing MYSQL structure. 00619 * 00620 * @return An integer greater than zero indicates the number of rows affected 00621 * or retrieved. Zero indicates that no records were updated for an 00622 * UPDATE statement, no rows matched the WHERE clause in the query or 00623 * that no query has yet been executed. -1 indicates that the query 00624 * returned an error or that, for a SELECT query, mysql_affected_rows() 00625 * was called prior to calling mysql_store_result(). Because 00626 * mysql_affected_rows() returns an unsigned value, you can check for -1 00627 * by comparing the return value to (my_ulonglong)-1 (or to 00628 * (my_ulonglong)~0, which is equivalent). 00629 */ 00630 int mysac_affected_rows(MYSAC *mysac); 00631 00632 /** 00633 * Returns the number of columns for the most recent query on the connection. 00634 * 00635 * @param res Should be the address of an existing MYSAC_RES structure. 00636 * 00637 * @return number of columns 00638 */ 00639 unsigned int mysac_field_count(MYSAC_RES *res); 00640 00641 /** 00642 * Returns the number of rows in the result set. 00643 * 00644 * mysql_num_rows() is intended for use with statements that return a result 00645 * set, such as SELECT. For statements such as INSERT, UPDATE, or DELETE, the 00646 * number of affected rows can be obtained with mysql_affected_rows(). 00647 * 00648 * @param res Should be the address of an existing MYSAC_RES structure. 00649 * 00650 * @return The number of rows in the result set. 00651 */ 00652 unsigned long mysac_num_rows(MYSAC_RES *res); 00653 00654 /** 00655 * Retrieves the next row of a result set. mysql_fetch_row() returns NULL when 00656 * there are no more rows to retrieve or if an error occurred. 00657 * 00658 * The number of values in the row is given by mysql_num_fields(result). 00659 * 00660 * The lengths of the field values in the row may be obtained by calling 00661 * mysql_fetch_lengths(). Empty fields and fields containing NULL both have 00662 * length 0; you can distinguish these by checking the pointer for the field 00663 * value. If the pointer is NULL, the field is NULL; otherwise, the field is 00664 * empty. 00665 * 00666 * @param res Should be the address of an existing MYSAC_RES structure. 00667 * 00668 * @return A MYSAC_ROW structure for the next row. NULL if there are no more 00669 * rows to retrieve or if an error occurred. 00670 */ 00671 MYSAC_ROW *mysac_fetch_row(MYSAC_RES *res); 00672 00673 /** 00674 * Set pointer on the first row, you can exec mysac_fetch_row, return it the 00675 * first row; 00676 */ 00677 void mysac_first_row(MYSAC_RES *res); 00678 00679 /** 00680 * Get current row, dont touch row ptr 00681 */ 00682 MYSAC_ROW *mysac_cur_row(MYSAC_RES *res); 00683 00684 /** 00685 * Returns the value generated for an AUTO_INCREMENT column by the previous 00686 * INSERT or UPDATE statement. Use this function after you have performed an 00687 * INSERT statement into a table that contains an AUTO_INCREMENT field 00688 * 00689 * http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.html 00690 * 00691 * @param m Should be the address of an existing MYSQL structure. 00692 * 00693 * @return the value generated for an AUTO_INCREMENT column 00694 */ 00695 unsigned long mysac_insert_id(MYSAC *m); 00696 00697 00698 #if 0 00699 mysql_fetch_fields() /*Returns an array of all field structures*/ 00700 mysql_fetch_field() /*Returns the type of the next table field*/ 00701 mysql_fetch_lengths() /*Returns the lengths of all columns in the current row*/ 00702 #endif 00703 00704 /** 00705 * Changes the user and causes the database specified by db to become the 00706 * default (current) database on the connection specified by mysql. In 00707 * subsequent queries, this database is the default for table references that 00708 * do not include an explicit database specifier. 00709 * 00710 * mysql_change_user() fails if the connected user cannot be authenticated or 00711 * doesn't have permission to use the database. In this case, the user and 00712 * database are not changed 00713 * 00714 * This command resets the state as if one had done a new connect. It always 00715 * performs a ROLLBACK of any active transactions, closes and drops all 00716 * temporary tables, and unlocks all locked tables. Session system variables 00717 * are reset to the values of the corresponding global system variables. 00718 * Prepared statements are released and HANDLER variables are closed. Locks 00719 * acquired with GET_LOCK() are released. These effects occur even if the user 00720 * didn't change. 00721 * 00722 * @param mysac Should be the address of an existing MYSQL structure. 00723 * 00724 * @param user The user parameter contains the user's MySQL login ID. If user 00725 * is NULL or the empty string "", the current user is assumed. 00726 * 00727 * @param passwd The passwd parameter contains the password for user. If passwd 00728 * is NULL, only entries in the user table for the user that have a blank 00729 * (empty) password field are checked for a match. 00730 * 00731 * @param db The db parameter may be set to NULL if you don't want to have a 00732 * default database. 00733 * 00734 * @return 00735 * CR_COMMANDS_OUT_OF_SYNC : Commands were executed in an improper order. 00736 * CR_SERVER_GONE_ERROR : The MySQL server has gone away. 00737 * CR_SERVER_LOST : The connection to the server was lost during 00738 * the query. 00739 * CR_UNKNOWN_ERROR : An unknown error occurred. 00740 * ER_UNKNOWN_COM_ERROR : The MySQL server doesn't implement this 00741 * command (probably an old server). 00742 * ER_ACCESS_DENIED_ERROR : The user or password was wrong. 00743 * ER_BAD_DB_ERROR : The database didn't exist. 00744 * ER_DBACCESS_DENIED_ERROR : The user did not have access rights to the 00745 * database. 00746 * ER_WRONG_DB_NAME : The database name was too long. 00747 */ 00748 int mysac_change_user(MYSAC *mysac, const char *user, const char *passwd, 00749 const char *db); 00750 00751 /** 00752 * Returns the default character set name for the current connection. 00753 * 00754 * @param mysac Should be the address of an existing MYSQL structure. 00755 * 00756 * @return The default character set name 00757 */ 00758 //const char *mysac_character_set_name(MYSAC *mysac); 00759 00760 /** 00761 * For the connection specified by mysql, mysql_errno() returns the error code 00762 * for the most recently invoked API function that can succeed or fail. A return 00763 * value of zero means that no error occurred. Client error message numbers are 00764 * listed in the MySQL errmsg.h header file. Server error message numbers are 00765 * listed in mysqld_error.h. Errors also are listed at Appendix B, Errors, Error 00766 * Codes, and Common Problems. 00767 * 00768 * @param mysac Should be the address of an existing MYSQL structure. 00769 */ 00770 unsigned int mysac_errno(MYSAC *mysac); 00771 00772 /** 00773 * For the connection specified by mysql, mysql_error() returns a null- 00774 * terminated string containing the error message for the most recently invoked 00775 * API function that failed. If a function didn't fail, the return value of 00776 * mysql_error() may be the previous error or an empty string to indicate no 00777 * error. 00778 * 00779 * @param mysac Should be the address of an existing MYSQL structure. 00780 */ 00781 const char *mysac_error(MYSAC *mysac); 00782 00783 /** 00784 * For the connection specified by mysql, mysql_error() returns a null- 00785 * terminated string containing the error message for the most recently invoked 00786 * API function that failed. If a function didn't fail, the return value of 00787 * mysql_error() may be the previous error or an empty string to indicate no 00788 * error. 00789 * 00790 * @param mysac Should be the address of an existing MYSQL structure. 00791 */ 00792 const char *mysac_advance_error(MYSAC *mysac); 00793 00794 /* 00795 1607 ulong STDCALL 00796 1608 mysac_escape_string(MYSQL *mysql, char *to,const char *from, 00797 1609 ulong length) 00798 1610 { 00799 1611 if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) 00800 1612 return escape_quotes_for_mysql(mysql->charset, to, 0, from, length); 00801 1613 return escape_string_for_mysql(mysql->charset, to, 0, from, length); 00802 1614 } 00803 */ 00804 00805 #if 0 00806 mysql_affected_rows() /*Returns the number of rows changed/deleted/inserted by the last UPDATE, DELETE, or INSERT query*/ 00807 mysql_autocommit() /*Toggles autocommit mode on/off*/ 00808 mysql_commit() /*Commits the transaction*/ 00809 mysql_create_db() /*Creates a database (this function is deprecated; use the SQL statement CREATE DATABASE instead)*/ 00810 mysql_data_seek() /*Seeks to an arbitrary row number in a query result set*/ 00811 mysql_debug() /*Does a DBUG_PUSH with the given string*/ 00812 mysql_drop_db() /*Drops a database (this function is deprecated; use the SQL statement DROP DATABASE instead)*/ 00813 mysql_dump_debug_info() /*Makes the server write debug information to the log*/ 00814 mysql_escape_string() /*Escapes special characters in a string for use in an SQL statement*/ 00815 mysql_fetch_field_direct() /*Returns the type of a table field, given a field number*/ 00816 mysql_field_seek() /*Puts the column cursor on a specified column*/ 00817 mysql_field_tell() /*Returns the position of the field cursor used for the last mysql_fetch_field()*/ 00818 mysql_free_result() /*Frees memory used by a result set*/ 00819 mysql_get_character_set_info() /*Return information about default character set*/ 00820 mysql_get_client_info() /*Returns client version information as a string*/ 00821 mysql_get_client_version() /*Returns client version information as an integer*/ 00822 mysql_get_host_info() /*Returns a string describing the connection*/ 00823 mysql_get_proto_info() /*Returns the protocol version used by the connection*/ 00824 mysql_get_server_info() /*Returns the server version number*/ 00825 mysql_get_server_version() /*Returns version number of server as an integer*/ 00826 mysql_get_ssl_cipher() /*Return current SSL cipher*/ 00827 mysql_hex_string() /*Encode string in hexadecimal format*/ 00828 mysql_info() /*Returns information about the most recently executed query*/ 00829 mysql_init() /*Gets or initializes a MYSQL structure*/ 00830 mysql_kill() /*Kills a given thread*/ 00831 mysql_library_end() /*Finalize the MySQL C API library*/ 00832 mysql_library_init() /*Initialize the MySQL C API library*/ 00833 mysql_list_dbs() /*Returns database names matching a simple regular expression*/ 00834 mysql_list_fields() /*Returns field names matching a simple regular expression*/ 00835 mysql_list_processes() /*Returns a list of the current server threads*/ 00836 mysql_list_tables() /*Returns table names matching a simple regular expression*/ 00837 mysql_more_results() /*Checks whether any more results exist*/ 00838 mysql_next_result() /*Returns/initiates the next result in multiple-statement executions*/ 00839 mysql_num_fields() /*Returns the number of columns in a result set*/ 00840 mysql_num_rows() /*Returns the number of rows in a result set*/ 00841 mysql_options() /*Sets connect options for mysql_real_connect()*/ 00842 mysql_ping() /*Checks whether the connection to the server is working, reconnecting as necessary*/ 00843 mysql_query() /*Executes an SQL query specified as a null-terminated string*/ 00844 mysql_real_connect() /*Connects to a MySQL server*/ 00845 mysql_real_escape_string() /*Escapes special characters in a string for use in an SQL statement, taking into account the current character set of the connection*/ 00846 mysql_real_query() /*Executes an SQL query specified as a counted string*/ 00847 mysql_refresh() /*Flush or reset tables and caches*/ 00848 mysql_reload() /*Tells the server to reload the grant tables*/ 00849 mysql_rollback() /*Rolls back the transaction*/ 00850 mysql_row_seek() /*Seeks to a row offset in a result set, using value returned from mysql_row_tell()*/ 00851 mysql_row_tell() /*Returns the row cursor position*/ 00852 mysql_select_db() /*Selects a database*/ 00853 mysql_server_end() /*Finalize the MySQL C API library*/ 00854 mysql_server_init() /*Initialize the MySQL C API library*/ 00855 mysql_set_character_set() /*Set default character set for current connection*/ 00856 mysql_set_local_infile_default() /*Set the LOAD DATA LOCAL INFILE handler callbacks to their default values*/ 00857 mysql_set_local_infile_handler() /*Install application-specific LOAD DATA LOCAL INFILE handler callbacks*/ 00858 mysql_set_server_option() /*Sets an option for the connection (like multi-statements)*/ 00859 mysql_sqlstate() /*Returns the SQLSTATE error code for the last error*/ 00860 mysql_shutdown() /*Shuts down the database server*/ 00861 mysql_ssl_set() /*Prepare to establish SSL connection to server*/ 00862 mysql_stat() /*Returns the server status as a string*/ 00863 mysql_store_result() /*Retrieves a complete result set to the client*/ 00864 mysql_thread_id() /*Returns the current thread ID*/ 00865 mysql_use_result() /*Initiates a row-by-row result set retrieval*/ 00866 mysql_warning_count() /*Returns the warning count for the previous SQL statement*/ 00867 #endif 00868 00869 00870 #endif