OSDN Git Service

on error option of sqlite3 function.
authorvisor <visor@users.sourceforge.jp>
Sat, 24 Jul 2010 10:06:47 +0000 (19:06 +0900)
committervisor <visor@users.sourceforge.jp>
Sat, 24 Jul 2010 10:06:47 +0000 (19:06 +0900)
config.h
ext/ml-sqlite3.cc
ext/ml-sqlite3.h

index 9f8d944..5c82f7d 100644 (file)
--- a/config.h
+++ b/config.h
@@ -20,5 +20,6 @@
 
 #define  SHARE_AUTHDB          1
 #define  WIKICOMPAT            1
+#define  TABLECOMPATFLAG       1
 
 #endif /* CONFIG_H */
index 41cb7b7..9267894 100644 (file)
@@ -269,6 +269,18 @@ sqlite3_int64  MLSqlite3::rowid () {
     return sqlite3_last_insert_rowid (dbh);
 }
 
+void  MLSqlite3::postError (ustring msg) {
+    if (errfunc ()) {
+       MNodePtr  ag;
+       MNodePtr  v;
+       ag = new MNode;
+       ag ()->set_car (newMNode_str (new ustring (msg)));
+       v = execDefun (mlenv, errfunc (), ag (), uEmpty);
+    } else {
+       throw (msg);
+    }
+}
+
 /*DOC:
 ===$sqlite3===
  ($sqlite3 DB [:limit NUM] [#create | :create BOOL] [SUBFUNCTION...])
@@ -287,6 +299,7 @@ MNode*  ml_sqlite3 (MNode* cell, MlEnv* mlenv) {
     static paramList  kwlist[] = {
        {CharConst ("limit"), false},
        {CharConst ("create"), true},
+       {CharConst ("onerror"), false},
        {NULL, 0, 0}
     };
 
@@ -300,7 +313,9 @@ MNode*  ml_sqlite3 (MNode* cell, MlEnv* mlenv) {
            obj.limit = kARRAYMAX;
     }
     obj.fcreate = eval_bool (keywords[1], mlenv);
-    
+    if (keywords[2])
+       obj.errfunc = eval (keywords[2], mlenv);
+
     if (db.size () == 0)
        throw (uErrorFilenameEmpty);
     dbfile = mlenv->env->path_db (db, kEXT_SQLITE3);
@@ -391,7 +406,8 @@ static MNode*  ml_sqlite3_sql_main (MNode* cell, MlEnv* mlenv, MLSqlite3::fsqlPa
                        par.bindValue.push_back (NULL);
                    }
                } else {
-                   throw (ustring ("\"") + *u () + ustring ("\": bad bind name."));
+//                 throw (ustring ("\"") + *u () + ustring ("\": bad bind name."));
+                   obj->postError (ustring ("\"") + *u () + ustring ("\": bad bind name."));
                }
            }
        } else {
@@ -497,7 +513,7 @@ static MNode*  ml_sqlite3_sql_main (MNode* cell, MlEnv* mlenv, MLSqlite3::fsqlPa
            }
        }
     } else {                   // ! SQLITE_OK
-       throw (ustring ("SQL error: ") + sqlite3_errmsg (obj->dbh));
+       obj->postError (ustring (CharConst ("SQL error: ")) + sqlite3_errmsg (obj->dbh));
     }
 
     return ans.release ();
index 990cd19..bd91ed5 100644 (file)
@@ -56,6 +56,7 @@ class  MLSqlite3: public MLFunc {
     sqlite3_stmt*  dbst;
     int  ncols;
     bool  fcreate;
+    MNodePtr  errfunc;
 
     MLSqlite3 (MlEnv* _mlenv): MLFunc (cMLSqlite3ID, _mlenv) {
        dbh = NULL;
@@ -84,6 +85,7 @@ class  MLSqlite3: public MLFunc {
     virtual MNode*  answer_list ();
     virtual MNode*  answer_list_ary ();
     virtual sqlite3_int64  rowid ();
+    virtual void  postError (ustring msg);
 };
 
 MNode*  ml_sqlite3 (MNode* cell, MlEnv* mlenv);