]> saetta.ns0.it Git - libgdaex/commitdiff
Added macro ZQ_INSERT. develop
authorAndrea Zagli <azagli@libero.it>
Sun, 27 Sep 2020 08:16:22 +0000 (10:16 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 27 Sep 2020 08:16:22 +0000 (10:16 +0200)
src/sqlbuilder.h
tests/sqlbuilder_macro.c

index 3c20f1afa77768507e0bc69e7055f6e9ea60266c..85dd41939209026badb68ab79c2341a529c1eac9 100644 (file)
@@ -129,6 +129,11 @@ gint gdaex_sql_builder_execute  (GdaExSqlBuilder *sqlb, GdaEx *gdaex, GdaSet *pa
        gdaex_sql_builder_fields (builder_name, __VA_ARGS__);
 
 
+#define ZQ_INSERT(builder_name, table_name)      \
+       GdaExSqlBuilder *builder_name; \
+       builder_name = gdaex_sql_builder_new (GDA_SQL_STATEMENT_INSERT); \
+       gdaex_sql_builder_from (builder_name, #table_name, "");
+
 #define ZQ_UPDATE(builder_name, table_name, ...)         \
        GdaExSqlBuilder *builder_name; \
        builder_name = gdaex_sql_builder_new (GDA_SQL_STATEMENT_UPDATE); \
index 1a98034861bff8f1a433d60a78d5bf773d456926..088e638e25162fae2ac40fdc751c7dcd8f1fd952 100644 (file)
@@ -217,48 +217,39 @@ main (int argc, char **argv)
 
        g_object_unref (sqlb2);
 
-       sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
-
-       gdaex_sql_builder_from_v (sqlb,
-                                                         "pippo", "pluto",
-                                                         "topolino", "",
-                                                         NULL);
+       ZQ_INSERT(sqlb4, "pippo");
 
        gval = g_new0 (GValue, 1);
        g_value_init (gval, G_TYPE_STRING);
        g_value_set_string (gval, "il nome di pippo");
-       gdaex_sql_builder_fields (sqlb,
+       gdaex_sql_builder_fields (sqlb4,
                                                          "pippo", "name", "", gval,
                                                          NULL);
 
        gval = g_new0 (GValue, 1);
        g_value_init (gval, G_TYPE_INT);
        g_value_set_int (gval, 1);
-       gdaex_sql_builder_where (sqlb, 0,
+       gdaex_sql_builder_where (sqlb4, 0,
                                                         "pippo", "id", "",
                                                         GDA_SQL_OPERATOR_TYPE_EQ,
                                                         gval,
                                                         NULL);
        g_value_unset (gval);
 
-       g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb, NULL, NULL));
+       g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb4, NULL, NULL));
 
-       g_object_unref (sqlb);
+       g_object_unref (sqlb4);
 
-       sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
+       ZQ_INSERT(sqlb5, "pippo");
 
-       gdaex_sql_builder_from_v (sqlb,
-                                 "pippo", "pluto",
-                                 NULL);
+       gdaex_sql_builder_field_boolean (sqlb5, "pippo", "married", "", FALSE);
+       gdaex_sql_builder_field_int (sqlb5, "pippo", "id", "", 44);
+       gdaex_sql_builder_field_string (sqlb5, "pippo", "named", "", "the field value'");
+       gdaex_sql_builder_field_float (sqlb5, "pippo", "income", "", 4128.65);
 
-       gdaex_sql_builder_field_boolean (sqlb, "pippo", "married", "", FALSE);
-       gdaex_sql_builder_field_int (sqlb, "pippo", "id", "", 44);
-       gdaex_sql_builder_field_string (sqlb, "pippo", "named", "", "the field value'");
-       gdaex_sql_builder_field_float (sqlb, "pippo", "income", "", 4128.65);
+       g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb5, NULL, NULL));
 
-       g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb, NULL, NULL));
-
-       g_object_unref (sqlb);
+       g_object_unref (sqlb5);
 
        return 0;
 }