![]() |
![]() |
![]() |
GNOME Data Access 4 manual | ![]() |
---|---|---|---|---|
Top | Description |
The GdaSqlBuilder can be used to build a GdaStatement from its structural description, much in the same way a GdaSqlParser can be used to build a GdaStatement from an SQL string.
The GdaBuilder internally constructs a GdaSqlStatement and uses it when requested to produce
a GdaStatement (see gda_sql_builder_get_statement()
), or a GdaSqlStatement (see
gda_sql_builder_get_sql_statement()
).
During the building process, some pieces of the statement are constructed, and assembled into the final statement. Each of these pieces can be reused anytime in the same GdaBuilder object, and each is identified using a single unsigned integer ID. That ID can either be specified by the user, or be dynamically allocated by the object (pass 0 as the requested ID).
The following example builds the equivalent of the "name='joe' AND age >= ##ageparam::int" expression:
GdaSqlBuilder *b=... gda_sql_builder_add_id (b, 1, "name"); // build the "name" SQL identifier with requested ID=1 gda_sql_builder_add_expr (b, 2, NULL, G_TYPE_STRING, "joe"); // 'joe' expression, requested ID=2 gda_sql_builder_add_cond2 (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2); // "name='joe'", requested ID=3 gda_sql_builder_add_cond2 (b, 4, GDA_SQL_OPERATOR_TYPE_GT, // requested ID=4 gda_sql_builder_add_id (b, 0, "age"), // build the "age" SQL identifier, no specific ID gda_sql_builder_add_param (b, 0, "ageparam", G_TYPE_INT, FALSE) // parameter, no specific ID ); gda_sql_builder_add_cond2 (b, 5, GDA_SQL_OPERATOR_TYPE_AND, 3, 4); // whole expression, requested ID=5
For more examples, see the Build statements without using a parser section.