|
|
| version 1.6, 2008/06/26 09:59:56 | version 1.8, 2008/06/30 09:29:55 |
|---|---|
| Line 78 public: | Line 78 public: |
| /** connect | /** connect |
| @param url | @param url |
| format: @b [localhost/]dbfile? | format: @b db-file|:memory:|temporary:? |
| autocommit=1& | autocommit=1& // =0 disable autocommit. in this case 1 connect == 1 transaction. |
| multi_statements=0& | // or you can use begin/commit|rollback explicitly |
| ClientCharset=UTF-8 | multi_statements=0& // =1 allow many statements in 1 query |
| ClientCharset=UTF-8 // will transcode to/from specified charset instead of UTF-8 (default for sqlite) | |
| */ | */ |
| void connect( | void connect( |
| char *url, | char *url, |
| Line 101 public: | Line 102 public: |
| char* db=url; | char* db=url; |
| char* options=lsplit(db, '?'); | char* options=lsplit(db, '?'); |
| if(strcmp(db, ":memory:")==0){ // in-memory table | if(strcmp(db, ":memory:")==0){ // in-memory temporary DB |
| db_path=db; | db_path=db; |
| } else if(strcmp(db, ":temporary:")==0){ // on disk temporary table (in :memory: style) | } else if(strcmp(db, ":temporary:")==0){ // on-disk temporary DB |
| // do nothing: empty path mean temporary table on disk | // do nothing: empty path mean temporary table on disk |
| } else { // build path to DB-file from document_root (as anywhere in parser) | } else { |
| if(char* document_root=(char*)services.request_document_root()){ | char* document_root=(char*)services.request_document_root(); |
| db_path=(char*)services.malloc_atomic(strlen(document_root)+strlen(db)+1+1); | if(!document_root) // path to DB-file which was specified by user is path from document_root as anywhere in parser |
| db_path=strncat(db_path, document_root, strlen(document_root)); | services._throw("document_root is empty"); |
| db_path=strncat(db_path, "/", 1); | |
| } else { | db_path=(char*)services.malloc_atomic(strlen(document_root)+1+strlen(db)+1); |
| // if document root empty -- build path from executable file | db_path=strcpy(db_path, document_root); |
| db_path=(char*)services.malloc_atomic(strlen(db)+2+1); | db_path=strcat(db_path, "/"); |
| db_path=strncat(db_path, "./", 2); | db_path=strcat(db_path, db); |
| } | |
| db_path=strncat(db_path, db, strlen(db)); | |
| } | } |
| //services._throw(db_path); | //services._throw(db_path); |
| Line 124 public: | Line 123 public: |
| if(char* key=lsplit(&options, '&')){ | if(char* key=lsplit(&options, '&')){ |
| if(*key) { | if(*key) { |
| if(char* value=lsplit(key, '=')){ | if(char* value=lsplit(key, '=')){ |
| if(strcasecmp(key, "multi_statements")==0) { | if(strcasecmp(key, "multi_statements")==0){ |
| if(atoi(value)!=0) | if(atoi(value)!=0) |
| connection.multi_statements=true; | connection.multi_statements=true; |
| } else if(strcasecmp(key, "autocommit")==0){ | } else if(strcasecmp(key, "autocommit")==0){ |
| if(atoi(value)==0) | if(atoi(value)==0) |
| connection.autocommit=false; | connection.autocommit=false; |
| continue; | continue; |
| } else if(strcmp(key, "ClientCharset")==0){ // transcoding with parser. | } else if(strcmp(key, "ClientCharset")==0){ |
| // by default we always transcode to UTF-8 (sqlite default) | |
| // so use this option only if you already stored data in your sqlite DB | |
| // in wrong encoding (1251 for ex.) | |
| toupper_str(value, value, strlen(value)); | toupper_str(value, value, strlen(value)); |
| connection.client_charset=value; | connection.client_charset=value; |
| continue; | continue; |
| Line 267 public: | Line 263 public: |
| rc=sqlite3_prepare(connection.handle, statement, -1, &SQL, &pzTail); | rc=sqlite3_prepare(connection.handle, statement, -1, &SQL, &pzTail); |
| next_statement_length=strlen(pzTail); | next_statement_length=strlen(pzTail); |
| if(rc!=SQLITE_OK){ | if(rc!=SQLITE_OK){ |
| sqlite3_free((char*)pzTail); | //sqlite3_free((char*)pzTail); |
| _throw(connection, sqlite3_errmsg(connection.handle)); | _throw(connection, sqlite3_errmsg(connection.handle)); |
| } | } |
| if(!connection.multi_statements && next_statement_length>0){ // multi statements was not allowed but pzTail point to not empty one | if(!connection.multi_statements && next_statement_length>0){ // multi statements was not allowed but pzTail point to not empty one |
| sqlite3_free((char*)pzTail); | //sqlite3_free((char*)pzTail); |
| _throw(connection, "multi statements are not allowed in this connection"); | _throw(connection, "multi statements are not allowed until opption ?multi_statements=1 in connect string is specified."); |
| } | } |
| #define CHECK(afailed) if(afailed){ failed=true; goto cleanup; } | #define CHECK(afailed) if(afailed){ failed=true; goto cleanup; } |