/** * gda_provider_meta_execute_query: * @prov: a #GdaProviderMeta * @sql: a string with the SQL to execute on provider * @params: (nullable): a #GdaSet with all paramaters to use in query * @error: place to store errors or %NULL * * SQL is specific for current provider. * * Returns: (transfer full) (nullable): a new #GdaDataModel with as a result of the query * Since: 6.0 * Stability: Unstable */ GdaDataModel *gda_provider_meta_execute_query (GdaProviderMeta *prov, const gchar *sql, GdaSet *params, GError **error) { g_return_val_if_fail (prov, NULL); g_return_val_if_fail (GDA_IS_PROVIDER_META (prov), NULL); g_return_val_if_fail (sql, NULL); GdaConnection *cnc = NULL; GdaStatement *stmt; g_object_get (G_OBJECT (prov), "connection", &cnc, NULL); if (cnc == NULL) { g_set_error (error, GDA_PROVIDER_META_ERROR, GDA_PROVIDER_META_NO_CONNECTION_ERROR, _("No connection is set")); return NULL; } if (!gda_connection_is_opened (cnc)) { g_set_error (error, GDA_PROVIDER_META_ERROR, GDA_PROVIDER_META_NO_CONNECTION_ERROR, _("Connection is no opened")); return NULL; } stmt = gda_connection_parse_sql_string (cnc, sql, NULL, error); if (stmt == NULL) { return NULL; } if (!gda_connection_statement_prepare (cnc, stmt, error)) { return NULL; } return gda_connection_statement_execute_select (cnc, stmt, params, error); }
static guint test4 (void) { g_print ("============= %s started =============\n", __FUNCTION__); GdaConnection *cnc; GError *error = NULL; cnc = gda_connection_new_from_string ("SQLite", "DB_NAMEEEE=test-cnc-opendb", NULL, GDA_CONNECTION_OPTIONS_AUTO_META_DATA, &error); if (!cnc) { g_print ("gda_connection_new_from_string() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } guint counter = 0; setup_main_context (cnc, &counter); GMainLoop *loop; loop = g_main_loop_new (gda_connection_get_main_context (cnc, NULL), FALSE); guint job_id; job_id = gda_connection_open_async (cnc, (GdaConnectionOpenFunc) test4_open_func, loop, &error); if (!job_id) { g_print ("gda_connection_open_async() failed: %s\n", error && error->message ? error->message : "No detail"); return 1; } else { g_print ("Connection opening job is %u\n", job_id); } g_main_loop_run (loop); gboolean opened; opened = gda_connection_is_opened (cnc); g_object_unref (cnc); if (counter == 0) { g_print ("gda_connection_open() failed: did not make GMainContext 'run'\n"); return 1; } else g_print ("Counter incremented to %u\n", counter); return opened ? 1 : 0; }