int DATABASE_SetParameterValue(char *path, dm_hash_t hash, char *instances, char *new_value, unsigned flags)
{
sqlite3_stmt *stmt;
int err;
int result = USP_ERR_INTERNAL_ERROR; // Assume an error
char *value_to_bind;
char obfuscated_value[MAX_DM_SHORT_VALUE_LEN];
int len;
// Exit if this function is not being called from the data model thread
if (OS_UTILS_IsDataModelThread(__FUNCTION__, PRINT_WARNING)==false)
{
return USP_ERR_INTERNAL_ERROR;
}
// Decide whether to obfuscate the value
len = strlen(new_value);
if (flags & OBFUSCATED_VALUE)
{
ObfuscatedCopy((unsigned char *)obfuscated_value, (unsigned char *)new_value, len);
value_to_bind = obfuscated_value;
}
else
{
value_to_bind = new_value;
}
// Exit if unable to set the value of the hash in the prepared statement
stmt = prepared_stmts[kSqlStmt_Set];
err = sqlite3_bind_int64(stmt, 1, (db_hash_t)hash);
if (err != SQLITE_OK)
{
USP_ERR_SQL_PARAM(db_handle, "sqlite3_bind_int");
goto exit;
}
// Exit if unable to set the value of the instances in the prepared statement
err = sqlite3_bind_text(stmt, 2, instances, SQLITE_ZERO_TERMINATED, SQLITE_STATIC);
if (err != SQLITE_OK)
{
USP_ERR_SQL_PARAM(db_handle, "sqlite3_bind_text");
goto exit;
}
// Exit if unable to set the new value of the parameter in the prepared statement
err = sqlite3_bind_text(stmt, 3, value_to_bind, len, SQLITE_STATIC);
if (err != SQLITE_OK)
{
USP_ERR_SQL_PARAM(db_handle, "sqlite3_bind_text");
goto exit;
}
//LogSQLStatement("SET", path, stmt);
// Exit if unable to perform the set
err = sqlite3_step(stmt);
if (err != SQLITE_DONE) // We are not expecting any rows
{
USP_ERR_SQL_PARAM(db_handle, "sqlite3_step");
goto exit;
}
// If the code gets here, then the parameter has been successfully set in the database
result = USP_ERR_OK;
exit:
// Always reset the statement in preparation for next time, even if an error occurred
err = sqlite3_reset(stmt);
if ((err != SQLITE_OK) && (result == USP_ERR_OK))
{
USP_ERR_SQL_PARAM(db_handle, "sqlite3_reset");
}
return result;
}
1.已经使用了sqlite3_prepare_v2的方法还是慢
2.设置PRAGMA synchronous = OFF还是不好使