--- parser3/src/sql/mysql/Attic/parser3mysql.C 2001/05/17 13:23:28 1.18 +++ parser3/src/sql/mysql/Attic/parser3mysql.C 2001/06/28 07:41:59 1.22 @@ -5,8 +5,9 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: parser3mysql.C,v 1.18 2001/05/17 13:23:28 parser Exp $ + $Id: parser3mysql.C,v 1.22 2001/06/28 07:41:59 parser Exp $ */ +static char *RCSId="$Id: parser3mysql.C,v 1.22 2001/06/28 07:41:59 parser Exp $"; #include "config_includes.h" @@ -51,7 +52,7 @@ public: } /** connect @param used_only_in_connect_url - format: @b user:pass@host[:port]/database/charset + format: @b user:pass@host[:port]|[/unix/socket]/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 @@ -62,8 +63,16 @@ public: void **connection ///< output: MYSQL * ) { char *user=used_only_in_connect_url; - char *host=lsplit(user, '@'); - char *db=lsplit(host, '/'); + char *s=lsplit(user, '@'); + char *host=0; + char *unix_socket=0; + if(s && s[0]=='[') { // unix socket + unix_socket=1+s; + s=lsplit(unix_socket, ']'); + } else { // IP + host=s; + } + char *db=lsplit(s, '/'); char *pwd=lsplit(user, ':'); char *error_pos=0; char *port_cstr=lsplit(host, ':'); @@ -72,7 +81,7 @@ public: MYSQL *mysql=mysql_init(NULL); if(!mysql_real_connect(mysql, - host, user, pwd, db, port?port:MYSQL_PORT, NULL, 0)) + host, user, pwd, db, port?port:MYSQL_PORT, unix_socket, 0)) services._throw(mysql_error(mysql)); if(charset) { @@ -150,11 +159,10 @@ public: if(!*column_count) // old client *column_count=mysql_field_count(mysql); - *columns=(Cell *)services.malloc(sizeof(Cell)*(*column_count)); + if(!*column_count) + services._throw("result contains no columns"); - *row_count=(unsigned long)mysql_num_rows(res); - *rows=(Cell **)services.malloc(sizeof(Cell *)*(*row_count)); - + *columns=(Cell *)services.malloc(sizeof(Cell)*(*column_count)); for(unsigned int i=0; i<(*column_count); i++){ MYSQL_FIELD *field=mysql_fetch_field(res); size_t size=strlen(field->name); @@ -163,19 +171,24 @@ public: memcpy((*columns)[i].ptr, field->name, size); } - for(unsigned long r=0; r<(*row_count); r++) - if(MYSQL_ROW mysql_row=mysql_fetch_row(res)) { // never false.. - unsigned long *lengths=mysql_fetch_lengths(res); - Cell *row=(Cell *)malloc(sizeof(Cell)*(*column_count)); - (*rows)[r]=row; - for(unsigned int i=0; i<(*column_count); i++){ - size_t size=(size_t)lengths[i]; - row[i].size=size; - row[i].ptr=services.malloc(size); - memcpy(row[i].ptr, mysql_row[i], size); + if(*row_count=(unsigned long)mysql_num_rows(res)) { + *rows=(Cell **)services.malloc(sizeof(Cell *)*(*row_count)); + + for(unsigned long r=0; r<(*row_count); r++) + if(MYSQL_ROW mysql_row=mysql_fetch_row(res)) { // never false.. + unsigned long *lengths=mysql_fetch_lengths(res); + Cell *row=(Cell *)malloc(sizeof(Cell)*(*column_count)); + (*rows)[r]=row; + for(unsigned int i=0; i<(*column_count); i++){ + size_t size=(size_t)lengths[i]; + row[i].size=size; + row[i].ptr=services.malloc(size); + memcpy(row[i].ptr, mysql_row[i], size); + } } - } - + } else + *rows=0; + mysql_free_result(res); }