[libgda] providers-tests: common now uses GdaDataModelSelect



commit 02f349bc4864e628195d0bb3d1f91e8ea2edfac0
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Fri Feb 15 16:45:41 2019 -0600

    providers-tests: common now uses GdaDataModelSelect
    
    Because GdaDataSelect is going to be deprecated about
    its functionality of auto-update, tests for providers
    now uses GdaDataModelSelect as is easy to use.

 libgda/gda-data-model-select.c     |  9 ++++--
 tests/providers/prov-test-common.c | 57 ++++++--------------------------------
 2 files changed, 16 insertions(+), 50 deletions(-)
---
diff --git a/libgda/gda-data-model-select.c b/libgda/gda-data-model-select.c
index ac47372b0..e8a4d59be 100644
--- a/libgda/gda-data-model-select.c
+++ b/libgda/gda-data-model-select.c
@@ -187,6 +187,11 @@ static void params_changed_cb (GdaSet *params, GdaHolder *holder, GdaDataModelSe
 GdaDataModelSelect*
 gda_data_model_select_new (GdaConnection *cnc, GdaStatement *stm, GdaSet *params)
 {
+  g_return_val_if_fail (cnc != NULL, NULL);
+  g_return_val_if_fail (stm != NULL, NULL);
+  g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
+  g_return_val_if_fail (GDA_IS_STATEMENT (stm), NULL);
+
   GdaDataModelSelect* model = GDA_DATA_MODEL_SELECT (g_object_new (GDA_TYPE_DATA_MODEL_SELECT, NULL));
   GdaDataModelSelectPrivate *priv = gda_data_model_select_get_instance_private (GDA_DATA_MODEL_SELECT 
(model));
 
@@ -212,6 +217,8 @@ gda_data_model_select_new (GdaConnection *cnc, GdaStatement *stm, GdaSet *params
 GdaDataModelSelect*
 gda_data_model_select_new_from_string (GdaConnection *cnc, const gchar *sql)
 {
+  g_return_val_if_fail (cnc != NULL, NULL);
+  g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
   GdaStatement *stm = gda_connection_parse_sql_string (cnc, sql, NULL, NULL);
   if (stm == NULL) {
     return NULL;
@@ -219,7 +226,6 @@ gda_data_model_select_new_from_string (GdaConnection *cnc, const gchar *sql)
 
   GdaSet *params = NULL;
   gda_statement_get_parameters (stm, &params, NULL);
-  g_message ("Params: %s", params != NULL ? "True" : "False");
 
   return gda_data_model_select_new (cnc, stm, params);
 }
@@ -278,7 +284,6 @@ gda_data_model_select_set_parameters  (GdaDataModelSelect *model, GdaSet *params
   priv->params = g_object_ref (priv->params);
   g_signal_connect (priv->params, "holder-changed", G_CALLBACK (params_changed_cb), model);
   params_changed_cb (priv->params, NULL, model);
-  g_message ("Setted parameters");
 }
 
 
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index 6767adaf7..b209fe670 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -892,15 +892,12 @@ prov_test_common_check_cursor_models (void)
 
 /*
  *
- * Check for the GdaDataModel returned from a SELECT combined with the GDA_STATEMENT_MODEL_ALLOW_NOPARAM
- * flag
+ * Check for the GdaDataModel returned from a SELECT with auto-update
  *
  */
 int 
 prov_test_common_check_data_select (void)
 {
-       GdaSqlParser *parser = NULL;
-       GdaStatement *stmt = NULL;
        GdaSet *params = NULL;
        GError *error = NULL;
        int number_failed = 0;
@@ -913,41 +910,15 @@ prov_test_common_check_data_select (void)
        g_print ("\n============= %s() =============\n", __FUNCTION__);
 #endif
 
-       parser = gda_connection_create_parser (cnc);
-       if (!parser)
-               parser = gda_sql_parser_new ();
-
        /* create statement */
-       stmt = gda_sql_parser_parse_string (parser, "SELECT * FROM actor WHERE actor_id <= ##theid::gint", 
-                                           &remain, &error);
-       if (!stmt) {
-               number_failed ++;
-               goto out;
-       }
-       if (remain) {
-               g_set_error (&error, TEST_ERROR, TEST_ERROR_PARSING,
-                            "Parsing error, remains: %s", remain);
-               number_failed ++;
-               goto out;
-       }
-       
-       /* get model */
-       if (! (gda_statement_get_parameters (stmt, &params, &error))) {
-               number_failed ++;
-               goto out;
-       }
-
-       model = gda_connection_statement_execute_select_full (cnc, stmt, params, 
GDA_STATEMENT_MODEL_ALLOW_NOPARAM,
-                                                              NULL, &error);
-       if (!model) {
-               number_failed ++;
-               goto out;
-       }
-
-       if (gda_data_model_get_n_rows (model) != 0) {
-               g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC,
-                            "Data model reports %d rows when 0 expected", gda_data_model_get_n_rows (model));
-               number_failed ++;
+       model = (GdaDataModel*) gda_data_model_select_new_from_string (cnc, "SELECT * FROM actor WHERE 
actor_id <= ##theid::gint");
+       g_assert (model);
+       g_assert (GDA_IS_DATA_MODEL_SELECT (model));
+       params = gda_data_model_select_get_parameters (GDA_DATA_MODEL_SELECT (model));
+       g_assert (params != NULL);
+       g_assert (GDA_IS_SET (params));
+       if (! gda_set_set_holder_value (params, &error, "theid", 9)) {
+               number_failed++;
                goto out;
        }
 
@@ -956,13 +927,6 @@ prov_test_common_check_data_select (void)
             i < ncols; i++) 
                columns = g_slist_append (columns, gda_data_model_describe_column (model, i));
 
-       /* change param */
-       g_object_set (model, "auto-reset", TRUE, NULL);
-       if (! gda_set_set_holder_value (params, &error, "theid", 9)) {
-                number_failed++;
-                goto out;
-        }
-
        if (gda_data_model_get_n_rows (model) != 9) {
                g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC,
                             "Data model reports %d rows when 9 expected", gda_data_model_get_n_rows (model));
@@ -991,13 +955,10 @@ prov_test_common_check_data_select (void)
        }
 
  out:
-       if (stmt)
-               g_object_unref (stmt);
        if (params)
                g_object_unref (params);
        if (model)
                g_object_unref (model);
-       g_object_unref (parser);
 
 #ifdef CHECK_EXTRA_INFO
        g_print ("GdaDataSelect test resulted in %d error(s)\n", number_failed);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]