Make GncSqlColumnTableEntry arrays into std::vectors.

Allows use of range for.
This commit is contained in:
John Ralls 2016-03-12 11:13:05 -08:00
parent be1a5f56d6
commit 96a8a7b99f
25 changed files with 458 additions and 524 deletions

View File

@ -215,7 +215,7 @@ static gboolean save_may_clobber_data (QofBackend* qbe);
static gchar* create_index_ddl (GncSqlConnection* conn,
const gchar* index_name,
const gchar* table_name,
const GncSqlColumnTableEntry* col_table);
const EntryVec& col_table);
static gchar* add_columns_ddl (GncSqlConnection* conn,
const gchar* table_name,
const ColVec& info_vec);
@ -2430,15 +2430,16 @@ stmt_to_sql (GncSqlStatement* stmt)
}
static void
stmt_add_where_cond (GncSqlStatement* stmt, QofIdTypeConst type_name,
gpointer obj, const GncSqlColumnTableEntry* table_row, GValue* value)
stmt_add_where_cond(GncSqlStatement* stmt, QofIdTypeConst type_name,
gpointer obj, const GncSqlColumnTableEntry& table_row,
GValue* value )
{
GncDbiSqlStatement* dbi_stmt = (GncDbiSqlStatement*)stmt;
gchar* buf;
gchar* value_str;
value_str = gnc_sql_get_sql_value (dbi_stmt->conn, value);
buf = g_strdup_printf (" WHERE %s = %s", table_row->col_name,
buf = g_strdup_printf (" WHERE %s = %s", table_row.col_name,
value_str);
g_free (value_str);
(void)g_string_append (dbi_stmt->sql, buf);
@ -2660,29 +2661,25 @@ conn_commit_transaction (GncSqlConnection* conn)
return success;
}
static gchar*
create_index_ddl (GncSqlConnection* conn,
const gchar* index_name,
const gchar* table_name,
const GncSqlColumnTableEntry* col_table)
static gchar*
create_index_ddl (GncSqlConnection* conn, const char* index_name,
const char* table_name, const EntryVec& col_table)
{
GString* ddl;
const GncSqlColumnTableEntry* table_row;
g_return_val_if_fail (conn != NULL, NULL);
g_return_val_if_fail (index_name != NULL, NULL);
g_return_val_if_fail (table_name != NULL, NULL);
g_return_val_if_fail (col_table != NULL, NULL);
ddl = g_string_new ("");
g_string_printf (ddl, "CREATE INDEX %s ON %s (", index_name, table_name);
for (table_row = col_table; table_row->col_name != NULL; ++table_row)
for (auto const& table_row : col_table)
{
if (table_row != col_table)
if (table_row != *col_table.begin())
{
(void)g_string_append (ddl, ", ");
}
g_string_append_printf (ddl, "%s", table_row->col_name);
g_string_append_printf (ddl, "%s", table_row.col_name);
}
(void)g_string_append (ddl, ")");
@ -2986,8 +2983,8 @@ conn_create_table (GncSqlConnection* conn, const gchar* table_name,
}
static gboolean
conn_create_index (GncSqlConnection* conn, const gchar* index_name,
const gchar* table_name, const GncSqlColumnTableEntry* col_table)
conn_create_index(GncSqlConnection* conn, const char* index_name,
const char* table_name, const EntryVec& col_table)
{
GncDbiSqlConnection* dbi_conn = (GncDbiSqlConnection*)conn;
gchar* ddl;
@ -2996,7 +2993,6 @@ conn_create_index (GncSqlConnection* conn, const gchar* index_name,
g_return_val_if_fail (conn != NULL, FALSE);
g_return_val_if_fail (index_name != NULL, FALSE);
g_return_val_if_fail (table_name != NULL, FALSE);
g_return_val_if_fail (col_table != NULL, FALSE);
ddl = create_index_ddl (conn, index_name, table_name, col_table);
if (ddl != NULL)

View File

@ -62,7 +62,7 @@ static void set_parent_guid (gpointer pObject, gpointer pValue);
#define ACCOUNT_MAX_CODE_LEN 2048
#define ACCOUNT_MAX_DESCRIPTION_LEN 2048
static const GncSqlColumnTableEntry col_table[] =
static const EntryVec col_table
{
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "name", CT_STRING, ACCOUNT_MAX_NAME_LEN, COL_NNUL, "name" },
@ -78,13 +78,11 @@ static const GncSqlColumnTableEntry col_table[] =
{ "description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, "description" },
{ "hidden", CT_BOOLEAN, 0, 0, "hidden" },
{ "placeholder", CT_BOOLEAN, 0, 0, "placeholder" },
{ NULL }
};
static GncSqlColumnTableEntry parent_col_table[] =
{
static EntryVec parent_col_table
({
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL, NULL, set_parent_guid },
{ NULL }
};
});
typedef struct
{
@ -403,7 +401,7 @@ gnc_sql_save_account (GncSqlBackend* be, QofInstance* inst)
static void
load_account_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -412,9 +410,8 @@ load_account_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -422,10 +419,10 @@ load_account_guid (const GncSqlBackend* be, GncSqlRow* row,
account = xaccAccountLookup (&guid, be->book);
if (account != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, account, NULL);
g_object_set (pObject, table_row.gobj_param_name, account, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -50,8 +50,8 @@ G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
#define ADDRESS_MAX_FAX_LEN 128
#define ADDRESS_MAX_EMAIL_LEN 256
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "name", CT_STRING, ADDRESS_MAX_NAME_LEN, COL_NNUL, "name" },
{ "addr1", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, "addr1" },
{ "addr2", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, "addr2" },
@ -60,8 +60,7 @@ static GncSqlColumnTableEntry col_table[] =
{ "phone", CT_STRING, ADDRESS_MAX_PHONE_LEN, COL_NNUL, "phone" },
{ "fax", CT_STRING, ADDRESS_MAX_FAX_LEN, COL_NNUL, "fax" },
{ "email", CT_STRING, ADDRESS_MAX_EMAIL_LEN, COL_NNUL, "email" },
{ NULL }
};
});
typedef void (*AddressSetterFunc) (gpointer, GncAddress*);
typedef GncAddress* (*AddressGetterFunc) (const gpointer);
@ -69,24 +68,24 @@ typedef GncAddress* (*AddressGetterFunc) (const gpointer);
static void
load_address (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
gchar* buf;
GncAddress* addr;
AddressSetterFunc a_setter = (AddressSetterFunc)setter;
const GncSqlColumnTableEntry* subtable;
const gchar* s;
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
addr = gncAddressCreate (be->book, QOF_INSTANCE(pObject));
for (subtable = col_table; subtable->col_name != NULL; subtable++)
for (auto const& subtable_row : col_table)
{
buf = g_strdup_printf ("%s_%s", table_row->col_name, subtable->col_name);
buf = g_strdup_printf ("%s_%s", table_row.col_name,
subtable_row.col_name);
val = gnc_sql_row_get_value_at_col_name (row, buf);
g_free (buf);
if (val == NULL)
@ -97,28 +96,28 @@ load_address (const GncSqlBackend* be, GncSqlRow* row,
{
s = g_value_get_string (val);
}
if (subtable->gobj_param_name != NULL)
if (subtable_row.gobj_param_name != NULL)
{
g_object_set (addr, subtable->gobj_param_name, s, NULL);
g_object_set (addr, subtable_row.gobj_param_name, s, NULL);
}
else
{
if (subtable->qof_param_name != NULL)
if (subtable_row.qof_param_name != NULL)
{
setter = qof_class_get_parameter_setter (GNC_ID_ADDRESS,
subtable->qof_param_name);
subtable_row.qof_param_name);
}
else
{
setter = subtable->setter;
setter = subtable_row.setter;
}
(*setter) (addr, (const gpointer)s);
}
}
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, addr, NULL);
g_object_set (pObject, table_row.gobj_param_name, addr, NULL);
qof_instance_decrease_editlevel (pObject);
}
else
@ -129,29 +128,27 @@ load_address (const GncSqlBackend* be, GncSqlRow* row,
static void
add_address_col_info_to_list(const GncSqlBackend* be,
const GncSqlColumnTableEntry* table_row,
const GncSqlColumnTableEntry& table_row,
ColVec& vec)
{
GncSqlColumnInfo* info;
gchar* buf;
const GncSqlColumnTableEntry* subtable_row;
g_return_if_fail (be != NULL);
g_return_if_fail (table_row != NULL);
for (subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++)
for (auto const& subtable_row : col_table)
{
buf = g_strdup_printf ("%s_%s", table_row->col_name, subtable_row->col_name);
buf = g_strdup_printf ("%s_%s", table_row.col_name, subtable_row.col_name);
GncSqlColumnInfo info(buf, BCT_STRING, subtable_row->size, true, false,
table_row->flags & COL_PKEY,
table_row->flags & COL_NNUL);
GncSqlColumnInfo info(buf, BCT_STRING, subtable_row.size, true, false,
table_row.flags & COL_PKEY,
table_row.flags & COL_NNUL);
vec.emplace_back(std::move(info));
}
}
static void
add_address_colname_to_list (const GncSqlColumnTableEntry* table_row,
add_address_colname_to_list (const GncSqlColumnTableEntry& table_row,
GList** pList)
{
gnc_sql_add_subtable_colnames_to_list (table_row, col_table, pList);
@ -160,7 +157,7 @@ add_address_colname_to_list (const GncSqlColumnTableEntry* table_row,
static void
get_gvalue_address (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry* table_row, GValue* value)
const GncSqlColumnTableEntry& table_row, GValue* value)
{
AddressGetterFunc getter;
GncAddress* addr;
@ -168,13 +165,11 @@ get_gvalue_address (const GncSqlBackend* be, QofIdTypeConst obj_name,
g_return_if_fail (be != NULL);
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
g_return_if_fail (value != NULL);
memset (value, 0, sizeof (GValue));
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
g_object_get (pObject, table_row->gobj_param_name, &addr, NULL);
g_object_get (pObject, table_row.gobj_param_name, &addr, NULL);
}
else
{
@ -187,7 +182,8 @@ get_gvalue_address (const GncSqlBackend* be, QofIdTypeConst obj_name,
static void
add_gvalue_address_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject, const GncSqlColumnTableEntry* table_row,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
GSList** pList)
{
GValue value;
@ -195,25 +191,23 @@ add_gvalue_address_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
GncAddress* addr;
gchar* s;
QofAccessFunc getter;
const GncSqlColumnTableEntry* subtable_row;
g_return_if_fail (be != NULL);
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
memset (&value, 0, sizeof (GValue));
get_gvalue_address (be, obj_name, pObject, table_row, &value);
if (G_VALUE_TYPE (&value) != 0)
{
addr = static_cast<decltype (addr)> (g_value_get_object (&value));
for (subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++)
addr = static_cast<decltype(addr)>(g_value_get_object(&value));
for (auto const& subtable_row : col_table)
{
subfield_value = g_new0 (GValue, 1);
if (subtable_row->gobj_param_name != NULL)
if (subtable_row.gobj_param_name != NULL)
{
g_object_get (addr, subtable_row->gobj_param_name, &s, NULL);
g_object_get (addr, subtable_row.gobj_param_name, &s, NULL);
}
else
{

File diff suppressed because it is too large Load Diff

View File

@ -52,7 +52,8 @@ extern "C"
#include <vector>
struct GncSqlColumnInfo;
struct GncSqlColumnTableEntry;
using EntryVec = std::vector<GncSqlColumnTableEntry>;
using ColVec = std::vector<GncSqlColumnInfo>;
using LoadOrder = std::vector<std::string>;
typedef struct GncSqlConnection GncSqlConnection;
@ -137,7 +138,6 @@ void gnc_sql_commit_edit (GncSqlBackend* qbe, QofInstance* inst);
/**
*/
typedef struct GncSqlColumnTableEntry GncSqlColumnTableEntry;
typedef struct GncSqlStatement GncSqlStatement;
typedef struct GncSqlResult GncSqlResult;
typedef struct GncSqlRow GncSqlRow;
@ -153,7 +153,7 @@ struct GncSqlStatement
void (*dispose) (GncSqlStatement*);
gchar* (*toSql) (GncSqlStatement*);
void (*addWhereCond) (GncSqlStatement*, QofIdTypeConst, gpointer,
const GncSqlColumnTableEntry*, GValue*);
const GncSqlColumnTableEntry&, GValue*);
};
#define gnc_sql_statement_dispose(STMT) \
(STMT)->dispose(STMT)
@ -179,7 +179,7 @@ struct GncSqlConnection
gboolean (*rollbackTransaction) (GncSqlConnection*); /**< Returns TRUE if successful, FALSE if error */
gboolean (*commitTransaction) (GncSqlConnection*); /**< Returns TRUE if successful, FALSE if error */
gboolean (*createTable) (GncSqlConnection*, const gchar*, const ColVec&); /**< Returns TRUE if successful, FALSE if error */
gboolean (*createIndex) (GncSqlConnection*, const gchar*, const gchar*, const GncSqlColumnTableEntry*); /**< Returns TRUE if successful, FALSE if error */
gboolean (*createIndex) (GncSqlConnection*, const gchar*, const gchar*, const EntryVec&); /**< Returns TRUE if successful, FALSE if error */
gboolean (*addColumnsToTable) (GncSqlConnection*, const gchar* table, const ColVec&); /**< Returns TRUE if successful, FALSE if error */
gchar* (*quoteString) (const GncSqlConnection*, gchar*);
};
@ -321,12 +321,18 @@ typedef enum
#define CT_LOTREF "ct_lotref"
#define CT_TXREF "ct_txref"
enum ColumnFlags : int
{
COL_NO_FLAG = 0,
COL_PKEY = 0x01, /**< The column is a primary key */
COL_NNUL = 0x02, /**< The column may not contain a NULL value */
COL_UNIQUE = 0x04, /**< The column must contain unique values */
COL_AUTOINC = 0x08 /**< The column is an auto-incrementing int */
};
/**
* @struct GncSqlColumnTableEntry
*
* The GncSqlColumnTableEntry struct contains all of the information
* required to copy information between an object and the database for a
* specific object property.
* Contains all of the information required to copy information between an
* object and the database for a specific object property.
*
* If an entry contains a gobj_param_name value, this string is used as the
* property name for a call to g_object_get() or g_object_set(). If the
@ -341,20 +347,46 @@ typedef enum
*/
struct GncSqlColumnTableEntry
{
const gchar* col_name; /**< Column name */
const gchar* col_type; /**< Column type */
unsigned int size; /**< Column size in bytes, for string columns */
#define COL_PKEY 0x01 /**< The column is a primary key */
#define COL_NNUL 0x02 /**< The column may not contain a NULL value */
#define COL_UNIQUE 0x04 /**< The column must contain unique values */
#define COL_AUTOINC 0x08 /**< The column is an auto-incrementing int */
gint flags; /**< Column flags */
const gchar* gobj_param_name; /**< If non-null, g_object param name */
const gchar* qof_param_name; /**< If non-null, qof parameter name */
QofAccessFunc getter; /**< General access function */
QofSetterFunc setter; /**< General setter function */
GncSqlColumnTableEntry (const char* name, const char*type, unsigned int s,
ColumnFlags f, const char* gobj_name = nullptr,
const char* qof_name = nullptr,
QofAccessFunc get = nullptr,
QofSetterFunc set = nullptr) :
col_name{name}, col_type{type}, size{s}, flags{f},
gobj_param_name{gobj_name}, qof_param_name{qof_name}, getter{get},
setter{set} {}
GncSqlColumnTableEntry (const char* name, const char*type, unsigned int s,
int f, const char* gobj_name = nullptr,
const char* qof_name = nullptr,
QofAccessFunc get = nullptr,
QofSetterFunc set = nullptr) :
col_name{name}, col_type{type}, size{s},
flags{static_cast<ColumnFlags>(f)},
gobj_param_name{gobj_name}, qof_param_name{qof_name}, getter{get},
setter{set} {}
const char* col_name; /**< Column name */
const char* col_type; /**< Column type */
unsigned int size; /**< Column size in bytes, for string columns */
ColumnFlags flags; /**< Column flags */
const char* gobj_param_name; /**< If non-null, g_object param name */
const char* qof_param_name; /**< If non-null, qof parameter name */
QofAccessFunc getter; /**< General access function */
QofSetterFunc setter; /**< General setter function */
};
inline bool operator==(const GncSqlColumnTableEntry& l,
const GncSqlColumnTableEntry& r)
{
return strcmp(l.col_name, r.col_name) == 0 &&
strcmp(l.col_type, r.col_type) == 0;
}
inline bool operator!=(const GncSqlColumnTableEntry& l,
const GncSqlColumnTableEntry& r)
{
return !(l == r);
}
/**
* information required to create a column in a table.
*/
@ -367,12 +399,12 @@ struct GncSqlColumnInfo
m_name{name}, m_type{type}, m_size{size}, m_unicode{unicode},
m_autoinc{autoinc}, m_primary_key{primary}, m_not_null{not_null}
{}
GncSqlColumnInfo(const GncSqlColumnTableEntry* e, GncSqlBasicColumnType t,
GncSqlColumnInfo(const GncSqlColumnTableEntry& e, GncSqlBasicColumnType t,
unsigned int size = 0, bool unicode = true) :
m_name{e->col_name}, m_type{t}, m_size{size}, m_unicode{unicode},
m_autoinc(e->flags & COL_AUTOINC),
m_primary_key(e->flags & COL_PKEY),
m_not_null(e->flags & COL_NNUL) {}
m_name{e.col_name}, m_type{t}, m_size{size}, m_unicode{unicode},
m_autoinc(e.flags & COL_AUTOINC),
m_primary_key(e.flags & COL_PKEY),
m_not_null(e.flags & COL_NNUL) {}
std::string m_name; /**< Column name */
GncSqlBasicColumnType m_type; /**< Column basic type */
unsigned int m_size; /**< Column size (string types) */
@ -404,15 +436,15 @@ typedef enum
typedef void (*GNC_SQL_LOAD_FN) (const GncSqlBackend* be,
GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table);
const GncSqlColumnTableEntry& table);
typedef void (*GNC_SQL_ADD_COL_INFO_TO_LIST_FN) (const GncSqlBackend* be,
const GncSqlColumnTableEntry* table_row,
const GncSqlColumnTableEntry& table_row,
ColVec& vec);
typedef void (*GNC_SQL_ADD_COLNAME_TO_LIST_FN) (const GncSqlColumnTableEntry* table_row, GList** pList);
typedef void (*GNC_SQL_ADD_COLNAME_TO_LIST_FN) (const GncSqlColumnTableEntry& table_row, GList** pList);
typedef void (*GNC_SQL_ADD_GVALUE_TO_SLIST_FN) (const GncSqlBackend* be,
QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry* table_row,
const GncSqlColumnTableEntry& table_row,
GSList** pList);
/**
@ -455,7 +487,7 @@ typedef struct
* @return Access function
*/
QofAccessFunc gnc_sql_get_getter (QofIdTypeConst obj_name,
const GncSqlColumnTableEntry* table_row);
const GncSqlColumnTableEntry& table_row);
/**
* Adds a column name to a list. If the column type spans multiple columns,
@ -464,7 +496,7 @@ QofAccessFunc gnc_sql_get_getter (QofIdTypeConst obj_name,
* @param table_row DB table column
* @param pList List
*/
void gnc_sql_add_colname_to_list (const GncSqlColumnTableEntry* table_row,
void gnc_sql_add_colname_to_list (const GncSqlColumnTableEntry& table_row,
GList** pList);
/**
@ -483,7 +515,7 @@ gboolean gnc_sql_do_db_operation (GncSqlBackend* be,
const gchar* table_name,
QofIdTypeConst obj_name,
gpointer pObject,
const GncSqlColumnTableEntry* table);
const EntryVec& table);
/**
* Executes an SQL SELECT statement and returns the result rows. If an error
@ -538,7 +570,7 @@ GncSqlStatement* gnc_sql_create_statement_from_sql (GncSqlBackend* be,
*/
void gnc_sql_load_object (const GncSqlBackend* be, GncSqlRow* row,
QofIdTypeConst obj_name, gpointer pObject,
const GncSqlColumnTableEntry* table);
const EntryVec& table);
/**
* Checks whether an object is in the database or not.
@ -552,8 +584,9 @@ void gnc_sql_load_object (const GncSqlBackend* be, GncSqlRow* row,
*/
gboolean gnc_sql_object_is_it_in_db (GncSqlBackend* be,
const gchar* table_name,
QofIdTypeConst obj_name, const gpointer pObject,
const GncSqlColumnTableEntry* table);
QofIdTypeConst obj_name,
const gpointer pObject,
const EntryVec& table );
/**
* Returns the version number for a DB table.
@ -581,7 +614,7 @@ gboolean gnc_sql_set_table_version (GncSqlBackend* be,
gboolean gnc_sql_create_table (GncSqlBackend* be,
const gchar* table_name,
gint table_version,
const GncSqlColumnTableEntry* col_table);
const EntryVec& col_table);
/**
* Creates a temporary table in the database. A temporary table does not
@ -594,7 +627,7 @@ gboolean gnc_sql_create_table (GncSqlBackend* be,
*/
gboolean gnc_sql_create_temp_table (const GncSqlBackend* be,
const gchar* table_name,
const GncSqlColumnTableEntry* col_table);
const EntryVec& col_table);
/**
* Creates an index in the database
@ -605,9 +638,8 @@ gboolean gnc_sql_create_temp_table (const GncSqlBackend* be,
* @param col_table Columns that the index should index
* @return TRUE if successful, FALSE if unsuccessful
*/
gboolean gnc_sql_create_index (const GncSqlBackend* be,
const gchar* index_name,
const gchar* table_name, const GncSqlColumnTableEntry* col_table);
gboolean gnc_sql_create_index (const GncSqlBackend* be, const char* index_name,
const char* table_name, const EntryVec& col_table);
/**
* Loads the object guid from a database row. The table must have a column
@ -662,7 +694,7 @@ void gnc_sql_register_col_type_handler (const gchar* colType,
void gnc_sql_add_gvalue_objectref_guid_to_slist (const GncSqlBackend* be,
QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry* table_row,
const GncSqlColumnTableEntry& table_row,
GSList** pList);
/**
@ -674,7 +706,7 @@ void gnc_sql_add_gvalue_objectref_guid_to_slist (const GncSqlBackend* be,
* @param pList List
*/
void gnc_sql_add_objectref_guid_col_info_to_list (const GncSqlBackend* be,
const GncSqlColumnTableEntry* table_row,
const GncSqlColumnTableEntry& table_row,
ColVec& vec);
/**
@ -695,9 +727,8 @@ guint gnc_sql_append_guid_list_to_sql (GString* str, GList* list,
* @param subtable Sub-column description table
* @param pList List
*/
void gnc_sql_add_subtable_colnames_to_list (const GncSqlColumnTableEntry*
table_row,
const GncSqlColumnTableEntry* subtable,
void gnc_sql_add_subtable_colnames_to_list (const GncSqlColumnTableEntry& table_row,
const EntryVec& subtable,
GList** pList);
/**
@ -739,7 +770,7 @@ void gnc_sql_finalize_version_info (GncSqlBackend* be);
gboolean gnc_sql_commit_standard_item (GncSqlBackend* be, QofInstance* inst,
const gchar* tableName,
QofIdTypeConst obj_name,
const GncSqlColumnTableEntry* col_table);
const EntryVec& col_table);
/**
* Gets an integer value (of any size) from a GValue.
@ -771,7 +802,7 @@ gchar* gnc_sql_convert_timespec_to_string (const GncSqlBackend* be,
* @param col_table Column table
*/
void gnc_sql_upgrade_table (GncSqlBackend* be, const gchar* table_name,
const GncSqlColumnTableEntry* col_table);
const EntryVec& col_table);
/**
* Adds one or more columns to an existing table.
@ -781,9 +812,8 @@ void gnc_sql_upgrade_table (GncSqlBackend* be, const gchar* table_name,
* @param new_col_table Column table for new columns
* @return TRUE if successful, FALSE if unsuccessful
*/
gboolean gnc_sql_add_columns_to_table (GncSqlBackend* be,
const gchar* table_name,
const GncSqlColumnTableEntry* new_col_table);
gboolean gnc_sql_add_columns_to_table (GncSqlBackend* be, const char* table_name,
const EntryVec& new_col_table);
/**
* Specifies the load order for a set of objects. When loading from a database,

View File

@ -61,7 +61,7 @@ static void bt_set_parent_guid (gpointer data, gpointer value);
#define TABLE_NAME "billterms"
#define TABLE_VERSION 2
static GncSqlColumnTableEntry col_table[] =
static EntryVec col_table
{
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
@ -83,13 +83,11 @@ static GncSqlColumnTableEntry col_table[] =
{ "discountdays", CT_INT, 0, 0, 0, GNC_BILLTERM_DISCDAYS },
{ "discount", CT_NUMERIC, 0, 0, 0, GNC_BILLTERM_DISCOUNT },
{ "cutoff", CT_INT, 0, 0, 0, GNC_BILLTERM_CUTOFF },
{ NULL }
};
static GncSqlColumnTableEntry billterm_parent_col_table[] =
static EntryVec billterm_parent_col_table
{
{ "parent", CT_GUID, 0, 0, NULL, NULL, NULL, (QofSetterFunc)bt_set_parent_guid },
{ NULL }
};
typedef struct
@ -353,7 +351,7 @@ gnc_sql_save_billterm (GncSqlBackend* be, QofInstance* inst)
static void
load_billterm_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -362,9 +360,8 @@ load_billterm_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -372,10 +369,10 @@ load_billterm_guid (const GncSqlBackend* be, GncSqlRow* row,
term = gncBillTermLookup (be->book, &guid);
if (term != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, term, NULL);
g_object_set (pObject, table_row.gobj_param_name, term, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -56,7 +56,7 @@ static void set_root_account_guid (gpointer pObject, gpointer pValue);
static gpointer get_root_template_guid (gpointer pObject);
static void set_root_template_guid (gpointer pObject, gpointer pValue);
static const GncSqlColumnTableEntry col_table[] =
static const EntryVec col_table
{
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{
@ -67,7 +67,6 @@ static const GncSqlColumnTableEntry col_table[] =
"root_template_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)get_root_template_guid, set_root_template_guid
},
{ NULL }
};
/* ================================================================= */

View File

@ -55,13 +55,12 @@ static QofLogModule log_module = G_LOG_DOMAIN;
#define BUDGET_MAX_NAME_LEN 2048
#define BUDGET_MAX_DESCRIPTION_LEN 2048
static const GncSqlColumnTableEntry col_table[] =
static const EntryVec col_table
{
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "name", CT_STRING, BUDGET_MAX_NAME_LEN, COL_NNUL, "name" },
{ "description", CT_STRING, BUDGET_MAX_DESCRIPTION_LEN, 0, "description" },
{ "num_periods", CT_INT, 0, COL_NNUL, "num_periods" },
{ NULL }
};
static QofInstance* get_budget (gpointer pObj);
@ -80,7 +79,7 @@ typedef struct
guint period_num;
} budget_amount_info_t;
static const GncSqlColumnTableEntry budget_amounts_col_table[] =
static const EntryVec budget_amounts_col_table
{
{ "id", CT_INT, 0, COL_NNUL | COL_PKEY | COL_AUTOINC },
{
@ -99,7 +98,6 @@ static const GncSqlColumnTableEntry budget_amounts_col_table[] =
"amount", CT_NUMERIC, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)get_amount, (QofSetterFunc)set_amount
},
{ NULL }
};
/* ================================================================= */
@ -484,7 +482,7 @@ write_budgets (GncSqlBackend* be)
static void
load_budget_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -493,9 +491,8 @@ load_budget_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -503,10 +500,10 @@ load_budget_guid (const GncSqlBackend* be, GncSqlRow* row,
budget = gnc_budget_lookup (&guid, be->book);
if (budget != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, budget, NULL);
g_object_set (pObject, table_row.gobj_param_name, budget, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -59,7 +59,7 @@ static void set_quote_source_name (gpointer pObject, gpointer pValue);
#define COMMODITY_MAX_QUOTESOURCE_LEN 2048
#define COMMODITY_MAX_QUOTE_TZ_LEN 2048
static const GncSqlColumnTableEntry col_table[] =
static const EntryVec col_table
{
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{
@ -77,7 +77,6 @@ static const GncSqlColumnTableEntry col_table[] =
(QofAccessFunc)get_quote_source_name, set_quote_source_name
},
{ "quote_tz", CT_STRING, COMMODITY_MAX_QUOTE_TZ_LEN, 0, "quote-tz" },
{ NULL }
};
/* ================================================================= */
@ -276,7 +275,7 @@ gnc_sql_commit_commodity (gnc_commodity* pCommodity)
static void
load_commodity_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -285,9 +284,8 @@ load_commodity_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -295,10 +293,10 @@ load_commodity_guid (const GncSqlBackend* be, GncSqlRow* row,
commodity = gnc_commodity_find_commodity_by_guid (&guid, be->book);
if (commodity != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, commodity, NULL);
g_object_set (pObject, table_row.gobj_param_name, commodity, NULL);
qof_instance_decrease_editlevel (pObject);
}
else if (setter != NULL)

View File

@ -58,8 +58,8 @@ static QofLogModule log_module = G_LOG_DOMAIN;
#define MAX_ID_LEN 2048
#define MAX_NOTES_LEN 2048
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, CUSTOMER_ID },
@ -83,8 +83,7 @@ static GncSqlColumnTableEntry col_table[] =
"taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
(QofAccessFunc)gncCustomerGetTaxTable, (QofSetterFunc)gncCustomerSetTaxTable
},
{ NULL }
};
});
static GncCustomer*
load_single_customer (GncSqlBackend* be, GncSqlRow* row)

View File

@ -58,8 +58,8 @@ static QofLogModule log_module = G_LOG_DOMAIN;
#define TABLE_NAME "employees"
#define TABLE_VERSION 2
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "username", CT_STRING, MAX_USERNAME_LEN, COL_NNUL, "username" },
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, "id" },
@ -71,8 +71,7 @@ static GncSqlColumnTableEntry col_table[] =
{ "workday", CT_NUMERIC, 0, COL_NNUL, "workday" },
{ "rate", CT_NUMERIC, 0, COL_NNUL, "rate" },
{ "addr", CT_ADDRESS, 0, 0, "address" },
{ NULL }
};
});
static GncEmployee*
load_single_employee (GncSqlBackend* be, GncSqlRow* row)

View File

@ -64,8 +64,8 @@ static QofLogModule log_module = G_LOG_DOMAIN;
static void entry_set_invoice (gpointer pObject, gpointer val);
static void entry_set_bill (gpointer pObject, gpointer val);
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "date", CT_TIMESPEC, 0, COL_NNUL, NULL, ENTRY_DATE },
{ "date_entered", CT_TIMESPEC, 0, 0, NULL, ENTRY_DATE_ENTERED },
@ -113,8 +113,7 @@ static GncSqlColumnTableEntry col_table[] =
"order_guid", CT_ORDERREF, 0, 0, NULL, NULL,
(QofAccessFunc)gncEntryGetOrder, (QofSetterFunc)gncEntrySetOrder
},
{ NULL }
};
});
static void
entry_set_invoice (gpointer pObject, gpointer val)

View File

@ -59,8 +59,8 @@ static QofLogModule log_module = G_LOG_DOMAIN;
#define MAX_NOTES_LEN 2048
#define MAX_BILLING_ID_LEN 2048
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, INVOICE_ID },
{ "date_opened", CT_TIMESPEC, 0, 0, NULL, INVOICE_OPENED },
@ -91,8 +91,7 @@ static GncSqlColumnTableEntry col_table[] =
"charge_amt", CT_NUMERIC, 0, 0, NULL, NULL,
(QofAccessFunc)gncInvoiceGetToChargeAmount, (QofSetterFunc)gncInvoiceSetToChargeAmount
},
{ NULL }
};
});
static GncInvoice*
load_single_invoice (GncSqlBackend* be, GncSqlRow* row)
@ -287,7 +286,7 @@ write_invoices (GncSqlBackend* be)
static void
load_invoice_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -296,9 +295,8 @@ load_invoice_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -306,10 +304,10 @@ load_invoice_guid (const GncSqlBackend* be, GncSqlRow* row,
invoice = gncInvoiceLookup (be->book, &guid);
if (invoice != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, invoice, NULL);
g_object_set (pObject, table_row.gobj_param_name, invoice, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -54,8 +54,8 @@ G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
#define MAX_NAME_LEN 2048
#define MAX_REFERENCE_LEN 2048
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, JOB_ID },
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
@ -68,8 +68,7 @@ static GncSqlColumnTableEntry col_table[] =
"owner", CT_OWNERREF, 0, 0, NULL, NULL,
(QofAccessFunc)gncJobGetOwner, (QofSetterFunc)gncJobSetOwner
},
{ NULL }
};
});
static GncJob*
load_single_job (GncSqlBackend* be, GncSqlRow* row)

View File

@ -54,16 +54,15 @@ static QofLogModule log_module = G_LOG_DOMAIN;
static gpointer get_lot_account (gpointer pObject);
static void set_lot_account (gpointer pObject, gpointer pValue);
static const GncSqlColumnTableEntry col_table[] =
{
static const EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{
"account_guid", CT_ACCOUNTREF, 0, 0, NULL, NULL,
(QofAccessFunc)get_lot_account, set_lot_account
},
{ "is_closed", CT_BOOLEAN, 0, COL_NNUL, "is-closed" },
{ NULL }
};
{ "is_closed", CT_BOOLEAN, 0, COL_NNUL, "is-closed" }
});
/* ================================================================= */
static gpointer
@ -217,7 +216,7 @@ write_lots (GncSqlBackend* be)
static void
load_lot_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -226,9 +225,8 @@ load_lot_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -236,10 +234,10 @@ load_lot_guid (const GncSqlBackend* be, GncSqlRow* row,
lot = gnc_lot_lookup (&guid, be->book);
if (lot != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, lot, NULL);
g_object_set (pObject, table_row.gobj_param_name, lot, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -54,8 +54,8 @@ static QofLogModule log_module = G_LOG_DOMAIN;
#define MAX_NOTES_LEN 2048
#define MAX_REFERENCE_LEN 2048
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, "id" },
{ "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, "notes" },
@ -64,8 +64,7 @@ static GncSqlColumnTableEntry col_table[] =
{ "date_opened", CT_TIMESPEC, 0, COL_NNUL, "date-opened" },
{ "date_closed", CT_TIMESPEC, 0, COL_NNUL, "date-closed" },
{ "owner", CT_OWNERREF, 0, COL_NNUL, NULL, ORDER_OWNER },
{ NULL },
};
});
static GncOrder*
load_single_order (GncSqlBackend* be, GncSqlRow* row)
@ -202,7 +201,7 @@ write_orders (GncSqlBackend* be)
static void
load_order_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -211,9 +210,8 @@ load_order_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -221,10 +219,10 @@ load_order_guid (const GncSqlBackend* be, GncSqlRow* row,
order = gncOrderLookup (be->book, &guid);
if (order != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, order, NULL);
g_object_set (pObject, table_row.gobj_param_name, order, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -51,7 +51,7 @@ typedef GncOwner* (*OwnerGetterFunc) (const gpointer);
static void
load_owner (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
gchar* buf;
@ -64,14 +64,13 @@ load_owner (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
book = be->book;
buf = g_strdup_printf ("%s_type", table_row->col_name);
buf = g_strdup_printf ("%s_type", table_row.col_name);
val = gnc_sql_row_get_value_at_col_name (row, buf);
type = (GncOwnerType)gnc_sql_get_integer_value (val);
g_free (buf);
buf = g_strdup_printf ("%s_guid", table_row->col_name);
buf = g_strdup_printf ("%s_guid", table_row.col_name);
val = gnc_sql_row_get_value_at_col_name (row, buf);
g_free (buf);
@ -156,10 +155,10 @@ load_owner (const GncSqlBackend* be, GncSqlRow* row,
PWARN ("Invalid owner type: %d\n", type);
}
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, &owner, NULL);
g_object_set (pObject, table_row.gobj_param_name, &owner, NULL);
qof_instance_decrease_editlevel (pObject);
}
else
@ -170,42 +169,42 @@ load_owner (const GncSqlBackend* be, GncSqlRow* row,
static void
add_owner_col_info_to_list(const GncSqlBackend* be,
const GncSqlColumnTableEntry* table_row,
const GncSqlColumnTableEntry& table_row,
ColVec& vec)
{
gchar* buf;
g_return_if_fail (be != NULL);
g_return_if_fail (table_row != NULL);
buf = g_strdup_printf ("%s_type", table_row->col_name);
buf = g_strdup_printf ("%s_type", table_row.col_name);
GncSqlColumnInfo info(buf, BCT_INT, 0, false, false,
table_row->flags & COL_PKEY,
table_row->flags & COL_NNUL);
table_row.flags & COL_PKEY,
table_row.flags & COL_NNUL);
vec.emplace_back(std::move(info));
buf = g_strdup_printf ("%s_guid", table_row->col_name);
buf = g_strdup_printf ("%s_guid", table_row.col_name);
GncSqlColumnInfo info2(buf, BCT_STRING, GUID_ENCODING_LENGTH,
false, false,
table_row->flags & COL_PKEY,
table_row->flags & COL_NNUL);
table_row.flags & COL_PKEY,
table_row.flags & COL_NNUL);
vec.emplace_back(std::move(info2));
}
static void
add_colname_to_list (const GncSqlColumnTableEntry* table_row, GList** pList)
add_colname_to_list (const GncSqlColumnTableEntry& table_row, GList** pList)
{
gchar* buf;
buf = g_strdup_printf ("%s_type", table_row->col_name);
buf = g_strdup_printf ("%s_type", table_row.col_name);
(*pList) = g_list_append ((*pList), buf);
buf = g_strdup_printf ("%s_guid", table_row->col_name);
buf = g_strdup_printf ("%s_guid", table_row.col_name);
(*pList) = g_list_append ((*pList), buf);
}
static void
add_gvalue_owner_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject, const GncSqlColumnTableEntry* table_row,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
GSList** pList)
{
GValue* subfield_value;
@ -220,14 +219,13 @@ add_gvalue_owner_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
g_return_if_fail (be != NULL);
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
getter = (OwnerGetterFunc)gnc_sql_get_getter (obj_name, table_row);
owner = (*getter) (pObject);
if (owner != NULL)
{
buf = g_strdup_printf ("%s_type", table_row->col_name);
buf = g_strdup_printf ("%s_type", table_row.col_name);
subfield_value = g_new0 (GValue, 1);
g_value_init (subfield_value, G_TYPE_INT);
type = gncOwnerGetType (owner);
@ -235,7 +233,7 @@ add_gvalue_owner_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
(*pList) = g_slist_append ((*pList), subfield_value);
g_free (buf);
buf = g_strdup_printf ("%s_guid", table_row->col_name);
buf = g_strdup_printf ("%s_guid", table_row.col_name);
subfield_value = g_new0 (GValue, 1);
switch (type)
{

View File

@ -53,17 +53,16 @@ static QofLogModule log_module = G_LOG_DOMAIN;
#define PRICE_MAX_SOURCE_LEN 2048
#define PRICE_MAX_TYPE_LEN 2048
static const GncSqlColumnTableEntry col_table[] =
{
static const EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "commodity_guid", CT_COMMODITYREF, 0, COL_NNUL, "commodity" },
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, "currency" },
{ "date", CT_TIMESPEC, 0, COL_NNUL, "date" },
{ "source", CT_STRING, PRICE_MAX_SOURCE_LEN, 0, "source" },
{ "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, "type" },
{ "value", CT_NUMERIC, 0, COL_NNUL, "value" },
{ NULL }
};
{ "value", CT_NUMERIC, 0, COL_NNUL, "value" }
});
/* ================================================================= */

View File

@ -69,8 +69,8 @@ static void set_recurrence_weekend_adjust (gpointer pObject, gpointer pValue);
static gpointer get_recurrence_period_start (gpointer pObject);
static void set_recurrence_period_start (gpointer pObject, gpointer pValue);
static const GncSqlColumnTableEntry col_table[] =
{
static const EntryVec col_table
({
{ "id", CT_INT, 0, COL_PKEY | COL_NNUL | COL_AUTOINC },
{
"obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
@ -91,29 +91,26 @@ static const GncSqlColumnTableEntry col_table[] =
{
"recurrence_weekend_adjust", CT_STRING, BUDGET_MAX_RECURRENCE_WEEKEND_ADJUST_LEN, COL_NNUL, NULL, NULL,
(QofAccessFunc)get_recurrence_weekend_adjust, set_recurrence_weekend_adjust
},
{ NULL }
};
}
});
/* Special column table because we need to be able to access the table by
a column other than the primary key */
static const GncSqlColumnTableEntry guid_col_table[] =
{
static const EntryVec guid_col_table
({
{
"obj_guid", CT_GUID, 0, 0, NULL, NULL,
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid
},
{ NULL }
};
}
});
/* Special column table used to upgrade table from version 1 to 2 */
static const GncSqlColumnTableEntry weekend_adjust_col_table[] =
{
static const EntryVec weekend_adjust_col_table
({
{
"recurrence_weekend_adjust", CT_STRING, BUDGET_MAX_RECURRENCE_WEEKEND_ADJUST_LEN, 0,
},
{ NULL }
};
}
});
/* ================================================================= */

View File

@ -55,8 +55,8 @@ G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
#define SX_MAX_NAME_LEN 2048
static const GncSqlColumnTableEntry col_table[] =
{
static const EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "name", CT_STRING, SX_MAX_NAME_LEN, 0, "name" },
{ "enabled", CT_BOOLEAN, 0, COL_NNUL, "enabled" },
@ -71,8 +71,7 @@ static const GncSqlColumnTableEntry col_table[] =
{ "adv_notify", CT_INT, 0, COL_NNUL, "advance-reminder-days" },
{ "instance_count", CT_INT, 0, COL_NNUL, "instance-count" },
{ "template_act_guid", CT_ACCOUNTREF, 0, COL_NNUL, "template-account" },
{ NULL }
};
});
/* ================================================================= */
static SchedXaction*

View File

@ -110,7 +110,7 @@ enum
gdate_val_col
};
static const GncSqlColumnTableEntry col_table[] =
static const EntryVec col_table
{
/* col_name, col_type, size, flags, g0bj_param_name, qof_param_name, getter, setter */
{ "id", CT_INT, 0, COL_PKEY | COL_NNUL | COL_AUTOINC },
@ -154,21 +154,18 @@ static const GncSqlColumnTableEntry col_table[] =
"gdate_val", CT_GDATE, 0, 0, NULL, NULL,
(QofAccessFunc)get_gdate_val, (QofSetterFunc)set_gdate_val
},
{ NULL }
};
/* Special column table because we need to be able to access the table by
a column other than the primary key */
static const GncSqlColumnTableEntry obj_guid_col_table[] =
static const EntryVec obj_guid_col_table
{
{ "obj_guid", CT_GUID, 0, 0, NULL, NULL, (QofAccessFunc)get_obj_guid, _retrieve_guid_ },
{ NULL }
};
static const GncSqlColumnTableEntry gdate_col_table[] =
static const EntryVec gdate_col_table
{
{ "gdate_val", CT_GDATE, 0, 0, },
{ NULL }
};
/* ================================================================= */
@ -751,7 +748,8 @@ gnc_sql_slots_delete (GncSqlBackend* be, const GncGUID* guid)
while (row != NULL)
{
GncSqlColumnTableEntry table_row = col_table[guid_val_col];
const GncSqlColumnTableEntry& table_row =
col_table[guid_val_col];
GncGUID child_guid;
const GValue* val =
gnc_sql_row_get_value_at_col_name (row, table_row.col_name);

View File

@ -65,8 +65,8 @@ static void tt_set_parent_guid (gpointer pObject, gpointer pValue);
#define TT_TABLE_NAME "taxtables"
#define TT_TABLE_VERSION 2
static GncSqlColumnTableEntry tt_col_table[] =
{
static EntryVec tt_col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
{ "refcount", CT_INT64, 0, COL_NNUL, "ref-count" },
@ -77,20 +77,18 @@ static GncSqlColumnTableEntry tt_col_table[] =
"parent", CT_GUID, 0, 0, NULL, NULL,
(QofAccessFunc)bt_get_parent, tt_set_parent
},
{ NULL }
};
});
static GncSqlColumnTableEntry tt_parent_col_table[] =
{
static EntryVec tt_parent_col_table
({
{ "parent", CT_GUID, 0, 0, NULL, NULL, NULL, tt_set_parent_guid },
{ NULL }
};
});
#define TTENTRIES_TABLE_NAME "taxtable_entries"
#define TTENTRIES_TABLE_VERSION 3
static GncSqlColumnTableEntry ttentries_col_table[] =
{
static EntryVec ttentries_col_table
({
{ "id", CT_INT, 0, COL_PKEY | COL_NNUL | COL_AUTOINC },
{
"taxtable", CT_TAXTABLEREF, 0, COL_NNUL, NULL, NULL,
@ -108,16 +106,14 @@ static GncSqlColumnTableEntry ttentries_col_table[] =
"type", CT_INT, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)gncTaxTableEntryGetType, (QofSetterFunc)gncTaxTableEntrySetType
},
{ NULL }
};
});
/* Special column table because we need to be able to access the table by
a column other than the primary key */
static GncSqlColumnTableEntry guid_col_table[] =
{
static EntryVec guid_col_table
({
{ "taxtable", CT_GUID, 0, 0, NULL, NULL, get_obj_guid, set_obj_guid },
{ NULL }
};
});
typedef struct
{
@ -511,7 +507,7 @@ write_taxtables (GncSqlBackend* be)
static void
load_taxtable_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -520,9 +516,8 @@ load_taxtable_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
if (val != NULL && G_VALUE_HOLDS_STRING (val) &&
g_value_get_string (val) != NULL)
{
@ -530,10 +525,10 @@ load_taxtable_guid (const GncSqlBackend* be, GncSqlRow* row,
taxtable = gncTaxTableLookup (be->book, &guid);
if (taxtable != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, taxtable, NULL);
g_object_set (pObject, table_row.gobj_param_name, taxtable, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -76,7 +76,7 @@ typedef struct
#define TX_MAX_NUM_LEN 2048
#define TX_MAX_DESCRIPTION_LEN 2048
static const GncSqlColumnTableEntry tx_col_table[] =
static const EntryVec tx_col_table
{
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, "currency" },
@ -84,7 +84,6 @@ static const GncSqlColumnTableEntry tx_col_table[] =
{ "post_date", CT_TIMESPEC, 0, 0, "post-date" },
{ "enter_date", CT_TIMESPEC, 0, 0, "enter-date" },
{ "description", CT_STRING, TX_MAX_DESCRIPTION_LEN, 0, "description" },
{ NULL }
};
static gpointer get_split_reconcile_state (gpointer pObject);
@ -94,7 +93,7 @@ static void set_split_lot (gpointer pObject, gpointer pLot);
#define SPLIT_MAX_MEMO_LEN 2048
#define SPLIT_MAX_ACTION_LEN 2048
static const GncSqlColumnTableEntry split_col_table[] =
static const EntryVec split_col_table
{
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "tx_guid", CT_TXREF, 0, COL_NNUL, "transaction" },
@ -112,25 +111,21 @@ static const GncSqlColumnTableEntry split_col_table[] =
"lot_guid", CT_LOTREF, 0, 0, NULL, NULL,
(QofAccessFunc)xaccSplitGetLot, set_split_lot
},
{ NULL }
};
static const GncSqlColumnTableEntry post_date_col_table[] =
static const EntryVec post_date_col_table
{
{ "post_date", CT_TIMESPEC, 0, 0, "post-date" },
{ NULL }
};
static const GncSqlColumnTableEntry account_guid_col_table[] =
static const EntryVec account_guid_col_table
{
{ "account_guid", CT_ACCOUNTREF, 0, COL_NNUL, "account" },
{ NULL }
};
static const GncSqlColumnTableEntry tx_guid_col_table[] =
static const EntryVec tx_guid_col_table
{
{ "tx_guid", CT_GUID, 0, 0, "guid" },
{ NULL }
};
/* ================================================================= */
@ -1322,12 +1317,11 @@ set_acct_bal_balance (gpointer pObject, gnc_numeric value)
bal->balance = value;
}
static const GncSqlColumnTableEntry acct_balances_col_table[] =
static const EntryVec acct_balances_col_table
{
{ "account_guid", CT_GUID, 0, 0, NULL, NULL, NULL, (QofSetterFunc)set_acct_bal_account_from_guid },
{ "reconcile_state", CT_STRING, 1, 0, NULL, NULL, NULL, (QofSetterFunc)set_acct_bal_reconcile_state },
{ "quantity", CT_NUMERIC, 0, 0, NULL, NULL, NULL, (QofSetterFunc)set_acct_bal_balance },
{ NULL }
};
G_GNUC_UNUSED static single_acct_balance_t*
@ -1444,7 +1438,7 @@ gnc_sql_get_account_balances_slist (GncSqlBackend* be)
static void
load_tx_guid (const GncSqlBackend* be, GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry* table_row)
const GncSqlColumnTableEntry& table_row)
{
const GValue* val;
GncGUID guid;
@ -1454,9 +1448,8 @@ load_tx_guid (const GncSqlBackend* be, GncSqlRow* row,
g_return_if_fail (be != NULL);
g_return_if_fail (row != NULL);
g_return_if_fail (pObject != NULL);
g_return_if_fail (table_row != NULL);
val = gnc_sql_row_get_value_at_col_name (row, table_row->col_name);
val = gnc_sql_row_get_value_at_col_name (row, table_row.col_name);
g_assert (val != NULL);
guid_str = g_value_get_string (val);
if (guid_str != NULL)
@ -1480,10 +1473,10 @@ load_tx_guid (const GncSqlBackend* be, GncSqlRow* row,
if (tx != NULL)
{
if (table_row->gobj_param_name != NULL)
if (table_row.gobj_param_name != NULL)
{
qof_instance_increase_editlevel (pObject);
g_object_set (pObject, table_row->gobj_param_name, tx, NULL);
g_object_set (pObject, table_row.gobj_param_name, tx, NULL);
qof_instance_decrease_editlevel (pObject);
}
else

View File

@ -61,8 +61,8 @@ G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
#define TABLE_NAME "vendors"
#define TABLE_VERSION 1
static GncSqlColumnTableEntry col_table[] =
{
static EntryVec col_table
({
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, "id" },
@ -74,8 +74,7 @@ static GncSqlColumnTableEntry col_table[] =
{ "terms", CT_BILLTERMREF, 0, 0, "terms" },
{ "tax_inc", CT_STRING, MAX_TAX_INC_LEN, 0, "tax-included-string" },
{ "tax_table", CT_TAXTABLEREF, 0, 0, "tax-table" },
{ NULL }
};
});
static GncVendor*
load_single_vendor (GncSqlBackend* be, GncSqlRow* row)

View File

@ -386,7 +386,7 @@ test_set_autoinc_id (Fixture *fixture, gconstpointer pData)
{
}*/
/* gnc_sql_get_getter
gnc_sql_get_getter (QofIdTypeConst obj_name, const GncSqlColumnTableEntry* table_row)// C: 3 in 2 */
gnc_sql_get_getter (QofIdTypeConst obj_name, const GncSqlColumnTableEntry& table_row)// C: 3 in 2 */
/* static void
test_gnc_sql_get_getter (Fixture *fixture, gconstpointer pData)
{
@ -394,7 +394,7 @@ test_gnc_sql_get_getter (Fixture *fixture, gconstpointer pData)
// Make Static
/* gnc_sql_add_colname_to_list
void
gnc_sql_add_colname_to_list (const GncSqlColumnTableEntry* table_row, GList** pList)// 9
gnc_sql_add_colname_to_list (const GncSqlColumnTableEntry& table_row, GList** pList)// 9
*/
/* static void
test_gnc_sql_add_colname_to_list (Fixture *fixture, gconstpointer pData)
@ -402,7 +402,7 @@ test_gnc_sql_add_colname_to_list (Fixture *fixture, gconstpointer pData)
}*/
/* gnc_sql_add_subtable_colnames_to_list
void
gnc_sql_add_subtable_colnames_to_list (const GncSqlColumnTableEntry* table_row, const GncSqlColumnTableEntry* subtable,
gnc_sql_add_subtable_colnames_to_list (const GncSqlColumnTableEntry& table_row, const EntryVec& subtable,
GList** pList)// C: 1 */
/* static void
test_gnc_sql_add_subtable_colnames_to_list (Fixture *fixture, gconstpointer pData)
@ -411,7 +411,7 @@ test_gnc_sql_add_subtable_colnames_to_list (Fixture *fixture, gconstpointer pDat
/* load_string
static void
load_string (const GncSqlBackend* be, GncSqlRow* row,
const GncSqlColumnTableEntry* table_row)// 2
const GncSqlColumnTableEntry& table_row)// 2
*/
/* static void
test_load_string (Fixture *fixture, gconstpointer pData)
@ -419,7 +419,7 @@ test_load_string (Fixture *fixture, gconstpointer pData)
}*/
/* add_string_col_info_to_list
static void
add_string_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
add_string_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,
GList** pList)// 2
*/
/* static void
@ -429,7 +429,7 @@ test_add_string_col_info_to_list (Fixture *fixture, gconstpointer pData)
/* add_gvalue_string_to_slist
static void
add_gvalue_string_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList)// 2
const gpointer pObject, const GncSqlColumnTableEntry& table_row, GSList** pList)// 2
*/
/* static void
test_add_gvalue_string_to_slist (Fixture *fixture, gconstpointer pData)
@ -445,7 +445,7 @@ test_load_int (Fixture *fixture, gconstpointer pData)
}*/
/* add_int_col_info_to_list
static void
add_int_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 2
add_int_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_int_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -469,7 +469,7 @@ test_load_boolean (Fixture *fixture, gconstpointer pData)
}*/
/* add_boolean_col_info_to_list
static void
add_boolean_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 2
add_boolean_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_boolean_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -493,7 +493,7 @@ test_load_int64 (Fixture *fixture, gconstpointer pData)
}*/
/* add_int64_col_info_to_list
static void
add_int64_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 2
add_int64_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_int64_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -517,7 +517,7 @@ test_load_double (Fixture *fixture, gconstpointer pData)
}*/
/* add_double_col_info_to_list
static void
add_double_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 2
add_double_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_double_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -541,7 +541,7 @@ test_load_guid (Fixture *fixture, gconstpointer pData)
}*/
/* add_guid_col_info_to_list
static void
add_guid_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 3
add_guid_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 3
*/
/* static void
test_add_guid_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -618,7 +618,7 @@ test_load_timespec (Fixture *fixture, gconstpointer pData)
}*/
/* add_timespec_col_info_to_list
static void
add_timespec_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 2
add_timespec_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_timespec_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -642,7 +642,7 @@ test_load_date (Fixture *fixture, gconstpointer pData)
}*/
/* add_date_col_info_to_list
static void
add_date_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 2
add_date_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_date_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -666,7 +666,7 @@ test_load_numeric (Fixture *fixture, gconstpointer pData)
}*/
/* add_numeric_col_info_to_list
static void
add_numeric_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,// 2
add_numeric_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_numeric_col_info_to_list (Fixture *fixture, gconstpointer pData)
@ -674,7 +674,7 @@ test_add_numeric_col_info_to_list (Fixture *fixture, gconstpointer pData)
}*/
/* add_numeric_colname_to_list
static void
add_numeric_colname_to_list (const GncSqlColumnTableEntry* table_row, GList** pList)// 2
add_numeric_colname_to_list (const GncSqlColumnTableEntry& table_row, GList** pList)// 2
*/
/* static void
test_add_numeric_colname_to_list (Fixture *fixture, gconstpointer pData)
@ -689,7 +689,7 @@ test_add_gvalue_numeric_to_slist (Fixture *fixture, gconstpointer pData)
{
}*/
/* get_handler
get_handler (const GncSqlColumnTableEntry* table_row)// C: 1 */
get_handler (const GncSqlColumnTableEntry& table_row)// C: 1 */
/* static void
test_get_handler (Fixture *fixture, gconstpointer pData)
{