/** execute_IF Executes if statements. * * if(<boolean expression>) * <statement>; * else if (<boolean expression>) * <statement>; * else * <statement>; * * @param p_function_id : routine ID this statement is apart of. */ void cx_executor::execute_IF(cx_symtab_node * p_function_id) { // if get_token(); // get the location of where to go to if <expr> is false. int at_false = get_location_marker(); get_token(); // ( //get_token(); execute_expression(); bool condition = top()->basic_types.bool__; // ) //get_token(); if (condition) { // True: { or single statement execute_statement(p_function_id); while (token == tc_semicolon)get_token(); // If there is an ELSE part, jump around it. if (token == tc_ELSE) { get_token(); go_to(get_location_marker()); get_token(); // token following the IF statement } } else { // False: Go to the false location. go_to(at_false); get_token(); if (token == tc_ELSE) { // ELSE <stmt-2> get_token(); get_location_marker(); // skip over location marker // { or single statement get_token(); execute_statement(p_function_id); while (token == tc_semicolon)get_token(); } } }
/** execute_statement_list Execute a list or compounded * statements until a terminator token * is reached. * * @param p_function_id : ptr to the routine symtab node * @param terminator : token to terminate compound execution. */ void cx_executor::execute_statement_list(cx_symtab_node *p_function_id, cx_token_code terminator) { do { execute_statement(p_function_id); while (token == tc_semicolon) get_token(); } while ((token != terminator) && (token != tc_dummy) && (!break_loop)); }
size_t connection::last_insert_id(){ std::string statement; switch(_handle->type){ case ODBC_Type::MySQL: statement = "SELECT LAST_INSERT_ID()"; break; case ODBC_Type::TSQL: statement = "SELECT SCOPE_IDENTITY"; break; case ODBC_Type::SQLite3: statement = "SELECT last_insert_rowid()"; break; case ODBC_Type::PostgreSQL: statement = "SELECT LASTVAL()"; break; default: throw sqlpp::exception("Can't get last insert id for ODBC_Type "+std::to_string(static_cast<int>(_handle->type))); } auto prepared_statement = prepare_statement(*_handle, statement); execute_statement(prepared_statement->stmt); int64_t ret; bool is_null; bind_result_t result(prepared_statement); if(!result.next_impl()){ std::cerr << "ODBC warning: next_impl failed!" << std::endl; return 0; } result._bind_integral_result(0, &ret, &is_null); if(is_null) { std::cerr << "ODBC warning: NULL returned from " << statement << std::endl; return 0; } return ret; }
size_t connection::insert_impl(const std::string& statement) { auto prepared = prepare_statement(*_handle, statement); execute_statement(*_handle, prepared); return sqlite3_last_insert_rowid(_handle->sqlite); }
// returns: 1 if everything was fine, 0 if error int lpg_finish_log(struct logger_t* logger) { // set timestamp of logging end char set_ending_timestamp[1000] = "update malwaresamples set endlogging = (select current_timestamp) where id = (select t.value from trumanbox_settings t where t. key = 'CURRENT_SAMPLE')"; if (!execute_statement(set_ending_timestamp)) return 0; return 1; }
bind_result_t connection::select_impl(const std::string& statement) { auto prepared = prepare_statement(*_handle, statement); if(!prepared || !*prepared) { throw sqlpp::exception("ODBC error: Could not store result set"); } execute_statement(prepared->stmt); return bind_result_t(prepared); }
void DBFacade::execute_statement(SqlStatement const * stmt) { switch (stmt->get_type()) { case SELECT: execute_statement((SelectStatement const *) stmt); break; case INSERT: execute_statement((InsertStatement const *) stmt); break; case CREATE_TABLE: execute_statement((CreateTableStatement const *) stmt); break; case CREATE_INDEX: execute_statement((CreateIndexStatement const *) stmt); break; case UPDATE: execute_statement((UpdateStatement const *) stmt); break; case DELETE: execute_statement((DeleteStatement const *) stmt); break; case DROP: execute_statement((DropStatement const *) stmt); break; case UNKNOWN: Utils::warning("[DBF] Given statement is unknown"); break; } }
/** execute_FOR Executes for statement. * initialize condition increment * for(<statement>; <expression>; <expression>) * <statement>; * * @param p_function_id */ void cx_executor::execute_FOR(cx_symtab_node * p_function_id) { bool condition = false; get_token(); // for // get the location of where to go to if <expr> is false. int break_point = get_location_marker(); get_token(); int statement_location = get_location_marker(); get_token(); int condition_marker = get_location_marker(); get_token(); int increment_marker = get_location_marker(); get_token(); // ( get_token(); if (token != tc_semicolon) { // declaration would go here // execute_assignment(p_node); } do { get_token(); // ; if (token != tc_semicolon) { // expr 2 execute_expression(); get_token(); // ; } else get_token(); condition = top()->basic_types.bool__; pop(); if (condition) { go_to(statement_location); get_token(); execute_statement(p_function_id); if (break_loop) go_to(break_point); } else { go_to(break_point); get_token(); break; } go_to(increment_marker); get_token(); // expr 3 execute_expression(); go_to(condition_marker); } while (current_location() == condition_marker); break_loop = false; }
void postsolve_model(MPL *mpl) { STATEMENT *stmt; xassert(!mpl->flag_p); mpl->flag_p = 1; for (stmt = mpl->stmt; stmt != NULL; stmt = stmt->next) execute_statement(mpl, stmt); mpl->stmt = NULL; return; }
void connection::start_transaction() { if (_transaction_active) { throw sqlpp::exception("MySQL: Cannot have more than one open transaction per connection"); } execute_statement(*_handle, "START TRANSACTION"); _transaction_active = true; }
void connection::commit_transaction() { if (not _transaction_active) { throw sqlpp::exception("MySQL: Cannot commit a finished or failed transaction"); } _transaction_active = false; execute_statement(*_handle, "COMMIT"); }
void generate_model(MPL *mpl) { STATEMENT *stmt; xassert(!mpl->flag_p); for (stmt = mpl->model; stmt != NULL; stmt = stmt->next) { execute_statement(mpl, stmt); if (mpl->stmt->type == A_SOLVE) break; } mpl->stmt = stmt; return; }
void connection::commit_transaction() { if (not _transaction_active) { throw sqlpp::exception("Sqlite3 error: Cannot commit a finished or failed transaction"); } _transaction_active = false; auto prepared = prepare_statement(*_handle, "COMMIT"); execute_statement(*_handle, prepared); }
void connection::start_transaction() { if (_transaction_active) { throw sqlpp::exception("Sqlite3 error: Cannot have more than one open transaction per connection"); } auto prepared = prepare_statement(*_handle, "BEGIN"); execute_statement(*_handle, prepared); _transaction_active = true; }
char_result_t connection::select_impl(const std::string& statement) { execute_statement(*_handle, statement); std::unique_ptr<detail::result_handle> result_handle(new detail::result_handle(mysql_store_result(_handle->mysql.get()), _handle->config->debug)); if (!result_handle) { throw sqlpp::exception("MySQL error: Could not store result set: " + std::string(mysql_error(_handle->mysql.get()))); } return {std::move(result_handle)}; }
void connection::rollback_transaction(bool report) { if (not _transaction_active) { throw sqlpp::exception("MySQL: Cannot rollback a finished or failed transaction"); } if (report) { std::cerr << "MySQL warning: Rolling back unfinished transaction" << std::endl; } _transaction_active = false; execute_statement(*_handle, "ROLLBACK"); }
// returns: 1 if creation was successful, 0 if not int lpg_create_log(struct logger_t* logger) { const char* testmode = conf_get(logger->config, "logging", "testmode"); if (strcmp(testmode,"0") == 0) { char update_trumanbox_runtime_id[1000] = "update trumanbox_settings set value = value+1 where key = 'CURRENT_SAMPLE'"; if (!execute_statement(update_trumanbox_runtime_id)) return 0; //char set_current_id[1000] = "update trumanbox_settings set value = (select t.value from trumanbox_settings t where t.key = 'SAMPLE_COUNTER') where key = 'CURRENT_SAMPLE'"; //if (!execute_statement(set_current_id)) // return 0; char new_malware_dataset[1000] = "insert into malwaresamples (id,beginlogging) values ((select t.value from trumanbox_settings t where t.key = 'CURRENT_SAMPLE'), (select current_timestamp))"; if (!execute_statement(new_malware_dataset)) return 0; } else { char set_current_id[1000] = "update trumanbox_settings set value = -1 where key = 'CURRENT_SAMPLE'"; if(!execute_statement(set_current_id)) return 0; } return 1; // by default, all tables are already created }
StatementResult crb_execute_statement_list(CRB_Interpreter *inter, CRB_LocalEnvironment *env, StatementList *list) { StatementList *pos; StatementResult result; result.type = NORMAL_STATEMENT_RESULT; for (pos = list; pos; pos = pos->next) { result = execute_statement(inter, env, pos->statement); if (result.type != NORMAL_STATEMENT_RESULT) goto FUNC_END; } FUNC_END: return result; }
int SQLite3DB::return_one_int(const char *str) { char *error=NULL; int cols=0; int affected_rows=0; int ret=0; SQLite3_result *resultset=NULL; execute_statement(str, &error , &cols , &affected_rows , &resultset); if (error) { proxy_error("Error on %s : %s\n", str, error); free(error); } else { for (std::vector<SQLite3_row *>::iterator it = resultset->rows.begin() ; it != resultset->rows.end(); ++it) { SQLite3_row *r=*it; ret=atoi(r->fields[0]); break; } } if (resultset) delete resultset; return ret; }
Instruction* ReturnInstruction::execute(ExecutionThread *executor, bool *wait) { Q_UNUSED(wait); Q_UNUSED(executor); setRunning(true); if (m_valid && statement) { ProgramVariables *vars = scheme()->variables(); drzewo_skladn *t = statement->syntacticTree(); if (t) { result = execute_statement(this, t, vars); scheme()->setFunctionReturnValue(result); qDebug() << "return value=" << result.toString(); } } setRunning(false); return nextInstruction(); }
size_t connection::run_prepared_remove_impl(prepared_statement_t& prepared_statement) { execute_statement(prepared_statement.native_handle()); return odbc_affected(prepared_statement.native_handle()); }
size_t connection::run_prepared_insert_impl(prepared_statement_t& prepared_statement) { execute_statement(*_handle, *prepared_statement._handle.get()); return sqlite3_last_insert_rowid(_handle->sqlite); }
size_t connection::remove_impl(const std::string& statement) { execute_statement(*_handle, statement); return mysql_affected_rows(_handle->mysql.get()); }
void connection::execute(const std::string& command) { execute_statement(*_handle, command); }
size_t connection::insert_impl(const std::string& statement) { execute_statement(*_handle, statement); return mysql_insert_id(_handle->mysql.get()); }
size_t connection::remove_impl(const std::string& statement) { auto prepared = prepare_statement(*_handle, statement); execute_statement(*_handle, prepared); return sqlite3_changes(_handle->sqlite); }
size_t connection::run_prepared_remove_impl(prepared_statement_t& prepared_statement) { execute_statement(*_handle, *prepared_statement._handle.get()); return sqlite3_changes(_handle->sqlite); }
size_t connection::insert_impl(const std::string& statement) { auto prepared = prepare_statement(*_handle, statement); execute_statement(prepared->stmt); return last_insert_id(); }
size_t connection::run_prepared_insert_impl(prepared_statement_t& prepared_statement) { execute_statement(prepared_statement.native_handle()); return last_insert_id(); }
size_t connection::remove_impl(const std::string& statement) { auto prepared = prepare_statement(*_handle, statement); execute_statement(prepared->stmt); return odbc_affected(prepared->stmt); }