--- sql/oracle/parser3oracle.C 2001/10/28 14:51:30 1.2 +++ sql/oracle/parser3oracle.C 2002/12/09 11:43:08 1.26 @@ -1,13 +1,13 @@ /** @file Parser Oracle driver. - Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) + Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexandr Petrosian (http://paf.design.ru) 2001.07.30 using Oracle 8.1.6 [@test tested with Oracle 7.x.x] */ -static const char *RCSId="$Id: parser3oracle.C,v 1.2 2001/10/28 14:51:30 paf Exp $"; +static const char *RCSId="$Id: parser3oracle.C,v 1.26 2002/12/09 11:43:08 paf Exp $"; #include "config_includes.h" @@ -38,6 +38,54 @@ inline int max(int a, int b) { return a> inline int min(int a, int b){ return a "''" - *to++='\''; - break; - case '\\': // "\" -> "\\" - *to++='\''; - break; + if(to) { // store mode + unsigned int result=length; + while(length--) { + switch(*from) { + case '\'': // "'" -> "''" + *to++='\''; result++; + break; + } + *to++=*from++; } - *to++=*from++; - } - return result; + return result; + } else // estimate mode + return length*2; } void query( SQL_Driver_services& services, void *connection, @@ -357,8 +443,11 @@ cleanup: // no check call after this poi if(stmthp) OCIHandleFree((dvoid *)stmthp, (ub4)OCI_HTYPE_STMT); - if(failed) + if(failed) { + if(cs.sql_exception.defined()) + services._throw(cs.sql_exception); services._throw(cs.error); + } } private: // private funcs @@ -397,7 +486,7 @@ private: // private funcs const char *start=o; bool escaped=false; while(*o && !(o[0]=='\'' && o[1]!='\'' && !escaped)) { - escaped=*o=='\\' || (o[0]=='\'' && o[1]=='\''); + escaped=o[0]=='\'' && o[1]=='\''; if(escaped) { // write pending, skip "\" or "'" if(size_t size=o-start) { @@ -462,6 +551,9 @@ private: // private funcs (dvoid *)stmthp, (ub4)OCI_HTYPE_STMT, (ub1 *)&stmt_type, (ub4 *)0, OCI_ATTR_STMT_TYPE, cs.errhp)); */ + + while(isspace(*statement)) + statement++; if(strncasecmp(statement, "select", 6)==0) stmt_type=OCI_STMT_SELECT; else if(strncasecmp(statement, "insert", 6)==0) @@ -512,6 +604,18 @@ private: // private funcs OCIStmt *stmthp, unsigned long offset, unsigned long limit, SQL_Driver_query_event_handlers& handlers) { + ub4 prefetch_rows=100; + check(services, cs, "AttrSet prefetch-rows", OCIAttrSet( + (dvoid *)stmthp, (ub4)OCI_HTYPE_STMT, + (dvoid *)&prefetch_rows, (ub4)0, + (ub4)OCI_ATTR_PREFETCH_ROWS, (OCIError *)cs.errhp)); + + ub4 prefetch_mem_size=100*0x400; + check(services, cs, "AttrSet prefetch-memory", OCIAttrSet( + (dvoid *)stmthp, (ub4)OCI_HTYPE_STMT, + (dvoid *)&prefetch_mem_size, (ub4)0, + (ub4)OCI_ATTR_PREFETCH_MEMORY, (OCIError *)cs.errhp)); + OCIParam *mypard; ub2 dtype; text *col_name; @@ -531,116 +635,125 @@ private: // private funcs failed=true; goto cleanup; } else { - // idea of preincrementing is that at error time all handles would free up - while(++column_count<=MAX_COLS) { - /* get next descriptor, if there is one */ - if(OCIParamGet(stmthp, OCI_HTYPE_STMT, cs.errhp, (void **)&mypard, - (ub4) column_count)!=OCI_SUCCESS) - break; - - /* Retrieve the data type attribute */ - check(services, cs, "get type", OCIAttrGet( - (dvoid*) mypard, (ub4)OCI_DTYPE_PARAM, - (dvoid*) &dtype, (ub4 *)0, (ub4)OCI_ATTR_DATA_TYPE, - (OCIError *)cs.errhp)); - - /* Retrieve the column name attribute */ - ub4 col_name_len; - check(services, cs, "get name", OCIAttrGet( - (dvoid*) mypard, (ub4)OCI_DTYPE_PARAM, - (dvoid**) &col_name, (ub4 *) &col_name_len, (ub4)OCI_ATTR_NAME, - (OCIError *)cs.errhp)); - - { - size_t size=(size_t)col_name_len; - char *ptr=(char *)services.malloc(size); - tolower(ptr, (char *)col_name, size); - handlers.add_column(ptr, size); - } - - ub2 coerce_type=dtype; - sb4 size=0; - void *ptr; - - switch(dtype) { - case SQLT_CLOB: + try { + + // idea of preincrementing is that at error time all handles would free up + while(++column_count<=MAX_COLS) { + /* get next descriptor, if there is one */ + if(OCIParamGet(stmthp, OCI_HTYPE_STMT, cs.errhp, (void **)&mypard, + (ub4) column_count)!=OCI_SUCCESS) { + --column_count; + break; + } + + /* Retrieve the data type attribute */ + check(services, cs, "get type", OCIAttrGet( + (dvoid*) mypard, (ub4)OCI_DTYPE_PARAM, + (dvoid*) &dtype, (ub4 *)0, (ub4)OCI_ATTR_DATA_TYPE, + (OCIError *)cs.errhp)); + + /* Retrieve the column name attribute */ + ub4 col_name_len; + check(services, cs, "get name", OCIAttrGet( + (dvoid*) mypard, (ub4)OCI_DTYPE_PARAM, + (dvoid**) &col_name, (ub4 *) &col_name_len, (ub4)OCI_ATTR_NAME, + (OCIError *)cs.errhp)); + { - check(services, cs, "alloc output var desc", OCIDescriptorAlloc( - (dvoid *)cs.envhp, (dvoid **)(ptr=&cols[column_count-1].var), - (ub4)OCI_DTYPE_LOB, - 0, (dvoid **)0)); - - size=0; + size_t size=(size_t)col_name_len; + char *ptr=(char *)services.malloc(size); + tolower(ptr, (char *)col_name, size); + handlers.add_column(ptr, size); + } + + ub2 coerce_type=dtype; + sb4 size=0; + void *ptr; + + switch(dtype) { + case SQLT_CLOB: + { + check(services, cs, "alloc output var desc", OCIDescriptorAlloc( + (dvoid *)cs.envhp, (dvoid **)(ptr=&cols[column_count-1].var), + (ub4)OCI_DTYPE_LOB, + 0, (dvoid **)0)); + + size=0; + break; + } + default: + coerce_type=SQLT_STR; + ptr=cols[column_count-1].str=(char *)services.malloc(MAX_OUT_STRING_LENGTH+1); + size=MAX_OUT_STRING_LENGTH; break; } - default: - coerce_type=SQLT_STR; - ptr=cols[column_count-1].str=(char *)services.malloc(MAX_OUT_STRING_LENGTH+1); - size=MAX_OUT_STRING_LENGTH; - break; + + cols[column_count-1].type=coerce_type; + + check(services, cs, "DefineByPos", OCIDefineByPos( + stmthp, &cols[column_count-1].def, cs.errhp, + column_count, (ub1 *) ptr, size, + coerce_type, (dvoid *) &cols[column_count-1].indicator, + (ub2 *)0, (ub2 *)0, OCI_DEFAULT)); } - cols[column_count-1].type=coerce_type; + handlers.before_rows(); - check(services, cs, "DefineByPos", OCIDefineByPos( - stmthp, &cols[column_count-1].def, cs.errhp, - column_count, (ub1 *) ptr, size, - coerce_type, (dvoid *) &cols[column_count-1].indicator, - (ub2 *)0, (ub2 *)0, OCI_DEFAULT)); - } - - handlers.before_rows(); - - for(unsigned long row=0; !limit||row=offset) { - handlers.add_row(); - for(int i=0; i=offset) { + handlers.add_row(); + for(int i=0; i