r18057 - gnucash/trunk/src/backend - Create an index for the slots table indexed on the obj guid. This is the last piece of
Phil Longstaff
plongstaff at code.gnucash.org
Sat Apr 25 21:08:19 EDT 2009
Author: plongstaff
Date: 2009-04-25 21:08:18 -0400 (Sat, 25 Apr 2009)
New Revision: 18057
Trac: http://svn.gnucash.org/trac/changeset/18057
Modified:
gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
gnucash/trunk/src/backend/sql/gnc-backend-sql.c
gnucash/trunk/src/backend/sql/gnc-slots-sql.c
Log:
Create an index for the slots table indexed on the obj guid. This is the last piece of
functionality from the old libgda backend.
Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c 2009-04-24 00:49:17 UTC (rev 18056)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c 2009-04-26 01:08:18 UTC (rev 18057)
@@ -102,6 +102,10 @@
pgsql_get_column_type_name
};
+static /*@ null @*/ gchar* create_index_ddl( GncSqlConnection* conn,
+ const gchar* index_name,
+ const gchar* table_name,
+ const GncSqlColumnTableEntry* col_table );
static GncSqlConnection* create_dbi_connection( /*@ observer @*/ provider_functions_t* provider, /*@ observer @*/ QofBackend* qbe, /*@ observer @*/ dbi_conn conn );
#define GNC_DBI_PROVIDER_SQLITE (&provider_sqlite3)
@@ -1336,7 +1340,6 @@
GString* ddl;
const GList* list_node;
guint col_num;
- gchar* ddl_result;
g_return_val_if_fail( conn != NULL, NULL );
g_return_val_if_fail( table_name != NULL, NULL );
@@ -1365,10 +1368,34 @@
}
(void)g_string_append( ddl, ")" );
- ddl_result = ddl->str;
- (void)g_string_free( ddl, FALSE );
+ return g_string_free( ddl, FALSE );
+}
- return ddl_result;
+static /*@ null @*/ gchar*
+create_index_ddl( GncSqlConnection* conn,
+ const gchar* index_name,
+ const gchar* table_name,
+ const GncSqlColumnTableEntry* 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 ) {
+ if( table_row != col_table ) {
+ (void)g_string_append( ddl, ", " );
+ }
+ g_string_append_printf( ddl, "%s", table_row->col_name );
+ }
+ (void)g_string_append( ddl, ")" );
+
+ return g_string_free( ddl, FALSE );
}
static /*@ null @*/ gchar*
@@ -1378,7 +1405,6 @@
GString* ddl;
const GList* list_node;
guint col_num;
- gchar* ddl_result;
g_return_val_if_fail( conn != NULL, NULL );
g_return_val_if_fail( table_name != NULL, NULL );
@@ -1410,10 +1436,7 @@
}
(void)g_string_append( ddl, ")" );
- ddl_result = ddl->str;
- (void)g_string_free( ddl, FALSE );
-
- return ddl_result;
+ return g_string_free( ddl, FALSE );
}
static /*@ null @*/ gchar*
@@ -1423,7 +1446,6 @@
GString* ddl;
const GList* list_node;
guint col_num;
- gchar* ddl_result;
gboolean is_unicode = FALSE;
g_return_val_if_fail( conn != NULL, NULL );
@@ -1456,10 +1478,7 @@
if( is_unicode ) {
}
- ddl_result = ddl->str;
- (void)g_string_free( ddl, FALSE );
-
- return ddl_result;
+ return g_string_free( ddl, FALSE );
}
static gboolean
@@ -1498,84 +1517,31 @@
conn_create_index( /*@ unused @*/ GncSqlConnection* conn, /*@ unused @*/ const gchar* index_name,
/*@ unused @*/ const gchar* table_name, /*@ unused @*/ const GncSqlColumnTableEntry* col_table )
{
-#if 0
- GdaServerOperation *op;
- GdaServerProvider *server;
- GdaConnection* cnn;
GncDbiSqlConnection* dbi_conn = (GncDbiSqlConnection*)conn;
- GError* error = NULL;
-
- g_return_val_if_fail( conn != NULL, FALSE );
+ gchar* ddl;
+ dbi_result result;
+ gint status;
+
+ 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 );
- cnn = gda_conn->conn;
- g_return_if_fail( cnn != NULL );
- g_return_if_fail( GDA_IS_CONNECTION(cnn) );
- g_return_if_fail( gda_connection_is_opened(cnn) );
+ ddl = create_index_ddl( conn, index_name, table_name, col_table );
+ if( ddl != NULL ) {
+ gint status;
- server = gda_conn->server;
- g_return_if_fail( server != NULL );
-
- op = gda_server_provider_create_operation( server, cnn,
- GDA_SERVER_OPERATION_CREATE_INDEX, NULL, &error );
- if( error != NULL ) {
- PERR( "gda_server_provider_create_operation(): %s\n", error->message );
- }
- if( op != NULL && GDA_IS_SERVER_OPERATION(op) ) {
- gint col;
- gboolean ok;
-
- ok = gda_server_operation_set_value_at( op, index_name, &error,
- "/INDEX_DEF_P/INDEX_NAME" );
- if( error != NULL ) {
- PERR( "set INDEX_NAME: %s\n", error->message );
+ DEBUG( "SQL: %s\n", ddl );
+ result = dbi_conn_query( dbi_conn->conn, ddl );
+ status = dbi_result_free( result );
+ if( status < 0 ) {
+ PERR( "Error in dbi_result_free() result\n" );
+ qof_backend_set_error( dbi_conn->qbe, ERR_BACKEND_SERVER_ERR );
}
- if( !ok ) return;
- ok = gda_server_operation_set_value_at( op, "", &error,
- "/INDEX_DEF_P/INDEX_TYPE" );
- if( error != NULL ) {
- PERR( "set INDEX_TYPE: %s\n", error->message );
- }
- if( !ok ) return;
- ok = gda_server_operation_set_value_at( op, "TRUE", &error,
- "/INDEX_DEF_P/INDEX_IFNOTEXISTS" );
- if( error != NULL ) {
- PERR( "set INDEX_IFNOTEXISTS: %s\n", error->message );
- }
- if( !ok ) return;
- ok = gda_server_operation_set_value_at( op, table_name, &error,
- "/INDEX_DEF_P/INDEX_ON_TABLE" );
- if( error != NULL ) {
- PERR( "set INDEX_ON_TABLE: %s\n", error->message );
- }
- if( !ok ) return;
+ } else {
+ return FALSE;
+ }
- for( col = 0; col_table[col].col_name != NULL; col++ ) {
- guint item;
-
- if( col != 0 ) {
- item = gda_server_operation_add_item_to_sequence( op, "/INDEX_FIELDS_S" );
- g_assert( item == col );
- }
- ok = gda_server_operation_set_value_at( op, col_table->col_name, &error,
- "/INDEX_FIELDS_S/%d/INDEX_FIELD", col );
- if( error != NULL ) {
- PERR( "set INDEX_FIELD %s: %s\n", col_table->col_name, error->message );
- }
- if( !ok ) break;
- }
-
- if( !gda_server_provider_perform_operation( server, cnn, op, &error ) ) {
- g_object_unref( op );
- return;
- }
-
- g_object_unref( op );
- }
-#endif
-
return TRUE;
}
Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.c 2009-04-24 00:49:17 UTC (rev 18056)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.c 2009-04-26 01:08:18 UTC (rev 18057)
@@ -104,7 +104,6 @@
static QofLogModule log_module = G_LOG_DOMAIN;
#define SQLITE_PROVIDER_NAME "SQLite"
-#define URI_PREFIX "gda://"
/* ================================================================= */
@@ -2544,11 +2543,7 @@
g_return_val_if_fail( be != NULL, 0 );
g_return_val_if_fail( table_name != NULL, 0 );
- /* If the db is pristine because it's being saved, the table does not
- * exist. This gets around a GDA-3 bug where deleting all tables and
- * updating the meta-data leaves the meta-data still thinking 1 table
- * exists.
- */
+ /* If the db is pristine because it's being saved, the table does not exist. */
if( be->is_pristine_db ) {
return 0;
}
Modified: gnucash/trunk/src/backend/sql/gnc-slots-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-slots-sql.c 2009-04-24 00:49:17 UTC (rev 18056)
+++ gnucash/trunk/src/backend/sql/gnc-slots-sql.c 2009-04-26 01:08:18 UTC (rev 18057)
@@ -563,14 +563,14 @@
version = gnc_sql_get_table_version( be, TABLE_NAME );
if( version == 0 ) {
+ gboolean ok;
+
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-#if 0
- // FIXME: Create index
- ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table, &error );
+
+ ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table );
if( !ok ) {
- PERR( "Unable to create index: %s\n", error->message );
+ PERR( "Unable to create index\n" );
}
-#endif
} else if( version == 1 ) {
/* Upgrade 64-bit int values to proper definition */
gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
More information about the gnucash-changes
mailing list