|
|
| version 1.20, 2004/03/30 08:18:25 | version 1.23, 2004/12/23 15:57:41 |
|---|---|
| Line 95 public: | Line 95 public: |
| #define PQclear_throwPQerror PQclear_throw(PQerrorMessage(connection.conn)) | #define PQclear_throwPQerror PQclear_throw(PQerrorMessage(connection.conn)) |
| /** connect | /** connect |
| @param used_only_in_connect_url | @param url |
| format: @b user:pass@host[:port]|[local]/database | format: @b user:pass@host[:port]|[local]/database |
| */ | */ |
| void connect( | void connect( |
| char *used_only_in_connect_url, | char *url, |
| SQL_Driver_services& services, | SQL_Driver_services& services, |
| void **connection_ref ///< output: Connection* | void **connection_ref ///< output: Connection* |
| ) { | ) { |
| char *user=used_only_in_connect_url; | char *user=url; |
| char *host=lsplit(user, '@'); | char *host=lsplit(user, '@'); |
| char *db=lsplit(host, '/'); | char *db=lsplit(host, '/'); |
| char *pwd=lsplit(user, ':'); | char *pwd=lsplit(user, ':'); |
| Line 127 public: | Line 127 public: |
| char *charset=0; | char *charset=0; |
| char *datestyle=0; | char *datestyle=0; |
| isDefaultTransaction = true; | |
| while(options) { | while(options) { |
| if(char *key=lsplit(&options, '&')) { | if(char *key=lsplit(&options, '&')) { |
| Line 139 public: | Line 140 public: |
| cstrBackwardCompAskServerToTranscode=value; | cstrBackwardCompAskServerToTranscode=value; |
| } else if(strcasecmp(key, "datestyle")==0) { | } else if(strcasecmp(key, "datestyle")==0) { |
| datestyle=value; | datestyle=value; |
| } else if(strcmp(key, "WithoutDefaultTransaction")==0) { | |
| isDefaultTransaction = false; | |
| } else | } else |
| services._throw("unknown connect option" /*key*/); | services._throw("unknown connect option" /*key*/); |
| } else | } else |
| Line 182 public: | Line 185 public: |
| connection.conn=0; | connection.conn=0; |
| } | } |
| void commit(void *aconnection) { | void commit(void *aconnection) { |
| Connection& connection=*static_cast<Connection*>(aconnection); | if(isDefaultTransaction) |
| { | |
| if(PGresult *res=PQexec(connection.conn, "COMMIT")) | Connection& connection=*static_cast<Connection*>(aconnection); |
| PQclear(res); | |
| else | if(PGresult *res=PQexec(connection.conn, "COMMIT")) |
| throwPQerror; | PQclear(res); |
| begin_transaction(connection); | else |
| throwPQerror; | |
| begin_transaction(connection); | |
| } | |
| } | } |
| void rollback(void *aconnection) { | void rollback(void *aconnection) { |
| Connection& connection=*static_cast<Connection*>(aconnection); | if(isDefaultTransaction) |
| { | |
| if(PGresult *res=PQexec(connection.conn, "ROLLBACK")) | Connection& connection=*static_cast<Connection*>(aconnection); |
| PQclear(res); | |
| else | if(PGresult *res=PQexec(connection.conn, "ROLLBACK")) |
| throwPQerror; | PQclear(res); |
| begin_transaction(connection); | else |
| throwPQerror; | |
| begin_transaction(connection); | |
| } | |
| } | } |
| bool ping(void *aconnection) { | bool ping(void *aconnection) { |
| Line 228 public: | Line 237 public: |
| return result; | return result; |
| } | } |
| void query(void *aconnection, | void query(void *aconnection, |
| const char *astatement, unsigned long offset, unsigned long limit, | const char *astatement, |
| size_t placeholders_count, Placeholder* placeholders, | |
| unsigned long offset, unsigned long limit, | |
| SQL_Driver_query_event_handlers& handlers) { | SQL_Driver_query_event_handlers& handlers) { |
| // _asm int 3; | // _asm int 3; |
| Connection& connection=*static_cast<Connection*>(aconnection); | Connection& connection=*static_cast<Connection*>(aconnection); |
| Line 236 public: | Line 247 public: |
| SQL_Driver_services& services=*connection.services; | SQL_Driver_services& services=*connection.services; |
| PGconn *conn=connection.conn; | PGconn *conn=connection.conn; |
| if(placeholders_count>0) | |
| services._throw("bind variables not supported (yet)"); | |
| // transcode from $request:charset to connect-string?client_charset | // transcode from $request:charset to connect-string?client_charset |
| if(cstrClientCharset) { | if(cstrClientCharset) { |
| size_t transcoded_statement_size; | size_t transcoded_statement_size; |
| Line 368 cleanup: | Line 382 cleanup: |
| private: // private funcs | private: // private funcs |
| void begin_transaction(Connection& connection) { | void begin_transaction(Connection& connection) { |
| if(PGresult *res=PQexec(connection.conn, "BEGIN")) | if(isDefaultTransaction) |
| PQclear(res); | { |
| else | if(PGresult *res=PQexec(connection.conn, "BEGIN")) |
| throwPQerror; | PQclear(res); |
| else | |
| throwPQerror; | |
| } | |
| } | } |
| const char *preprocess_statement(Connection& connection, | const char *preprocess_statement(Connection& connection, |
| Line 555 private: // conn client library funcs li | Line 572 private: // conn client library funcs li |
| return 0; | return 0; |
| } | } |
| // Default transaction flag, if true make it. | |
| bool isDefaultTransaction; | |
| }; | }; |
| extern "C" SQL_Driver *SQL_DRIVER_CREATE() { | extern "C" SQL_Driver *SQL_DRIVER_CREATE() { |