]> saetta.ns0.it Git - libgdaex/commitdiff
Added functions GdaExSqlBuilder::field_*.
authorAndrea Zagli <azagli@libero.it>
Fri, 4 Oct 2019 13:32:00 +0000 (15:32 +0200)
committerAndrea Zagli <azagli@libero.it>
Fri, 4 Oct 2019 13:32:00 +0000 (15:32 +0200)
src/sqlbuilder.c
src/sqlbuilder.h
tests/sqlbuilder.c

index d86dd074b4e43a4c6b3ba68d8cc0dd14187ece92..3360b5c1d0a8fb8d19307c33c897c81a03b6933d 100644 (file)
@@ -370,6 +370,62 @@ gdaex_sql_builder_field (GdaExSqlBuilder *sqlb, const gchar *table_name, const g
        gdaex_sql_builder_get_field (sqlb, t, field_name, field_alias, gval, TRUE);
 }
 
+void
+gdaex_sql_builder_field_boolean (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, gboolean val)
+{
+       GValue *gval;
+
+       gval = g_new0 (GValue, 1);
+       g_value_init (gval, G_TYPE_BOOLEAN);
+       g_value_set_boolean (gval, val);
+
+       gdaex_sql_builder_field (sqlb, table_name, field_name, field_alias, gval);
+
+       g_value_unset (gval);
+}
+
+void
+gdaex_sql_builder_field_int (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, gint val)
+{
+       GValue *gval;
+
+       gval = g_new0 (GValue, 1);
+       g_value_init (gval, G_TYPE_INT);
+       g_value_set_int (gval, val);
+
+       gdaex_sql_builder_field (sqlb, table_name, field_name, field_alias, gval);
+
+       g_value_unset (gval);
+}
+
+void
+gdaex_sql_builder_field_float (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, gfloat val)
+{
+       GValue *gval;
+
+       gval = g_new0 (GValue, 1);
+       g_value_init (gval, G_TYPE_FLOAT);
+       g_value_set_float (gval, val);
+
+       gdaex_sql_builder_field (sqlb, table_name, field_name, field_alias, gval);
+
+       g_value_unset (gval);
+}
+
+void
+gdaex_sql_builder_field_string (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, const gchar *val)
+{
+       GValue *gval;
+
+       gval = g_new0 (GValue, 1);
+       g_value_init (gval, G_TYPE_STRING);
+       g_value_set_string (gval, val);
+
+       gdaex_sql_builder_field (sqlb, table_name, field_name, field_alias, gval);
+
+       g_value_unset (gval);
+}
+
 /**
  * gdaex_sql_builder_fields:
  * @sqlb:
index 4866121a9c74c638ff8d0a8c8d121d1be8fcdaa2..39145be0ecd6bf9e494d1c3a7710058b7178648d 100644 (file)
@@ -66,6 +66,10 @@ void gdaex_sql_builder_join (GdaExSqlBuilder *sqlb,
                                                         ...);
 
 void gdaex_sql_builder_field (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, GValue *gval);
+void gdaex_sql_builder_field_boolean (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, gboolean val);
+void gdaex_sql_builder_field_int (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, gint val);
+void gdaex_sql_builder_field_float (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, gfloat val);
+void gdaex_sql_builder_field_string (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *field_name, const gchar *field_alias, const gchar *val);
 void gdaex_sql_builder_fields (GdaExSqlBuilder *sqlb, ...);
 
 GdaSqlBuilderId gdaex_sql_builder_where (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op,
index d4cc1c2642609418b5da0cce27cdacaad637b62d..89f0a8631d294b0f4806340b7c4c2066a8303612 100644 (file)
@@ -258,5 +258,20 @@ main (int argc, char **argv)
 
        g_object_unref (sqlb);
 
+       sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
+
+       gdaex_sql_builder_from_v (sqlb,
+                                 "pippo", "pluto",
+                                 NULL);
+
+       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 (sqlb, NULL, NULL));
+
+       g_object_unref (sqlb);
+
        return 0;
 }