Diff for /sql/sqlite/parser3sqlite.C between versions 1.4 and 1.5

version 1.4, 2008/06/24 17:46:57 version 1.5, 2008/06/24 17:50:47
Line 27 Line 27
 static char *lsplit(char *string, char delim) {  static char *lsplit(char *string, char delim) {
     if(string) {      if(string) {
                 char *v=strchr(string, delim);                  char *v=strchr(string, delim);
                 if(v) {                  if(v){
                         *v=0;                          *v=0;
                         return v+1;                          return v+1;
                 }                  }
Line 94  public: Line 94  public:
                 connection.cstrClientCharset=SQLITE_DEFAULT_CHARSET;                      connection.cstrClientCharset=SQLITE_DEFAULT_CHARSET;    
                 connection.autocommit=true;                  connection.autocommit=true;
   
                 char *db = url;                  char* db = url;
                 char *options = lsplit(db, '?');                  char* options = lsplit(db, '?');
                   
                 char *db_path=(char*)services.malloc(strlen((char*)services.request_document_root()) + strlen(db) + 2);                   //char* document_root=(char*)services.request_document_root();
                 db_path=strncat(db_path, (char*)services.request_document_root(), MAX_STRING);                  char* document_root=0;
                 db_path+="/";                  char *db_path=(char*)services.malloc(strlen(document_root) + strlen(db) + 2); 
                   if(document_root){
                           db_path=strncat(db_path, document_root, MAX_STRING);
                           db_path+='/';
                   }
                 db_path=strncat(db_path, db, MAX_STRING);                  db_path=strncat(db_path, db, MAX_STRING);
   
                 while(options) {                  while(options) {
Line 130  public: Line 134  public:
                         services.request_charset(),                          services.request_charset(),
                         SQLITE_DEFAULT_CHARSET);                          SQLITE_DEFAULT_CHARSET);
                                   
                 rc = sqlite3_open(db_path, &connection.handle);                  rc=sqlite3_open(db_path, &connection.handle);
   
                 if( SQLITE_OK != rc ){                  if(rc!=SQLITE_OK){
                         const char* errmsg = sqlite3_errmsg(connection.handle);                          _throw(connection, sqlite3_errmsg(connection.handle));
                         _throw(connection, errmsg);  
                         sqlite3_close(connection.handle);                          sqlite3_close(connection.handle);
                 }                  }
   
                 *connection_ref=&connection;                  *connection_ref=&connection;
                   
                 if(!connection.autocommit)                  if(!connection.autocommit)
                         exec(connection, "SET AUTOCOMMIT=0");                          exec(connection, "SET AUTOCOMMIT=0");
                                                   
         }          }
   
         void exec(Connection& connection, const char* statement) {          void exec(Connection& connection, const char* statement) {
                 char *zErr;                  char* zErr;
                 int rc;                  int rc;
                 rc=sqlite3_exec(connection.handle, statement, 0, 0, &zErr);                  rc=sqlite3_exec(connection.handle, statement, 0, 0, &zErr);
                 if(rc!=SQLITE_OK){                  if(rc!=SQLITE_OK){
Line 210  public: Line 213  public:
                 const char* cstrClientCharset=connection.cstrClientCharset;                  const char* cstrClientCharset=connection.cstrClientCharset;
   
                 if(placeholders_count>0)                  if(placeholders_count>0)
                         _throw(connection, "bind variables not supported yet");                          services._throw("bind variables not supported yet");
         
                 // transcode from $request:charset to ClientCharset                  // transcode from $request:charset to ClientCharset
                 if(cstrClientCharset) {                  if(cstrClientCharset) {
Line 243  public: Line 246  public:
                 int rc;                  int rc;
                 int i;                  int i;
                 SQL_Error sql_error;                  SQL_Error sql_error;
                 bool failed = false;                  bool failed=false;
   
                 do{ // cycling through SQL commands                  do{ // cycling through SQL commands
   
Line 251  public: Line 254  public:
   
                         if(rc!=SQLITE_OK){                          if(rc!=SQLITE_OK){
                                 _throw(connection, sqlite3_errmsg(connection.handle));                                  _throw(connection, sqlite3_errmsg(connection.handle));
                                 sqlite3_free(pzTail); // error? can't free memory after throw                                  sqlite3_free((char*)pzTail); // error? can't free memory after throw
                         }                          }
                                                   
   
Line 283  public: Line 286  public:
                                 CHECK(handlers.before_rows(sql_error));                                  CHECK(handlers.before_rows(sql_error));
   
                                 int column_type;                                  int column_type;
                                 const unsigned char *str;                                  const char *str;
                                 size_t length = 0;                                  size_t length = 0;
   
                                 do{                                  do{
Line 302  public: Line 305  public:
                                                         // но switch я всё-таки сделал - так, на будущее                                                          // но switch я всё-таки сделал - так, на будущее
                                                         switch(column_type) {                                                          switch(column_type) {
                                                                 case SQLITE_TEXT:                                                                  case SQLITE_TEXT:
                                                                         str=(const unsigned char*)sqlite3_column_text(SQL, i);                                                                          str=(const char*)sqlite3_column_text(SQL, i);
                                                                         length=strlen(str);                                                                          length=strlen((const char*)str);
                                                                         break;                                                                          break;
                                                                 case SQLITE_INTEGER:                                                                  case SQLITE_INTEGER:
                                                                         str=(const unsigned char*)sqlite3_column_text(SQL, i);                                                                          str=(const char*)sqlite3_column_text(SQL, i);
                                                                         length=strlen(str);                                                                          length=strlen((const char*)str);
                                                                         break;                                                                          break;
                                                                 case SQLITE_NULL:                                                                  case SQLITE_NULL:
                                                                         str=NULL;                                                                          str=NULL;
                                                                         length=0;                                                                          length=0;
                                                                         break;                                                                          break;
                                                                 default:                                                                  default:
                                                                         str=(const unsigned char*)sqlite3_column_text(SQL, i);                                                                          str=(const char*)sqlite3_column_text(SQL, i);
                                                                         length=strlen(str);                                                                          length=strlen((const char*)str);
                                                                         break;                                                                          break;
                                                         }                                                          }
   
                                                         if(length){                                                          if(length){
                                                                 char* strm=(char*)services.malloc_atomic(length+1);                                                                  char* strm=(char*)services.malloc_atomic(length+1);
                                                                 memcpy(strm, str, length+1);                                                                  memcpy(strm, str, length+1);
                                                                 str = strm;                                                                  str=strm;
   
                                                                 // transcode to $request:charset from connect-string?ClientCharset                                                                  // transcode to $request:charset from connect-string?ClientCharset
                                                                 if(cstrClientCharset) {                                                                  if(cstrClientCharset) {
Line 338  public: Line 341  public:
   
                                                 }                                                  }
                                         }                                          }
                                 } while( rc == SQLITE_BUSY || rc == SQLITE_ROW );                                  } while(rc == SQLITE_BUSY || rc == SQLITE_ROW);
   
                         }  // if column                          }  // if column
   
                         if( rc == SQLITE_ERROR || rc == SQLITE_MISUSE ){                          if(rc == SQLITE_ERROR || rc == SQLITE_MISUSE){
                                 _throw(connection, sqlite3_errmsg(connection.handle));                                  _throw(connection, sqlite3_errmsg(connection.handle));
                         }                          }
   
Line 352  public: Line 355  public:
                 } while (strlen(pzTail) > 0);                  } while (strlen(pzTail) > 0);
   
                 if(failed)                  if(failed)
                         _throw(connection, sql_error);                          services._throw(sql_error);
         }          }
   
 private:  private:
         void _throw(Connection& connection, const char* aerr_msg) {          void _throw(Connection& connection, const char* aerr_msg){
                         size_t err_length=strlen(aerr_msg);                          size_t err_length=strlen(aerr_msg);
                         if(err_length && connection.cstrClientCharset) {                          if(err_length && connection.cstrClientCharset) {
                                 connection.services->transcode(aerr_msg, err_length,                                  connection.services->transcode(aerr_msg, err_length,
Line 367  private: Line 370  private:
                         connection.services->_throw(aerr_msg);                          connection.services->_throw(aerr_msg);
         }          }
   
   
 private: // sqlite client library funcs  private: // sqlite client library funcs
   
         typedef int (*t_sqlite3_open)(const char *filename, sqlite3 **ppDb); t_sqlite3_open sqlite3_open;          typedef int (*t_sqlite3_open)(const char *filename, sqlite3 **ppDb); t_sqlite3_open sqlite3_open;
Line 394  private: // sqlite client library funcs Line 396  private: // sqlite client library funcs
   
         typedef const unsigned char *(* t_sqlite3_column_text)(sqlite3_stmt*, int iCol); t_sqlite3_column_text sqlite3_column_text;          typedef const unsigned char *(* t_sqlite3_column_text)(sqlite3_stmt*, int iCol); t_sqlite3_column_text sqlite3_column_text;
   
   
 private: // sqlite client library funcs linking  private: // sqlite client library funcs linking
   
         const char *dlink(const char *dlopen_file_spec) {          const char *dlink(const char *dlopen_file_spec) {

Removed from v.1.4  
changed lines
  Added in v.1.5


E-mail: