object sqlite3::compile(flusspferd::string sql_in, value bind ) { local_root_scope scope; size_t n_bytes = sql_in.length() * 2; sqlite3_stmt * sth = 0; js_char16_t * tail = 0; // uncompiled part of the sql (when multiple stmts) if (sqlite3_prepare16_v2(db, sql_in.data(), n_bytes, &sth, (const void**)&tail) != SQLITE_OK) { raise_sqlite_error(db); } object cursor = create<sqlite3_cursor>(fusion::make_vector(sth)); string tail_str; if (tail) { tail_str = string(tail); } string sql = sql_in.substr( 0, sql_in.size() - tail_str.size() ); cursor.define_property("sql", sql); cursor.define_property("tail", tail_str); if ( !bind.is_undefined_or_null() ) { cursor.call("bind", bind ); } return cursor; }
void JS_fwrite( flusspferd::string fileName, flusspferd::string str ) { std::ofstream OutFile( ( std::string("./js_files/") + fileName.to_string()).c_str() ); if( OutFile.is_open() ) { OutFile.write( str.to_string().c_str(), MIN(str.size(),1024) ); } OutFile.close(); }
void JS_saveSingleObjectToDatabase(JSObject *object, flusspferd::string holderType, flusspferd::string holderId) { if(object->toReal() && object->toReal()->IsPurged() == false) { if(holderType.size() < 1) { throw flusspferd::exception("Attempting to save object to database with an empty holder type."); } Object::saveItemToTopLevelHolder(holderType.c_str()[0], holderId.to_string(), object->toReal()); } }
flusspferd::array JS_loadObjectsByHolderFromDatabase(flusspferd::string holderType, flusspferd::string holderId) { flusspferd::array objects = flusspferd::create_array(); if(holderType.size() == 0) { throw flusspferd::exception("Attempting to load objects from holder of empty type."); } std::list< Object* > objectList = Object::loadItemList(true, holderType.c_str()[0], holderId.to_string()); while(objectList.empty() == false) { objects.call("push", lookupValue(objectList.front())); // objects.push(lookupValue(objectList.front())); objectList.pop_front(); } return objects; }