|
|
| version 1.8, 2001/08/01 09:30:35 | version 1.14, 2001/09/05 09:22:45 |
|---|---|
| Line 14 static const char *RCSId="$Id$"; | Line 14 static const char *RCSId="$Id$"; |
| #include "pa_sql_driver.h" | #include "pa_sql_driver.h" |
| #include <libpq-fe.h> | #include <libpq-fe.h> |
| #include <libpq-fs.h> | #include <libpq/libpq-fs.h> |
| // OIDOID from #include <catalog/pg_type.h> | // OIDOID from catalog/pg_type.h |
| #define OIDOID 26 | #define OIDOID 26 |
| // LO_BUFSIZE from interfaces\libpq\fe-lobj.c = 8192 (0x2000) | // LO_BUFSIZE from interfaces\libpq\fe-lobj.c = 8192 (0x2000) |
| // actually writing chunks of that size failed, reduced it twice | // actually writing chunks of that size failed, reduced it twice |
| #define LO_BUFSIZE 0x1000 | #define LO_BUFSIZE 0x1000 |
| // from postgres_ext.h | |
| #define InvalidOid ((Oid) 0) | |
| #include "ltdl.h" | #include "ltdl.h" |
| Line 64 public: | Line 67 public: |
| return dlopen_file_spec? | return dlopen_file_spec? |
| dlink(dlopen_file_spec):"client library column is empty"; | dlink(dlopen_file_spec):"client library column is empty"; |
| } | } |
| #define throwPQerror services._throw(PQerrorMessage(conn)) | |
| /** connect | /** connect |
| @param used_only_in_connect_url | @param used_only_in_connect_url |
| format: @b user:pass@host[:port]|[local]/database | format: @b user:pass@host[:port]|[local]/database |
| Line 85 public: | Line 91 public: |
| if(!conn) | if(!conn) |
| services._throw("PQsetdbLogin failed"); | services._throw("PQsetdbLogin failed"); |
| if(PQstatus(conn)!=CONNECTION_OK) | if(PQstatus(conn)!=CONNECTION_OK) |
| services._throw(PQerrorMessage(conn)); | throwPQerror; |
| *(PGconn **)connection=conn; | *(PGconn **)connection=conn; |
| begin_transaction(services, conn); | begin_transaction(services, conn); |
| } | } |
| void disconnect(SQL_Driver_services&, void *connection) { | void disconnect(void *connection) { |
| PQfinish((PGconn *)connection); | PQfinish((PGconn *)connection); |
| } | } |
| void commit(SQL_Driver_services& services, void *connection) { | void commit(SQL_Driver_services& services, void *connection) { |
| Line 98 public: | Line 104 public: |
| if(PGresult *res=PQexec(conn, "COMMIT")) | if(PGresult *res=PQexec(conn, "COMMIT")) |
| PQclear(res); | PQclear(res); |
| else | else |
| services._throw(PQerrorMessage(conn)); | throwPQerror; |
| begin_transaction(services, conn); | begin_transaction(services, conn); |
| } | } |
| void rollback(SQL_Driver_services& services, void *connection) { | void rollback(SQL_Driver_services& services, void *connection) { |
| Line 106 public: | Line 112 public: |
| if(PGresult *res=PQexec(conn, "ROLLBACK")) | if(PGresult *res=PQexec(conn, "ROLLBACK")) |
| PQclear(res); | PQclear(res); |
| else | else |
| services._throw(PQerrorMessage(conn)); | throwPQerror; |
| begin_transaction(services, conn); | begin_transaction(services, conn); |
| } | } |
| Line 152 public: | Line 158 public: |
| PGresult *res=PQexec(conn, statement); | PGresult *res=PQexec(conn, statement); |
| if(!res) | if(!res) |
| services._throw(PQerrorMessage(conn)); | throwPQerror; |
| switch(PQresultStatus(res)) { | switch(PQresultStatus(res)) { |
| case PGRES_EMPTY_QUERY: | case PGRES_EMPTY_QUERY: |
| Line 241 private: // private funcs | Line 247 private: // private funcs |
| if(PGresult *res=PQexec(conn, "BEGIN")) | if(PGresult *res=PQexec(conn, "BEGIN")) |
| PQclear(res); | PQclear(res); |
| else | else |
| services._throw(PQerrorMessage(conn)); | throwPQerror; |
| } | } |
| const char *preprocess_statement(SQL_Driver_services& services, PGconn *conn, | const char *preprocess_statement(SQL_Driver_services& services, PGconn *conn, |
| const char *astatement, unsigned long offset, unsigned long limit) { | const char *astatement, unsigned long offset, unsigned long limit) { |
| size_t statement_size=strlen(astatement); | size_t statement_size=strlen(astatement); |
| //_asm int 3; | |
| #define throwPQerror services._throw(PQerrorMessage(conn)) | |
| char *result=(char *)services.malloc(statement_size | char *result=(char *)services.malloc(statement_size |
| +MAX_NUMBER*2+15 // limit # offset # | +MAX_NUMBER*2+15 // limit # offset # |
| Line 420 private: // conn client library funcs li | Line 423 private: // conn client library funcs li |
| }; | }; |
| extern "C" SQL_Driver *create() { | extern "C" SQL_Driver *SQL_DRIVER_CREATE() { |
| return new PgSQL_Driver(); | return new PgSQL_Driver(); |
| } | } |