|
|
| version 1.6, 2002/02/08 08:32:50 | version 1.8, 2002/03/22 16:19:13 |
|---|---|
| Line 51 static char *lsplit(char *string, char d | Line 51 static char *lsplit(char *string, char d |
| return 0; | return 0; |
| } | } |
| static char *lsplit(char **string_ref, char delim) { | |
| char *result=*string_ref; | |
| char *next=lsplit(*string_ref, delim); | |
| *string_ref=next; | |
| return result; | |
| } | |
| /** | /** |
| PgSQL server driver | PgSQL server driver |
| */ | */ |
| Line 69 public: | Line 76 public: |
| } | } |
| #define throwPQerror services._throw(PQerrorMessage(conn)) | #define throwPQerror services._throw(PQerrorMessage(conn)) |
| #define PQclear_throw(msg) { \ | |
| PQclear(res); \ | |
| services._throw(msg); \ | |
| } | |
| #define PQclear_throwPQerror PQclear_throw(PQerrorMessage(conn)) | |
| /** connect | /** connect |
| @param used_only_in_connect_url | @param used_only_in_connect_url |
| Line 85 public: | Line 97 public: |
| char *pwd=lsplit(user, ':'); | char *pwd=lsplit(user, ':'); |
| char *port=lsplit(host, ':'); | char *port=lsplit(host, ':'); |
| char *options=lsplit(db, '?'); | |
| PGconn *conn=PQsetdbLogin( | PGconn *conn=PQsetdbLogin( |
| strcasecmp(host, "local")==0?NULL/* local Unix domain socket */:host, port, | (host&&strcasecmp(host, "local")==0)?NULL/* local Unix domain socket */:host, port, |
| NULL, NULL, db, user, pwd); | NULL, NULL, db, user, pwd); |
| if(!conn) | if(!conn) |
| services._throw("PQsetdbLogin failed"); | services._throw("PQsetdbLogin failed"); |
| if(PQstatus(conn)!=CONNECTION_OK) | if(PQstatus(conn)!=CONNECTION_OK) |
| throwPQerror; | throwPQerror; |
| char *charset=0; | |
| char *datestyle=0; | |
| while(options) { | |
| if(char *key=lsplit(&options, '&')) { | |
| if(*key) { | |
| if(char *value=lsplit(key, '=')) { | |
| if(strcasecmp(key, "charset")==0) { | |
| charset=value; | |
| } else if(strcasecmp(key, "datestyle")==0) { | |
| datestyle=value; | |
| } else | |
| services._throw("unknown connect option" /*key*/); | |
| } else | |
| services._throw("connect option without =value" /*key*/); | |
| } | |
| } | |
| } | |
| if(charset) { | |
| // set CLIENT_ENCODING | |
| char statement[MAX_STRING]="set CLIENT_ENCODING="; // win | |
| strncat(statement, charset, MAX_STRING); | |
| PGresult *res=PQexec(conn, statement); | |
| if(!res) | |
| throwPQerror; | |
| PQclear(res); // throw out the result [don't need but must call] | |
| } | |
| if(datestyle) { | |
| // set DATESTYLE | |
| char statement[MAX_STRING]="set DATESTYLE="; // ISO,SQL,Postgres,European,NonEuropean=US,German,DEFAULT=ISO | |
| strncat(statement, charset, MAX_STRING); | |
| PGresult *res=PQexec(conn, statement); | |
| if(!res) | |
| throwPQerror; | |
| PQclear(res); // throw out the result [don't need but must call] | |
| } | |
| *(PGconn **)connection=conn; | *(PGconn **)connection=conn; |
| begin_transaction(services, conn); | begin_transaction(services, conn); |
| } | } |
| Line 147 public: | Line 202 public: |
| // _asm int 3; | // _asm int 3; |
| PGconn *conn=(PGconn *)connection; | PGconn *conn=(PGconn *)connection; |
| #define PQclear_throw(msg) { \ | |
| PQclear(res); \ | |
| services._throw(msg); \ | |
| } | |
| #define PQclear_throwPQerror PQclear_throw(PQerrorMessage(conn)) | |
| const char *statement=preprocess_statement(services, conn, | const char *statement=preprocess_statement(services, conn, |
| astatement, offset, limit); | astatement, offset, limit); |