mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug #677488 - DROP INDEX missing ON <table>
BP git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22450 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
8573f4576e
commit
7dfa452b7d
@ -56,18 +56,20 @@ typedef enum
|
||||
GNC_DBI_FAIL_TEST
|
||||
} GncDbiTestResult;
|
||||
|
||||
typedef gchar* (*CREATE_TABLE_DDL_FN)( GncSqlConnection* conn,
|
||||
typedef gchar* (*CREATE_TABLE_DDL_FN) ( GncSqlConnection* conn,
|
||||
const gchar* table_name,
|
||||
const GList* col_info_list );
|
||||
typedef GSList* (*GET_TABLE_LIST_FN)( dbi_conn conn, const gchar* dbname );
|
||||
typedef void (*APPEND_COLUMN_DEF_FN)( GString* ddl, GncSqlColumnInfo* info );
|
||||
typedef GSList* (*GET_INDEX_LIST_FN)( dbi_conn conn );
|
||||
typedef GSList* (*GET_TABLE_LIST_FN) ( dbi_conn conn, const gchar* dbname );
|
||||
typedef void (*APPEND_COLUMN_DEF_FN) ( GString* ddl, GncSqlColumnInfo* info );
|
||||
typedef GSList* (*GET_INDEX_LIST_FN) ( dbi_conn conn );
|
||||
typedef void (*DROP_INDEX_FN) ( dbi_conn conn, const gchar* index );
|
||||
typedef struct
|
||||
{
|
||||
CREATE_TABLE_DDL_FN create_table_ddl;
|
||||
GET_TABLE_LIST_FN get_table_list;
|
||||
APPEND_COLUMN_DEF_FN append_col_def;
|
||||
GET_INDEX_LIST_FN get_index_list;
|
||||
DROP_INDEX_FN drop_index;
|
||||
} provider_functions_t;
|
||||
|
||||
|
||||
|
@ -86,12 +86,14 @@ static GSList* conn_get_table_list( dbi_conn conn, const gchar* dbname );
|
||||
static GSList* conn_get_table_list_sqlite3( dbi_conn conn, const gchar* dbname );
|
||||
static void append_sqlite3_col_def( GString* ddl, GncSqlColumnInfo* info );
|
||||
static GSList *conn_get_index_list_sqlite3( dbi_conn conn );
|
||||
static void conn_drop_index_sqlite3 (dbi_conn conn, const gchar *index );
|
||||
static provider_functions_t provider_sqlite3 =
|
||||
{
|
||||
conn_create_table_ddl_sqlite3,
|
||||
conn_get_table_list_sqlite3,
|
||||
append_sqlite3_col_def,
|
||||
conn_get_index_list_sqlite3
|
||||
conn_get_index_list_sqlite3,
|
||||
conn_drop_index_sqlite3
|
||||
};
|
||||
#define SQLITE3_TIMESPEC_STR_FORMAT "%04d%02d%02d%02d%02d%02d"
|
||||
|
||||
@ -100,12 +102,14 @@ static /*@ null @*/ gchar* conn_create_table_ddl_mysql( GncSqlConnection* conn,
|
||||
const GList* col_info_list );
|
||||
static void append_mysql_col_def( GString* ddl, GncSqlColumnInfo* info );
|
||||
static GSList *conn_get_index_list_mysql( dbi_conn conn );
|
||||
static void conn_drop_index_mysql (dbi_conn conn, const gchar *index );
|
||||
static provider_functions_t provider_mysql =
|
||||
{
|
||||
conn_create_table_ddl_mysql,
|
||||
conn_get_table_list,
|
||||
append_mysql_col_def,
|
||||
conn_get_index_list_mysql
|
||||
conn_get_index_list_mysql,
|
||||
conn_drop_index_mysql
|
||||
};
|
||||
#define MYSQL_TIMESPEC_STR_FORMAT "%04d%02d%02d%02d%02d%02d"
|
||||
|
||||
@ -115,13 +119,15 @@ static /*@ null @*/ gchar* conn_create_table_ddl_pgsql( GncSqlConnection* conn,
|
||||
static GSList* conn_get_table_list_pgsql( dbi_conn conn, const gchar* dbname );
|
||||
static void append_pgsql_col_def( GString* ddl, GncSqlColumnInfo* info );
|
||||
static GSList *conn_get_index_list_pgsql( dbi_conn conn );
|
||||
static void conn_drop_index_pgsql (dbi_conn conn, const gchar *index );
|
||||
|
||||
static provider_functions_t provider_pgsql =
|
||||
{
|
||||
conn_create_table_ddl_pgsql,
|
||||
conn_get_table_list_pgsql,
|
||||
append_pgsql_col_def,
|
||||
conn_get_index_list_pgsql
|
||||
conn_get_index_list_pgsql,
|
||||
conn_drop_index_pgsql
|
||||
};
|
||||
#define PGSQL_TIMESPEC_STR_FORMAT "%04d%02d%02d %02d%02d%02d"
|
||||
|
||||
@ -393,6 +399,14 @@ conn_get_index_list_sqlite3( dbi_conn conn )
|
||||
return list;
|
||||
}
|
||||
|
||||
static void
|
||||
conn_drop_index_sqlite3 (dbi_conn conn, const gchar *index )
|
||||
{
|
||||
dbi_result result = dbi_conn_queryf (conn, "DROP INDEX %s", index);
|
||||
if ( result )
|
||||
dbi_result_free( result );
|
||||
}
|
||||
|
||||
static void
|
||||
mysql_error_fn( dbi_conn conn, void* user_data )
|
||||
{
|
||||
@ -978,7 +992,7 @@ conn_get_index_list_mysql( dbi_conn conn )
|
||||
while ( dbi_result_next_row( result ) != 0 )
|
||||
{
|
||||
const gchar* index_name = dbi_result_get_string_idx( result, 3 );
|
||||
index_list = g_slist_prepend( index_list, strdup( index_name ) );
|
||||
index_list = g_slist_prepend( index_list, g_strjoin( " ", index_name, table_name, NULL ) );
|
||||
}
|
||||
dbi_result_free( result );
|
||||
}
|
||||
@ -986,6 +1000,31 @@ conn_get_index_list_mysql( dbi_conn conn )
|
||||
return index_list;
|
||||
}
|
||||
|
||||
static void
|
||||
conn_drop_index_mysql (dbi_conn conn, const gchar *index )
|
||||
{
|
||||
dbi_result result;
|
||||
gchar **index_table_split = g_strsplit (index, " ", 2);
|
||||
int splitlen = -1;
|
||||
|
||||
/* Check if the index split can be valid */
|
||||
while (index_table_split[++splitlen] != NULL)
|
||||
{ /* do nothing, just count split members */ }
|
||||
|
||||
if (splitlen != 2)
|
||||
{
|
||||
g_print ("Drop index error: invalid MySQL index format (<index> <table>): %s", index);
|
||||
return;
|
||||
}
|
||||
|
||||
result = dbi_conn_queryf (conn, "DROP INDEX %s ON %s",
|
||||
index_table_split[0], index_table_split[1]);
|
||||
if ( result )
|
||||
dbi_result_free( result );
|
||||
|
||||
g_strfreev (index_table_split);
|
||||
}
|
||||
|
||||
static void
|
||||
pgsql_error_fn( dbi_conn conn, void* user_data )
|
||||
{
|
||||
@ -1273,6 +1312,14 @@ conn_get_index_list_pgsql( dbi_conn conn )
|
||||
return list;
|
||||
}
|
||||
|
||||
static void
|
||||
conn_drop_index_pgsql (dbi_conn conn, const gchar *index )
|
||||
{
|
||||
dbi_result result = dbi_conn_queryf (conn, "DROP INDEX %s", index);
|
||||
if ( result )
|
||||
dbi_result_free( result );
|
||||
}
|
||||
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
@ -1590,10 +1637,7 @@ gnc_dbi_safe_sync_all( QofBackend *qbe, QofBook *book )
|
||||
for ( iter = index_list; iter != NULL; iter = g_slist_next( iter) )
|
||||
{
|
||||
const char *errmsg;
|
||||
dbi_result result =
|
||||
dbi_conn_queryf( conn->conn, "DROP INDEX %s", iter->data );
|
||||
if ( result )
|
||||
dbi_result_free( result );
|
||||
conn->provider->drop_index (conn->conn, iter->data);
|
||||
if ( DBI_ERROR_NONE != dbi_conn_error( conn->conn, &errmsg ) )
|
||||
{
|
||||
qof_backend_set_error( qbe, ERR_BACKEND_SERVER_ERR );
|
||||
|
Loading…
Reference in New Issue
Block a user