bool OfferFrame::exists(Database& db, LedgerKey const& key) { std::string actIDStrKey = KeyUtils::toStrKey(key.offer().sellerID); int exists = 0; auto timer = db.getSelectTimer("offer-exists"); auto prep = db.getPreparedStatement("SELECT EXISTS (SELECT NULL FROM offers " "WHERE sellerid=:id AND offerid=:s)"); auto& st = prep.statement(); st.exchange(use(actIDStrKey)); st.exchange(use(key.offer().offerID)); st.exchange(into(exists)); st.define_and_bind(); st.execute(true); return exists != 0; }
void compoundStatement(void) { TRACE(lstFile,"[compoundStatement]"); /* Process statements until END encountered */ do { getToken(); statement(); } while (token == ';'); /* Verify that it really was END */ if (token != tEND) error (eEND); else getToken(); }
Stmt* Parser::labeledStatement() { Str* label = identifier(); eat(T_Colon); Stmt* stmt = statement(); Stmt* s = stmt; while (s->isLabeledStmt()) s = ((LabeledStmt*)s)->stmt; if (s->isLabelSetStmt()) { LabelSetStmt* ls = (LabelSetStmt*)s; ls->labels = ALLOC(Seq<Str*>, (label, ls->labels)); } return ALLOC(LabeledStmt, (label, stmt)); }
/* * Process a single external definition */ extdef() { register o, elsize; int type, sclass; register struct hshtab *ds; if(((o=symbol())==EOF) || o==SEMI) return; peeksym = o; type = INT; sclass = EXTERN; xdflg = FNDEL; if ((elsize = getkeywords(&sclass, &type)) == -1 && peeksym!=NAME) goto syntax; if (type==STRUCT) blkhed(); do { defsym = 0; decl1(EXTERN, type, 0, elsize); if ((ds=defsym)==0) return; funcsym = ds; ds->hflag =| FNDEL; outcode("BS", SYMDEF, ds->name); xdflg = 0; if ((ds->type&XTYPE)==FUNC) { if ((peeksym=symbol())==LBRACE || peeksym==KEYW) { funcblk.type = decref(ds->type); cfunc(ds->name); return; } } else cinit(ds); } while ((o=symbol())==COMMA); if (o==SEMI) return; syntax: if (o==RBRACE) { error("Too many }'s"); peeksym = 0; return; } error("External definition syntax"); errflush(o); statement(0); }
bool ApplicationCacheStorage::store(ApplicationCacheGroup* group) { ASSERT(group->storageID() == 0); SQLiteStatement statement(m_database, "INSERT INTO CacheGroups (manifestHostHash, manifestURL) VALUES (?, ?)"); if (statement.prepare() != SQLResultOk) return false; statement.bindInt64(1, urlHostHash(group->manifestURL())); statement.bindText(2, group->manifestURL()); if (!executeStatement(statement)) return false; group->setStorageID((unsigned)m_database.lastInsertRowID()); return true; }
CassError PolicyTool::query_return_error(CassSession* session, int n, CassConsistency cl) { std::string select_query = str(boost::format("SELECT * FROM %s WHERE k = 0") % test_utils::SIMPLE_TABLE); for (int i = 0; i < n; ++i) { test_utils::CassStatementPtr statement (cass_statement_new_n(select_query.data(), select_query.size(), 0)); cass_statement_set_consistency(statement.get(), cl); test_utils::CassFuturePtr future(cass_session_execute(session, statement.get())); CassError rc = test_utils::wait_and_return_error(future.get()); if (rc != CASS_OK) { return rc; } add_coordinator(cass::get_host_from_future(future.get())); } return CASS_OK; }
void DmapClient::getDatabasesFinished() { QByteArray array = databaseReply->readAll(); DmapStatement statement(array.data(), array.data() + (array.size() - 1), 1); QString name("miid"); QString inside("mlit"); QString insideRef("minm"); QByteArray dataArray = libraryName.toUtf8(); DmapStatement *session = statement.findValue(name, inside, insideRef, dataArray); dbid = DmapStatement::byteToInt<quint32>(session->getData()); databaseReply->deleteLater(); emit getDatabasesCompleted(); }
void DmapClient::getLibraryContainerFinished() { QByteArray array = containersReply->readAll(); DmapStatement statement(array.data(), array.data() + (array.size() - 1), 1); QString name("miid"); QString inside("mlit"); QString insideRef("abpl"); char c = 0x01; QByteArray dataArray(1, c); DmapStatement *number = statement.findValue(name, inside, insideRef, dataArray); libid = DmapStatement::byteToInt<quint32>(number->getData()); containersReply->deleteLater(); emit getLibraryContainerCompleted(); }
void syslogd_configure (struct syslogd * syslogs, flag_t flags, char const * filename) { file_t fd; char string [TEXTLINE_MAX]; size_t lineno = 0; #if SYSLOGD_TRACE trace_enter ("syslogd_configure"); #endif if ((fd = open (filename, O_RDONLY)) == - 1) { syslogd_error (errno, "cant open %s", filename); return; } while (statement (fd, string, sizeof (string), & lineno)) { if (* string != (char) (0)) { struct syslogd * syslog = NEW (struct syslogd); syslogd_parse (syslog, flags, string); if (syslog->f_type == SYSLOGD_TYPE_NONE) { free (syslog->f_name); free (syslog); continue; } syslog->prev = syslogs->prev; syslogs->prev->next = syslog; syslogs->prev = syslog; syslog->next = syslogs; } } close (fd); #if SYSLOGD_TRACE trace_leave ("syslogd_configure"); #endif return; }
void block() { int prev_mod = mod; level++; mod = 4; if(current_token.type == constsym) const_decl(); if(current_token.type == varsym) var_decl(); if(current_token.type == procsym) proc_decl(); emit(INC, 0,mod); statement(); level--; mod = prev_mod; }
/* Returns a list of tables in the database */ std::vector< std::string > Database::tables() { Statement statement(*this, "SELECT name FROM sqlite_master WHERE type = 'table'"); if (!statement.valid()) { return std::vector< std::string >(); } if (!(statement.execute() && statement.hasData())) { return std::vector< std::string >(); } std::vector< std::string > tables; do { tables.push_back(statement.toText(0u)); } while (statement.nextRow()); return tables; }
String DatabaseTracker::fullPathForDatabaseNoLock(SecurityOrigin* origin, const String& name, bool createIfNotExists) { ASSERT(!m_databaseGuard.tryLock()); String originIdentifier = origin->databaseIdentifier(); String originPath = this->originPath(origin); // Make sure the path for this SecurityOrigin exists if (createIfNotExists && !SQLiteFileSystem::ensureDatabaseDirectoryExists(originPath)) return String(); // See if we have a path for this database yet if (!m_database.isOpen()) return String(); SQLiteStatement statement(m_database, "SELECT path FROM Databases WHERE origin=? AND name=?;"); if (statement.prepare() != SQLITE_OK) return String(); statement.bindText(1, originIdentifier); statement.bindText(2, name); int result = statement.step(); if (result == SQLITE_ROW) return SQLiteFileSystem::appendDatabaseFileNameToPath(originPath, statement.getColumnText(0)); if (!createIfNotExists) return String(); if (result != SQLITE_DONE) { LOG_ERROR("Failed to retrieve filename from Database Tracker for origin %s, name %s", originIdentifier.ascii().data(), name.ascii().data()); return String(); } statement.finalize(); String fileName = generateDatabaseFileName(); if (!addDatabase(origin, name, fileName)) return String(); // If this origin's quota is being tracked (open handle to a database in this origin), add this new database // to the quota manager now String fullFilePath = SQLiteFileSystem::appendDatabaseFileNameToPath(originPath, fileName); return fullFilePath; }
OracleLOB * BingoStorage::_getLob (OracleEnv &env, int no) { OracleStatement statement(env); AutoPtr<OracleLOB> lob(new OracleLOB(env)); statement.append("SELECT bindata FROM %s where ID = :id FOR UPDATE", _table_name.ptr()); statement.prepare(); statement.bindIntByName(":id", &no); statement.defineBlobByPos(1, lob.ref()); statement.execute(); if (statement.fetch()) env.dbgPrintf("WARNING: more than 1 row have id = %d in table %s\n", no, _table_name.ptr()); lob->enableBuffering(); return lob.release(); }
void Statistics::addStoreDecisionsToDatabase(const Vector<std::pair<StringCapture, StoreDecision>>& storeDecisions) { ASSERT(!RunLoop::isMain()); ASSERT(WebCore::SQLiteDatabaseTracker::hasTransactionInProgress()); ASSERT(m_database.isOpen()); WebCore::SQLiteStatement statement(m_database, ASCIILiteral("INSERT OR REPLACE INTO UncachedReason (hash, reason) VALUES (?, ?)")); if (statement.prepare() != SQLITE_OK) return; for (auto& pair : storeDecisions) { statement.bindText(1, pair.first.string()); statement.bindInt(2, static_cast<int>(pair.second)); executeSQLStatement(statement); statement.reset(); } }
//略过第一个符号 'while' void grammar_parser::while_statement(set<e_word_t> follows,int& stk_index) { word lmbranch=m_words.get(); if(lmbranch.m_type==ewt_key_lsbranch) { grammar_debug(lmbranch); int test_begin=get_new_code_addr(false); expression(_create_syms(follows,ewt_key_rsbranch),stk_index); word rmbranch=m_words.get(); if(rmbranch.m_type==ewt_key_rsbranch) { grammar_debug(rmbranch); _instruction* p_while_jmp=gen_code(e_jpc,eab_relat_ip); stk_index--; while_context context; context.m_begin_stk_index=stk_index; word lbbranch=m_words.get(); if(lbbranch.m_type==ewt_key_lbbranch) { grammar_debug(lbbranch); body(follows,stk_index,&context); } else { m_words.push(lbbranch); statement(_create_syms(follows,ewt_key_else),stk_index,&context); } _instruction* p_loop_jmp=gen_code(e_jmp,eab_relat_ip); p_loop_jmp->m_addr=test_begin-(p_loop_jmp->m_index+1); p_while_jmp->m_addr=get_new_code_addr()-(p_while_jmp->m_index+1); for(vector<_instruction*>::iterator it=context.breaks.begin();it!=context.breaks.end();it++) { (*it)->m_addr=get_new_code_addr()-((*it)->m_index+1); } for(vector<_instruction*>::iterator it=context.continues.begin();it!=context.continues.end();it++) { (*it)->m_addr=test_begin-((*it)->m_index+1); } } } else { m_words.push(lmbranch); test_and_skip(follows,_create_syms()); } }
void Statistics::addHashesToDatabase(const Vector<StringCapture>& hashes) { ASSERT(!RunLoop::isMain()); ASSERT(WebCore::SQLiteDatabaseTracker::hasTransactionInProgress()); ASSERT(m_database.isOpen()); WebCore::SQLiteStatement statement(m_database, ASCIILiteral("INSERT OR IGNORE INTO AlreadyRequested (hash) VALUES (?)")); if (statement.prepare() != SQLITE_OK) return; for (auto& hash : hashes) { statement.bindText(1, hash.string()); if (executeSQLStatement(statement)) ++m_approximateEntryCount; statement.reset(); } }
bool insert_task(const std::string& query, CassConsistency consistency, int rows_per_id) { bool is_successful = true; for (int i = 0; i < rows_per_id; ++i) { if (version.major == 1) { if (!create_and_execute_insert(query, consistency)) { is_successful = false; } } else { test_utils::CassStatementPtr statement(cass_statement_new(query.c_str(), 3)); cass_statement_set_consistency(statement.get(), consistency); if (!bind_and_execute_insert(statement.get())) { is_successful = false; } } } return is_successful; }
int main (int argc, char const *argv []) { char buffer [100]; size_t lineno = 0; file_t fd; if ((fd = open (*++argv, O_RDONLY)) == -1) { error (1, errno, "can't open %s", *argv); } while (statement (fd, buffer, sizeof (buffer), &lineno)) { printf ("%d [%s]\n", lineno, buffer); } close (fd); return; }
static Block *block(void) { Block *p = 0; Statement *first = statement(); if (first) { p = NEW(Block); p->first = first; p->rest = block(); if (p->rest) { p->n = p->rest->n + 1; } else { p->n = 1; } } return p; }
bool DatabaseTracker::hasEntryForOriginNoLock(SecurityOrigin* origin) { ASSERT(!m_databaseGuard.tryLock()); openTrackerDatabase(DontCreateIfDoesNotExist); if (!m_database.isOpen()) return false; SQLiteStatement statement(m_database, "SELECT origin FROM Origins where origin=?;"); if (statement.prepare() != SQLResultOk) { LOG_ERROR("Failed to prepare statement."); return false; } statement.bindText(1, origin->databaseIdentifier()); return statement.step() == SQLResultRow; }
// Note: This function is currently only used in AllowTrustOpFrame, which means // the asset parameter will never satisfy asset.type() == ASSET_TYPE_NATIVE. As // a consequence, I have not implemented that possibility so this function // throws in that case. std::vector<LedgerEntry> LedgerStateRoot::Impl::loadOffersByAccountAndAsset(AccountID const& accountID, Asset const& asset) const { std::string sql = "SELECT sellerid, offerid, " "sellingassettype, sellingassetcode, sellingissuer, " "buyingassettype, buyingassetcode, buyingissuer, " "amount, pricen, priced, flags, lastmodified " "FROM offers "; sql += " WHERE sellerid = :acc" " AND ((sellingassetcode = :code AND sellingissuer = :iss)" " OR (buyingassetcode = :code AND buyingissuer = :iss))"; std::string accountStr = KeyUtils::toStrKey(accountID); std::string assetCode; std::string assetIssuer; if (asset.type() == ASSET_TYPE_CREDIT_ALPHANUM4) { assetCodeToStr(asset.alphaNum4().assetCode, assetCode); assetIssuer = KeyUtils::toStrKey(asset.alphaNum4().issuer); } else if (asset.type() == ASSET_TYPE_CREDIT_ALPHANUM12) { assetCodeToStr(asset.alphaNum12().assetCode, assetCode); assetIssuer = KeyUtils::toStrKey(asset.alphaNum12().issuer); } else { throw std::runtime_error("Invalid asset type"); } auto prep = mDatabase.getPreparedStatement(sql); auto& st = prep.statement(); st.exchange(soci::use(accountStr, "acc")); st.exchange(soci::use(assetCode, "code")); st.exchange(soci::use(assetIssuer, "iss")); std::vector<LedgerEntry> offers; { auto timer = mDatabase.getSelectTimer("offer"); offers = loadOffers(prep); } return offers; }
Seq<CaseClause*>* Parser::caseElements() { SeqBuilder<CaseClause*> cases(allocator); bool hasDefault = false; CaseClause* last = NULL; for (;;) { switch (hd ()) { case T_RightBrace: return cases.get(); case T_Default: { if (hd2() != T_Colon) goto just_a_statement; // default xml namespace eat(T_Default); eat(T_Colon); if (hasDefault) compiler->syntaxError(position(), SYNTAXERR_DUPLICATE_DEFAULT); hasDefault = true; cases.addAtEnd(last = ALLOC(CaseClause, (0, NULL))); break; } case T_Case: { eat(T_Case); uint32_t pos = position(); Expr* expr = commaExpression(0); eat(T_Colon); cases.addAtEnd(last = ALLOC(CaseClause, (pos, expr))); } /*FALLTHROUGH*/ just_a_statement: default: { if (last == NULL) compiler->syntaxError(position(), SYNTAXERR_EXPECT_CASE_OR_DEFAULT); AvmAssert(last->stmts == NULL); SeqBuilder<Stmt*> stmts(allocator); while (hd() != T_RightBrace && hd() != T_Case && hd() != T_Default) stmts.addAtEnd(statement()); last->stmts = stmts.get(); break; } } } }
static ksp_tree_t* factor(ksp_parser_t* parser) { ksp_lexer_t* lexer = parser->lexer; ksp_word_t* w = ksp_word_look(lexer); ksp_tag_t tag = w->tag; if (tag == TAG_ID) { ksp_word_t* wi = ksp_word_next(lexer); w = ksp_word_look(lexer); if (w->tag == TAG_RBL) { ksp_tree_t* t = tree_new3(parser, FUNC_CALL, wi); tree_set_left(t, call_args(parser)); w = ksp_word_look(lexer); if (w->tag == TAG_COLON) { ksp_word_next(lexer); } return t; } else if (w->tag == TAG_SBL) { ksp_word_next(lexer); ksp_tree_t* t = tree_new3(parser, ARR_AC, wi); tree_set_left(t, expr(parser)); ksp_word_next_tag(lexer,TAG_SBR); return t; } else { ksp_tree_t* t = tree_new3(parser, VAR, wi); return t; } } else if (tag == TAG_RBL) { ksp_word_next(lexer); ksp_tree_t* t = tree_new(parser, BRACKET); tree_set_left(t,statement(parser)); ksp_word_next_tag(lexer,TAG_RBR); return t; } else if (tag == TAG_NUMBER) { ksp_tree_t* t = tree_new3(parser, NUMBER, w); ksp_word_next(lexer); return t; } else { return K_NULL; } }
void program() { level++; trace("program"); while (current.token != done) { if (current.token == iconst) { match(iconst); match(colon); } statement(); another_statement(); match(nline); dumpword(); } level--; }
shared_ptr<IDbStatement> Connection::_prepare(const String &sql) { //RealtimeStatsScopeTimer RSS(_S("Debug"), _S("Sqlite - Connection::prepare")); //OS_LOG_WARNING(sql); #ifdef OS_ENABLE_DATABASE_ANALYZE RealtimeStatsScopeTimer RSS(_S("Debug"), _S("Sqlite - ") + preAnalyze(sql)); #endif shared_ptr<Statement> statement(OS_NEW Statement(m_cs)); statement->prepare(m_connection, sql); #ifdef OS_ENABLE_DATABASE_ANALYZE postAnalyze(sql); #endif return statement; }
bool parserCls::block(EinstructionWord &ews12 , int & ii18 ) {EinstructionWord est;bool etlnoc , bb1 = true ;int ii12 = 0 ; for(;;){ statement(etlnoc , est) ;// return can addLine ; if(etlnoc == false ) bb1 = false ; if(errorReportCls::unrecoverAbleError) {out1<<"unrecover able error occurred "<<"\n";bb1=false;break;} if((est==EndOfFileInstr)||(est==LabelInstr)||(est==NoInstr)) break; if(++ii12 >=MAX_LINE_IN_PROCEDURE ) {bb1 = false ;est = EndOfFileInstr;blockError(0) ;break;} } if(bb1) if(!ii12) blockError(1); else if(est==LabelInstr) bb1=getLabel(); ews12 = est ; ii18 = ii12+2 ;addEndLineToProc(); return bb1 ; }
/** * "while" statement */ dowhile() { loop_t loop; loop.symbol_idx = local_table_index; loop.stack_pointer = stkp; loop.type = WSWHILE; loop.test_label = getlabel (); loop.exit_label = getlabel (); addloop (&loop); generate_label (loop.test_label); test (loop.exit_label, FALSE); statement (NO); gen_jump (loop.test_label); generate_label (loop.exit_label); local_table_index = loop.symbol_idx; stkp = gen_modify_stack (loop.stack_pointer); delloop (); }
/** * "while" statement */ void dowhile(void) { WHILE ws; ws.symbol_idx = local_table_index; ws.stack_pointer = stkp; ws.type = WSWHILE; ws.case_test = getlabel (); ws.while_exit = getlabel (); addwhile (&ws); generate_label (ws.case_test); test (ws.while_exit, FALSE); statement (NO); gen_jump (ws.case_test); generate_label (ws.while_exit); local_table_index = ws.symbol_idx; stkp = gen_modify_stack (ws.stack_pointer); delwhile (); }
void block(int is_func) /* {}内の処理 */ { TknKind kd = Others; token = nextTkn(); ++blkNest; if (is_func) { /* 関数ブロックなら変数宣言処理 */ while (token.kind == Int) { set_type(); set_name(); varDecl(); } } while (token.kind != '}') { /* 文を処理 */ kd = token.kind; statement(); } last_statement = kd; /* 関数末尾のreturn有無確認に用いる */ --blkNest; token = nextTkn(); }
NodePointer Parser::getNextParseTree() { if (!currentParseTree_) { getNextSymbol(); } if (currentSymbol_.symbolType_ != END) { currentParseTree_ = statement(); } else { currentParseTree_ = NodePointer(); } return currentParseTree_; }