[anjuta/sdb-queries] symbol-db: Misc fixes to make it work
- From: Naba Kumar <naba src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/sdb-queries] symbol-db: Misc fixes to make it work
- Date: Fri, 11 Jun 2010 18:33:12 +0000 (UTC)
commit 2a60c3361afc038ce2ee809e6b0e1c95a397d7f2
Author: Naba Kumar <naba gnome org>
Date: Fri Jun 11 22:28:32 2010 +0300
symbol-db: Misc fixes to make it work
libanjuta/interfaces/libanjuta.idl | 17 ++-
plugins/class-inheritance/class-inherit.c | 9 +-
plugins/symbol-db/plugin.c | 15 +-
plugins/symbol-db/symbol-db-query-result.c | 75 ++++++---
plugins/symbol-db/symbol-db-query.c | 232 ++++++++++++++++++++--------
plugins/symbol-db/symbol-db-query.h | 3 +-
6 files changed, 250 insertions(+), 101 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index e0652a8..3468dd3 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -5215,6 +5215,7 @@ interface IAnjutaSymbol
*/
enum Type
{
+ TYPE_NONE = 0,
TYPE_UNDEF = 1,
TYPE_CLASS = 2,
TYPE_ENUM = 4,
@@ -5339,11 +5340,17 @@ interface IAnjutaSymbolQuery
MODE_QUEUED_SINGLE,
MODE_QUEUED_MULTI
}
+
+ enum Db
+ {
+ DB_PROJECT,
+ DB_SYSTEM
+ }
enum Name
{
- SEARCH_SYSTEM,
- SEARCH_PROJECT,
+ SEARCH,
+ SEARCH_ALL,
SEARCH_FILE,
SEARCH_ID,
SEARCH_MEMBERS,
@@ -5369,8 +5376,8 @@ interface IAnjutaSymbolQuery
void set_offset (gint offset);
void set_limit (gint limit);
- IAnjutaIterable* search_system (const gchar *pattern);
- IAnjutaIterable* search_project (const gchar *pattern);
+ IAnjutaIterable* search (const gchar *pattern);
+ IAnjutaIterable* search_all ();
IAnjutaIterable* search_file (const gchar *pattern, const GFile *file);
IAnjutaIterable* search_members (IAnjutaSymbol *symbol);
IAnjutaIterable* search_class_parents (IAnjutaSymbol *symbol);
@@ -5415,7 +5422,7 @@ interface IAnjutaSymbolManager
*/
void ::sys_scan_end (gint process_id);
- IAnjutaSymbolQuery* create_query (IAnjutaSymbolQueryName name);
+ IAnjutaSymbolQuery* create_query (IAnjutaSymbolQueryName name, IAnjutaSymbolQueryDb db);
}
/**
diff --git a/plugins/class-inheritance/class-inherit.c b/plugins/class-inheritance/class-inherit.c
index 242b021..65cb7ff 100644
--- a/plugins/class-inheritance/class-inherit.c
+++ b/plugins/class-inheritance/class-inherit.c
@@ -986,8 +986,7 @@ cls_inherit_update (AnjutaClassInheritance *plugin)
goto cleanup;
/* Get all classes */
- iter = ianjuta_symbol_query_search_project (plugin->query_project,
- NULL, &err);
+ iter = ianjuta_symbol_query_search_all (plugin->query_project, &err);
if (err)
{
g_warning ("Classes query in project failed: %s", err->message);
@@ -1219,7 +1218,8 @@ cls_inherit_init (AnjutaClassInheritance *plugin)
IAnjutaSymbolManager, NULL);
plugin->query_project =
ianjuta_symbol_manager_create_query (sym_manager,
- IANJUTA_SYMBOL_QUERY_SEARCH_PROJECT,
+ IANJUTA_SYMBOL_QUERY_SEARCH_ALL,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
NULL);
ianjuta_symbol_query_set_fields (plugin->query_project,
sizeof (query_fields_simple)/sizeof (IAnjutaSymbolField),
@@ -1233,6 +1233,7 @@ cls_inherit_init (AnjutaClassInheritance *plugin)
plugin->query_id =
ianjuta_symbol_manager_create_query (sym_manager,
IANJUTA_SYMBOL_QUERY_SEARCH_ID,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
NULL);
ianjuta_symbol_query_set_fields (plugin->query_id,
sizeof (query_fields_simple)/sizeof (IAnjutaSymbolField),
@@ -1241,6 +1242,7 @@ cls_inherit_init (AnjutaClassInheritance *plugin)
plugin->query_members =
ianjuta_symbol_manager_create_query (sym_manager,
IANJUTA_SYMBOL_QUERY_SEARCH_MEMBERS,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
NULL);
ianjuta_symbol_query_set_fields (plugin->query_members,
sizeof (query_fields)/sizeof (IAnjutaSymbolField),
@@ -1249,6 +1251,7 @@ cls_inherit_init (AnjutaClassInheritance *plugin)
plugin->query_parents =
ianjuta_symbol_manager_create_query (sym_manager,
IANJUTA_SYMBOL_QUERY_SEARCH_CLASS_PARENTS,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
NULL);
ianjuta_symbol_query_set_fields (plugin->query_parents,
sizeof (query_fields_simple)/sizeof (IAnjutaSymbolField),
diff --git a/plugins/symbol-db/plugin.c b/plugins/symbol-db/plugin.c
index cfd6168..76fd6a1 100644
--- a/plugins/symbol-db/plugin.c
+++ b/plugins/symbol-db/plugin.c
@@ -206,8 +206,8 @@ goto_file_tag (SymbolDBPlugin *sdb_plugin, const gchar *word,
iterator = NULL;
if (symbol_db_engine_is_connected (engine))
{
- iterator = ianjuta_symbol_query_search_project (sdb_plugin->search_query,
- word, NULL);
+ iterator = ianjuta_symbol_query_search (sdb_plugin->search_query,
+ word, NULL);
}
if (iterator != NULL && ianjuta_iterable_get_length (iterator, NULL) > 0)
@@ -294,9 +294,9 @@ on_goto_file_tag_decl_activate (GtkAction *action, SymbolDBPlugin *sdb_plugin)
static void
on_find_symbol (GtkAction *action, SymbolDBPlugin *sdb_plugin)
{
+#if 0
DEBUG_PRINT ("on_find_symbol (GtkAction *action, gpointer user_data)");
GtkEntry * entry;
-#if 0
anjuta_shell_present_widget(ANJUTA_PLUGIN(sdb_plugin)->shell,
sdb_plugin->dbv_main, NULL);
@@ -2189,7 +2189,8 @@ symbol_db_activate (AnjutaPlugin *plugin)
IANJUTA_SYMBOL_FIELD_FILE_POS
};
sdb_plugin->search_query = ianjuta_symbol_manager_create_query (IANJUTA_SYMBOL_MANAGER (sdb_plugin),
- IANJUTA_SYMBOL_QUERY_SEARCH_PROJECT,
+ IANJUTA_SYMBOL_QUERY_SEARCH,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
NULL);
ianjuta_symbol_query_set_fields (sdb_plugin->search_query, 3, search_fields, NULL);
return TRUE;
@@ -2503,14 +2504,16 @@ ipreferences_iface_init(IAnjutaPreferencesIface* iface)
/* IAnjutaSymbolManager implementation */
static IAnjutaSymbolQuery*
isymbol_manager_create_query (IAnjutaSymbolManager *isymbol_manager,
- IAnjutaSymbolQueryName query_name, GError **err)
+ IAnjutaSymbolQueryName query_name,
+ IAnjutaSymbolQueryDb db,
+ GError **err)
{
SymbolDBPlugin *sdb_plugin;
SymbolDBQuery *query;
sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (isymbol_manager);
query = symbol_db_query_new (sdb_plugin->sdbe_globals,
- sdb_plugin->sdbe_project, query_name);
+ sdb_plugin->sdbe_project, query_name, db);
return IANJUTA_SYMBOL_QUERY (query);
}
diff --git a/plugins/symbol-db/symbol-db-query-result.c b/plugins/symbol-db/symbol-db-query-result.c
index 07d07bb..40f4be3 100644
--- a/plugins/symbol-db/symbol-db-query-result.c
+++ b/plugins/symbol-db/symbol-db-query-result.c
@@ -41,15 +41,21 @@ enum {
struct _SymbolDBQueryResultPriv
{
- IAnjutaSymbolField valid_fields;
gint *col_map;
+ GdaDataModel *data_model;
GdaDataModelIter *iter;
const GHashTable *sym_type_conversion_hash;
gchar *project_root;
};
-static GObjectClass* parent_class = NULL;
+static void isymbol_iface_init (IAnjutaSymbolIface *iface);
+static void isymbol_iter_iface_init (IAnjutaIterableIface *iface);
+G_DEFINE_TYPE_WITH_CODE (SymbolDBQueryResult, sdb_query_result, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IANJUTA_TYPE_SYMBOL,
+ isymbol_iface_init)
+ G_IMPLEMENT_INTERFACE (IANJUTA_TYPE_ITERABLE,
+ isymbol_iter_iface_init));
GQuark
symbol_db_query_result_error_quark (void)
{
@@ -69,22 +75,26 @@ sdb_query_result_validate_field (SymbolDBQueryResult *result,
SYMBOL_DB_QUERY_RESULT_ERROR_INVALID_FIELD,
"Invalid symbol query field '%d'. It should be less than '%d'",
field, IANJUTA_SYMBOL_FIELD_END);
+ g_warning ("Invalid symbol query field '%d'. It should be less than '%d'",
+ field, IANJUTA_SYMBOL_FIELD_END);
return FALSE;
}
- if (result->priv->valid_fields & field)
+ if (result->priv->col_map [field] == -1)
{
g_set_error (err, SYMBOL_DB_QUERY_RESULT_ERROR,
SYMBOL_DB_QUERY_RESULT_ERROR_FIELD_NOT_PRESENT,
"Symbol field '%' is present in the query. Make sure to "
"include the during query creation.", field);
+ g_warning ("Symbol field '%' is present in the query. Make sure to "
+ "include the during query creation.", field);
return FALSE;
}
return TRUE;
}
static void
-sdb_query_result_instance_init (SymbolDBQueryResult *result)
+sdb_query_result_init (SymbolDBQueryResult *result)
{
gint i;
@@ -95,12 +105,30 @@ sdb_query_result_instance_init (SymbolDBQueryResult *result)
}
static void
+sdb_query_result_dispose (GObject *object)
+{
+ SymbolDBQueryResult *result = SYMBOL_DB_QUERY_RESULT (object);
+ if (result->priv->data_model)
+ {
+ g_object_unref (result->priv->data_model);
+ result->priv->data_model = NULL;
+ }
+ if (result->priv->iter)
+ {
+ g_object_unref (result->priv->iter);
+ result->priv->iter = NULL;
+ }
+ G_OBJECT_CLASS (sdb_query_result_parent_class)->dispose (object);
+}
+
+static void
sdb_query_result_finalize (GObject *object)
{
SymbolDBQueryResult *result = SYMBOL_DB_QUERY_RESULT (object);
-
+
+ g_free (result->priv->project_root);
g_free (result->priv->col_map);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (sdb_query_result_parent_class)->finalize (object);
}
static void
@@ -122,7 +150,7 @@ sdb_query_result_set_property (GObject *object, guint prop_id,
priv->col_map[i] = -1;
i = 0;
cols_order = g_value_get_pointer (value);
- while (!(*cols_order & IANJUTA_SYMBOL_FIELD_END))
+ while (!(*cols_order == IANJUTA_SYMBOL_FIELD_END))
{
priv->col_map[*cols_order] = i;
i++;
@@ -130,12 +158,13 @@ sdb_query_result_set_property (GObject *object, guint prop_id,
}
break;
case PROP_SDB_DATA_MODEL:
+ data_model = GDA_DATA_MODEL (g_value_get_object (value));
+ if (priv->data_model) g_object_unref (priv->data_model);
+ priv->data_model = data_model;
if (priv->iter)
g_object_unref (priv->iter);
- data_model = GDA_DATA_MODEL (g_value_get_object (value));
priv->iter = gda_data_model_create_iter (data_model);
gda_data_model_iter_move_at_row (priv->iter, 0);
- g_object_unref (data_model);
break;
case PROP_SDB_SYM_TYPE_CONVERSION_HASH:
priv->sym_type_conversion_hash = g_value_get_pointer (value);
@@ -185,12 +214,14 @@ sdb_query_result_class_init (SymbolDBQueryResultClass *klass)
object_class->set_property = sdb_query_result_set_property;
object_class->get_property = sdb_query_result_get_property;
object_class->finalize = sdb_query_result_finalize;
+ object_class->dispose = sdb_query_result_dispose;
g_object_class_install_property
(object_class, PROP_SDB_COLUMNS,
g_param_spec_pointer ("fields-order",
"Fields order",
"List of data fields in the order found in data model terminated by end field",
+ G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_SDB_DATA_MODEL,
@@ -198,6 +229,7 @@ sdb_query_result_class_init (SymbolDBQueryResultClass *klass)
"a GdaDataModel",
"GdaDataModel of the result set",
GDA_TYPE_DATA_MODEL,
+ G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_SDB_DATA_ITER,
@@ -257,11 +289,15 @@ isymbol_get_int (IAnjutaSymbol *isymbol, IAnjutaSymbolField field,
col = result->priv->col_map[field];
val = gda_data_model_iter_get_value_at (result->priv->iter, col);
- if (field & IANJUTA_SYMBOL_FIELD_TYPE)
+ if (!val) return 0;
+ if (field == IANJUTA_SYMBOL_FIELD_TYPE)
{
const gchar* type_str = g_value_get_string (val);
- return (gint)g_hash_table_lookup ((GHashTable*)result->priv->sym_type_conversion_hash,
- type_str);
+ gint type_val =
+ (gint)g_hash_table_lookup ((GHashTable*)result->priv->sym_type_conversion_hash,
+ type_str);
+ DEBUG_PRINT ("Type str = %s = %d", type_str, type_val);
+ return type_val;
}
return g_value_get_int (val);
}
@@ -281,6 +317,7 @@ isymbol_get_string (IAnjutaSymbol *isymbol, IAnjutaSymbolField field,
col = result->priv->col_map[field];
val = gda_data_model_iter_get_value_at (result->priv->iter, col);
+ if (!val) return NULL;
return (const gchar*) g_value_get_string (val);
}
@@ -419,16 +456,11 @@ isymbol_iter_get_position (IAnjutaIterable *iterable, GError **err)
static gint
isymbol_iter_get_length (IAnjutaIterable *iterable, GError **err)
{
- GdaDataModel *data_model;
- gint len;
SymbolDBQueryResult *result;
g_return_val_if_fail (SYMBOL_DB_IS_QUERY_RESULT (iterable), FALSE);
result = SYMBOL_DB_QUERY_RESULT (iterable);
- g_object_get (G_OBJECT (result->priv->iter), "data-model", &data_model, NULL);
- len = gda_data_model_get_n_rows (data_model);
- g_object_unref (data_model);
- return len;
+ return gda_data_model_get_n_rows (result->priv->data_model);
}
static IAnjutaIterable *
@@ -445,7 +477,7 @@ isymbol_iter_assign (IAnjutaIterable *iter, IAnjutaIterable *src_iter, GError **
}
static void
-isymbol_iter_iface_init (IAnjutaIterableIface *iface, GError **err)
+isymbol_iter_iface_init (IAnjutaIterableIface *iface)
{
iface->first = isymbol_iter_first;
iface->next = isymbol_iter_next;
@@ -472,8 +504,3 @@ symbol_db_query_result_new (GdaDataModel *data_model,
"project-root", project_root_dir,
NULL);
}
-
-ANJUTA_TYPE_BEGIN (SymbolDBQueryResult, sdb_query_result, SYMBOL_DB_TYPE_QUERY_RESULT);
-ANJUTA_TYPE_ADD_INTERFACE (isymbol, IANJUTA_TYPE_SYMBOL);
-ANJUTA_TYPE_ADD_INTERFACE (isymbol_iter, IANJUTA_TYPE_ITERABLE);
-ANJUTA_TYPE_END;
diff --git a/plugins/symbol-db/symbol-db-query.c b/plugins/symbol-db/symbol-db-query.c
index ee8f4d9..a2b458b 100644
--- a/plugins/symbol-db/symbol-db-query.c
+++ b/plugins/symbol-db/symbol-db-query.c
@@ -20,6 +20,7 @@
#include <limits.h>
#include <stdarg.h>
#include <libgda/gda-statement.h>
+#include <libanjuta/anjuta-debug.h>
#include <libanjuta/interfaces/ianjuta-symbol-query.h>
#include "symbol-db-engine.h"
#include "symbol-db-query.h"
@@ -32,6 +33,7 @@ enum
{
PROP_0,
PROP_QUERY_NAME,
+ PROP_QUERY_DB,
PROP_QUERY_MODE,
PROP_FILTERS,
PROP_FILE_SCOPE,
@@ -45,6 +47,7 @@ enum
struct _SymbolDBQueryPriv {
GdaStatement *stmt;
+ gchar *sql_stmt;
gboolean prepared;
IAnjutaSymbolQueryName name;
@@ -103,15 +106,15 @@ SdbQueryFieldSpec field_specs[] = {
{"symbol.name ", SDB_QUERY_TABLE_SYMBOL},
{"symbol.file_position ", SDB_QUERY_TABLE_SYMBOL},
{"symbol.scope_definition_id ", SDB_QUERY_TABLE_SYMBOL},
+ {"symbol.is_file_scope ", SDB_QUERY_TABLE_SYMBOL},
{"symbol.signature ", SDB_QUERY_TABLE_SYMBOL},
{"symbol.returntype ", SDB_QUERY_TABLE_SYMBOL},
- {"symbol.is_file_scope ", SDB_QUERY_TABLE_SYMBOL},
{"file.file_path", SDB_QUERY_TABLE_FILE},
{"sym_implementation.implementation_name", SDB_QUERY_TABLE_IMPLEMENTATION},
{"sym_access.access_name", SDB_QUERY_TABLE_ACCESS},
+ {"sym_kind.kind_name ", SDB_QUERY_TABLE_KIND},
{"sym_type.type_type ", SDB_QUERY_TABLE_TYPE},
{"sym_type.type_name", SDB_QUERY_TABLE_TYPE},
- {"sym_kind.kind_name ", SDB_QUERY_TABLE_KIND},
{"sym_kind.is_container", SDB_QUERY_TABLE_KIND}
};
@@ -122,6 +125,7 @@ SdbQueryFieldSpec field_specs[] = {
*/
static gchar* kind_names[] =
{
+ NULL,
"undef",
"class",
"enum",
@@ -161,6 +165,7 @@ sdb_query_build_sql_head (SymbolDBQuery *query, GString *sql)
gboolean tables_joined[SDB_QUERY_TABLE_MAX];
SymbolDBQueryPriv *priv;
IAnjutaSymbolField *field_ptr;
+ gboolean first_field = TRUE;
g_return_if_fail (SYMBOL_DB_IS_QUERY (query));
g_return_if_fail (sql != NULL);
@@ -174,28 +179,37 @@ sdb_query_build_sql_head (SymbolDBQuery *query, GString *sql)
for (i = 0; i < SDB_QUERY_TABLE_MAX; i++)
tables_joined[i] = FALSE;
- /* "symbol" table is in built, so skip it */
+ /* "symbol" table is in-built, so skip it */
tables_joined[SDB_QUERY_TABLE_SYMBOL] = TRUE;
g_string_assign (sql, "SELECT ");
- sql_joins = g_string_new_len ("", 512);
+ sql_joins = g_string_sized_new (512);
field_ptr = priv->fields;
while (*field_ptr != IANJUTA_SYMBOL_FIELD_END)
{
+ if (first_field)
+ first_field = FALSE;
+ else
+ g_string_append (sql, ", ");
+
+ DEBUG_PRINT ("table id = %d", field_specs[*field_ptr].table);
+ DEBUG_PRINT ("table jd = %d", tables_joined[field_specs[*field_ptr].table]);
+
g_string_append (sql, field_specs[*field_ptr].column);
- g_string_append (sql, " ");
- if (!tables_joined[field_specs[*field_ptr].table])
+ if (tables_joined[field_specs[*field_ptr].table] == FALSE)
{
- tables_joined[field_specs[*field_ptr].table] = TRUE;
+ DEBUG_PRINT ("Joining: %s" , table_joins[field_specs[*field_ptr].table]);
g_string_append (sql_joins,
table_joins[field_specs[*field_ptr].table]);
g_string_append (sql_joins, " ");
+ tables_joined[field_specs[*field_ptr].table] = TRUE;
}
field_ptr++;
}
- g_string_append (sql, "FROM symbol ");
+ DEBUG_PRINT ("Join str = %s", sql_joins->str);
+ g_string_append (sql, " FROM symbol ");
g_string_append (sql, sql_joins->str);
- g_string_append (sql, "WHERE ");
+ g_string_append (sql, " WHERE ");
g_string_free (sql_joins, TRUE);
}
@@ -215,9 +229,10 @@ sdb_query_build_sql_kind_filter (SymbolDBQuery *query, GString *sql)
filters = priv->filters;
if (filters)
{
- g_string_append (sql, "(symbol.kind_id IN (SELECT kind_id FROM sym_kind WHERE kind_name IN (");
+ g_string_append (sql, "(symbol.kind_id IN (SELECT sym_kind_id FROM sym_kind WHERE kind_name IN (");
while (filters)
{
+ bit_count++;
if (filters & 1)
{
if (first) first = FALSE;
@@ -228,7 +243,7 @@ sdb_query_build_sql_kind_filter (SymbolDBQuery *query, GString *sql)
}
filters >>= 1;
}
- g_string_append (sql, ")) ");
+ g_string_append (sql, "))) ");
return TRUE;
}
return FALSE;
@@ -247,13 +262,11 @@ sdb_query_update (SymbolDBQuery *query)
/* Prepare select conditions */
switch (priv->name)
{
- case IANJUTA_SYMBOL_QUERY_SEARCH_PROJECT:
+ case IANJUTA_SYMBOL_QUERY_SEARCH:
condition = " (symbol.name LIKE ## /* name:'pattern' type:gchararray */) ";
- priv->dbe_selected = priv->dbe_project;
break;
- case IANJUTA_SYMBOL_QUERY_SEARCH_SYSTEM:
- condition = " (symbol.name LIKE ## /* name:'pattern' type:gchararray */) ";
- priv->dbe_selected = priv->dbe_system;
+ case IANJUTA_SYMBOL_QUERY_SEARCH_ALL:
+ condition = "1 = 1 ";
break;
case IANJUTA_SYMBOL_QUERY_SEARCH_FILE:
condition = " \
@@ -278,7 +291,7 @@ sdb_query_update (SymbolDBQuery *query)
FROM symbol \
WHERE symbol.symbol_id = ## /* name:'symbolid' type:gint */ \
) \
- AND symbol.scope_id > 0) ORDER BY symbol.name) ";
+ AND symbol.scope_id > 0) ORDER BY symbol.name ";
break;
case IANJUTA_SYMBOL_QUERY_SEARCH_CLASS_PARENTS:
condition =
@@ -339,9 +352,17 @@ sdb_query_update (SymbolDBQuery *query)
g_string_append (sql, "LIMIT ## /* name:'limit' type:gint */ ");
g_string_append (sql, "OFFSET ## /* name:'offset' type:gint */ ");
+ DEBUG_PRINT ("sql = %s", sql->str);
+
/* Prepare statement */
- priv->stmt = symbol_db_engine_get_statement (priv->dbe_selected, sql->str);
- g_string_free (sql, TRUE);
+ g_free (priv->sql_stmt);
+ priv->sql_stmt = sql->str;
+ if (priv->stmt) g_object_unref (priv->stmt);
+ if (symbol_db_engine_is_connected (priv->dbe_selected))
+ priv->stmt = symbol_db_engine_get_statement (priv->dbe_selected, sql->str);
+ else
+ priv->stmt = NULL;
+ g_string_free (sql, FALSE);
}
static IAnjutaIterable*
@@ -359,6 +380,7 @@ sdb_query_execute_real (SymbolDBQuery *query)
data_model = symbol_db_engine_execute_select (priv->dbe_selected,
priv->stmt,
priv->params);
+ if (!data_model) return NULL;
iter = symbol_db_query_result_new (data_model,
priv->fields,
symbol_db_engine_get_type_conversion_hash (priv->dbe_selected),
@@ -404,13 +426,32 @@ sdb_query_async_cancel (AnjutaCommand *command)
}
static void
+on_sdb_query_dbe_connected (SymbolDBEngine *dbe, SymbolDBQuery *query)
+{
+ g_return_if_fail (SYMBOL_DB_IS_QUERY (query));
+
+ if (!query->priv->stmt)
+ {
+ g_assert (query->priv->sql_stmt);
+ query->priv->stmt =
+ symbol_db_engine_get_statement (query->priv->dbe_selected,
+ query->priv->sql_stmt);
+ }
+}
+
+static void
+on_sdb_query_dbe_disconnected (SymbolDBEngine *dbe, SymbolDBQuery *query)
+{
+}
+
+static void
on_sdb_query_dbe_scan_end (SymbolDBEngine *dbe, gint something,
SymbolDBQuery *query)
{
g_return_if_fail (SYMBOL_DB_IS_QUERY (query));
- g_return_if_fail (query->priv->mode == IANJUTA_SYMBOL_QUERY_MODE_QUEUED_SINGLE);
- if (!query->priv->is_canceled && query->priv->query_queued &&
+ if (query->priv->mode == IANJUTA_SYMBOL_QUERY_MODE_QUEUED_SINGLE &&
+ !query->priv->is_canceled && query->priv->query_queued &&
!symbol_db_engine_is_scanning (query->priv->dbe_system) &&
!symbol_db_engine_is_scanning (query->priv->dbe_project))
{
@@ -485,13 +526,65 @@ sdb_query_init (SymbolDBQuery *query)
priv->is_canceled = FALSE;
priv->async_result = NULL;
priv->query_queued = FALSE;
- g_signal_connect (query, "notify-data-arrived",
+ g_signal_connect (query, "data-arrived",
G_CALLBACK (on_sdb_query_async_data_arrived), query);
}
static void
+sdb_query_dispose (GObject *object)
+{
+ SymbolDBQueryPriv *priv;
+
+ priv = SYMBOL_DB_QUERY (object)->priv;
+ if (priv->dbe_selected)
+ {
+ g_signal_handlers_disconnect_by_func (priv->dbe_selected,
+ on_sdb_query_dbe_scan_end,
+ object);
+ g_signal_handlers_disconnect_by_func (priv->dbe_selected,
+ on_sdb_query_dbe_connected,
+ object);
+ g_signal_handlers_disconnect_by_func (priv->dbe_selected,
+ on_sdb_query_dbe_disconnected,
+ object);
+ g_object_unref (priv->dbe_selected);
+ priv->dbe_selected = NULL;
+ }
+ if (priv->dbe_system)
+ {
+ g_object_unref (priv->dbe_system);
+ priv->dbe_system = NULL;
+ }
+ if (priv->dbe_project)
+ {
+ g_object_unref (priv->dbe_project);
+ priv->dbe_project = NULL;
+ }
+ if (priv->stmt)
+ {
+ g_object_unref (priv->stmt);
+ priv->stmt = NULL;
+ }
+ if (priv->params)
+ {
+ g_object_unref (priv->params);
+ priv->params = NULL;
+ }
+ if (priv->async_result)
+ {
+ g_object_unref (priv->async_result);
+ priv->async_result = NULL;
+ }
+ G_OBJECT_CLASS (sdb_query_parent_class)->dispose (object);
+}
+
+static void
sdb_query_finalize (GObject *object)
{
+ SymbolDBQueryPriv *priv;
+
+ priv = SYMBOL_DB_QUERY (object)->priv;
+ g_free (priv->sql_stmt);
G_OBJECT_CLASS (sdb_query_parent_class)->finalize (object);
}
@@ -529,31 +622,33 @@ sdb_query_set_property (GObject *object, guint prop_id, const GValue *value, GPa
gda_holder_set_value (priv->param_offset, value, NULL);
break;
case PROP_DB_ENGINE_SYSTEM:
- if (priv->dbe_system)
- {
- g_signal_handlers_disconnect_by_func (priv->dbe_system,
- on_sdb_query_dbe_scan_end,
- query);
- }
- g_object_unref (priv->dbe_system);
+ g_assert (priv->dbe_system == NULL);
priv->dbe_system = g_value_get_object (value);
- g_signal_connect (priv->dbe_system, "scan-end",
- G_CALLBACK (on_sdb_query_dbe_scan_end), query);
break;
case PROP_DB_ENGINE_PROJECT:
- if (priv->dbe_project)
+ g_assert (priv->dbe_project == NULL);
+ priv->dbe_project = g_value_get_object (value);
+ break;
+ case PROP_QUERY_DB:
+ g_assert (priv->dbe_project != NULL);
+ g_assert (priv->dbe_system != NULL);
+ g_assert (priv->dbe_selected == NULL);
+ switch (g_value_get_enum (value))
{
- g_signal_handlers_disconnect_by_func (priv->dbe_project,
- on_sdb_query_dbe_scan_end,
- query);
+ case IANJUTA_SYMBOL_QUERY_DB_PROJECT:
+ priv->dbe_selected = priv->dbe_project;
+ break;
+ case IANJUTA_SYMBOL_QUERY_DB_SYSTEM:
+ priv->dbe_selected = priv->dbe_system;
+ break;
}
- g_object_unref (priv->dbe_system);
- priv->dbe_project = g_value_get_object (value);
- g_signal_connect (priv->dbe_project, "scan-end",
+ g_object_ref (priv->dbe_selected);
+ g_signal_connect (priv->dbe_selected, "scan-end",
G_CALLBACK (on_sdb_query_dbe_scan_end), query);
- break;
- case PROP_DB_ENGINE_SELECTED:
- priv->dbe_selected = g_value_get_object (value);
+ g_signal_connect (priv->dbe_selected, "db-connected",
+ G_CALLBACK (on_sdb_query_dbe_connected), query);
+ g_signal_connect (priv->dbe_selected, "db-disconnected",
+ G_CALLBACK (on_sdb_query_dbe_disconnected), query);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -598,6 +693,9 @@ sdb_query_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
case PROP_DB_ENGINE_PROJECT:
g_value_set_object (value, priv->dbe_project);
break;
+ case PROP_DB_ENGINE_SELECTED:
+ g_value_set_object (value, priv->dbe_selected);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -613,6 +711,7 @@ sdb_query_class_init (SymbolDBQueryClass *klass)
g_type_class_add_private (klass, sizeof (SymbolDBQueryPriv));
object_class->finalize = sdb_query_finalize;
+ object_class->dispose = sdb_query_dispose;
object_class->set_property = sdb_query_set_property;
object_class->get_property = sdb_query_get_property;
@@ -625,9 +724,19 @@ sdb_query_class_init (SymbolDBQueryClass *klass)
"Query name",
"The query name",
IANJUTA_TYPE_SYMBOL_QUERY_NAME,
- IANJUTA_SYMBOL_QUERY_SEARCH_PROJECT,
+ IANJUTA_SYMBOL_QUERY_SEARCH,
G_PARAM_READABLE |
- G_PARAM_CONSTRUCT));
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_QUERY_DB,
+ g_param_spec_enum ("query-db",
+ "Query DB",
+ "The query database",
+ IANJUTA_TYPE_SYMBOL_QUERY_DB,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_QUERY_MODE,
g_param_spec_enum ("query-mode",
@@ -643,7 +752,7 @@ sdb_query_class_init (SymbolDBQueryClass *klass)
"Symbol type filters",
"The symbol type filters",
IANJUTA_TYPE_SYMBOL_TYPE,
- -1,
+ IANJUTA_SYMBOL_TYPE_NONE,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
@@ -689,7 +798,7 @@ sdb_query_class_init (SymbolDBQueryClass *klass)
SYMBOL_TYPE_DB_ENGINE,
G_PARAM_READABLE |
G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT));
+ G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_DB_ENGINE_PROJECT,
g_param_spec_object ("db-engine-project",
@@ -698,7 +807,7 @@ sdb_query_class_init (SymbolDBQueryClass *klass)
SYMBOL_TYPE_DB_ENGINE,
G_PARAM_READABLE |
G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT));
+ G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_DB_ENGINE_SELECTED,
g_param_spec_object ("db-engine-selected",
@@ -721,6 +830,7 @@ sdb_query_set_fields (IAnjutaSymbolQuery *query, gint n_fields,
for (i = 0; i < n_fields; i++)
priv->fields[i] = fields[i];
priv->fields[i] = IANJUTA_SYMBOL_FIELD_END;
+ sdb_query_update (SYMBOL_DB_QUERY (query));
}
static void
@@ -759,8 +869,8 @@ sdb_query_set_file_scope (IAnjutaSymbolQuery *query,
}
static IAnjutaIterable*
-sdb_query_search_system (IAnjutaSymbolQuery *query,
- const gchar *search_string, GError **error)
+sdb_query_search (IAnjutaSymbolQuery *query, const gchar *search_string,
+ GError **error)
{
GValue sv = {0};
SymbolDBQueryPriv *priv;
@@ -768,7 +878,7 @@ sdb_query_search_system (IAnjutaSymbolQuery *query,
g_return_val_if_fail (SYMBOL_DB_IS_QUERY (query), NULL);
priv = SYMBOL_DB_QUERY (query)->priv;
- g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_SYSTEM, NULL);
+ g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH, NULL);
g_value_init (&sv, G_TYPE_STRING);
g_value_set_static_string (&sv, search_string);
@@ -777,20 +887,14 @@ sdb_query_search_system (IAnjutaSymbolQuery *query,
}
static IAnjutaIterable*
-sdb_query_search_project (IAnjutaSymbolQuery *query,
- const gchar *search_string, GError **error)
+sdb_query_search_all (IAnjutaSymbolQuery *query, GError **error)
{
- GValue sv = {0};
SymbolDBQueryPriv *priv;
g_return_val_if_fail (SYMBOL_DB_IS_QUERY (query), NULL);
priv = SYMBOL_DB_QUERY (query)->priv;
- g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_PROJECT, NULL);
-
- g_value_init (&sv, G_TYPE_STRING);
- g_value_set_static_string (&sv, search_string);
- gda_holder_set_value (priv->param_pattern, &sv, NULL);
+ g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_ALL, NULL);
return sdb_query_execute (SYMBOL_DB_QUERY (query));
}
@@ -805,7 +909,7 @@ sdb_query_search_file (IAnjutaSymbolQuery *query, const gchar *search_string,
g_return_val_if_fail (SYMBOL_DB_IS_QUERY (query), NULL);
priv = SYMBOL_DB_QUERY (query)->priv;
- g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_SYSTEM, NULL);
+ g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_FILE, NULL);
g_value_init (&sv, G_TYPE_STRING);
g_value_set_static_string (&sv, search_string);
@@ -854,6 +958,8 @@ sdb_query_search_members (IAnjutaSymbolQuery *query, IAnjutaSymbol *symbol,
priv = SYMBOL_DB_QUERY (query)->priv;
g_return_val_if_fail (priv->name == IANJUTA_SYMBOL_QUERY_SEARCH_MEMBERS, NULL);
+ DEBUG_PRINT ("Getting members of %d", ianjuta_symbol_get_int (symbol, IANJUTA_SYMBOL_FIELD_ID, NULL));
+
g_value_init (&iv, G_TYPE_INT);
g_value_set_int (&iv, ianjuta_symbol_get_int (symbol, IANJUTA_SYMBOL_FIELD_ID, NULL));
gda_holder_set_value (priv->param_id, &iv, NULL);
@@ -969,8 +1075,8 @@ ianjuta_symbol_query_iface_init (IAnjutaSymbolQueryIface *iface)
iface->set_file_scope = sdb_query_set_file_scope;
iface->set_limit = sdb_query_set_limit;
iface->set_offset = sdb_query_set_offset;
- iface->search_system = sdb_query_search_system;
- iface->search_project = sdb_query_search_project;
+ iface->search = sdb_query_search;
+ iface->search_all = sdb_query_search_all;
iface->search_file = sdb_query_search_file;
iface->search_id = sdb_query_search_id;
iface->search_members = sdb_query_search_members;
@@ -983,10 +1089,12 @@ ianjuta_symbol_query_iface_init (IAnjutaSymbolQueryIface *iface)
SymbolDBQuery *
symbol_db_query_new (SymbolDBEngine *system_db_engine,
SymbolDBEngine *project_db_engine,
- IAnjutaSymbolQueryName name)
+ IAnjutaSymbolQueryName name,
+ IAnjutaSymbolQueryDb db)
{
return g_object_new (SYMBOL_DB_TYPE_QUERY,
"db-engine-system", system_db_engine,
"db-engine-project", project_db_engine,
- "query-name", name, NULL);
+ "query-db", db, "query-name", name,
+ NULL);
}
diff --git a/plugins/symbol-db/symbol-db-query.h b/plugins/symbol-db/symbol-db-query.h
index e38feb4..35423ce 100644
--- a/plugins/symbol-db/symbol-db-query.h
+++ b/plugins/symbol-db/symbol-db-query.h
@@ -52,7 +52,8 @@ struct _SymbolDBQuery
GType sdb_query_get_type (void) G_GNUC_CONST;
SymbolDBQuery* symbol_db_query_new (SymbolDBEngine *system_db_engine,
SymbolDBEngine *project_db_engine,
- IAnjutaSymbolQueryName name);
+ IAnjutaSymbolQueryName name,
+ IAnjutaSymbolQueryDb db);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]