[libgda] sqlite: implement GdaProvider interface
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] sqlite: implement GdaProvider interface
- Date: Sun, 21 Oct 2018 20:55:36 +0000 (UTC)
commit 4f1d3f434e3e8c85965323a96e1ffd85ea68c010
Author: Daniel Espinosa <esodan gmail com>
Date: Sun Oct 14 23:05:37 2018 -0500
sqlite: implement GdaProvider interface
Added new method to GdaProvider: gda_provider_get_last_inserted()
Fixed gda_provider_meta_view_columns() annotations
Reverted changes from: 4960245e4f50d8cfe57a95f9c3f5ff714dc3dd07
* GdaConfig initialization
* GdaQuarkList modifications
libgda/gda-init.c | 5 -
libgda/gda-provider-meta.c | 2 +-
libgda/gda-provider.c | 23 +++
libgda/gda-provider.h | 7 +-
libgda/gda-quark-list.c | 5 +-
libgda/sqlite/gda-sqlite-provider.c | 286 ++++++++++++++++++++++++++++++++++++
6 files changed, 319 insertions(+), 9 deletions(-)
---
diff --git a/libgda/gda-init.c b/libgda/gda-init.c
index 75053ab8c..315cde548 100644
--- a/libgda/gda-init.c
+++ b/libgda/gda-init.c
@@ -273,11 +273,6 @@ gda_init (void)
g_free (file);
- /* Initializing global GdaConfig */
- GdaConfig *config = gda_config_get ();
- g_assert (config != NULL);
- g_object_unref (config);
-
initialized = TRUE;
g_mutex_unlock (&init_mutex);
}
diff --git a/libgda/gda-provider-meta.c b/libgda/gda-provider-meta.c
index 943ac4bc9..43e82b3cb 100644
--- a/libgda/gda-provider-meta.c
+++ b/libgda/gda-provider-meta.c
@@ -723,7 +723,7 @@ gda_provider_meta_views_columns (GdaProviderMeta *prov, GError **error)
return NULL;
}
/**
- * gda_provider_meta_view_colums:
+ * gda_provider_meta_view_columns:
*
* Returns: (transfer full):
* Since: 6.0
diff --git a/libgda/gda-provider.c b/libgda/gda-provider.c
index ccb9df857..dfa550b9e 100644
--- a/libgda/gda-provider.c
+++ b/libgda/gda-provider.c
@@ -500,3 +500,26 @@ gda_provider_statement_execute (GdaProvider *provider, GdaConnection *cnc,
}
return NULL;
}
+
+/**
+ * gda_provider_get_last_inserted:
+ * @provider: a #GdaProvider object
+ * @cnc: a #GdaConnection to get last inserted from
+ * @error: a place to put errors
+ *
+ * This command should be called inmediately called after a INSERT SQL command
+ *
+ * Return: (transfer full): a #GdaSet with all data of the last inserted row
+ */
+GdaSet*
+gda_provider_get_last_inserted (GdaProvider *provider,
+ GdaConnection *cnc,
+ GError **error)
+{
+ g_return_val_if_fail (provider, NULL);
+ GdaProviderInterface *iface = GDA_PROVIDER_GET_IFACE (provider);
+ if (iface->get_last_inserted) {
+ return iface->get_last_inserted (provider, cnc, error);
+ }
+ return NULL;
+}
diff --git a/libgda/gda-provider.h b/libgda/gda-provider.h
index e3d55d41d..01a97715d 100644
--- a/libgda/gda-provider.h
+++ b/libgda/gda-provider.h
@@ -85,7 +85,10 @@ struct _GdaProviderInterface
GObject *(* statement_execute) (GdaProvider *provider, GdaConnection *cnc,
GdaStatement *stmt, GdaSet *params,
GdaStatementModelUsage model_usage,
- GType *col_types, GdaSet **last_inserted_row, GError **error);
+ GType *col_types, GdaSet **last_inserted_row,
+ GError **error);
+ GdaSet *(* get_last_inserted) (GdaProvider *provider, GdaConnection *cnc,
+ GError **error);
/* Padding for future expansion */
gpointer padding[12];
@@ -150,6 +153,8 @@ GObject *gda_provider_statement_execute (GdaProvider *provider, G
GdaStatementModelUsage model_usage,
GType *col_types, GdaSet **last_inserted_row,
GError **error);
+GdaSet *gda_provider_get_last_inserted (GdaProvider *provider, GdaConnection *cnc,
+ GError **error);
G_END_DECLS
diff --git a/libgda/gda-quark-list.c b/libgda/gda-quark-list.c
index 1a57f68b1..1e5e76e33 100644
--- a/libgda/gda-quark-list.c
+++ b/libgda/gda-quark-list.c
@@ -369,11 +369,12 @@ void
gda_quark_list_add_from_string (GdaQuarkList *qlist, const gchar *string, gboolean cleanup)
{
g_return_if_fail (qlist != NULL);
- g_return_if_fail (string != NULL);
- g_return_if_fail (g_strrstr (string, ";") != NULL);
gchar **arr;
+ if (!string || !*string)
+ return;
+
if (cleanup)
gda_quark_list_clear (qlist);
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 29fa4a9e2..ca774c475 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -66,6 +66,7 @@
#define _GDA_PSTMT(x) ((GdaPStmt*)(x))
#include <libgda/gda-debug-macros.h>
#include <libgda/gda-provider-meta.h>
+#include <libgda/gda-provider.h>
#define FILE_EXTENSION ".db"
static gchar *get_table_nth_column_name (GdaServerProvider *prov, GdaConnection *cnc, const gchar
*table_name, gint pos);
@@ -334,6 +335,8 @@ static gchar *gda_sqlite_provider_escape_string (GdaServerProvider
const gchar *string);
static gchar *gda_sqlite_provider_unescape_string (GdaServerProvider *provider, GdaConnection
*cnc,
const gchar *string);
+GdaSet *gda_sqlite_provider_get_last_inserted (GdaServerProvider *provider,
+ GdaConnection *cnc, GError **error);
/*
* private connection data destroy
@@ -602,6 +605,102 @@ gda_sqlite_provider_meta_iface_init (GdaProviderMetaInterface *iface) {
iface->index_col = gda_sqlite_provider_meta_index_col;
}
+static const gchar *gda_sqlite_provider_iface_get_name (GdaProvider *provider);
+static const gchar *gda_sqlite_provider_iface_get_version (GdaProvider *provider);
+static const gchar *gda_sqlite_provider_iface_get_server_version (GdaProvider *provider,
GdaConnection *cnc);
+static gboolean gda_sqlite_provider_iface_supports_feature (GdaProvider *provider,
GdaConnection *cnc,
+ GdaConnectionFeature feature);
+static GdaSqlParser *gda_sqlite_provider_iface_create_parser (GdaProvider *provider,
GdaConnection *cnc); /* may be NULL */
+static GdaConnection *gda_sqlite_provider_iface_create_connection (GdaProvider *provider);
+static GdaDataHandler *gda_sqlite_provider_iface_get_data_handler (GdaProvider *provider,
GdaConnection *cnc, /* may be NULL */
+ GType g_type, const gchar *dbms_type);
+static const gchar *gda_sqlite_provider_iface_get_def_dbms_type (GdaProvider *provider,
GdaConnection *cnc,
+ GType g_type); /* may be NULL */
+static gboolean gda_sqlite_provider_iface_supports_operation (GdaProvider *provider,
GdaConnection *cnc,
+ GdaServerOperationType type, GdaSet *options);
+static GdaServerOperation *gda_sqlite_provider_iface_create_operation (GdaProvider *provider,
GdaConnection *cnc,
+ GdaServerOperationType type, GdaSet *options,
+ GError **error);
+static gchar *gda_sqlite_provider_iface_render_operation (GdaProvider *provider,
GdaConnection *cnc,
+ GdaServerOperation *op, GError **error);
+static gchar *gda_sqlite_provider_iface_statement_to_sql (GdaProvider *provider,
GdaConnection *cnc,
+ GdaStatement *stmt, GdaSet *params,
+ GdaStatementSqlFlag flags,
+ GSList **params_used, GError **error);
+static gchar *gda_sqlite_provider_iface_identifier_quote (GdaProvider *provider,
GdaConnection *cnc, /* may be NULL */
+ const gchar *id,
+ gboolean for_meta_store, gboolean force_quotes);
+static GdaSqlStatement *gda_sqlite_provider_iface_statement_rewrite (GdaProvider *provider,
GdaConnection *cnc,
+ GdaStatement *stmt, GdaSet *params, GError **error);
+static gboolean gda_sqlite_provider_iface_open_connection (GdaProvider *provider,
GdaConnection *cnc,
+ GdaQuarkList *params, GdaQuarkList *auth);
+static gboolean gda_sqlite_provider_iface_prepare_connection (GdaProvider *provider,
GdaConnection *cnc,
+ GdaQuarkList *params, GdaQuarkList *auth);
+static gboolean gda_sqlite_provider_iface_close_connection (GdaProvider *provider,
GdaConnection *cnc);
+static gchar *gda_sqlite_provider_iface_escape_string (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *str); /* may be NULL */
+static gchar *gda_sqlite_provider_iface_unescape_string (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *str); /* may be NULL */
+static gboolean gda_sqlite_provider_iface_perform_operation (GdaProvider *provider,
GdaConnection *cnc, /* may be NULL */
+ GdaServerOperation *op, GError **error);
+static gboolean gda_sqlite_provider_iface_begin_transaction (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *name, GdaTransactionIsolation level,
+ GError **error);
+static gboolean gda_sqlite_provider_iface_commit_transaction (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *name, GError **error);
+static gboolean gda_sqlite_provider_iface_rollback_transaction (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *name, GError **error);
+static gboolean gda_sqlite_provider_iface_add_savepoint (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *name, GError **error);
+static gboolean gda_sqlite_provider_iface_rollback_savepoint (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *name, GError **error);
+static gboolean gda_sqlite_provider_iface_delete_savepoint (GdaProvider *provider,
GdaConnection *cnc,
+ const gchar *name, GError **error);
+static gboolean gda_sqlite_provider_iface_statement_prepare (GdaProvider *provider,
GdaConnection *cnc,
+ GdaStatement *stmt, GError **error);
+static GObject *gda_sqlite_provider_iface_statement_execute (GdaProvider *provider,
GdaConnection *cnc,
+ GdaStatement *stmt, GdaSet *params,
+ GdaStatementModelUsage model_usage,
+ GType *col_types, GdaSet **last_inserted_row,
+ GError **error);
+static GdaSet *gda_sqlite_provider_iface_get_last_inserted (GdaProvider *provider,
GdaConnection *cnc,
+ GError **error);
+
+
+static void
+gda_sqlite_provider_iface_init (GdaProviderInterface *iface)
+{
+ iface->get_name = gda_sqlite_provider_iface_get_name;
+ iface->get_version = gda_sqlite_provider_iface_get_version;
+ iface->get_server_version = gda_sqlite_provider_iface_get_server_version;
+ iface->supports_feature = gda_sqlite_provider_iface_supports_feature;
+ iface->create_parser = gda_sqlite_provider_iface_create_parser;
+ iface->create_connection = gda_sqlite_provider_iface_create_connection;
+ iface->get_data_handler = gda_sqlite_provider_iface_get_data_handler;
+ iface->get_def_dbms_type = gda_sqlite_provider_iface_get_def_dbms_type;
+ iface->supports_operation = gda_sqlite_provider_iface_supports_operation;
+ iface->create_operation = gda_sqlite_provider_iface_create_operation;
+ iface->render_operation = gda_sqlite_provider_iface_render_operation;
+ iface->statement_to_sql = gda_sqlite_provider_iface_statement_to_sql;
+ iface->identifier_quote = gda_sqlite_provider_iface_identifier_quote;
+ iface->statement_rewrite = gda_sqlite_provider_iface_statement_rewrite;
+ iface->open_connection = gda_sqlite_provider_iface_open_connection;
+ iface->prepare_connection = gda_sqlite_provider_iface_prepare_connection;
+ iface->close_connection = gda_sqlite_provider_iface_close_connection;
+ iface->escape_string = gda_sqlite_provider_iface_escape_string;
+ iface->unescape_string = gda_sqlite_provider_iface_unescape_string;
+ iface->perform_operation = gda_sqlite_provider_iface_perform_operation;
+ iface->begin_transaction = gda_sqlite_provider_iface_begin_transaction;
+ iface->commit_transaction = gda_sqlite_provider_iface_commit_transaction;
+ iface->rollback_transaction = gda_sqlite_provider_iface_rollback_transaction;
+ iface->add_savepoint = gda_sqlite_provider_iface_add_savepoint;
+ iface->rollback_savepoint = gda_sqlite_provider_iface_rollback_savepoint;
+ iface->delete_savepoint = gda_sqlite_provider_iface_delete_savepoint;
+ iface->statement_prepare = gda_sqlite_provider_iface_statement_prepare;
+ iface->statement_execute = gda_sqlite_provider_iface_statement_execute;
+ iface->get_last_inserted = gda_sqlite_provider_iface_get_last_inserted;
+}
+
/*
* Prepared internal statements
*/
@@ -904,6 +1003,12 @@ gda_sqlite_provider_get_type (void)
NULL
};
g_type_add_interface_static (type, GDA_TYPE_PROVIDER_META, &ifaceinfo);
+ static GInterfaceInfo ifaceproviderinfo = {
+ (GInterfaceInitFunc) gda_sqlite_provider_iface_init,
+ NULL,
+ NULL
+ };
+ g_type_add_interface_static (type, GDA_TYPE_PROVIDER, &ifaceproviderinfo);
}
g_mutex_unlock (®istering);
}
@@ -4829,4 +4934,185 @@ gda_sqlite_provider_meta_index_col (GdaProviderMeta *prov,
return NULL;
}
+/* GdaProvider Implementation */
+
+const gchar*
+gda_sqlite_provider_iface_get_name (GdaProvider *provider) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+const gchar*
+gda_sqlite_provider_iface_get_version (GdaProvider *provider) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+const gchar*
+gda_sqlite_provider_iface_get_server_version (GdaProvider *provider, GdaConnection *cnc) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+gboolean
+gda_sqlite_provider_iface_supports_feature (GdaProvider *provider, GdaConnection *cnc,
+ GdaConnectionFeature feature) {
+ g_return_val_if_fail (provider, TRUE);
+ return TRUE;
+}
+GdaSqlParser*
+gda_sqlite_provider_iface_create_parser (GdaProvider *provider, GdaConnection *cnc) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+} /* may be NULL */
+GdaConnection*
+gda_sqlite_provider_iface_create_connection (GdaProvider *provider) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+GdaDataHandler*
+gda_sqlite_provider_iface_get_data_handler (GdaProvider *provider, GdaConnection *cnc, /* may be NULL */
+ GType g_type, const gchar *dbms_type) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+const gchar*
+gda_sqlite_provider_iface_get_def_dbms_type (GdaProvider *provider, GdaConnection *cnc,
+ GType g_type) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+} /* may be NULL */
+gboolean
+gda_sqlite_provider_iface_supports_operation (GdaProvider *provider, GdaConnection *cnc,
+ GdaServerOperationType type, GdaSet *options) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+GdaServerOperation*
+gda_sqlite_provider_iface_create_operation (GdaProvider *provider, GdaConnection *cnc,
+ GdaServerOperationType type, GdaSet *options,
+ GError **error) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+gchar*
+gda_sqlite_provider_iface_render_operation (GdaProvider *provider, GdaConnection *cnc,
+ GdaServerOperation *op, GError **error) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+gchar*
+gda_sqlite_provider_iface_statement_to_sql (GdaProvider *provider, GdaConnection *cnc,
+ GdaStatement *stmt, GdaSet *params,
+ GdaStatementSqlFlag flags,
+ GSList **params_used, GError **error) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+gchar*
+gda_sqlite_provider_iface_identifier_quote (GdaProvider *provider, GdaConnection *cnc, /* may be NULL */
+ const gchar *id,
+ gboolean for_meta_store, gboolean force_quotes) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+GdaSqlStatement*
+gda_sqlite_provider_iface_statement_rewrite (GdaProvider *provider, GdaConnection *cnc,
+ GdaStatement *stmt, GdaSet *params, GError **error) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+gboolean
+gda_sqlite_provider_iface_open_connection (GdaProvider *provider, GdaConnection *cnc,
+ GdaQuarkList *params, GdaQuarkList *auth) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_prepare_connection (GdaProvider *provider, GdaConnection *cnc,
+ GdaQuarkList *params, GdaQuarkList *auth) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_close_connection (GdaProvider *provider, GdaConnection *cnc) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gchar*
+gda_sqlite_provider_iface_escape_string (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *str) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+} /* may be NULL */
+gchar*
+gda_sqlite_provider_iface_unescape_string (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *str) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+} /* may be NULL */
+gboolean
+gda_sqlite_provider_iface_perform_operation (GdaProvider *provider, GdaConnection *cnc, /* may be NULL */
+ GdaServerOperation *op, GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_begin_transaction (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *name, GdaTransactionIsolation level,
+ GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_commit_transaction (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *name, GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_rollback_transaction (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *name, GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_add_savepoint (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *name, GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_rollback_savepoint (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *name, GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_delete_savepoint (GdaProvider *provider, GdaConnection *cnc,
+ const gchar *name, GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+gboolean
+gda_sqlite_provider_iface_statement_prepare (GdaProvider *provider, GdaConnection *cnc,
+ GdaStatement *stmt, GError **error) {
+ g_return_val_if_fail (provider, FALSE);
+ return FALSE;
+}
+GObject*
+gda_sqlite_provider_iface_statement_execute (GdaProvider *provider, GdaConnection *cnc,
+ GdaStatement *stmt, GdaSet *params,
+ GdaStatementModelUsage model_usage,
+ GType *col_types, GdaSet **last_inserted_row,
+ GError **error) {
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
+
+GdaSet*
+gda_sqlite_provider_iface_get_last_inserted (GdaProvider *provider,
+ GdaConnection *cnc,
+ GError **error)
+{
+ g_return_val_if_fail (provider, NULL);
+ return NULL;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]