Show
Ignore:
Timestamp:
09/28/08 11:03:03 (6 years ago)
Author:
tokuhirom
Message:

added transaction support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/llv8call/trunk/ext/sqlite3/sqlite3.cc

    r20059 r20087  
     1// based on Python DB API 2.0 
     2// see also 
     3//   http://www.python.org/dev/peps/pep-0249/ 
     4//   http://www.python.jp/doc/contrib/peps/pep-0249.txt 
     5 
    16#include "sqlite3.h" 
    27#include <v8.h> 
     
    3439        return str; 
    3540    } 
     41    if ( sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK) { 
     42        return throw_errmsg(db); 
     43    } 
    3644    args.This()->SetInternalField(0, External::New((void*)db)); 
    3745    return args.This(); 
     46} 
     47 
     48static Handle<Value> _commit(const Arguments& args) { 
     49    assert_args(args, 0); 
     50    HandleScope handle_scope; 
     51    sqlite3 *db = handle<sqlite3>(args, 0); 
     52    if ( sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != SQLITE_OK) { 
     53        return throw_errmsg(db); 
     54    } 
     55    if ( sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK) { 
     56        return throw_errmsg(db); 
     57    } 
     58    return Undefined(); 
     59} 
     60 
     61static Handle<Value> _rollback(const Arguments& args) { 
     62    assert_args(args, 0); 
     63    HandleScope handle_scope; 
     64    sqlite3 *db = handle<sqlite3>(args, 0); 
     65    if ( sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK) { 
     66        return throw_errmsg(db); 
     67    } 
     68    return Undefined(); 
    3869} 
    3970 
     
    186217    Handle<ObjectTemplate>   ot = ft->InstanceTemplate(); 
    187218 
    188     ot->Set(String::New("Close"), FunctionTemplate::New(_close)); 
    189     ot->Set(String::New("Cursor"), FunctionTemplate::New(_cursor)); 
     219    ot->Set(String::New("Close"),    FunctionTemplate::New(_close)); 
     220    ot->Set(String::New("Commit"),   FunctionTemplate::New(_commit)); 
     221    ot->Set(String::New("Rollback"), FunctionTemplate::New(_rollback)); 
     222    ot->Set(String::New("Cursor"),   FunctionTemplate::New(_cursor)); 
    190223 
    191224    {