r18244 - gnucash/trunk/src - Add autoincrementing int primary column 'id' to recurrences, slots and taxtable_entries tables.
Phil Longstaff
plongstaff at code.gnucash.org
Tue Aug 11 19:51:37 EDT 2009
Author: plongstaff
Date: 2009-08-11 19:51:37 -0400 (Tue, 11 Aug 2009)
New Revision: 18244
Trac: http://svn.gnucash.org/trac/changeset/18244
Modified:
gnucash/trunk/src/backend/sql/gnc-backend-sql.c
gnucash/trunk/src/backend/sql/gnc-recurrence-sql.c
gnucash/trunk/src/backend/sql/gnc-slots-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c
Log:
Add autoincrementing int primary column 'id' to recurrences, slots and taxtable_entries tables.
THIS REQUIRES THAT YOUR DATABASE BE DELETED AND RECREATED - You can back it up to an XML file.
Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.c 2009-08-09 22:28:34 UTC (rev 18243)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.c 2009-08-11 23:51:37 UTC (rev 18244)
@@ -945,7 +945,7 @@
/*@ null @*/ static gpointer
get_autoinc_id()
{
- // Just need a 0 to force a new recurrence id
+ // Just need a 0 to force a new autoinc value
return (gpointer)0;
}
@@ -998,7 +998,7 @@
static GncSqlColumnInfo*
create_column_info( const GncSqlColumnTableEntry* table_row, GType type,
- gint size, gboolean is_unicode )
+ gint size, gboolean is_unicode, gboolean is_autoinc )
{
GncSqlColumnInfo* info;
@@ -1010,6 +1010,7 @@
info->is_primary_key = ((table_row->flags & COL_PKEY) != 0) ? TRUE : FALSE;
info->null_allowed = ((table_row->flags & COL_NNUL) != 0) ? FALSE : TRUE;
info->is_unicode = is_unicode;
+ info->is_autoinc = is_autoinc;
return info;
}
@@ -1049,7 +1050,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_STRING, table_row->size, TRUE );
+ info = create_column_info( table_row, G_TYPE_STRING, table_row->size, TRUE, FALSE );
*pList = g_list_append( *pList, info );
}
@@ -1135,7 +1136,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_INT, 0, FALSE );
+ info = create_column_info( table_row, G_TYPE_INT, 0, FALSE, ((table_row->flags & COL_AUTOINC) != 0) );
*pList = g_list_append( *pList, info );
}
@@ -1219,7 +1220,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_INT, 0, FALSE );
+ info = create_column_info( table_row, G_TYPE_INT, 0, FALSE, FALSE );
*pList = g_list_append( *pList, info );
}
@@ -1296,7 +1297,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_INT64, 0, FALSE );
+ info = create_column_info( table_row, G_TYPE_INT64, 0, FALSE, FALSE );
*pList = g_list_append( *pList, info );
}
@@ -1375,7 +1376,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_DOUBLE, 0, FALSE );
+ info = create_column_info( table_row, G_TYPE_DOUBLE, 0, FALSE, FALSE );
*pList = g_list_append( *pList, info );
}
@@ -1460,7 +1461,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_STRING, GUID_ENCODING_LENGTH, FALSE );
+ info = create_column_info( table_row, G_TYPE_STRING, GUID_ENCODING_LENGTH, FALSE, FALSE );
*pList = g_list_append( *pList, info );
}
@@ -1626,7 +1627,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_STRING, TIMESPEC_COL_SIZE, FALSE );
+ info = create_column_info( table_row, G_TYPE_STRING, TIMESPEC_COL_SIZE, FALSE, FALSE );
*pList = g_list_append( *pList, info );
}
@@ -1724,7 +1725,7 @@
g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != NULL );
- info = create_column_info( table_row, G_TYPE_STRING, DATE_COL_SIZE, FALSE );
+ info = create_column_info( table_row, G_TYPE_STRING, DATE_COL_SIZE, FALSE, FALSE );
*pList = g_list_append( *pList, info );
}
@@ -2345,6 +2346,9 @@
GSList* values;
GSList* node;
gchar* sqlbuf;
+ GList* colnames = NULL;
+ GList* colname;
+ const GncSqlColumnTableEntry* table_row;
g_return_val_if_fail( be != NULL, NULL );
g_return_val_if_fail( table_name != NULL, NULL );
@@ -2352,9 +2356,32 @@
g_return_val_if_fail( pObject != NULL, NULL );
g_return_val_if_fail( table != NULL, NULL );
- sqlbuf = g_strdup_printf( "INSERT INTO %s VALUES(", table_name );
+ sqlbuf = g_strdup_printf( "INSERT INTO %s(", table_name );
sql = g_string_new( sqlbuf );
g_free( sqlbuf );
+
+ // Get all col names and all values
+ for( table_row = table; table_row->col_name != NULL; table_row++ ) {
+ if(( table_row->flags & COL_AUTOINC ) == 0 ) {
+ GncSqlColumnTypeHandler* pHandler;
+
+ // Add col names to the list
+ pHandler = get_handler( table_row );
+ g_assert( pHandler != NULL );
+ pHandler->add_colname_to_list_fn( table_row, &colnames );
+ }
+ }
+ g_assert( colnames != NULL );
+
+ for( colname = colnames; colname != NULL; colname = colname->next ) {
+ if( colname != colnames ) {
+ g_string_append( sql, "," );
+ }
+ g_string_append( sql, (gchar*)colname->data );
+ }
+ g_list_free( colnames );
+
+ g_string_append( sql, ") VALUES(" );
values = create_gslist_from_values( be, obj_name, pObject, table );
for( node = values; node != NULL; node = node->next ) {
GValue* value = (GValue*)node->data;
@@ -2390,7 +2417,7 @@
GSList* value;
GList* colname;
gboolean firstCol;
- const GncSqlColumnTableEntry* table_row = table;
+ const GncSqlColumnTableEntry* table_row;
gchar* sqlbuf;
g_return_val_if_fail( be != NULL, NULL );
@@ -2400,13 +2427,15 @@
g_return_val_if_fail( table != NULL, NULL );
// Get all col names and all values
- for( ; table_row->col_name != NULL; table_row++ ) {
- GncSqlColumnTypeHandler* pHandler;
+ for( table_row = table; table_row->col_name != NULL; table_row++ ) {
+ if(( table_row->flags & COL_AUTOINC ) == 0 ) {
+ GncSqlColumnTypeHandler* pHandler;
- // Add col names to the list
- pHandler = get_handler( table_row );
- g_assert( pHandler != NULL );
- pHandler->add_colname_to_list_fn( table_row, &colnames );
+ // Add col names to the list
+ pHandler = get_handler( table_row );
+ g_assert( pHandler != NULL );
+ pHandler->add_colname_to_list_fn( table_row, &colnames );
+ }
}
g_assert( colnames != NULL );
values = create_gslist_from_values( be, obj_name, pObject, table );
Modified: gnucash/trunk/src/backend/sql/gnc-recurrence-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-recurrence-sql.c 2009-08-09 22:28:34 UTC (rev 18243)
+++ gnucash/trunk/src/backend/sql/gnc-recurrence-sql.c 2009-08-11 23:51:37 UTC (rev 18244)
@@ -67,6 +67,7 @@
static const GncSqlColumnTableEntry col_table[] =
{
/*@ -full_init_block @*/
+ { "id", CT_INT, 0, COL_PKEY|COL_NNUL|COL_AUTOINC },
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid },
{ "recurrence_mult", CT_INT, 0, COL_NNUL, NULL, NULL,
Modified: gnucash/trunk/src/backend/sql/gnc-slots-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-slots-sql.c 2009-08-09 22:28:34 UTC (rev 18243)
+++ gnucash/trunk/src/backend/sql/gnc-slots-sql.c 2009-08-11 23:51:37 UTC (rev 18244)
@@ -81,6 +81,7 @@
static const GncSqlColumnTableEntry col_table[] =
{
/*@ -full_init_block @*/
+ { "id", CT_INT, 0, COL_PKEY|COL_NNUL|COL_AUTOINC },
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid },
{ "name", CT_STRING, SLOT_MAX_PATHNAME_LEN, COL_NNUL, NULL, NULL,
Modified: gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c 2009-08-09 22:28:34 UTC (rev 18243)
+++ gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c 2009-08-11 23:51:37 UTC (rev 18244)
@@ -78,10 +78,11 @@
};
#define TTENTRIES_TABLE_NAME "taxtable_entries"
-#define TTENTRIES_TABLE_VERSION 2
+#define TTENTRIES_TABLE_VERSION 3
static GncSqlColumnTableEntry ttentries_col_table[] =
{
+ { "id", CT_INT, 0, COL_PKEY|COL_NNUL|COL_AUTOINC },
{ "taxtable", CT_TAXTABLEREF, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)gncTaxTableEntryGetTable, set_obj_guid },
{ "account", CT_ACCOUNTREF, 0, COL_NNUL, NULL, NULL,
More information about the gnucash-changes
mailing list