## GdaSqlBuilder GdaSqlBuilder — Factory object for statements |

## Stability Level

Stable, unless otherwise indicated

## Functions

GdaSqlBuilder * | gda_sql_builder_new ()
GdaStatement * | gda_sql_builder_get_statement ()
GdaSqlStatement * | gda_sql_builder_get_sql_statement ()
void | gda_sql_builder_set_table ()
void | gda_sql_builder_add_field_value ()
void | gda_sql_builder_add_field_value_as_gvalue ()
void | gda_sql_builder_add_field_value_id ()
GdaSqlBuilderId | gda_sql_builder_add_function ()
GdaSqlBuilderId | gda_sql_builder_add_function_v ()
GdaSqlBuilderId | gda_sql_builder_add_id ()
GdaSqlBuilderId | gda_sql_builder_add_field_id ()
GdaSqlBuilderId | gda_sql_builder_add_expr ()
GdaSqlBuilderId | gda_sql_builder_add_expr_value ()
GdaSqlBuilderId | gda_sql_builder_add_param ()
GdaSqlBuilderId | gda_sql_builder_add_case ()
GdaSqlBuilderId | gda_sql_builder_add_case_v ()
GdaSqlBuilderId | gda_sql_builder_add_sub_select ()
GdaSqlBuilderId | gda_sql_builder_add_cond ()
GdaSqlBuilderId | gda_sql_builder_add_cond_v ()
void | gda_sql_builder_set_where ()
GdaSqlBuilderId | gda_sql_builder_select_add_target ()
GdaSqlBuilderId | gda_sql_builder_select_add_target_id ()
GdaSqlBuilderId | gda_sql_builder_select_add_field ()
GdaSqlBuilderId | gda_sql_builder_select_join_targets ()
void | gda_sql_builder_join_add_field ()
void | gda_sql_builder_select_order_by ()
void | gda_sql_builder_select_set_distinct ()
void | gda_sql_builder_select_set_limit ()
void | gda_sql_builder_select_set_having ()
void | gda_sql_builder_select_group_by ()
void | gda_sql_builder_compound_add_sub_select ()
void | gda_sql_builder_compound_set_type ()
GdaSqlExpr * | gda_sql_builder_export_expression ()
GdaSqlBuilderId | gda_sql_builder_import_expression ()

## Properties

GdaSqlStatementType | stmt-type | Write / Construct Only

## Types and Values

struct | GdaSqlBuilder
typedef | GdaSqlBuilderId

## Object Hierarchy

        GObject
        ╰── GdaSqlBuilder

## 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 GdaSqlBuilder 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 GdaSqlBuilder object, and each is identified using a single unsigned integer ID. That ID is dynamically allocated by the object.

The following example builds the equivalent of the "name='joe' AND age >= #<link linkend="ageparam-int"><type>“int”</type></link>" expression:

    GdaSqlBuilder *b=...
    guint id_field = gda_sql_builder_add_id (b, "name"); // build the "name" SQL identifier
    guint id_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "joe"); // 'joe' expression
    guint id_cond1 = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_value, 0); // "name='joe'"

    guint id_cond2 = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_GT,
         gda_sql_builder_add_id (b, "age"), // build the "age" SQL identifier
         gda_sql_builder_add_param (b, "ageparam", G_TYPE_INT, FALSE), // parameter
         0);
    guint id_cond_and = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_AND, id_cond1, id_cond2, 0); // whole expression

For more examples, see the Build statements without using a parser section.

## Functions

### gda_sql_builder_new ()

    GdaSqlBuilder *
    gda_sql_builder_new (GdaSqlStatementType stmt_type);

Create a new GdaSqlBuilder object to build GdaStatement or GdaSqlStatement objects of type `stmt_type`

#### Parameters

stmt_type | the type of statement to build |

#### Returns

the newly created object, or `NULL` if an error occurred (such as unsupported statement type).

[transfer full]

Since 4.2

### gda_sql_builder_get_statement ()

    GdaStatement *
    gda_sql_builder_get_statement (GdaSqlBuilder *builder,
                                   GError **error);

Creates a new GdaStatement statement from `builder` 's contents.

#### Parameters

builder | a GdaSqlBuilder object |
error | a place to store errors, or `NULL`. | [allow-none]

#### Returns

a new GdaStatement object, or `NULL` if an error occurred.

[transfer full]

Since 4.2

### gda_sql_builder_get_sql_statement ()

    GdaSqlStatement *
    gda_sql_builder_get_sql_statement (GdaSqlBuilder *builder);

Creates a new GdaSqlStatement structure from `builder` 's contents.

The returned pointer belongs to `builder` 's internal representation. Use `gda_sql_statement_copy()` if you need to keep it.

#### Parameters

builder | a GdaSqlBuilder object |

#### Returns

a GdaSqlStatement pointer.

[transfer none][allow-none]

Since 4.2

### gda_sql_builder_set_table ()

    void
    gda_sql_builder_set_table (GdaSqlBuilder *builder,
                               const gchar *table_name);

Valid only for: INSERT, UPDATE, DELETE statements

Sets the name of the table on which the built statement operates.

#### Parameters

builder | a GdaSqlBuilder object |
table_name | a table name |

Since 4.2

### gda_sql_builder_add_field_value ()

    void
    gda_sql_builder_add_field_value (GdaSqlBuilder *builder,
                                     const gchar *field_name,
                                     GType type,
                                     ...);

Valid only for: INSERT, UPDATE statements.

Specifies that the field represented by `field_name` will be set to the value identified by @... of type `type` . See `gda_sql_builder_add_expr()` for more information.

This is a C convenience function. See also `gda_sql_builder_add_field_value_as_gvalue()`.

#### Parameters

builder | a GdaSqlBuilder object |
field_name | a field name |
type | the GType of the following argument |
... | value to set the field to, of the type specified by `type` |

Since 4.2

### gda_sql_builder_add_field_value_as_gvalue ()

    void
    gda_sql_builder_add_field_value_as_gvalue
                                   (GdaSqlBuilder *builder,
                                    const gchar *field_name,
                                    const GValue *value);

Valid only for: INSERT, UPDATE statements.

Specifies that the field represented by `field_name` will be set to the value identified by `value`

#### Parameters

builder | a GdaSqlBuilder object |
field_name | a field name |
value | value to set the field to, or `NULL` or a GDA_TYPE_NULL value to represent an SQL NULL. | [allow-none]

Since 4.2

### gda_sql_builder_add_field_value_id ()

    void
    gda_sql_builder_add_field_value_id (GdaSqlBuilder *builder,
                                        GdaSqlBuilderId field_id,
                                        GdaSqlBuilderId value_id);

Valid only for: INSERT, UPDATE, SELECT statements

- For UPDATE: specifies that the field represented by `field_id` will be set to the value identified by `value_id`.

- For SELECT: add a selected item to the statement, and if `value_id` is not `0`, then use it as an alias

- For INSERT: if `field_id` represents an SQL identifier (obtained using `gda_sql_builder_add_id()`): then if `value_id` is not `0` then specifies that the field represented by `field_id` will be set to the value identified by `value_id`, otherwise just specifies a named field to be given a value. If `field_id` represents a sub SELECT (obtained using `gda_sql_builder_add_sub_select()`), then this method call defines the sub SELECT from which values to insert are taken.

See also `gda_sql_builder_add_field_value()` and `gda_sql_builder_add_field_value_as_gvalue()`.

#### Parameters

builder | a GdaSqlBuilder object |
field_id | the ID of the field's name or definition |
value_id | the ID of the value to set the field to, or `0` |

Since 4.2

### gda_sql_builder_add_function ()

    GdaSqlBuilderId
    gda_sql_builder_add_function (GdaSqlBuilder *builder,
                                  const gchar *func_name,
                                  ...);

Builds a new expression which represents a function applied to some arguments

#### Parameters

builder | a GdaSqlBuilder object |
func_name | the functions's name |
... | a list, terminated with `0`, of each function's argument's ID |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_function_v ()

    GdaSqlBuilderId
    gda_sql_builder_add_function_v (GdaSqlBuilder *builder,
                                    const gchar *func_name,
                                    const GdaSqlBuilderId *args,
                                    gint args_size);

Builds a new expression which represents a function applied to some arguments

#### Parameters

builder | a GdaSqlBuilder object |
func_name | the functions's name |
args | an array of IDs representing the function's arguments. | [array length=args_size]
args_size | `args` 's size |

#### Returns

the ID of the new expression, or `0` if there was an error

Rename to: gda_sql_builder_add_function

Since 4.2

### gda_sql_builder_add_id ()

    GdaSqlBuilderId
    gda_sql_builder_add_id (GdaSqlBuilder *builder,
                            const gchar *str);

Defines an expression representing an identifier in `builder` , which may be reused to build other parts of a statement, for instance as a parameter to `gda_sql_builder_add_cond()` or `gda_sql_builder_add_field_value_id()`.

The new expression will contain the `str` literal. For example:

    gda_sql_builder_add_id (b, "name")
    gda_sql_builder_add_id (b, "date")

will be rendered as SQL as:

    name
    "date"

because "date" is an SQL reserved keyword.

For fields, see `gda_sql_builder_add_field_id()`.

#### Parameters

builder | a GdaSqlBuilder object |
str | a string |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_field_id ()

    GdaSqlBuilderId
    gda_sql_builder_add_field_id (GdaSqlBuilder *builder,
                                  const gchar *field_name,
                                  const gchar *table_name);

Defines an expression representing a field in `builder` , which may be reused to build other parts of a statement, for instance as a parameter to `gda_sql_builder_add_cond()` or `gda_sql_builder_add_field_value_id()`.

Calling this with a `NULL` `table_name` is equivalent to calling `gda_sql_builder_add_id()`.

For SELECT queries, see `gda_sql_builder_select_add_field()`.

#### Parameters

builder | a GdaSqlBuilder object |
field_name | a field name |
table_name | a table name, or `NULL`. | [allow-none]

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_expr ()

    GdaSqlBuilderId
    gda_sql_builder_add_expr (GdaSqlBuilder *builder,
                              GdaDataHandler *dh,
                              GType type,
                              ...);

Defines an expression in `builder` which may be reused to build other parts of a statement.

The new expression will contain the value passed as the @... argument.

If `type` is G_TYPE_STRING then it is possible to customize how the value has to be interpreted by passing a specific GdaDataHandler object as `dh` . This feature is very rarely used and the `dh` argument should generally be `NULL`.

Note that for composite types such as GdaNumeric, Gdate, GdaTime, ... pointer to these structures are expected, they should no be passed by value. For example:

    GDate *date = g_date_new_dmy (27, G_DATE_MAY, 1972);
    id = gda_sql_builder_add_expr (b, NULL, G_TYPE_DATE, date);
    g_date_free (date);

    id = gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "my string");
    id = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 25);

will correspond in SQL to:

    '05-27-1972'
    'my string'
    25

#### Parameters

builder | a GdaSqlBuilder object |
dh | deprecated useless argument, just pass `NULL`. | [allow-none]
type | the GType of the following argument |
... | value to set the expression to, of the type specified by `type` |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_expr_value ()

    GdaSqlBuilderId
    gda_sql_builder_add_expr_value (GdaSqlBuilder *builder,
                                    GdaDataHandler *dh,
                                    const GValue *value);

Defines an expression in `builder` which may be reused to build other parts of a statement.

The new expression will contain the value passed as the `value` argument.

If `value` 's type is a string then it is possible to customize how the value has to be interpreted by passing a specific GdaDataHandler object as `dh` . This feature is very rarely used and the `dh` argument should generally be `NULL`.

#### Parameters

builder | a GdaSqlBuilder object |
dh | deprecated useless argument, just pass `NULL`. | [allow-none]
value | value to set the expression to, or `NULL` or a GDA_TYPE_NULL value to represent an SQL NULL. | [allow-none]

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_param ()

    GdaSqlBuilderId
    gda_sql_builder_add_param (GdaSqlBuilder *builder,
                               const gchar *param_name,
                               GType type,
                               gboolean nullok);

Defines a parameter in `builder` which may be reused to build other parts of a statement.

The new expression will contain the `string` literal. For example:

    gda_sql_builder_add_param (b, "age", G_TYPE_INT, FALSE)

will be rendered as SQL as:

    ##age::int

#### Parameters

builder | a GdaSqlBuilder object |
param_name | parameter's name |
type | parameter's type |
nullok | TRUE if the parameter can be set to `NULL` |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_case ()

    GdaSqlBuilderId
    gda_sql_builder_add_case (GdaSqlBuilder *builder,
                              GdaSqlBuilderId test_expr,
                              GdaSqlBuilderId else_expr,
                              ...);

Creates a new CASE ... WHEN ... THEN ... ELSE ... END expression.

#### Parameters

builder | a GdaSqlBuilder object |
test_expr | the expression ID representing the test of the CASE, or `0` |
else_expr | the expression ID representing the ELSE expression, or `0` |
... | a list, terminated by a `0`, of (WHEN expression ID, THEN expression ID) representing all the test cases |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_case_v ()

    GdaSqlBuilderId
    gda_sql_builder_add_case_v (GdaSqlBuilder *builder,
                                GdaSqlBuilderId test_expr,
                                GdaSqlBuilderId else_expr,
                                const GdaSqlBuilderId *when_array,
                                const GdaSqlBuilderId *then_array,
                                gint args_size);

Creates a new CASE ... WHEN ... THEN ... ELSE ... END expression. The WHEN expression and the THEN expression IDs are taken from the `when_array` and `then_array` at the same index, for each index inferior to `args_size` .

#### Parameters

builder | a GdaSqlBuilder object |
test_expr | the expression ID representing the test of the CASE, or `0` |
else_expr | the expression ID representing the ELSE expression, or `0` |
when_array | an array containing each WHEN expression ID, having at least `args_size` elements. | [array length=args_size]
then_array | an array containing each THEN expression ID, having at least `args_size` elements. | [array length=args_size]
args_size | the size of `when_array` and `then_array` |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_sub_select ()

    GdaSqlBuilderId
    gda_sql_builder_add_sub_select (GdaSqlBuilder *builder,
                                    GdaSqlStatement *sqlst);

Adds an expression which is a subselect.

#### Parameters

builder | a GdaSqlBuilder object |
sqlst | a pointer to a GdaSqlStatement, which has to be a SELECT or compound SELECT. This will be copied. |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_cond ()

    GdaSqlBuilderId
    gda_sql_builder_add_cond (GdaSqlBuilder *builder,
                              GdaSqlOperatorType op,
                              GdaSqlBuilderId op1,
                              GdaSqlBuilderId op2,
                              GdaSqlBuilderId op3);

Builds a new expression which represents a condition (or operation).

#### Parameters

builder | a GdaSqlBuilder object |
op | type of condition |
op1 | the ID of the 1st argument (not 0) |
op2 | the ID of the 2nd argument (may be `0` if `op` needs only one operand) |
op3 | the ID of the 3rd argument (may be `0` if `op` needs only one or two operand) |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_add_cond_v ()

    GdaSqlBuilderId
    gda_sql_builder_add_cond_v (GdaSqlBuilder *builder,
                                GdaSqlOperatorType op,
                                const GdaSqlBuilderId *op_ids,
                                gint op_ids_size);

Builds a new expression which represents a condition (or operation).

As a side case, if `ops_ids_size` is 1, then `op` is ignored, and the returned ID represents `op_ids` [0] (this avoids any problem for example when `op` is GDA_SQL_OPERATOR_TYPE_AND and there is in fact only one operand).

#### Parameters

builder | a GdaSqlBuilder object |
op | type of condition |
op_ids | an array of ID for the arguments (not `0`). | [array length=op_ids_size]
op_ids_size | size of `ops_ids` |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

### gda_sql_builder_set_where ()

    void
    gda_sql_builder_set_where (GdaSqlBuilder *builder,
                               GdaSqlBuilderId cond_id);

Valid only for: UPDATE, DELETE, SELECT statements

Sets the WHERE condition of the statement

#### Parameters

builder | a GdaSqlBuilder object |
cond_id | the ID of the expression to set as WHERE condition, or 0 to unset any previous WHERE condition |

Since 4.2

### gda_sql_builder_select_add_target ()

    GdaSqlBuilderId
    gda_sql_builder_select_add_target (GdaSqlBuilder *builder,
                                       const gchar *table_name,
                                       const gchar *alias);

Adds a new target to a SELECT statement

#### Parameters

builder | a GdaSqlBuilder object |
table_name | the name of the target table |
alias | the alias to give to the target, or `NULL`. | [allow-none]

#### Returns

the ID of the new target, or `0` if there was an error

Since 4.2

### gda_sql_builder_select_add_target_id ()

    GdaSqlBuilderId
    gda_sql_builder_select_add_target_id (GdaSqlBuilder *builder,
                                          GdaSqlBuilderId table_id,
                                          const gchar *alias);

Adds a new target to a SELECT statement. If there already exists a target representing the same table and the same alias (or with the same absence of alias) then the same target ID is returned instead of the ID of a new target.

#### Parameters

builder | a GdaSqlBuilder object |
table_id | the ID of the expression holding a table reference (not `0`) |
alias | the alias to give to the target, or `NULL`. | [allow-none]

#### Returns

the ID of the new (or existing) target, or `0` if there was an error

Since 4.2

### gda_sql_builder_select_add_field ()

    GdaSqlBuilderId
    gda_sql_builder_select_add_field (GdaSqlBuilder *builder,
                                      const gchar *field_name,
                                      const gchar *table_name,
                                      const gchar *alias);

Valid only for: SELECT statements.

Add a selected selected item to the SELECT statement.

For non-SELECT statements, see `gda_sql_builder_add_field_id()`.

#### Parameters

builder | a GdaSqlBuilder object |
field_name | a field name |
table_name | a table name, or `NULL`. | [allow-none]
alias | an alias (eg. for the "AS" clause), or `NULL`. | [allow-none]

#### Returns

the ID of the added field, or `0` if there was an error

Since 4.2

### gda_sql_builder_select_join_targets ()

    GdaSqlBuilderId
    gda_sql_builder_select_join_targets (GdaSqlBuilder *builder,
                                         GdaSqlBuilderId left_target_id,
                                         GdaSqlBuilderId right_target_id,
                                         GdaSqlSelectJoinType join_type,
                                         GdaSqlBuilderId join_expr);

Joins two targets in a SELECT statement, using the `join_type` type of join.

Note: if the target represented by `left_target_id` is actually situated after (on the right) of the target represented by `right_target_id` , then the actual type of join may be switched from `GDA_SQL_SELECT_JOIN_LEFT` to `GDA_SQL_SELECT_JOIN_RIGHT` or from `GDA_SQL_SELECT_JOIN_RIGHT` to `GDA_SQL_SELECT_JOIN_LEFT`.

#### Parameters

builder | a GdaSqlBuilder object |
left_target_id | the ID of the left target to use (not `0`) |
right_target_id | the ID of the right target to use (not `0`) |
join_type | the type of join |
join_expr | joining expression's ID, or `0` |

#### Returns

the ID of the new join, or `0` if there was an error

Since 4.2

### gda_sql_builder_join_add_field ()

    void
    gda_sql_builder_join_add_field (GdaSqlBuilder *builder,
                                    GdaSqlBuilderId join_id,
                                    const gchar *field_name);

Alter a join in a SELECT statement to make its condition use equal field values in the fields named `field_name` in both tables, via the USING keyword.

#### Parameters

builder | a GdaSqlBuilder object |
join_id | the ID of the join to modify (not `0`) |
field_name | the name of the field to use in the join condition (not `NULL`) |

#### Returns

the ID of the new join, or `0` if there was an error

Since 4.2

### gda_sql_builder_select_order_by ()

    void
    gda_sql_builder_select_order_by (GdaSqlBuilder *builder,
                                     GdaSqlBuilderId expr_id,
                                     gboolean asc,
                                     const gchar *collation_name);

Adds a new ORDER BY expression to a SELECT statement.

#### Parameters

builder | a GdaSqlBuiler |
expr_id | the ID of the expression to use during sorting (not `0`) |
asc | `TRUE` for an ascending sorting |
collation_name | name of the collation to use when sorting, or `NULL`. | [allow-none]

Since 4.2

### gda_sql_builder_select_set_distinct ()

    void
    gda_sql_builder_select_set_distinct (GdaSqlBuilder *builder,
                                         gboolean distinct,
                                         GdaSqlBuilderId expr_id);

Defines (if `distinct` is `TRUE`) or removes (if `distinct` is `FALSE`) a DISTINCT clause for a SELECT statement.

If `distinct` is `TRUE`, then the ID of an expression can be specified as the `expr_id` argument: if not `0`, this is the expression used to apply the DISTINCT clause on (the resuting SQL will then usually be "... DISTINCT ON <expression>...").

#### Parameters

builder | a GdaSqlBuilder object |
distinct | set to `TRUE` to have the DISTINCT requirement |
expr_id | the ID of the DISTINCT ON expression, or `0` if no expression is to be used. It is ignored if `distinct` is `FALSE`. |

Since 4.2

### gda_sql_builder_select_set_limit ()

    void
    gda_sql_builder_select_set_limit (GdaSqlBuilder *builder,
                                      GdaSqlBuilderId limit_count_expr_id,
                                      GdaSqlBuilderId limit_offset_expr_id);

If `limit_count_expr_id` is not `0`, defines the maximum number of rows in the GdaDataModel resulting from the execution of the built statement. In this case, the offset from which the rows must be collected can be defined by the `limit_offset_expr_id` expression if not `0` (note that this feature may not be supported by all the database providers).

If `limit_count_expr_id` is `0`, then removes any LIMIT which may have been imposed by a previous call to this method.

#### Parameters

builder | a GdaSqlBuilder object |
limit_count_expr_id | the ID of the LIMIT expression, or `0` |
limit_offset_expr_id | the ID of the OFFSET expression, or `0` |

Since 4.2

### gda_sql_builder_select_set_having ()

    void
    gda_sql_builder_select_set_having (GdaSqlBuilder *builder,
                                       GdaSqlBuilderId cond_id);

Valid only for: SELECT statements

Sets the HAVING condition of the statement

#### Parameters

builder | a GdaSqlBuilder object |
cond_id | the ID of the expression to set as HAVING condition, or 0 to unset any previous HAVING condition |

Since 4.2

### gda_sql_builder_select_group_by ()

    void
    gda_sql_builder_select_group_by (GdaSqlBuilder *builder,
                                     GdaSqlBuilderId expr_id);

Valid only for: SELECT statements

Adds the `expr_id` expression to the GROUP BY clause's expressions list

#### Parameters

builder | a GdaSqlBuilder object |
expr_id | the ID of the expression to set use in the GROUP BY clause, or 0 to unset any previous GROUP BY clause |

Since 4.2

### gda_sql_builder_compound_add_sub_select ()

    void
    gda_sql_builder_compound_add_sub_select
                                   (GdaSqlBuilder *builder,
                                    GdaSqlStatement *sqlst);

Add a sub select to a COMPOUND statement

#### Parameters

builder | a GdaSqlBuilder object |
sqlst | a pointer to a GdaSqlStatement, which has to be a SELECT or compound SELECT. This will be copied. |

Since 4.2

### gda_sql_builder_compound_set_type ()

    void
    gda_sql_builder_compound_set_type (GdaSqlBuilder *builder,
                                       GdaSqlStatementCompoundType compound_type);

Changes the type of compound which `builder` is making, for a COMPOUND statement

#### Parameters

builder | a GdaSqlBuilder object |
compound_type | a type of compound |

Since 4.2

### gda_sql_builder_export_expression ()

    GdaSqlExpr *
    gda_sql_builder_export_expression (GdaSqlBuilder *builder,
                                       GdaSqlBuilderId id);

Exports a part managed by `builder` as a new GdaSqlExpr, which can represent any expression in a statement.

#### Parameters

builder | a GdaSqlBuilder object |
id | the ID of the expression to be exported, (must be a valid ID in `builder` , not `0`) |

#### Returns

a pointer to a new GdaSqlExpr structure, free using `gda_sql_expr_free()` when not needed anymore. If the part with `id` as ID cannot be found, the returned value is `NULL`.

Since 4.2

### gda_sql_builder_import_expression ()

    GdaSqlBuilderId
    gda_sql_builder_import_expression (GdaSqlBuilder *builder,
                                       GdaSqlExpr *expr);

Imports the `expr` into `builder` .

#### Parameters

builder | a GdaSqlBuilder object |
expr | a GdaSqlExpr obtained using `gda_sql_builder_export_expression()` |

#### Returns

the ID of the new expression, or `0` if there was an error

Since 4.2

## Types and Values

### struct GdaSqlBuilder

    struct GdaSqlBuilder;

### GdaSqlBuilderId

    typedef guint GdaSqlBuilderId;

## Property Details

### The `“stmt-type”` property

      “stmt-type”                GdaSqlStatementType

Specifies the type of statement to be built, can only be GDA_SQL_STATEMENT_SELECT, GDA_SQL_STATEMENT_INSERT, GDA_SQL_STATEMENT_UPDATE or GDA_SQL_STATEMENT_DELETE

Flags: Write / Construct Only

Default value: GDA_SQL_STATEMENT_UNKNOWN

## See Also

GdaSqlParser, GdaSqlStatement and GdaStatement