|
|
| version 1.6, 2001/07/31 14:22:00 | version 1.7, 2001/08/01 07:41:37 |
|---|---|
| Line 18 static const char *RCSId="$Id$"; | Line 18 static const char *RCSId="$Id$"; |
| // #include <catalog/pg_type.h> | // #include <catalog/pg_type.h> |
| #define OIDOID 26 | #define OIDOID 26 |
| #define LO_BUFSIZE 8192 | #define LO_BUFSIZE 0x1000/*8192*/ |
| #include "ltdl.h" | #include "ltdl.h" |
| Line 218 public: | Line 218 public: |
| if(size) { | if(size) { |
| // read | // read |
| ptr=services.malloc(size); | ptr=services.malloc(size); |
| char *buf=(char *)ptr; | if(!lo_read_ex(conn, fd, (const char *)ptr, size_tell)) |
| int countdown=size_tell; | |
| int size_read; | |
| while(countdown && (size_read=lo_read(conn, fd, buf, min(LO_BUFSIZE, countdown)))>0) { | |
| buf+=size_read; | |
| countdown-=size_read; | |
| } | |
| if(countdown) | |
| PQclear_throw("lo_read can not read all bytes of object"); | PQclear_throw("lo_read can not read all bytes of object"); |
| } else | } else |
| ptr=0; | ptr=0; |
| Line 263 private: // private funcs | Line 256 private: // private funcs |
| size_t statement_size=strlen(astatement); | size_t statement_size=strlen(astatement); |
| //_asm int 3; | //_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 # |
| +MAX_STRING // in case of short 'strings' | +MAX_STRING // in case of short 'strings' |
| Line 280 private: // private funcs | Line 275 private: // private funcs |
| } else | } else |
| o=astatement; | o=astatement; |
| // /*:zzzz*/'literal' -> oid | // /**xxx**/'literal' -> oid |
| char *n=result; | char *n=result; |
| while(*o) { | while(*o) { |
| if( | if( |
| o[0]=='/' && | o[0]=='/' && |
| o[1]=='*' && | o[1]=='*' && |
| o[2]==':') { // name start | o[2]=='*') { // name start |
| o+=3; | o+=3; |
| while(*o) | while(*o) |
| if( | if( |
| o[0]=='*' && | o[0]=='*' && |
| o[1]=='/' && | o[1]=='*' && |
| o[2]=='\'') { // name end | o[2]=='/' && |
| o+=3; | o[3]=='\'') { // name end |
| o+=4; | |
| Oid oid=lo_creat(conn, INV_READ|INV_WRITE); | Oid oid=lo_creat(conn, INV_READ|INV_WRITE); |
| if(oid==InvalidOid) | |
| throwPQerror; | |
| int fd=lo_open(conn, oid, INV_WRITE); | int fd=lo_open(conn, oid, INV_WRITE); |
| const char *start=o; | if(fd>=0) { |
| bool escaped=false; | const char *start=o; |
| while(*o && !(o[0]=='\'' && o[1]!='\'' && !escaped)) { | bool escaped=false; |
| escaped=*o=='\\' || (o[0]=='\'' && o[1]=='\''); | while(*o && !(o[0]=='\'' && o[1]!='\'' && !escaped)) { |
| if(escaped) { | escaped=*o=='\\' || (o[0]=='\'' && o[1]=='\''); |
| // write pending, skip "\" or "'" | if(escaped) { |
| if(o!=start) | // write pending, skip "\" or "'" |
| lo_write(conn, fd, start, o-start); | if(!lo_write_ex(conn, fd, start, o-start)) |
| start=++o; | services._throw("lo_write could not write all bytes of object (1)"); |
| } else | start=++o; |
| o++; | } else |
| } | o++; |
| if(o!=start) | } |
| lo_write(conn, fd, start, o-start); | if(!lo_write_ex(conn, fd, start, o-start)) |
| lo_close(conn, fd); | services._throw("lo_write can not write all bytes of object (2)"); |
| if(lo_close(conn, fd)<0) | |
| throwPQerror; | |
| } else | |
| throwPQerror; | |
| if(*o) | if(*o) |
| o++; // skip "'" | o++; // skip "'" |
| n+=snprintf(n, MAX_NUMBER, "%u", oid); | n+=snprintf(n, MAX_NUMBER, "%u", oid); |
| break; | break; |
| } else | } else |
| o++; // /*:skip*/ | o++; // /**skip**/'xxx' |
| } else | } else |
| *n++=*o++; | *n++=*o++; |
| } | } |
| Line 326 private: // private funcs | Line 328 private: // private funcs |
| return result; | return result; |
| } | } |
| private: // lo_read/write exchancements | |
| bool lo_read_ex(PGconn *conn, int fd, const/*paf*/ char *buf, size_t len) { | |
| int size_read; | |
| while(len && (size_read=lo_read(conn, fd, buf, min(LO_BUFSIZE, len)))>0) { | |
| buf+=size_read; | |
| len-=size_read; | |
| } | |
| return len==0; | |
| } | |
| bool lo_write_ex(PGconn *conn, int fd, const/*paf*/ char *buf, size_t len) { | |
| int size_written; | |
| while(len && (size_written=lo_write(conn, fd, buf, min(LO_BUFSIZE, len)))>0) { | |
| buf+=size_written; | |
| len-=size_written; | |
| } | |
| return len==0; | |
| } | |
| private: // conn client library funcs | private: // conn client library funcs |
| typedef PGconn* (*t_PQsetdbLogin)( | typedef PGconn* (*t_PQsetdbLogin)( |