--- parser3/src/sql/mysql/Attic/parser3mysql.C 2001/04/17 15:02:11 1.13.2.3 +++ parser3/src/sql/mysql/Attic/parser3mysql.C 2001/05/17 08:52:40 1.17 @@ -1,11 +1,11 @@ /** @file - Parser: MySQL driver. + Parser MySQL driver. Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: parser3mysql.C,v 1.13.2.3 2001/04/17 15:02:11 paf Exp $ + $Id: parser3mysql.C,v 1.17 2001/05/17 08:52:40 parser Exp $ */ #include "config_includes.h" @@ -36,10 +36,6 @@ static char *lsplit(char *string, char d /** MySQL server driver - - @todo figure out about memory for errors: - static=add multithread locks; - dynamic=who should free it up? */ class MySQL_Driver : public SQL_Driver { public: @@ -53,14 +49,18 @@ public: const char *initialize(const char *dlopen_file_spec) { return dlink(dlopen_file_spec); } - /// connect + /** connect + @param used_only_to_connect_url + format: @b user:pass@host[:port]/database/charset + 3.23.22b + Currently the only option for @b character_set_name is cp1251_koi8. + WARNING: must be used only to connect, for buffer doesn't live long + */ void connect( - char *url, /**< @b user:pass@host[:port]/database/charset - 3.23.22b - Currently the only option for character_set_name is cp1251_koi8 */ + char *used_only_to_connect_url, void **connection ///< output: MYSQL * ) { - char *user=url; + char *user=used_only_to_connect_url; char *host=lsplit(user, '@'); char *db=lsplit(host, '/'); char *pwd=lsplit(user, ':'); @@ -144,6 +144,9 @@ public: } *column_count=mysql_num_fields(res); + if(!*column_count) // old client + *column_count=mysql_field_count(mysql); + *columns=(Cell *)services->malloc(sizeof(Cell)*(*column_count)); *row_count=(unsigned long)mysql_num_rows(res); @@ -175,23 +178,14 @@ public: private: // mysql client library funcs -#ifndef STDCALL -# if !defined(WIN32) -# define STDCALL -# else -# define STDCALL __stdcall -# endif -#endif - typedef MYSQL* (STDCALL *t_mysql_init)(MYSQL *); t_mysql_init mysql_init; + typedef MYSQL_RES* (STDCALL *t_mysql_store_result)(MYSQL *); t_mysql_store_result mysql_store_result; + typedef int (STDCALL *t_mysql_query)(MYSQL *, const char *q); t_mysql_query mysql_query; - //typedef char * (*t_mysql_error)(MYSQL *); t_mysql_error mysql_error; -#ifndef mysql_error - char* STDCALL mysql_error(MYSQL *mysql) { - return (mysql)->net.last_error; - } -#endif + + typedef char * (STDCALL *t_mysql_error)(MYSQL *); t_mysql_error mysql_error; + static char* STDCALL subst_mysql_error(MYSQL *mysql) { return (mysql)->net.last_error; } typedef MYSQL* (STDCALL *t_mysql_real_connect)(MYSQL *, const char *host, const char *user, @@ -202,32 +196,28 @@ private: // mysql client library funcs unsigned int clientflag); t_mysql_real_connect mysql_real_connect; typedef void (STDCALL *t_mysql_close)(MYSQL *); t_mysql_close mysql_close; + typedef int (STDCALL *t_mysql_ping)(MYSQL *); t_mysql_ping mysql_ping; + typedef unsigned long (STDCALL *t_mysql_escape_string)(char *to,const char *from, unsigned long from_length); t_mysql_escape_string mysql_escape_string; + typedef void (STDCALL *t_mysql_free_result)(MYSQL_RES *result); t_mysql_free_result mysql_free_result; + typedef unsigned long* (STDCALL *t_mysql_fetch_lengths)(MYSQL_RES *result); t_mysql_fetch_lengths mysql_fetch_lengths; + typedef MYSQL_ROW (STDCALL *t_mysql_fetch_row)(MYSQL_RES *result); t_mysql_fetch_row mysql_fetch_row; + typedef MYSQL_FIELD* (STDCALL *t_mysql_fetch_field)(MYSQL_RES *result); t_mysql_fetch_field mysql_fetch_field; - //typedef my_ulonglong (STDCALL *t_mysql_num_rows)(MYSQL_RES *); t_mysql_num_rows mysql_num_rows; -#ifndef mysql_num_rows - my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res) { - return res->row_count; - } -#endif - //typedef unsigned int (STDCALL *t_mysql_num_fields)(MYSQL_RES *); t_mysql_num_fields mysql_num_fields; -#ifndef mysql_num_fields - unsigned int STDCALL mysql_num_fields(MYSQL_RES *res) { - return res->field_count; - } -#endif + + typedef my_ulonglong (STDCALL *t_mysql_num_rows)(MYSQL_RES *); t_mysql_num_rows mysql_num_rows; + static my_ulonglong STDCALL subst_mysql_num_rows(MYSQL_RES *res) { return res->row_count; } + + typedef unsigned int (STDCALL *t_mysql_num_fields)(MYSQL_RES *); t_mysql_num_fields mysql_num_fields; + static unsigned int STDCALL subst_mysql_num_fields(MYSQL_RES *res) { return res->field_count; } -// typedef unsigned int (STDCALL *t_mysql_field_count)(MYSQL *); t_mysql_field_count mysql_field_count; -#ifndef mysql_field_count - unsigned int STDCALL mysql_field_count(MYSQL *mysql) { - return mysql->field_count; - } -#endif + typedef unsigned int (STDCALL *t_mysql_field_count)(MYSQL *); t_mysql_field_count mysql_field_count; + static unsigned int STDCALL subst_mysql_field_count(MYSQL *mysql) { return mysql->field_count; } private: // mysql client library funcs linking @@ -236,15 +226,18 @@ private: // mysql client library funcs l if (!handle) return "can not open the dynamic link module"; - #define DLINK(name) \ + #define DSLINK(name, action) \ name=(t_##name)lt_dlsym(handle, #name); \ - if(!name) \ - return "function " #name " was not found"; + if(!name) \ + action; + + #define DLINK(name) DSLINK(name, return "function " #name " was not found") + #define SLINK(name) DSLINK(name, name=subst_##name) DLINK(mysql_init); DLINK(mysql_store_result); DLINK(mysql_query); - //DLINK(mysql_error); + SLINK(mysql_error); DLINK(mysql_real_connect); DLINK(mysql_close); DLINK(mysql_ping); @@ -253,9 +246,9 @@ private: // mysql client library funcs l DLINK(mysql_fetch_lengths); DLINK(mysql_fetch_row); DLINK(mysql_fetch_field); -// DLINK(mysql_num_rows); -// DLINK(mysql_num_fields); -// DLINK(mysql_field_count); + SLINK(mysql_num_rows); + SLINK(mysql_num_fields); + SLINK(mysql_field_count); return 0; }