|
|
| version 1.22, 2004/06/23 07:32:07 | version 1.25, 2004/12/23 16:54:52 |
|---|---|
| Line 58 static char *lsplit(char **string_ref, c | Line 58 static char *lsplit(char **string_ref, c |
| return result; | return result; |
| } | } |
| static char* rsplit(char* string, char delim) { | |
| if(string) { | |
| char* v=strrchr(string, delim); | |
| if(v) { | |
| *v=0; | |
| return v+1; | |
| } | |
| } | |
| return NULL; | |
| } | |
| static void toupper_str(char *out, const char *in, size_t size) { | static void toupper_str(char *out, const char *in, size_t size) { |
| while(size--) | while(size--) |
| *out++=(char)toupper(*in++); | *out++=(char)toupper(*in++); |
| Line 104 public: | Line 115 public: |
| void **connection_ref ///< output: Connection* | void **connection_ref ///< output: Connection* |
| ) { | ) { |
| char *user=url; | char *user=url; |
| char *host=lsplit(user, '@'); | char *host=rsplit(user, '@'); |
| char *db=lsplit(host, '/'); | char *db=lsplit(host, '/'); |
| char *pwd=lsplit(user, ':'); | char *pwd=lsplit(user, ':'); |
| char *port=lsplit(host, ':'); | char *port=lsplit(host, ':'); |
| Line 127 public: | Line 138 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 151 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 196 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 373 cleanup: | Line 393 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 560 private: // conn client library funcs li | Line 583 private: // conn client library funcs li |
| return 0; | return 0; |
| } | } |
| bool isDefaultTransaction; | |
| }; | }; |
| extern "C" SQL_Driver *SQL_DRIVER_CREATE() { | extern "C" SQL_Driver *SQL_DRIVER_CREATE() { |