--- sql/oracle/parser3oracle.C 2004/03/04 09:10:13 1.52 +++ sql/oracle/parser3oracle.C 2004/06/18 15:55:52 1.60 @@ -7,7 +7,7 @@ 2001.07.30 using Oracle 8.1.6 [@test tested with Oracle 7.x.x] */ -static const char *RCSId="$Id: parser3oracle.C,v 1.52 2004/03/04 09:10:13 paf Exp $"; +static const char *RCSId="$Id: parser3oracle.C,v 1.60 2004/06/18 15:55:52 paf Exp $"; #include "config_includes.h" @@ -83,7 +83,6 @@ static int pa_setenv(const char *name, c strcat(buf, value); value=buf; } - return setenv(name, value, 1/*overwrite*/); } else { unsetenv(name); @@ -130,7 +129,7 @@ struct Connection { } options; }; -struct OracleSQL_query_lobs { +struct Query_lobs { struct return_rows { struct return_row { OCILobLocator *locator; ub4 len; @@ -139,24 +138,23 @@ struct OracleSQL_query_lobs { } *row; int count; }; - struct cbf_context_struct { - Connection *connection; - return_rows *rows; - }; struct Item { const char *name_ptr; size_t name_size; char *data_ptr; size_t data_size; OCILobLocator *locator; OCIBind *bind; return_rows rows; + Connection *connection; } items[MAX_IN_LOBS]; int count; }; + #endif // forwards -void check(Connection& connection, const char *step, sword status); -void check(Connection& connection, bool error); +static void faile(Connection& connection, const char *msg); +static void check(Connection& connection, const char *step, sword status); +static void check(Connection& connection, bool error); static sb4 cbf_no_data( dvoid *ctxp, OCIBind *bindp, @@ -173,8 +171,8 @@ static sb4 cbf_get_data(dvoid *ctxp, ub1 *piecep, dvoid **indpp, ub2 **rcodepp); -static void tolower(char *out, const char *in, size_t size); -static void toupper(char *out, const char *in, size_t size); +static void tolower_str(char *out, const char *in, size_t size); +static void toupper_str(char *out, const char *in, size_t size); static const char *options2env(char *s, Connection::Options* options) { while(s) { @@ -183,7 +181,7 @@ static const char *options2env(char *s, if(char *value=lsplit(key, '=')) { if( strcmp( key, "ClientCharset" ) == 0 ) { if(options) { - toupper(value, value, strlen(value)); + toupper_str(value, value, strlen(value)); options->cstrClientCharset = value; } continue; @@ -249,7 +247,7 @@ public: } /** connect - @param used_only_in_connect_url + @param url format: @b user:pass@service? ORACLE_HOME=/u01/app/oracle/product/8.1.5& ORA_NLS33=/u01/app/oracle/product/8.1.5/ocommon/nls/admin/data& @@ -257,18 +255,21 @@ public: ORA_ENCRYPT_LOGIN=TRUE @todo environment manupulation doesnt look thread safe + @todo allocate 'aused_only_in_connect_url' on gc heap, so it can be manipulated directly */ void connect( - char *used_only_in_connect_url, + char *url, SQL_Driver_services& services, void **connection_ref ///< output: Connection * - ) { + ) + { + // connections are cross-request, do not use services._alloc [linked with request] Connection& connection=*(Connection *)services.malloc(sizeof(Connection)); connection.services=&services; connection.options.bLowerCaseColumnNames = true; *connection_ref=&connection; - char *user=used_only_in_connect_url; + char *user=url; char *service=lsplit(user, '@'); char *pwd=lsplit(user, ':'); char *options=lsplit(service, '?'); @@ -345,13 +346,15 @@ public: void disconnect(void *aconnection) { Connection& connection=*static_cast(aconnection); - // free fetch buffers + // free fetch buffers. leave that to GC [no such services func. yet?] + /* for(int i=0; ifree(fetch_buffer); else break; - } + } + */ // Terminate a user session OCISessionEnd( @@ -372,8 +375,8 @@ public: OCIHandleFree( (dvoid *)connection.envhp, (ub4)OCI_HTYPE_ENV); - // connections are cross-request, do not use services._alloc [linked with request] - ::free(&connection); + // free connection. leave that to GC [no such services func. yet?] + // connection.services->free(&connection); } void commit(void *aconnection) { Connection& connection=*static_cast(aconnection); @@ -415,23 +418,27 @@ public: *to=0; return result; } - void query(void *aconnection, - const char *astatement, unsigned long offset, unsigned long limit, + void query(void* aconnection, + const char* astatement, + size_t placeholders_count, Placeholder* placeholders, + unsigned long offset, unsigned long limit, SQL_Driver_query_event_handlers& handlers) { Connection& connection=*static_cast(aconnection); - OracleSQL_query_lobs lobs={{0}, 0}; + const char* cstrClientCharset=connection.options.cstrClientCharset; + Query_lobs lobs={{0}, 0}; OCIStmt *stmthp=0; SQL_Driver_services& services=*connection.services; // transcode from $request:charset to connect-string?client_charset - size_t transcoded_statement_size; - if(const char* cstrClientCharset=connection.options.cstrClientCharset) + if(cstrClientCharset) { + size_t transcoded_xxx_size; services.transcode(astatement, strlen(astatement), - astatement, transcoded_statement_size, + astatement, transcoded_xxx_size, services.request_charset(), cstrClientCharset); + } bool failed=false; if(setjmp(connection.mark)) { @@ -446,30 +453,107 @@ public: OCIStmtPrepare(stmthp, connection.errhp, (unsigned char *)statement, (ub4)strlen((char *)statement), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT)); + + struct Bind_info { + OCIBind *bind; + sb2 indicator; + }; + + int binds_size=sizeof(Bind_info) * placeholders_count; + Bind_info* binds=static_cast(services.malloc_atomic(binds_size)); { + for(size_t i=0; icount; r++) { OCILobLocator *locator=rows->row[r].locator; check(connection, "lobwrite", OCILobWrite ( @@ -650,6 +734,7 @@ private: // private funcs OCIStmt *stmthp, unsigned long offset, unsigned long limit, SQL_Driver_query_event_handlers& handlers) { + const char* cstrClientCharset=connection.options.cstrClientCharset; SQL_Driver_services& services=*connection.services; ub4 prefetch_rows=100; @@ -705,7 +790,7 @@ private: // private funcs (dvoid**) &col_name, (ub4 *) &col_name_len, (ub4)OCI_ATTR_NAME, (OCIError *)connection.errhp)); // transcode to $request:charset from connect-string?client_charset - if(const char* cstrClientCharset=connection.options.cstrClientCharset) { + if(cstrClientCharset) { services.transcode(col_name, col_name_len, col_name, col_name_len, cstrClientCharset, @@ -717,7 +802,7 @@ private: // private funcs size_t length=(size_t)col_name_len; char *ptr=(char *)services.malloc_atomic(length+1); if( connection.options.bLowerCaseColumnNames ) - tolower(ptr, col_name, length); + tolower_str(ptr, col_name, length); else memcpy(ptr, col_name, length); ptr[length]=0; @@ -744,7 +829,7 @@ private: // private funcs char*& buf=connection.fetch_buffers[column_count-1]; ptr=buf; // get cached buffer if(!ptr) // allocate if needed, caching it - ptr=buf=(char *)::/*see disconnect*/malloc(MAX_OUT_STRING_LENGTH+1/*terminator*/); + ptr=buf=(char *)services.malloc_atomic(MAX_OUT_STRING_LENGTH+1/*terminator*/); col.str=(char*)ptr; size=MAX_OUT_STRING_LENGTH; break; @@ -778,7 +863,14 @@ private: // private funcs for(int i=0; i(ctxp); if(index==0) { static ub4 rows; @@ -1099,12 +1197,12 @@ static sb4 cbf_get_data(dvoid *ctxp, OracleSQL_driver->OCIAttrGet( (CONST dvoid *) bindp, OCI_HTYPE_BIND, (dvoid *)&rows, (ub4 *)sizeof(ub2), OCI_ATTR_ROWS_RETURNED, context.connection->errhp)) ; - context.rows->count=(ub2)rows; - context.rows->row=(OracleSQL_query_lobs::return_rows::return_row *) - context.connection->services->malloc_atomic(sizeof(OracleSQL_query_lobs::return_rows::return_row)*rows); + context.rows.count=(ub2)rows; + context.rows.row=(Query_lobs::return_rows::return_row *) + context.connection->services->malloc_atomic(sizeof(Query_lobs::return_rows::return_row)*rows); } - OracleSQL_query_lobs::return_rows::return_row &var=context.rows->row[index]; + Query_lobs::return_rows::return_row &var=context.rows.row[index]; check(*context.connection, "alloc output var desc dynamic", OracleSQL_driver->OCIDescriptorAlloc( (dvoid *) context.connection->envhp, (dvoid **)&var.locator, @@ -1120,11 +1218,11 @@ static sb4 cbf_get_data(dvoid *ctxp, return OCI_CONTINUE; } -static void tolower(char *out, const char *in, size_t size) { +static void tolower_str(char *out, const char *in, size_t size) { while(size--) *out++=(char)tolower(*in++); } -static void toupper(char *out, const char *in, size_t size) { +static void toupper_str(char *out, const char *in, size_t size) { while(size--) *out++=(char)toupper(*in++); }