int database::add_device_channel(int DeviceID, int ChannelNumber, int Type, int Func, int FList, int UserID, bool *new_channel) { MYSQL_BIND pbind[6]; memset(pbind, 0, sizeof(pbind)); pbind[0].buffer_type = MYSQL_TYPE_LONG; pbind[0].buffer = (char *)&Type; pbind[1].buffer_type = MYSQL_TYPE_LONG; pbind[1].buffer = (char *)&Func; pbind[2].buffer_type = MYSQL_TYPE_LONG; pbind[2].buffer = (char *)&UserID; pbind[3].buffer_type = MYSQL_TYPE_LONG; pbind[3].buffer = (char *)&ChannelNumber; pbind[4].buffer_type = MYSQL_TYPE_LONG; pbind[4].buffer = (char *)&DeviceID; pbind[5].buffer_type = MYSQL_TYPE_LONG; pbind[5].buffer = (char *)&FList; { const char sql[] = "INSERT INTO `supla_dev_channel` (`type`, `func`, `param1`, `param2`, " "`param3`, `user_id`, `channel_number`, `iodevice_id`, `flist`) VALUES " "(?,?,0,0,0,?,?,?,?)"; MYSQL_STMT *stmt; if (!stmt_execute((void **)&stmt, sql, pbind, 6, false)) { mysql_stmt_close(stmt); return 0; } else if (new_channel) { *new_channel = true; } if (stmt != NULL) mysql_stmt_close(stmt); } return get_device_channel(DeviceID, ChannelNumber, NULL); }
if_status_t IF_db_disconnect () { if ( stmtInsertRecord != NULL ) { mysql_stmt_close(stmtInsertRecord); stmtInsertRecord = NULL; } mysql_close(&mysql); return ( IF_OK ); }
static void config_reset(struct config *conf) { size_t i; for (i = 0; i < SQL_MAX; i++) if (conf->statements[i]) { mysql_stmt_close(conf->statements[i]); conf->statements[i] = NULL; } if (conf->stmt_fetch_source) { mysql_stmt_close(conf->stmt_fetch_source); conf->stmt_fetch_source = NULL; } if (conf->db) { mysql_close(conf->db); conf->db = NULL; } }
static int test_bug11111(MYSQL *mysql) { MYSQL_STMT *stmt; MYSQL_BIND my_bind[2]; char buf[2][20]; ulong len[2]; int i; int rc; const char *query= "SELECT DISTINCT f1,ff2 FROM v1"; rc= mysql_query(mysql, "drop table if exists t1, t2, v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "drop view if exists t1, t2, v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t1 (f1 int, f2 int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t2 (ff1 int, ff2 int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create view v1 as select * from t1, t2 where f1=ff1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "insert into t1 values (1,1), (2,2), (3,3)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "insert into t2 values (1,1), (2,2), (3,3)"); check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); memset(my_bind, '\0', sizeof(my_bind)); for (i=0; i < 2; i++) { my_bind[i].buffer_type= MYSQL_TYPE_STRING; my_bind[i].buffer= (uchar* *)&buf[i]; my_bind[i].buffer_length= 20; my_bind[i].length= &len[i]; } rc= mysql_stmt_bind_result(stmt, my_bind); check_stmt_rc(rc, stmt); rc= mysql_stmt_fetch(stmt); check_stmt_rc(rc, stmt); FAIL_UNLESS(!strcmp(buf[1],"1"), "buf[1] != '1'"); mysql_stmt_close(stmt); rc= mysql_query(mysql, "drop view v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "drop table t1, t2"); check_mysql_rc(rc, mysql); return OK; }
int TreeViewCategories_CategoryRenameAddToDatabase(TreeViewCategories* c, gchar* row_cat_name, unsigned int row_id) { MYSQL_STMT* stmt = NULL; MYSQL_BIND param_update[2]; char* stmt_update_str = "UPDATE categories SET name = ? WHERE id = ?;\n"; unsigned int ret = 1; unsigned long row_cat_name_strlen; stmt = mysql_stmt_init(c->MySQL); if (stmt == NULL) { fprintf(stderr, "%s(): mysql_stmt_init() error.\n", __func__); ret = 0; goto END; } if (mysql_stmt_prepare(stmt, stmt_update_str, strlen(stmt_update_str))) { fprintf(stderr, "%s(): mysql_stmt_prepare() error.\n", __func__); ret = 0; goto END; } memset(param_update, 0, sizeof(param_update)); row_cat_name_strlen = strlen(row_cat_name); param_update[0].buffer_type = MYSQL_TYPE_VAR_STRING; param_update[0].buffer = (void*) row_cat_name; param_update[0].buffer_length = row_cat_name_strlen + 1; param_update[0].length = &row_cat_name_strlen; param_update[1].buffer_type = MYSQL_TYPE_LONG; param_update[1].buffer = (void*) &row_id; param_update[1].is_unsigned = 1; if (mysql_stmt_bind_param(stmt, param_update)) { fprintf(stderr, "%s(): mysql_stmt_bind_param() error.\n", __func__); ret = 0; goto END; } if (mysql_stmt_execute(stmt)) { fprintf(stderr, "%s(): mysql_stmt_execute() error.\n", __func__); ret = 0; goto END; } END: if (stmt != NULL) mysql_stmt_close(stmt); return ret; }
static bool my_sharelog(struct server_auxchain *aux, const char *rem_host, const char *username, const char *our_result, const char *upstream_result, const char *reason, const char *solution) { MYSQL *db = srv.db_cxn; MYSQL_STMT *stmt; MYSQL_BIND bind_param[6]; unsigned long bind_lengths[6]; bool rc = false; const char *step = "init"; const char *stmt_sharelog = aux ? aux->db_stmt_auxsharelog : srv.db_stmt_sharelog; if(!stmt_sharelog) { applog(LOG_ERR, "mysql sharelog failed due to missing statement"); return false; } stmt = mysql_stmt_init(db); if (!stmt) return false; memset(bind_param, 0, sizeof(bind_param)); memset(bind_lengths, 0, sizeof(bind_lengths)); bind_instr(bind_param, bind_lengths, 0, rem_host); bind_instr(bind_param, bind_lengths, 1, username); bind_instr(bind_param, bind_lengths, 2, our_result); bind_instr(bind_param, bind_lengths, 3, upstream_result); bind_instr(bind_param, bind_lengths, 4, reason); bind_instr(bind_param, bind_lengths, 5, solution); step = "prep"; if (mysql_stmt_prepare(stmt, stmt_sharelog, strlen(stmt_sharelog))) goto err_out; step = "bind-param"; if (mysql_stmt_bind_param(stmt, bind_param)) goto err_out; step = "execute"; if (mysql_stmt_execute(stmt)) goto err_out; rc = true; out: mysql_stmt_close(stmt); return rc; err_out: applog(LOG_ERR, "mysql sharelog failed at %s", step); goto out; }
MySQLPreparedStatement::~MySQLPreparedStatement() { ClearParameters(); if (m_Mstmt->bind_result_done) { delete[] m_Mstmt->bind->length; delete[] m_Mstmt->bind->is_null; } mysql_stmt_close(m_Mstmt); delete[] m_bind; }
void FormAccounts_ButtonAccountAddClicked(GtkButton* button, FormAccounts* fa) { MYSQL_STMT* stmt = NULL; MYSQL_BIND param_insert[1]; gchar* Text = NULL; unsigned long TextStrLength; const char* mysql_stmt_str = "INSERT INTO accounts(name) VALUES (?);"; gtk_input_dialog("Создать новый счёт", "Введите наименование нового счёта.", "", &Text); if (Text) { g_print("%s(): создать счёт '%s'\n", __func__, Text); stmt = mysql_stmt_init(fa->MySQL); if (stmt == NULL) { g_print("%s(): mysql_stmt_init() error.\n", __func__); goto END; } if (mysql_stmt_prepare(stmt, mysql_stmt_str, strlen(mysql_stmt_str))) { g_print("%s(): mysql_stmt_prepare() error.\n", __func__); goto END; } TextStrLength = strlen(Text); memset(param_insert, 0, sizeof(param_insert)); param_insert[0].buffer_type = MYSQL_TYPE_VAR_STRING; param_insert[0].buffer = (void*) Text; param_insert[0].buffer_length = TextStrLength + 1; param_insert[0].length = &TextStrLength; if (mysql_stmt_bind_param(stmt, param_insert)) { g_print("%s(): mysql_stmt_bind() error.\n", __func__); goto END; } if (mysql_stmt_execute(stmt)) { g_print("%s(): mysql_stmt_bind() error.\n", __func__); goto END; } FormAccounts_UpdateData(fa); } END: if (Text) g_free(Text); if (stmt) mysql_stmt_close(stmt); }
void wb_dbms_query::error(const char *method, const char *func) { char s[200]; if (m_stmt) mysql_stmt_close(m_stmt); m_stmt = 0; m_prepared = false; sprintf(s, "*** query \"%s\" %s %s %s\n", m_query, method, func, mysql_error(m_db->con())); throw wb_dbms_error(m_db, s); }
static MYSQL_STMT *STDCALL mysql_simple_prepare(MYSQL *mysql_arg, const char *query) { MYSQL_STMT *stmt= mysql_stmt_init(mysql_arg); if (stmt && mysql_stmt_prepare(stmt, query, (ulong)strlen(query))) { mysql_stmt_close(stmt); return 0; } return stmt; }
bool wxMySQLRecordset::Close() { printf("MYSQL_STMT_CLOSE\r\n"); bool res = (m_Stmt == NULL ? true : !mysql_stmt_close(m_Stmt)); m_Stmt = NULL; if(m_ColDefs) { delete [] m_ColDefs; m_ColDefs = NULL; } return res; }
int MySQLService::ExcuteBinary(const char *cmd, SQLParam *param) { MYSQL_BIND *bind = 0; int err = 0; MYSQL_STMT *stmt; do { stmt = mysql_stmt_init(_connection); if(!stmt) break; if(mysql_stmt_prepare(stmt, cmd, strlen(cmd))) { err = mysql_errno(_connection); break; } uint32 count = mysql_stmt_param_count(stmt); bind = new MYSQL_BIND[count]; memset(bind, 0, sizeof(bind) * count); for(uint32 i = 0; i < count; i++) { bind[i].buffer = param[i].data; bind[i].buffer_type = MYSQL_TYPE_BLOB; bind[i].length= 0; bind[i].buffer_length = param[i].length; bind[i].is_null= 0; if (mysql_stmt_bind_param(stmt, bind)) { err = mysql_errno(_connection); break; } } if(!err) { if(mysql_stmt_execute(stmt)) { err = mysql_errno(_connection); } } }while(0); if(stmt) mysql_stmt_close(stmt); delete [] bind; return err; }
int test_sp_reset(MYSQL *mysql) { int i, rc; MYSQL_STMT *stmt; int a[] = {10,20,30}; MYSQL_BIND bind[3]; char *stmtstr= "CALL P1(?,?,?)"; rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19), IN p_in INT, INOUT p_inout INT)" "BEGIN " " SET p_in = 300, p_out := 'This is OUT param', p_inout = 200; " " SELECT p_inout, p_in, substring(p_out, 9);" "END"); check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); check_mysql_rc(rc, mysql); rc= mysql_stmt_prepare(stmt, stmtstr, strlen(stmtstr)); check_stmt_rc(rc, stmt); FAIL_IF(mysql_stmt_param_count(stmt) != 3, "expected param_count=3"); memset(bind, 0, sizeof(MYSQL_BIND) * 3); for (i=0; i < 3; i++) { bind[i].buffer= &a[i]; bind[i].buffer_type= MYSQL_TYPE_LONG; } bind[0].buffer_type= MYSQL_TYPE_NULL; rc= mysql_stmt_bind_param(stmt, bind); check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); rc= mysql_stmt_fetch(stmt); check_stmt_rc(rc, stmt); rc= mysql_stmt_reset(stmt); check_stmt_rc(rc, stmt); /*connection shouldn't be blocked now */ rc= mysql_query(mysql, "DROP PROCEDURE p1"); check_mysql_rc(rc, mysql); rc= mysql_stmt_close(stmt); return OK; }
MySqlResultReader::~MySqlResultReader() { FreeFieldBuffers(); if (resultMetadata != NULL) { mysql_free_result(resultMetadata); } if (stmt != NULL) { mysql_stmt_close(stmt); } if (connection != NULL) { mysql_close(connection); } }
unsigned int GetMultiStatements(MADB_Stmt *Stmt, BOOL ExecDirect) { int i= 0; unsigned int MaxParams= 0; char *p= Stmt->Query.RefinedText; Stmt->MultiStmtNr= 0; Stmt->MultiStmts= (MYSQL_STMT **)MADB_CALLOC(sizeof(MYSQL_STMT) * STMT_COUNT(Stmt->Query)); while (p < Stmt->Query.RefinedText + Stmt->Query.RefinedLength) { Stmt->MultiStmts[i]= i == 0 ? Stmt->stmt : MADB_NewStmtHandle(Stmt); MDBUG_C_PRINT(Stmt->Connection, "-->inited&preparing %0x(%d,%s)", Stmt->MultiStmts[i], i, p); if (mysql_stmt_prepare(Stmt->MultiStmts[i], p, (unsigned long)strlen(p))) { MADB_SetNativeError(&Stmt->Error, SQL_HANDLE_STMT, Stmt->MultiStmts[i]); CloseMultiStatements(Stmt); /* Last paranoid attempt make sure that we did not have a parsing error. More to preserve "backward-compatimility" - we did this before, but before trying to prepare "multi-statement". */ if (i == 0 && Stmt->Error.NativeError !=1295 /*ER_UNSUPPORTED_PS*/) { Stmt->stmt= MADB_NewStmtHandle(Stmt); if (mysql_stmt_prepare(Stmt->stmt, STMT_STRING(Stmt), (unsigned long)strlen(STMT_STRING(Stmt)))) { mysql_stmt_close(Stmt->stmt); Stmt->stmt= NULL; } else { MADB_DeleteSubqueries(&Stmt->Query); return 0; } } return 1; } if (mysql_stmt_param_count(Stmt->MultiStmts[i]) > MaxParams) { MaxParams= mysql_stmt_param_count(Stmt->MultiStmts[i]); } p+= strlen(p) + 1; ++i; } if (MaxParams) { Stmt->params= (MYSQL_BIND *)MADB_CALLOC(sizeof(MYSQL_BIND) * MaxParams); } return 0; }
void lmt_db_destroy (lmt_db_t db) { assert (db->magic == LMT_DBHANDLE_MAGIC); if (db->name) free (db->name); if (db->ins_timestamp_info) mysql_stmt_close (db->ins_timestamp_info); if (db->ins_mds_data) mysql_stmt_close (db->ins_mds_data); if (db->ins_mds_ops_data) mysql_stmt_close (db->ins_mds_ops_data); if (db->ins_oss_data) mysql_stmt_close (db->ins_oss_data); if (db->ins_ost_data) mysql_stmt_close (db->ins_ost_data); if (db->ins_router_data) mysql_stmt_close (db->ins_router_data); if (db->idhash) hash_destroy (db->idhash); if (db->conn) mysql_close (db->conn); db->magic = 0; free (db); }
/* * connect to the database and do initial setup */ static int netsnmp_mysql_connect(void) { char trap_stmt[] = "INSERT INTO notifications " "(date_time, host, auth, type, version, request_id, snmpTrapOID, transport, security_model, v3msgid, v3security_level, v3context_name, v3context_engine, v3security_name, v3security_engine) " "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; char vb_stmt[] = "INSERT INTO varbinds " "(trap_id, oid, type, value) VALUES (?,?,?,?)"; /** initialize connection handler */ if (_sql.connected) return 0; DEBUGMSGTL(("sql:connection","connecting\n")); /** connect to server */ if (mysql_real_connect (_sql.conn, _sql.host_name, _sql.user_name, _sql.password, _sql.db_name, _sql.port_num, _sql.socket_name, _sql.flags) == NULL) { netsnmp_sql_error("mysql_real_connect() failed"); goto err; } _sql.connected = 1; /** disable autocommit */ if(0 != mysql_autocommit(_sql.conn, 0)) { netsnmp_sql_error("mysql_autocommit(0) failed"); goto err; } netsnmp_assert((_sql.trap_stmt == NULL) && (_sql.vb_stmt == NULL)); /** prepared statement for inserts */ if (0 != netsnmp_mysql_bind(trap_stmt,sizeof(trap_stmt), &_sql.trap_stmt, _tbind)) goto err; if (0 != netsnmp_mysql_bind(vb_stmt,sizeof(vb_stmt),&_sql.vb_stmt, _vbind)) { mysql_stmt_close(_sql.trap_stmt); _sql.trap_stmt = NULL; goto err; } return 0; err: if (_sql.connected) _sql.connected = 0; return -1; }
/** * prepare_stmt - Initialize and prepare a query statement. * @handle: connected handle * @query: query statement string to execute * @bind_parm: values for unbound variables (parameters) in @query * @nparams: length of @bind_parms * @bind_col: typed array to contain the column results * ==> non-NULL 'is_null'/'error' fields are taken to mean * that NULL values/errors are not acceptable * @ncols: number of expected columns (length of @bind_col) * Return prepared statement handle on success, NULL on error. */ MYSQL_STMT *prepare_stmt(MYSQL *handle, const char *query, MYSQL_BIND bind_parm[], unsigned long nparams, MYSQL_BIND bind_col[], unsigned long ncols) { MYSQL_STMT *stmt; unsigned long param_count; if (query == NULL || *query == '\0') return NULL; /* Initialize statement (fails only if out of memory). */ stmt = mysql_stmt_init(handle); if (stmt == NULL) { error("can not allocate handle for \"%s\"", query); return NULL; } if (mysql_stmt_prepare(stmt, query, strlen(query))) { error("can not prepare statement \"%s\": %s", query, mysql_stmt_error(stmt)); goto prepare_failed; } /* Verify the parameter count */ param_count = mysql_stmt_param_count(stmt); if (nparams != nparams) { error("expected %lu parameters for \"%s\" but got %lu", nparams, query, param_count); goto prepare_failed; } if (!validate_stmt_column_count(stmt, query, ncols)) goto prepare_failed; if (nparams && mysql_stmt_bind_param(stmt, bind_parm)) { error("can not bind parameter buffers for \"%s\": %s", query, mysql_stmt_error(stmt)); goto prepare_failed; } if (mysql_stmt_bind_result(stmt, bind_col)) { error("can not bind output buffers for \"%s\": %s", query, mysql_stmt_error(stmt)); goto prepare_failed; } return stmt; prepare_failed: (void)mysql_stmt_close(stmt); return NULL; }
static int test_view_star(MYSQL *mysql) { MYSQL_STMT *stmt; int rc, i; MYSQL_BIND my_bind[8]; char parms[8][100]; ulong length[8]; const char *query= "SELECT * FROM vt1 WHERE a IN (?,?)"; rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, vt1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW IF EXISTS t1, vt1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE t1 (a int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE VIEW vt1 AS SELECT a FROM t1"); check_mysql_rc(rc, mysql); memset(my_bind, '\0', sizeof(MYSQL_BIND)); for (i= 0; i < 2; i++) { sprintf((char *)&parms[i], "%d", i); my_bind[i].buffer_type = MYSQL_TYPE_VAR_STRING; my_bind[i].buffer = (char *)&parms[i]; my_bind[i].buffer_length = 100; my_bind[i].is_null = 0; my_bind[i].length = &length[i]; length[i] = 1; } stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); rc= mysql_stmt_bind_param(stmt, my_bind); check_stmt_rc(rc, stmt); for (i= 0; i < 3; i++) { rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); rc= mysql_stmt_fetch(stmt); FAIL_UNLESS(MYSQL_NO_DATA == rc, "Expected 0 rows"); } mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE t1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW vt1"); check_mysql_rc(rc, mysql); return OK; }
void MysqlPreparedStatement_free(T *P) { assert(P && *P); FREE((*P)->bind); mysql_stmt_free_result((*P)->stmt); #if MYSQL_VERSION_ID >= 50503 /* In case the statement returns multiple result sets or in a stored procedure case, think it does, we need to run them down. mysql_stmt_reset does not seem to work here. */ while (mysql_stmt_next_result((*P)->stmt) == 0); #endif mysql_stmt_close((*P)->stmt); FREE((*P)->params); FREE(*P); }
void CMySQLDynamicRecordSet::Destory() { if(m_hStmt) { mysql_stmt_close(m_hStmt); m_hStmt=NULL; } m_pDBConnection=NULL; m_pColumnInfos.Clear(); m_RowBuffer.Clear(); m_IsBOF=true; m_IsEOF=true; }
void database_handler_delete(database_handler_t* handler) { if (handler) { /* Todo: free mysql_config */ if (handler->stmt) { mysql_stmt_close(handler->stmt); mysql_close(&handler->mysql_handler); } SAFE_FREE(handler); } }
void output_mysql_close() { #if HAVE_LIBMYSQLCLIENT if (cfg.mysql_stmt) mysql_stmt_close(cfg.mysql_stmt); if (cfg.mysql_conn) { mysql_close(cfg.mysql_conn); cfg.mysql_conn = NULL; } mysql_library_end(); #endif }
int mysql_drv_close(db_stmt_t *stmt) { #ifdef HAVE_PS if (stmt->ptr == NULL) return 1; DEBUG("mysql_stmt_close(%p)", stmt->ptr); return mysql_stmt_close(stmt->ptr); #else (void)stmt; /* unused */ return 0; #endif }
void stmt_fetch_close(Stmt_fetch *fetch) { unsigned i; DBUG_ENTER("stmt_fetch_close"); for (i= 0; i < fetch->column_count; ++i) free(fetch->out_data[i]); free(fetch->out_data); free(fetch->out_data_length); free(fetch->bind_array); mysql_stmt_close(fetch->handle); DBUG_VOID_RETURN; }
void MysqlResultSet_free(T *R) { assert(R && *R); for (int i = 0; i < (*R)->columnCount; i++) FREE((*R)->columns[i].buffer); mysql_stmt_free_result((*R)->stmt); if ((*R)->keep == false) mysql_stmt_close((*R)->stmt); if ((*R)->meta) mysql_free_result((*R)->meta); FREE((*R)->columns); FREE((*R)->bind); FREE(*R); }
void database::get_client_locations(int ClientID, supla_client_locations *locs) { MYSQL_STMT *stmt; const char sql[] = "SELECT `id`, `caption` FROM `supla_v_client_location` WHERE " "`client_id` = ?"; MYSQL_BIND pbind[1]; memset(pbind, 0, sizeof(pbind)); pbind[0].buffer_type = MYSQL_TYPE_LONG; pbind[0].buffer = (char *)&ClientID; if (stmt_execute((void **)&stmt, sql, pbind, 1, true)) { my_bool is_null[2]; MYSQL_BIND rbind[2]; memset(rbind, 0, sizeof(rbind)); int id; unsigned long size; char caption[401]; // utf8 rbind[0].buffer_type = MYSQL_TYPE_LONG; rbind[0].buffer = (char *)&id; rbind[0].is_null = &is_null[0]; rbind[1].buffer_type = MYSQL_TYPE_STRING; rbind[1].buffer = caption; rbind[1].buffer_length = 401; rbind[1].length = &size; rbind[1].is_null = &is_null[1]; if (mysql_stmt_bind_result(stmt, rbind)) { supla_log(LOG_ERR, "MySQL - stmt bind error - %s", mysql_stmt_error(stmt)); } else { mysql_stmt_store_result(stmt); if (mysql_stmt_num_rows(stmt) > 0) { while (!mysql_stmt_fetch(stmt)) { caption[size] = 0; locs->add_location(id, caption); } } } mysql_stmt_close(stmt); } }
void set_mysql_results(MYSQL_STMT *handle) { int i; /* Clear any old statement handles. */ if (sth) { numrows = 0; mysql_stmt_close(sth); } sth = handle; resultoffset = 0; /* Get result metadata. */ if (results) { mysql_free_result(results); } results = mysql_stmt_result_metadata(sth); if (results == NULL) { return; } /* Buffer results. */ if (r_bind) { for (i = 0; i < numfields; i++) { free(r_bind[i].buffer); free(r_bind[i].is_null); free(r_bind[i].length); free(r_bind[i].error); } free(r_bind); } numfields = mysql_num_fields(results); fields = mysql_fetch_fields(results); r_bind = safe_malloc(numfields * sizeof(MYSQL_BIND)); memset(r_bind, 0, numfields * sizeof(MYSQL_BIND)); for (i = 0; i < numfields; i++) { r_bind[i].buffer_type = fields[i].type; r_bind[i].buffer_length = fields[i].length; r_bind[i].buffer = safe_malloc(fields[i].length); r_bind[i].is_null = safe_malloc(sizeof(*r_bind[i].is_null)); r_bind[i].length = safe_malloc(sizeof(*r_bind[i].length)); r_bind[i].error = safe_malloc(sizeof(*r_bind[i].error)); } mysql_stmt_bind_result(sth, r_bind); mysql_stmt_store_result(sth); numrows = mysql_stmt_num_rows(sth); }
bool CACHE_SESSION::save() { bool ret = false; MYSQL_STMT *stmt; MYSQL_BIND bind[2]; char *query = (char *)("UPDATE cache SET session=? WHERE session_id=?"); char *binbuff; unsigned long binlen; int session_id = this->session_id; MYSQL *mysql = (MYSQL *)epublisher->get_native_conn(); if( (stmt = mysql_stmt_init(mysql)) ) { if( (mysql_stmt_prepare(stmt, query, strlen(query))) == 0 ) { binlen = this->get_binsize(); // get size needed if(binbuff = (char *)EMALLOC(binlen)) { memset(binbuff, 0, binlen); binlen = this->serialize_bin((long *)binbuff); // serialize and get the real size memset(bind, 0, sizeof(bind)); bind[0].buffer_type = MYSQL_TYPE_VAR_STRING; bind[0].buffer = binbuff; bind[0].buffer_length = binlen; bind[0].is_null= 0; bind[0].length= &binlen; bind[1].buffer_type= MYSQL_TYPE_LONG; bind[1].buffer= (char *)&session_id; bind[1].is_null= 0; bind[1].length= 0; if (mysql_stmt_bind_param(stmt, bind) == 0) { if (mysql_stmt_execute(stmt) == 0) { if(mysql_stmt_affected_rows(stmt) == 1) { ret = true; } } } EFREE(binbuff); } } mysql_stmt_close(stmt); } return(ret); }
static int test_bad_union(MYSQL *mysql) { MYSQL_STMT *stmt; int rc; const char *query= "SELECT 1, 2 union SELECT 1"; stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, query, strlen(query)); FAIL_UNLESS(rc && mysql_errno(mysql) == 1222, "Error expected"); mysql_stmt_close(stmt); return OK; }