size_t Sqlite3_Database::row_count(const std::string& table_name) { auto stmt = new_statement("select count(*) from " + table_name); if(stmt->step()) return stmt->get_size_t(0); else throw SQL_DB_Error("Querying size of table " + table_name + " failed"); }
PraghaPreparedStatement * pragha_database_create_statement (PraghaDatabase *database, const gchar *sql) { PraghaDatabasePrivate *priv = database->priv; PraghaPreparedStatement *cached = g_hash_table_lookup (priv->statements_cache, sql); if (cached) { g_hash_table_steal (priv->statements_cache, sql); return cached; } return new_statement (database, sql); }
Statement* push_funcall(const char* funname, ArgArray args) { Function* curf = cur_func(); Statement* statm = new_statement(funname, args); // set all labels and pop while(curlabels != llist_empty) { llist_head(curlabels)->statm = statm; curlabels = llist_tail(curlabels); } // register array_push(curf->statms, Statement*, statm); return statm; }
void parser_push(const context_t *ctx, const line_t *line) { position_t *pos = line->position; // is the first block already set? if (p->blk == NULL) { p->blk = block_init(NULL, pos); } statement_t *stmt = new_statement(ctx); const operation_t *op = NULL; const char *name = NULL; label_t *label = NULL; // allow the tokenizer to fold comma into ",x" etc addressing mode tokens int allow_index = 0; // tokenize the line pstate_t state = P_INIT; tokenizer_t *tok = tokenizer_init(line->line); while (tokenizer_next(tok, allow_index)) { switch(state) { case P_OP: if (tok->type == T_TOKEN && tok->vals.op == OP_COLON) { // accept after label // continue to next stmt->type = S_LABEQPC; statement_push(stmt); stmt = new_statement(ctx); state = P_INIT; break; } if (tok->type == T_TOKEN && tok->vals.op == OP_ASSIGN) { // after label, that's a label value definition stmt->type = S_LABDEF; // next define the label from param state = P_PARAM; break; } // fall-through! case P_INIT: switch(tok->type) { case T_NAME: name = mem_alloc_strn(tok->line + tok->ptr, tok->len); op = operation_find(name); if (op != NULL) { // check if the operation is compatible with the current CPU if (0 == (ctx->cpu->isa & op->isa)) { // TODO: config for either no message or error warn_operation_not_for_cpu(pos, name, ctx->cpu->name); op = NULL; } } if (op == NULL) { // label // TODO: redefinition? label = label_init(ctx, name, pos); if (state == P_OP) { // we already had a label stmt->type = S_LABEQPC; statement_push(stmt); stmt = new_statement(ctx); } stmt->label = label; // expect operation next (but accept labels too) state = P_OP; } else { // operation stmt->op = op; state = P_PARAM; } break; default: // syntax error error_syntax(pos); goto end; break; } break; case P_PARAM: // parse parameters arith_parse(tok, allow_index, &stmt->param); break; default: error_syntax(pos); goto end; break; }; } statement_push(stmt); end: tokenizer_free(tok); }