|
|
| version 1.8, 2008/06/30 09:29:55 | version 1.9, 2008/07/03 07:17:25 |
|---|---|
| Line 14 | Line 14 |
| #include "sqlite3.h" | #include "sqlite3.h" |
| #include "ltdl.h" | #include "ltdl.h" |
| #define MAX_COLS 500 | |
| #define MAX_STRING 0x400 | #define MAX_STRING 0x400 |
| #define MAX_NUMBER 20 | #define MAX_NUMBER 20 |
| Line 112 public: | Line 113 public: |
| services._throw("document_root is empty"); | services._throw("document_root is empty"); |
| db_path=(char*)services.malloc_atomic(strlen(document_root)+1+strlen(db)+1); | db_path=(char*)services.malloc_atomic(strlen(document_root)+1+strlen(db)+1); |
| db_path=strcpy(db_path, document_root); | strcpy(db_path, document_root); |
| db_path=strcat(db_path, "/"); | strcat(db_path, "/"); |
| db_path=strcat(db_path, db); | strcat(db_path, db); |
| } | } |
| //services._throw(db_path); | //services._throw(db_path); |
| Line 222 public: | Line 223 public: |
| if(placeholders_count>0) | if(placeholders_count>0) |
| services._throw("bind variables not supported yet"); | services._throw("bind variables not supported yet"); |
| const char* request_charset=services.request_charset(); | |
| const char* client_charset=connection.client_charset; | |
| bool transcode_needed=_transcode_required(connection); | bool transcode_needed=_transcode_required(connection); |
| // transcode query from $request:charset to ?ClientCharset | // transcode query from $request:charset to ?ClientCharset |
| Line 230 public: | Line 233 public: |
| size_t length=strlen(astatement); | size_t length=strlen(astatement); |
| services.transcode(astatement, length, | services.transcode(astatement, length, |
| astatement, length, | astatement, length, |
| services.request_charset(), | request_charset, |
| connection.client_charset); | client_charset); |
| } | } |
| const char *statement; | const char *statement; |
| Line 278 public: | Line 281 public: |
| if(!column_count){ // empty result: insert|delete|update|... | if(!column_count){ // empty result: insert|delete|update|... |
| rc=sqlite3_step(SQL); | rc=sqlite3_step(SQL); |
| } else { | } else { |
| if(column_count>MAX_COLS) | |
| column_count=MAX_COLS; | |
| int column_types[MAX_COLS]; | |
| bool transcode_column[MAX_COLS]; | |
| for(int i=0; i<column_count; i++){ | for(int i=0; i<column_count; i++){ |
| const char *column_name=sqlite3_column_name(SQL, i); | const char *column_name=sqlite3_column_name(SQL, i); |
| size_t length=strlen(column_name); | size_t length=strlen(column_name); |
| Line 289 public: | Line 298 public: |
| if(transcode_needed){ | if(transcode_needed){ |
| services.transcode(str, length, | services.transcode(str, length, |
| str, length, | str, length, |
| connection.client_charset, | client_charset, |
| services.request_charset()); | request_charset); |
| } | } |
| CHECK(handlers.add_column(sql_error, (const char*)str, length)); | CHECK(handlers.add_column(sql_error, (const char*)str, length)); |
| } | } |
| CHECK(handlers.before_rows(sql_error)); | CHECK(handlers.before_rows(sql_error)); |
| int column_type; | |
| const char *str; | const char *str; |
| size_t length=0; | size_t length=0; |
| bool first_row=true; | |
| do{ | do{ |
| rc=sqlite3_step(SQL); | rc=sqlite3_step(SQL); |
| Line 308 public: | Line 317 public: |
| CHECK(handlers.add_row(sql_error)); | CHECK(handlers.add_row(sql_error)); |
| for(int i=0; i<column_count; i++){ | for(int i=0; i<column_count; i++){ |
| if(first_row){ | |
| column_types[i]=sqlite3_column_type(SQL, i); | |
| switch(column_types[i]){ | |
| case SQLITE_INTEGER: | |
| case SQLITE_FLOAT: | |
| case SQLITE_NULL: | |
| transcode_column[i]=false; | |
| break; | |
| default: | |
| transcode_column[i]=transcode_needed; | |
| break; | |
| } | |
| } | |
| // SQLite allow to get value of any type using sqlite3_column_text function | // SQLite allow to get value of any type using sqlite3_column_text function |
| column_type=sqlite3_column_type(SQL, i); | switch(column_types[i]){ |
| bool transcode_value=false; | |
| switch(column_type){ | |
| case SQLITE_NULL: | case SQLITE_NULL: |
| length=0; | length=0; |
| str=NULL; | str=NULL; |
| Line 320 public: | Line 341 public: |
| str=(const char*)sqlite3_column_blob(SQL, i); | str=(const char*)sqlite3_column_blob(SQL, i); |
| length=(size_t)sqlite3_column_bytes(SQL, i); | length=(size_t)sqlite3_column_bytes(SQL, i); |
| break; | break; |
| case SQLITE_TEXT: // for text transcoding can be required | default: // anything else? |
| transcode_value=transcode_needed; | |
| case SQLITE_INTEGER: | |
| case SQLITE_FLOAT: | |
| default: // what else? may be for future purposes | |
| str=(const char*)sqlite3_column_text(SQL, i); | str=(const char*)sqlite3_column_text(SQL, i); |
| length=(size_t)sqlite3_column_bytes(SQL, i); | length=(size_t)sqlite3_column_bytes(SQL, i); |
| break; | break; |
| Line 335 public: | Line 352 public: |
| memcpy(strm, str, length+1); | memcpy(strm, str, length+1); |
| str=strm; | str=strm; |
| // transcode cell value from ?ClientCharset to $request:charset | if(transcode_column[i]){ |
| if(transcode_value){ | // transcode cell value from ?ClientCharset to $request:charset |
| services.transcode(str, length, | services.transcode(str, length, |
| str, length, | str, length, |
| connection.client_charset, | client_charset, |
| services.request_charset()); | request_charset); |
| } | } |
| } else | } else |
| str=0; | str=0; |
| Line 348 public: | Line 365 public: |
| CHECK(handlers.add_row_cell(sql_error, str, length)); | CHECK(handlers.add_row_cell(sql_error, str, length)); |
| } | } |
| first_row=false; | |
| } | } |
| } while(rc==SQLITE_BUSY || rc==SQLITE_ROW); | } while(rc==SQLITE_BUSY || rc==SQLITE_ROW); |