mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Use a std::unique_ptr for GncSqlStatement for better memory management.
This commit is contained in:
parent
64c1fda6ec
commit
12e763884e
@ -2349,7 +2349,8 @@ conn_dispose (GncSqlConnection* conn)
|
||||
}
|
||||
|
||||
static GncSqlResultPtr
|
||||
conn_execute_select_statement (GncSqlConnection* conn, GncSqlStatement* stmt)
|
||||
conn_execute_select_statement (GncSqlConnection* conn,
|
||||
const GncSqlStatementPtr& stmt)
|
||||
{
|
||||
GncDbiSqlConnection* dbi_conn = (GncDbiSqlConnection*)conn;
|
||||
dbi_result result;
|
||||
@ -2370,7 +2371,7 @@ conn_execute_select_statement (GncSqlConnection* conn, GncSqlStatement* stmt)
|
||||
|
||||
static gint
|
||||
conn_execute_nonselect_statement (GncSqlConnection* conn,
|
||||
GncSqlStatement* stmt)
|
||||
const GncSqlStatementPtr& stmt)
|
||||
{
|
||||
GncDbiSqlConnection* dbi_conn = (GncDbiSqlConnection*)conn;
|
||||
dbi_result result;
|
||||
@ -2399,10 +2400,10 @@ conn_execute_nonselect_statement (GncSqlConnection* conn,
|
||||
return num_rows;
|
||||
}
|
||||
|
||||
static GncSqlStatement*
|
||||
static GncSqlStatementPtr
|
||||
conn_create_statement_from_sql (GncSqlConnection* conn, const gchar* sql)
|
||||
{
|
||||
return new GncDbiSqlStatement (conn, sql);
|
||||
return std::unique_ptr<GncSqlStatement>(new GncDbiSqlStatement (conn, sql));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -213,7 +213,6 @@ load_single_account (GncSqlBackend* be, GncSqlRow& row,
|
||||
void
|
||||
GncSqlAccountBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt = NULL;
|
||||
QofBook* pBook;
|
||||
GList* l_accounts_needing_parents = NULL;
|
||||
GSList* bal_slist;
|
||||
@ -225,14 +224,13 @@ GncSqlAccountBackend::load_all (GncSqlBackend* be)
|
||||
|
||||
pBook = be->book;
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
if (stmt == NULL)
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
if (stmt == nullptr)
|
||||
{
|
||||
LEAVE ("stmt == NULL");
|
||||
return;
|
||||
}
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
for (auto row : *result)
|
||||
load_single_account (be, row, &l_accounts_needing_parents);
|
||||
|
||||
|
@ -86,18 +86,21 @@ static void gnc_sql_init_object_handlers (void);
|
||||
static void update_progress (GncSqlBackend* be);
|
||||
static void finish_progress (GncSqlBackend* be);
|
||||
static gboolean reset_version_info (GncSqlBackend* be);
|
||||
static GncSqlStatement* build_insert_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const EntryVec& table);
|
||||
static GncSqlStatement* build_update_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const EntryVec& table);
|
||||
static GncSqlStatement* build_delete_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const EntryVec& table);
|
||||
static GncSqlStatementPtr build_insert_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name,
|
||||
gpointer pObject,
|
||||
const EntryVec& table);
|
||||
static GncSqlStatementPtr build_update_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name,
|
||||
gpointer pObject,
|
||||
const EntryVec& table);
|
||||
static GncSqlStatementPtr build_delete_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name,
|
||||
gpointer pObject,
|
||||
const EntryVec& table);
|
||||
|
||||
static GList* post_load_commodities = NULL;
|
||||
|
||||
@ -1832,22 +1835,19 @@ gnc_sql_load_object (const GncSqlBackend* be, GncSqlRow& row,
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
GncSqlStatement*
|
||||
GncSqlStatementPtr
|
||||
gnc_sql_create_select_statement (GncSqlBackend* be, const gchar* table_name)
|
||||
{
|
||||
gchar* sql;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_val_if_fail (be != NULL, NULL);
|
||||
g_return_val_if_fail (table_name != NULL, NULL);
|
||||
|
||||
sql = g_strdup_printf ("SELECT * FROM %s", table_name);
|
||||
stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
auto sql = g_strdup_printf ("SELECT * FROM %s", table_name);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
g_free (sql);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
static GncSqlStatement*
|
||||
static GncSqlStatementPtr
|
||||
create_single_col_select_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
const GncSqlColumnTableEntryPtr table_row)
|
||||
@ -1862,7 +1862,8 @@ create_single_col_select_statement (GncSqlBackend* be,
|
||||
/* ================================================================= */
|
||||
|
||||
GncSqlResultPtr
|
||||
gnc_sql_execute_select_statement (GncSqlBackend* be, GncSqlStatement* stmt)
|
||||
gnc_sql_execute_select_statement (GncSqlBackend* be,
|
||||
const GncSqlStatementPtr& stmt)
|
||||
{
|
||||
|
||||
g_return_val_if_fail (be != NULL, NULL);
|
||||
@ -1879,15 +1880,13 @@ gnc_sql_execute_select_statement (GncSqlBackend* be, GncSqlStatement* stmt)
|
||||
return result;
|
||||
}
|
||||
|
||||
GncSqlStatement*
|
||||
GncSqlStatementPtr
|
||||
gnc_sql_create_statement_from_sql (GncSqlBackend* be, const gchar* sql)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_val_if_fail (be != NULL, NULL);
|
||||
g_return_val_if_fail (sql != NULL, NULL);
|
||||
|
||||
stmt = gnc_sql_connection_create_statement_from_sql (be->conn, sql);
|
||||
auto stmt = gnc_sql_connection_create_statement_from_sql (be->conn, sql);
|
||||
if (stmt == NULL)
|
||||
{
|
||||
PERR ("SQL error: %s\n", sql);
|
||||
@ -1901,18 +1900,15 @@ gnc_sql_create_statement_from_sql (GncSqlBackend* be, const gchar* sql)
|
||||
GncSqlResultPtr
|
||||
gnc_sql_execute_select_sql (GncSqlBackend* be, const gchar* sql)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_val_if_fail (be != NULL, NULL);
|
||||
g_return_val_if_fail (sql != NULL, NULL);
|
||||
|
||||
stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
if (stmt == NULL)
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
if (stmt == nullptr)
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
auto result = gnc_sql_connection_execute_select_statement (be->conn, stmt);
|
||||
delete stmt;
|
||||
if (result == NULL)
|
||||
{
|
||||
PERR ("SQL error: %s\n", sql);
|
||||
@ -1926,19 +1922,16 @@ gnc_sql_execute_select_sql (GncSqlBackend* be, const gchar* sql)
|
||||
gint
|
||||
gnc_sql_execute_nonselect_sql (GncSqlBackend* be, const gchar* sql)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
gint result;
|
||||
|
||||
g_return_val_if_fail (be != NULL, 0);
|
||||
g_return_val_if_fail (sql != NULL, 0);
|
||||
|
||||
stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
if (stmt == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
result = gnc_sql_connection_execute_nonselect_statement (be->conn, stmt);
|
||||
delete stmt;
|
||||
auto result = gnc_sql_connection_execute_nonselect_statement (be->conn,
|
||||
stmt);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1987,7 +1980,6 @@ get_object_values (GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
return vec;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
gnc_sql_object_is_it_in_db (GncSqlBackend* be, const gchar* table_name,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
@ -2007,7 +1999,6 @@ gnc_sql_object_is_it_in_db (GncSqlBackend* be, const gchar* table_name,
|
||||
PairVec values{get_object_values(be, obj_name, pObject, table)};
|
||||
stmt->add_where_cond(obj_name, values);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
if (result != NULL)
|
||||
{
|
||||
auto retval = result->size() > 0;
|
||||
@ -2024,7 +2015,7 @@ gnc_sql_do_db_operation (GncSqlBackend* be,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const EntryVec& table)
|
||||
{
|
||||
GncSqlStatement* stmt = NULL;
|
||||
GncSqlStatementPtr stmt;
|
||||
gboolean ok = FALSE;
|
||||
|
||||
g_return_val_if_fail (be != NULL, FALSE);
|
||||
@ -2048,7 +2039,7 @@ gnc_sql_do_db_operation (GncSqlBackend* be,
|
||||
{
|
||||
g_assert (FALSE);
|
||||
}
|
||||
if (stmt != NULL)
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
gint result;
|
||||
|
||||
@ -2063,19 +2054,18 @@ gnc_sql_do_db_operation (GncSqlBackend* be,
|
||||
{
|
||||
ok = TRUE;
|
||||
}
|
||||
delete stmt;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static GncSqlStatement*
|
||||
static GncSqlStatementPtr
|
||||
build_insert_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const EntryVec& table)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlStatementPtr stmt;
|
||||
PairVec col_values;
|
||||
std::ostringstream sql;
|
||||
|
||||
@ -2108,13 +2098,13 @@ build_insert_statement (GncSqlBackend* be,
|
||||
return stmt;
|
||||
}
|
||||
|
||||
static GncSqlStatement*
|
||||
static GncSqlStatementPtr
|
||||
build_update_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const EntryVec& table)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlStatementPtr stmt;
|
||||
std::ostringstream sql;
|
||||
|
||||
g_return_val_if_fail (be != NULL, NULL);
|
||||
@ -2145,13 +2135,12 @@ build_update_statement (GncSqlBackend* be,
|
||||
return stmt;
|
||||
}
|
||||
|
||||
static GncSqlStatement*
|
||||
static GncSqlStatementPtr
|
||||
build_delete_statement (GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const EntryVec& table)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
std::ostringstream sql;
|
||||
|
||||
g_return_val_if_fail (be != NULL, NULL);
|
||||
@ -2160,8 +2149,8 @@ build_delete_statement (GncSqlBackend* be,
|
||||
g_return_val_if_fail (pObject != NULL, NULL);
|
||||
|
||||
sql << "DELETE FROM " << table_name;
|
||||
stmt = gnc_sql_connection_create_statement_from_sql (be->conn,
|
||||
sql.str().c_str());
|
||||
auto stmt = gnc_sql_connection_create_statement_from_sql (be->conn,
|
||||
sql.str().c_str());
|
||||
|
||||
/* WHERE */
|
||||
PairVec values;
|
||||
|
@ -155,6 +155,8 @@ public:
|
||||
virtual void add_where_cond (QofIdTypeConst, const PairVec&) = 0;
|
||||
};
|
||||
|
||||
using GncSqlStatementPtr = std::unique_ptr<GncSqlStatement>;
|
||||
|
||||
/**
|
||||
* @struct GncSqlConnection
|
||||
*
|
||||
@ -164,9 +166,9 @@ public:
|
||||
struct GncSqlConnection
|
||||
{
|
||||
void (*dispose) (GncSqlConnection*);
|
||||
GncSqlResultPtr (*executeSelectStatement) (GncSqlConnection*, GncSqlStatement*); /**< Returns NULL if error */
|
||||
gint (*executeNonSelectStatement) (GncSqlConnection*, GncSqlStatement*); /**< Returns -1 if error */
|
||||
GncSqlStatement* (*createStatementFromSql) (GncSqlConnection*, const gchar*);
|
||||
GncSqlResultPtr (*executeSelectStatement) (GncSqlConnection*, const GncSqlStatementPtr&); /**< Returns NULL if error */
|
||||
gint (*executeNonSelectStatement) (GncSqlConnection*, const GncSqlStatementPtr&); /**< Returns -1 if error */
|
||||
GncSqlStatementPtr (*createStatementFromSql) (GncSqlConnection*, const gchar*);
|
||||
gboolean (*doesTableExist) (GncSqlConnection*, const gchar*); /**< Returns true if successful */
|
||||
gboolean (*beginTransaction) (GncSqlConnection*); /**< Returns TRUE if successful, FALSE if error */
|
||||
gboolean (*rollbackTransaction) (GncSqlConnection*); /**< Returns TRUE if successful, FALSE if error */
|
||||
@ -763,7 +765,7 @@ gboolean gnc_sql_do_db_operation (GncSqlBackend* be,
|
||||
* @return Results, or NULL if an error has occured
|
||||
*/
|
||||
GncSqlResultPtr gnc_sql_execute_select_statement (GncSqlBackend* be,
|
||||
GncSqlStatement* statement);
|
||||
const GncSqlStatementPtr& statement);
|
||||
|
||||
/**
|
||||
* Executes an SQL SELECT statement from an SQL char string and returns the
|
||||
@ -792,8 +794,8 @@ gint gnc_sql_execute_nonselect_sql (GncSqlBackend* be, const gchar* sql);
|
||||
* @param sql SQL char string
|
||||
* @return Statement
|
||||
*/
|
||||
GncSqlStatement* gnc_sql_create_statement_from_sql (GncSqlBackend* be,
|
||||
const gchar* sql);
|
||||
GncSqlStatementPtr gnc_sql_create_statement_from_sql (GncSqlBackend* be,
|
||||
const gchar* sql);
|
||||
|
||||
/**
|
||||
* Loads a Gnucash object from the database.
|
||||
@ -906,8 +908,8 @@ const GncGUID* gnc_sql_load_tx_guid (const GncSqlBackend* be, GncSqlRow& row);
|
||||
* @param table_name Table name
|
||||
* @return Statement
|
||||
*/
|
||||
GncSqlStatement* gnc_sql_create_select_statement (GncSqlBackend* be,
|
||||
const gchar* table_name);
|
||||
GncSqlStatementPtr gnc_sql_create_select_statement (GncSqlBackend* be,
|
||||
const gchar* table_name);
|
||||
|
||||
/**
|
||||
* Appends the ascii strings for a list of GUIDs to the end of an SQL string.
|
||||
|
@ -235,13 +235,11 @@ load_single_billterm (GncSqlBackend* be, GncSqlRow& row,
|
||||
void
|
||||
GncSqlBillTermBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* list = NULL;
|
||||
GList* l_billterms_needing_parents = NULL;
|
||||
|
||||
|
@ -169,15 +169,12 @@ load_single_book (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlBookBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, BOOK_TABLE);
|
||||
if (stmt != NULL)
|
||||
auto stmt = gnc_sql_create_select_statement (be, BOOK_TABLE);
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
auto row = result->begin();
|
||||
|
||||
/* If there are no rows, try committing the book; unset
|
||||
|
@ -206,22 +206,19 @@ static void
|
||||
load_budget_amounts (GncSqlBackend* be, GncBudget* budget)
|
||||
{
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH + 1];
|
||||
gchar* sql;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
g_return_if_fail (budget != NULL);
|
||||
|
||||
(void)guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (budget)),
|
||||
guid_buf);
|
||||
sql = g_strdup_printf ("SELECT * FROM %s WHERE budget_guid='%s'",
|
||||
AMOUNTS_TABLE, guid_buf);
|
||||
stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
auto sql = g_strdup_printf ("SELECT * FROM %s WHERE budget_guid='%s'",
|
||||
AMOUNTS_TABLE, guid_buf);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
g_free (sql);
|
||||
if (stmt != NULL)
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
budget_amount_info_t info = { budget, NULL, 0 };
|
||||
|
||||
for (auto row : *result)
|
||||
@ -335,16 +332,14 @@ load_single_budget (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlBudgetBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GList* list = NULL;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, BUDGET_TABLE);
|
||||
if (stmt != NULL)
|
||||
auto stmt = gnc_sql_create_select_statement (be, BUDGET_TABLE);
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
for (auto row : *result)
|
||||
{
|
||||
auto b = load_single_budget (be, row);
|
||||
|
@ -143,14 +143,12 @@ load_single_commodity (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlCommodityBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
gnc_commodity_table* pTable;
|
||||
|
||||
pTable = gnc_commodity_table_get_table (be->book);
|
||||
stmt = gnc_sql_create_select_statement (be, COMMODITIES_TABLE);
|
||||
if (stmt == NULL) return;
|
||||
auto stmt = gnc_sql_create_select_statement (be, COMMODITIES_TABLE);
|
||||
if (stmt == nullptr) return;
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
|
||||
for (auto row : *result)
|
||||
{
|
||||
|
@ -124,14 +124,11 @@ load_single_customer (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlCustomerBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* list = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
@ -110,13 +110,10 @@ load_single_employee (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlEmployeeBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
|
||||
GList* list = NULL;
|
||||
|
||||
|
@ -192,13 +192,10 @@ load_single_entry (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlEntryBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* list = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
@ -131,13 +131,10 @@ load_single_invoice (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlInvoiceBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* list = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
@ -103,12 +103,10 @@ load_single_job (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlJobBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* list = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
@ -125,14 +125,12 @@ load_single_lot (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlLotsBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
if (stmt != NULL)
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
if (result->begin () == nullptr)
|
||||
return;
|
||||
for (auto row : *result)
|
||||
|
@ -103,12 +103,10 @@ load_single_order (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlOrderBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* list = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
@ -101,7 +101,6 @@ load_single_price (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlPriceBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
QofBook* pBook;
|
||||
GNCPriceDB* pPriceDB;
|
||||
|
||||
@ -109,11 +108,10 @@ GncSqlPriceBackend::load_all (GncSqlBackend* be)
|
||||
|
||||
pBook = be->book;
|
||||
pPriceDB = gnc_pricedb_get_db (pBook);
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
if (stmt != NULL)
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
if (result->begin() == result->end())
|
||||
return;
|
||||
|
||||
|
@ -314,7 +314,6 @@ gnc_sql_set_recurrences_from_db (GncSqlBackend* be, const GncGUID* guid)
|
||||
{
|
||||
gchar* buf;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH + 1];
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_val_if_fail (be != NULL, NULL);
|
||||
g_return_val_if_fail (guid != NULL, NULL);
|
||||
@ -322,10 +321,9 @@ gnc_sql_set_recurrences_from_db (GncSqlBackend* be, const GncGUID* guid)
|
||||
(void)guid_to_string_buff (guid, guid_buf);
|
||||
buf = g_strdup_printf ("SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME,
|
||||
guid_buf);
|
||||
stmt = gnc_sql_connection_create_statement_from_sql (be->conn, buf);
|
||||
auto stmt = gnc_sql_connection_create_statement_from_sql (be->conn, buf);
|
||||
g_free (buf);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -121,14 +121,11 @@ load_single_sx (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlSchedXactionBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt = NULL;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, SCHEDXACTION_TABLE);
|
||||
auto stmt = gnc_sql_create_select_statement (be, SCHEDXACTION_TABLE);
|
||||
if (stmt == NULL) return;
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
SchedXactions* sxes;
|
||||
GList* list = NULL;
|
||||
sxes = gnc_book_get_schedxactions (be->book);
|
||||
|
@ -732,7 +732,6 @@ gnc_sql_slots_delete (GncSqlBackend* be, const GncGUID* guid)
|
||||
{
|
||||
gchar* buf;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH + 1];
|
||||
GncSqlStatement* stmt;
|
||||
slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new (NULL) };
|
||||
|
||||
g_return_val_if_fail (be != NULL, FALSE);
|
||||
@ -742,12 +741,11 @@ gnc_sql_slots_delete (GncSqlBackend* be, const GncGUID* guid)
|
||||
|
||||
buf = g_strdup_printf ("SELECT * FROM %s WHERE obj_guid='%s' and slot_type in ('%d', '%d') and not guid_val is null",
|
||||
TABLE_NAME, guid_buf, KvpValue::Type::FRAME, KvpValue::Type::GLIST);
|
||||
stmt = gnc_sql_create_statement_from_sql (be, buf);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, buf);
|
||||
g_free (buf);
|
||||
if (stmt != NULL)
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
for (auto row : *result)
|
||||
{
|
||||
try
|
||||
@ -828,7 +826,6 @@ slots_load_info (slot_info_t* pInfo)
|
||||
{
|
||||
gchar* buf;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH + 1];
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (pInfo != NULL);
|
||||
g_return_if_fail (pInfo->be != NULL);
|
||||
@ -839,12 +836,11 @@ slots_load_info (slot_info_t* pInfo)
|
||||
|
||||
buf = g_strdup_printf ("SELECT * FROM %s WHERE obj_guid='%s'",
|
||||
TABLE_NAME, guid_buf);
|
||||
stmt = gnc_sql_create_statement_from_sql (pInfo->be, buf);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (pInfo->be, buf);
|
||||
g_free (buf);
|
||||
if (stmt != NULL)
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
auto result = gnc_sql_execute_select_statement (pInfo->be, stmt);
|
||||
delete stmt;
|
||||
for (auto row : *result)
|
||||
load_slot (pInfo, row);
|
||||
}
|
||||
@ -893,7 +889,6 @@ void
|
||||
gnc_sql_slots_load_for_list (GncSqlBackend* be, GList* list)
|
||||
{
|
||||
QofCollection* coll;
|
||||
GncSqlStatement* stmt;
|
||||
GString* sql;
|
||||
gboolean single_item;
|
||||
|
||||
@ -926,8 +921,8 @@ gnc_sql_slots_load_for_list (GncSqlBackend* be, GList* list)
|
||||
}
|
||||
|
||||
// Execute the query and load the slots
|
||||
stmt = gnc_sql_create_statement_from_sql (be, sql->str);
|
||||
if (stmt == NULL)
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, sql->str);
|
||||
if (stmt == nullptr)
|
||||
{
|
||||
PERR ("stmt == NULL, SQL = '%s'\n", sql->str);
|
||||
(void)g_string_free (sql, TRUE);
|
||||
@ -935,7 +930,6 @@ gnc_sql_slots_load_for_list (GncSqlBackend* be, GList* list)
|
||||
}
|
||||
(void)g_string_free (sql, TRUE);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
for (auto row : *result)
|
||||
load_slot_for_list_item (be, row, coll);
|
||||
}
|
||||
@ -982,7 +976,6 @@ void gnc_sql_slots_load_for_sql_subquery (GncSqlBackend* be,
|
||||
BookLookupFn lookup_fn)
|
||||
{
|
||||
gchar* sql;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
@ -994,8 +987,8 @@ void gnc_sql_slots_load_for_sql_subquery (GncSqlBackend* be,
|
||||
subquery);
|
||||
|
||||
// Execute the query and load the slots
|
||||
stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
if (stmt == NULL)
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, sql);
|
||||
if (stmt == nullptr)
|
||||
{
|
||||
PERR ("stmt == NULL, SQL = '%s'\n", sql);
|
||||
g_free (sql);
|
||||
@ -1003,7 +996,6 @@ void gnc_sql_slots_load_for_sql_subquery (GncSqlBackend* be,
|
||||
}
|
||||
g_free (sql);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
for (auto row : *result)
|
||||
load_slot_for_book_object (be, row, lookup_fn);
|
||||
}
|
||||
|
@ -227,7 +227,6 @@ load_taxtable_entries (GncSqlBackend* be, GncTaxTable* tt)
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH + 1];
|
||||
GValue value;
|
||||
gchar* buf;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
g_return_if_fail (tt != NULL);
|
||||
@ -238,10 +237,9 @@ load_taxtable_entries (GncSqlBackend* be, GncTaxTable* tt)
|
||||
g_value_set_string (&value, guid_buf);
|
||||
buf = g_strdup_printf ("SELECT * FROM %s WHERE taxtable='%s'",
|
||||
TTENTRIES_TABLE_NAME, guid_buf);
|
||||
stmt = gnc_sql_connection_create_statement_from_sql (be->conn, buf);
|
||||
auto stmt = gnc_sql_connection_create_statement_from_sql (be->conn, buf);
|
||||
g_free (buf);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
for (auto row : *result)
|
||||
load_single_ttentry (be, row, tt);
|
||||
}
|
||||
@ -293,14 +291,11 @@ load_single_taxtable (GncSqlBackend* be, GncSqlRow& row,
|
||||
void
|
||||
GncSqlTaxTableBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
/* First time, create the query */
|
||||
stmt = gnc_sql_create_select_statement (be, TT_TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TT_TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* tt_needing_parents = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
@ -355,7 +355,7 @@ typedef struct
|
||||
* @param stmt SQL statement
|
||||
*/
|
||||
static void
|
||||
query_transactions (GncSqlBackend* be, GncSqlStatement* stmt)
|
||||
query_transactions (GncSqlBackend* be, const GncSqlStatementPtr& stmt)
|
||||
{
|
||||
g_return_if_fail (be != NULL);
|
||||
g_return_if_fail (stmt != NULL);
|
||||
@ -765,7 +765,6 @@ void gnc_sql_transaction_load_tx_for_account (GncSqlBackend* be,
|
||||
const GncGUID* guid;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH + 1];
|
||||
gchar* query_sql;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
g_return_if_fail (account != NULL);
|
||||
@ -775,12 +774,11 @@ void gnc_sql_transaction_load_tx_for_account (GncSqlBackend* be,
|
||||
query_sql = g_strdup_printf (
|
||||
"SELECT DISTINCT t.* FROM %s AS t, %s AS s WHERE s.tx_guid=t.guid AND s.account_guid ='%s'",
|
||||
TRANSACTION_TABLE, SPLIT_TABLE, guid_buf);
|
||||
stmt = gnc_sql_create_statement_from_sql (be, query_sql);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, query_sql);
|
||||
g_free (query_sql);
|
||||
if (stmt != NULL)
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
query_transactions (be, stmt);
|
||||
delete stmt;
|
||||
}
|
||||
}
|
||||
|
||||
@ -793,18 +791,14 @@ void gnc_sql_transaction_load_tx_for_account (GncSqlBackend* be,
|
||||
void
|
||||
GncSqlTransBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
gchar* query_sql;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
query_sql = g_strdup_printf ("SELECT * FROM %s", TRANSACTION_TABLE);
|
||||
stmt = gnc_sql_create_statement_from_sql (be, query_sql);
|
||||
auto query_sql = g_strdup_printf ("SELECT * FROM %s", TRANSACTION_TABLE);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, query_sql);
|
||||
g_free (query_sql);
|
||||
if (stmt != NULL)
|
||||
if (stmt != nullptr)
|
||||
{
|
||||
query_transactions (be, stmt);
|
||||
delete stmt;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1033,7 +1027,7 @@ convert_query_term_to_sql (const GncSqlBackend* be, const gchar* fieldName,
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlStatementPtr stmt;
|
||||
gboolean has_been_run;
|
||||
} split_query_info_t;
|
||||
|
||||
@ -1213,8 +1207,7 @@ run_split_query (GncSqlBackend* be, gpointer pQuery)
|
||||
{
|
||||
query_transactions (be, query_info->stmt);
|
||||
query_info->has_been_run = TRUE;
|
||||
delete query_info->stmt;
|
||||
query_info->stmt = NULL;
|
||||
query_info->stmt = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1300,7 +1293,6 @@ GSList*
|
||||
gnc_sql_get_account_balances_slist (GncSqlBackend* be)
|
||||
{
|
||||
#if LOAD_TRANSACTIONS_AS_NEEDED
|
||||
GncSqlStatement* stmt;
|
||||
gchar* buf;
|
||||
GSList* bal_slist = NULL;
|
||||
|
||||
@ -1308,11 +1300,10 @@ gnc_sql_get_account_balances_slist (GncSqlBackend* be)
|
||||
|
||||
buf = g_strdup_printf ("SELECT account_guid, reconcile_state, sum(quantity_num) as quantity_num, quantity_denom FROM %s GROUP BY account_guid, reconcile_state, quantity_denom ORDER BY account_guid, reconcile_state",
|
||||
SPLIT_TABLE);
|
||||
stmt = gnc_sql_create_statement_from_sql (be, buf);
|
||||
g_assert (stmt != NULL);
|
||||
auto stmt = gnc_sql_create_statement_from_sql (be, buf);
|
||||
g_assert (stmt != nullptr);
|
||||
g_free (buf);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
acct_balances_t* bal = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
@ -113,13 +113,10 @@ load_single_vendor (GncSqlBackend* be, GncSqlRow& row)
|
||||
void
|
||||
GncSqlVendorBackend::load_all (GncSqlBackend* be)
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail (be != NULL);
|
||||
|
||||
stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
|
||||
auto result = gnc_sql_execute_select_statement (be, stmt);
|
||||
delete stmt;
|
||||
GList* list = NULL;
|
||||
|
||||
for (auto row : *result)
|
||||
|
Loading…
Reference in New Issue
Block a user