diff --git a/src/backend/sql/gnc-account-sql.c b/src/backend/sql/gnc-account-sql.c index 9600507ef3..1d7f2b70f8 100644 --- a/src/backend/sql/gnc-account-sql.c +++ b/src/backend/sql/gnc-account-sql.c @@ -341,7 +341,7 @@ load_account_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t account_guid_handler +static GncSqlColumnTypeHandler account_guid_handler = { load_account_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list, diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c index 9ea16d51a4..146005e37b 100644 --- a/src/backend/sql/gnc-backend-sql.c +++ b/src/backend/sql/gnc-backend-sql.c @@ -989,7 +989,7 @@ add_gvalue_string_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t string_handler +static GncSqlColumnTypeHandler string_handler = { load_string, add_string_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1072,7 +1072,7 @@ add_gvalue_int_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t int_handler +static GncSqlColumnTypeHandler int_handler = { load_int, add_int_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1155,7 +1155,7 @@ add_gvalue_boolean_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t boolean_handler +static GncSqlColumnTypeHandler boolean_handler = { load_boolean, add_boolean_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1231,7 +1231,7 @@ add_gvalue_int64_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t int64_handler +static GncSqlColumnTypeHandler int64_handler = { load_int64, add_int64_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1311,7 +1311,7 @@ add_gvalue_double_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t double_handler +static GncSqlColumnTypeHandler double_handler = { load_double, add_double_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1391,7 +1391,7 @@ add_gvalue_guid_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t guid_handler +static GncSqlColumnTypeHandler guid_handler = { load_guid, add_guid_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1538,7 +1538,7 @@ add_gvalue_timespec_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t timespec_handler +static GncSqlColumnTypeHandler timespec_handler = { load_timespec, add_timespec_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1631,7 +1631,7 @@ add_gvalue_date_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), value ); } -static col_type_handler_t date_handler +static GncSqlColumnTypeHandler date_handler = { load_date, add_date_col_info_to_list, gnc_sql_add_colname_to_list, @@ -1751,7 +1751,7 @@ add_gvalue_numeric_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, (*pList) = g_slist_append( (*pList), denom_value ); } -static col_type_handler_t numeric_handler +static GncSqlColumnTypeHandler numeric_handler = { load_numeric, add_numeric_col_info_to_list, add_numeric_colname_to_list, @@ -1761,7 +1761,7 @@ static col_type_handler_t numeric_handler static GHashTable* g_columnTypeHash = NULL; void -gnc_sql_register_col_type_handler( const gchar* colType, const col_type_handler_t* handler ) +gnc_sql_register_col_type_handler( const gchar* colType, const GncSqlColumnTypeHandler* handler ) { g_return_if_fail( colType != NULL ); g_return_if_fail( handler != NULL ); @@ -1774,10 +1774,10 @@ gnc_sql_register_col_type_handler( const gchar* colType, const col_type_handler_ DEBUG( "Col type %s registered\n", colType ); } -static col_type_handler_t* +static GncSqlColumnTypeHandler* get_handler( const GncSqlColumnTableEntry* table_row ) { - col_type_handler_t* pHandler; + GncSqlColumnTypeHandler* pHandler; g_return_val_if_fail( table_row != NULL, NULL ); g_return_val_if_fail( table_row->col_type != NULL, NULL ); @@ -1864,7 +1864,7 @@ gnc_sql_load_object( const GncSqlBackend* be, GncSqlRow* row, { int col; QofSetterFunc setter; - col_type_handler_t* pHandler; + GncSqlColumnTypeHandler* pHandler; g_return_if_fail( be != NULL ); g_return_if_fail( row != NULL ); @@ -2043,7 +2043,7 @@ gnc_sql_object_is_it_in_db( GncSqlBackend* be, const gchar* table_name, { GncSqlStatement* sqlStmt; int count; - col_type_handler_t* pHandler; + GncSqlColumnTypeHandler* pHandler; GSList* list = NULL; g_return_val_if_fail( be != NULL, FALSE ); @@ -2109,7 +2109,7 @@ create_gslist_from_values( GncSqlBackend* be, const GncSqlColumnTableEntry* table ) { GSList* list = NULL; - col_type_handler_t* pHandler; + GncSqlColumnTypeHandler* pHandler; const GncSqlColumnTableEntry* table_row; for( table_row = table; table_row->col_name != NULL; table_row++ ) { @@ -2222,7 +2222,7 @@ build_update_statement( GncSqlBackend* be, // Get all col names and all values for( ; table_row->col_name != NULL; table_row++ ) { - col_type_handler_t* pHandler; + GncSqlColumnTypeHandler* pHandler; // Add col names to the list pHandler = get_handler( table_row ); @@ -2270,7 +2270,7 @@ build_delete_statement( GncSqlBackend* be, { GncSqlStatement* stmt; GString* sql; - col_type_handler_t* pHandler; + GncSqlColumnTypeHandler* pHandler; GSList* list = NULL; gchar* sqlbuf; @@ -2334,7 +2334,7 @@ create_table( const GncSqlBackend* be, const gchar* table_name, g_return_val_if_fail( col_table != NULL, FALSE ); for( ; col_table->col_name != NULL; col_table++ ) { - col_type_handler_t* pHandler; + GncSqlColumnTypeHandler* pHandler; pHandler = get_handler( col_table ); pHandler->add_col_info_to_list_fn( be, col_table, &col_info_list ); diff --git a/src/backend/sql/gnc-backend-sql.h b/src/backend/sql/gnc-backend-sql.h index 76baa784ce..2cd92160ee 100644 --- a/src/backend/sql/gnc-backend-sql.h +++ b/src/backend/sql/gnc-backend-sql.h @@ -237,7 +237,7 @@ struct GncSqlResult * @struct GncSqlObjectBackend * * Struct used to handle a specific engine object type for an SQL backend. - * This * handler should be registered with qof_object_register_backend(). + * This handler should be registered with qof_object_register_backend(). * * commit() - commit an object to the db * initial_load() - load stuff when new db opened @@ -271,6 +271,9 @@ typedef struct /** * @struct GncSqlColumnInfo + * + * The GncSqlColumnInfo structure contains information required to create + * a column in a table. */ typedef struct { const gchar* name; /**< Column name */ @@ -299,7 +302,17 @@ typedef struct { * @struct GncSqlColumnTableEntry * * The GncSqlColumnTableEntry struct contains all of the information - * required to copy information between an object and the database. + * 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 + * gobj_param_name value is NULL but qof_param_name is not NULL, this value + * is used as the parameter name for a call to + * qof_class_get_parameter_getter(). If both of these values are NULL, getter + * and setter are the addresses of routines to return or set the parameter + * value, respectively. + * * The database description for an object consists of an array of * GncSqlColumnTableEntry objects, with a final member having col_name == NULL. */ @@ -307,10 +320,10 @@ struct GncSqlColumnTableEntry { const gchar* col_name; /**< Column name */ const gchar* col_type; /**< Column type */ gint size; /**< Column size in bytes, for string columns */ -#define COL_PKEY 0x01 -#define COL_NNUL 0x02 -#define COL_UNIQUE 0x04 -#define COL_AUTOINC 0x08 +#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 */ @@ -336,12 +349,36 @@ typedef void (*GNC_SQL_ADD_GVALUE_TO_SLIST_FN)( const GncSqlBackend* be, QofIdTypeConst obj_name, const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList ); +/** + * @struct GncSqlColumnTypeHandler + * + * The GncSqlColumnTypeHandler struct contains pointers to routines to handle + * different options for a specific column type. + * + * A column type maps a property value to one or more columns in the database. + */ typedef struct { + /** + * Routine to load a value into an object from the database row. + */ GNC_SQL_LOAD_FN load_fn; + + /** + * Routine to add a GncSqlColumnInfo structure for the column type to a + * GList. + */ GNC_SQL_ADD_COL_INFO_TO_LIST_FN add_col_info_to_list_fn; + + /** + * Routine to add a column name string for the column type to a GList. + */ GNC_SQL_ADD_COLNAME_TO_LIST_FN add_colname_to_list_fn; + + /** + * Routine to add a GValue for the property to a GSList. + */ GNC_SQL_ADD_GVALUE_TO_SLIST_FN add_gvalue_to_slist_fn; -} col_type_handler_t; +} GncSqlColumnTypeHandler; /** * Returns the QOF access function for a column. @@ -502,7 +539,7 @@ GncSqlStatement* gnc_sql_create_select_statement( const GncSqlBackend* be, * @param colType Column type * @param handler Column handler */ -void gnc_sql_register_col_type_handler( const gchar* colType, const col_type_handler_t* handler ); +void gnc_sql_register_col_type_handler( const gchar* colType, const GncSqlColumnTypeHandler* handler ); /** * Adds a GValue for an object reference GUID to the end of a GSList. diff --git a/src/backend/sql/gnc-commodity-sql.c b/src/backend/sql/gnc-commodity-sql.c index f1503f5c96..ed8eca23cb 100644 --- a/src/backend/sql/gnc-commodity-sql.c +++ b/src/backend/sql/gnc-commodity-sql.c @@ -236,7 +236,7 @@ load_commodity_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t commodity_guid_handler +static GncSqlColumnTypeHandler commodity_guid_handler = { load_commodity_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list, diff --git a/src/backend/sql/gnc-lots-sql.c b/src/backend/sql/gnc-lots-sql.c index 8acdb0ac7a..403c5a0730 100644 --- a/src/backend/sql/gnc-lots-sql.c +++ b/src/backend/sql/gnc-lots-sql.c @@ -221,7 +221,7 @@ load_lot_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t lot_guid_handler +static GncSqlColumnTypeHandler lot_guid_handler = { load_lot_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list, diff --git a/src/backend/sql/gnc-transaction-sql.c b/src/backend/sql/gnc-transaction-sql.c index d7b67375b1..3496eaf738 100644 --- a/src/backend/sql/gnc-transaction-sql.c +++ b/src/backend/sql/gnc-transaction-sql.c @@ -714,7 +714,7 @@ load_tx_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t tx_guid_handler +static GncSqlColumnTypeHandler tx_guid_handler = { load_tx_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list, diff --git a/src/business/business-core/sql/gnc-address-sql.c b/src/business/business-core/sql/gnc-address-sql.c index a5337860ee..e8fd3165d7 100644 --- a/src/business/business-core/sql/gnc-address-sql.c +++ b/src/business/business-core/sql/gnc-address-sql.c @@ -197,7 +197,7 @@ add_gvalue_address_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, } } -static col_type_handler_t address_handler +static GncSqlColumnTypeHandler address_handler = { load_address, add_address_col_info_to_list, add_address_colname_to_list, diff --git a/src/business/business-core/sql/gnc-bill-term-sql.c b/src/business/business-core/sql/gnc-bill-term-sql.c index fd1fbeab66..b70952fc5d 100644 --- a/src/business/business-core/sql/gnc-bill-term-sql.c +++ b/src/business/business-core/sql/gnc-bill-term-sql.c @@ -215,7 +215,7 @@ load_billterm_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t billterm_guid_handler +static GncSqlColumnTypeHandler billterm_guid_handler = { load_billterm_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list, diff --git a/src/business/business-core/sql/gnc-invoice-sql.c b/src/business/business-core/sql/gnc-invoice-sql.c index d4a6860393..a572998f3a 100644 --- a/src/business/business-core/sql/gnc-invoice-sql.c +++ b/src/business/business-core/sql/gnc-invoice-sql.c @@ -261,7 +261,7 @@ load_invoice_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t invoice_guid_handler +static GncSqlColumnTypeHandler invoice_guid_handler = { load_invoice_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list, diff --git a/src/business/business-core/sql/gnc-order-sql.c b/src/business/business-core/sql/gnc-order-sql.c index af25b1b9de..442eb36435 100644 --- a/src/business/business-core/sql/gnc-order-sql.c +++ b/src/business/business-core/sql/gnc-order-sql.c @@ -217,7 +217,7 @@ load_order_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t order_guid_handler +static GncSqlColumnTypeHandler order_guid_handler = { load_order_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list, diff --git a/src/business/business-core/sql/gnc-owner-sql.c b/src/business/business-core/sql/gnc-owner-sql.c index 62816e8740..bf1e54a3dd 100644 --- a/src/business/business-core/sql/gnc-owner-sql.c +++ b/src/business/business-core/sql/gnc-owner-sql.c @@ -269,7 +269,7 @@ add_gvalue_owner_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name, } } -static col_type_handler_t owner_handler +static GncSqlColumnTypeHandler owner_handler = { load_owner, add_owner_col_info_to_list, add_colname_to_list, diff --git a/src/business/business-core/sql/gnc-tax-table-sql.c b/src/business/business-core/sql/gnc-tax-table-sql.c index a4783ad83a..7b4ec1e8b8 100644 --- a/src/business/business-core/sql/gnc-tax-table-sql.c +++ b/src/business/business-core/sql/gnc-tax-table-sql.c @@ -386,7 +386,7 @@ load_taxtable_guid( const GncSqlBackend* be, GncSqlRow* row, } } -static col_type_handler_t taxtable_guid_handler +static GncSqlColumnTypeHandler taxtable_guid_handler = { load_taxtable_guid, gnc_sql_add_objectref_guid_col_info_to_list, gnc_sql_add_colname_to_list,