src/statement.cc
// { Database db, String sql, Array params, Function callback }
{ Database db, String sql, Array params, Function callback }
{ Database db String sql Array params Function callback }
Handle<Value> Statement::New(const Arguments& args) {
    HandleScope scope;
    if (!args.IsConstructCall()) {
        return ThrowException(Exception::TypeError(
            String::New("Use the new operator to create new Statement objects"))
        );
    }
    int length = args.Length();
    if (length <= 0 || !Database::HasInstance(args[0])) {
        return ThrowException(Exception::TypeError(
            String::New("Database object expected")));
    }
    else if (length <= 1 || !args[1]->IsString()) {
        return ThrowException(Exception::TypeError(
            String::New("SQL query expected")));
    }
    else if (length > 2 && !args[2]->IsUndefined() && !args[2]->IsFunction()) {
        return ThrowException(Exception::TypeError(
            String::New("Callback expected")));
    }
    Database* db = ObjectWrap::Unwrap<Database>(args[0]->ToObject());
    Local<String> sql = Local<String>::Cast(args[1]);
    args.This()->Set(String::NewSymbol("sql"), sql, ReadOnly);
    Statement* stmt = new Statement(db);
    stmt->Wrap(args.This());
    PrepareBaton* baton = new PrepareBaton(db, Local<Function>::Cast(args[2]), stmt);
    baton->sql = std::string(*String::Utf8Value(sql));
    db->Schedule(Work_BeginPrepare, baton);
    return args.This();
}
Handle < Value > Statement :: New ( const Arguments & args ) { HandleScope scope ; if ( ! args . IsConstructCall ( ) ) { return ThrowException ( Exception :: TypeError ( String :: New ( " " ) ) ) ; } int length = args . Length ( ) ; if ( length <= 0 || ! Database :: HasInstance ( args [ 0 ] ) ) { return ThrowException ( Exception :: TypeError ( String :: New ( " " ) ) ) ; } else if ( length <= 1 || ! args [ 1 ] -> IsString ( ) ) { return ThrowException ( Exception :: TypeError ( String :: New ( " " ) ) ) ; } else if ( length > 2 && ! args [ 2 ] -> IsUndefined ( ) && ! args [ 2 ] -> IsFunction ( ) ) { return ThrowException ( Exception :: TypeError ( String :: New ( " " ) ) ) ; } Database * db = ObjectWrap :: Unwrap < Database > ( args [ 0 ] -> ToObject ( ) ) ; Local < String > sql = Local < String > :: Cast ( args [ 1 ] ) ; args . This ( ) -> Set ( String :: NewSymbol ( " " ) , sql , ReadOnly ) ; Statement * stmt = new Statement ( db ) ; stmt -> Wrap ( args . This ( ) ) ; PrepareBaton * baton = new PrepareBaton ( db , Local < Function > :: Cast ( args [ 2 ] ) , stmt ) ; baton -> sql = std :: string ( * String :: Utf8Value ( sql ) ) ; db -> Schedule ( Work_BeginPrepare , baton ) ; return args . This ( ) ; }
{ Database db, String sql, Array params, Function callback }
{ Database db String sql Array params Function callback }