## GdaSqlBuilder GdaSqlBuilder — Factory object for statements |

## Synopsis

                        GdaSqlBuilder;
    typedef             GdaSqlBuilderId;
    GdaSqlBuilder *     gda_sql_builder_new                 (GdaSqlStatementType stmt_type);
    GdaStatement *      gda_sql_builder_get_statement       (GdaSqlBuilder *builder,
                                                             GError **error);
    GdaSqlStatement *   gda_sql_builder_get_sql_statement   (GdaSqlBuilder *builder);

    void                gda_sql_builder_set_table           (GdaSqlBuilder *builder,
                                                             const gchar *table_name);
    void                gda_sql_builder_add_field_value     (GdaSqlBuilder *builder,
                                                             const gchar *field_name,
                                                             GType type,
                                                             ...);
    void                gda_sql_builder_add_field_value_as_gvalue
                                                            (GdaSqlBuilder *builder,
                                                             const gchar *field_name,
                                                             const GValue *value);
    void                gda_sql_builder_add_field_value_id  (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId field_id,
                                                             GdaSqlBuilderId value_id);
    GdaSqlBuilderId     gda_sql_builder_add_function        (GdaSqlBuilder *builder,
                                                             const gchar *func_name,
                                                             ...);
    GdaSqlBuilderId     gda_sql_builder_add_function_v      (GdaSqlBuilder *builder,
                                                             const gchar *func_name,
                                                             const GdaSqlBuilderId *args,
                                                             gint args_size);

    GdaSqlBuilderId     gda_sql_builder_add_id              (GdaSqlBuilder *builder,
                                                             const gchar *string);
    GdaSqlBuilderId     gda_sql_builder_add_field_id        (GdaSqlBuilder *builder,
                                                             const gchar *field_name,
                                                             const gchar *table_name);
    GdaSqlBuilderId     gda_sql_builder_add_expr            (GdaSqlBuilder *builder,
                                                             GdaDataHandler *dh,
                                                             GType type,
                                                             ...);
    GdaSqlBuilderId     gda_sql_builder_add_expr_value      (GdaSqlBuilder *builder,
                                                             GdaDataHandler *dh,
                                                             const GValue *value);
    GdaSqlBuilderId     gda_sql_builder_add_param           (GdaSqlBuilder *builder,
                                                             const gchar *param_name,
                                                             GType type,
                                                             gboolean nullok);
    GdaSqlBuilderId     gda_sql_builder_add_case            (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId test_expr,
                                                             GdaSqlBuilderId else_expr,
                                                             ...);
    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);
    GdaSqlBuilderId     gda_sql_builder_add_sub_select      (GdaSqlBuilder *builder,
                                                             GdaSqlStatement *sqlst);

    GdaSqlBuilderId     gda_sql_builder_add_cond            (GdaSqlBuilder *builder,
                                                             GdaSqlOperatorType op,
                                                             GdaSqlBuilderId op1,
                                                             GdaSqlBuilderId op2,
                                                             GdaSqlBuilderId op3);
    GdaSqlBuilderId     gda_sql_builder_add_cond_v          (GdaSqlBuilder *builder,
                                                             GdaSqlOperatorType op,
                                                             const GdaSqlBuilderId *op_ids,
                                                             gint op_ids_size);
    void                gda_sql_builder_set_where           (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId cond_id);

    GdaSqlBuilderId     gda_sql_builder_select_add_target   (GdaSqlBuilder *builder,
                                                             const gchar *table_name,
                                                             const gchar *alias);
    GdaSqlBuilderId     gda_sql_builder_select_add_target_id
                                                            (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId table_id,
                                                             const gchar *alias);
    GdaSqlBuilderId     gda_sql_builder_select_add_field    (GdaSqlBuilder *builder,
                                                             const gchar *field_name,
                                                             const gchar *table_name,
                                                             const gchar *alias);
    GdaSqlBuilderId     gda_sql_builder_select_join_targets (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId left_target_id,
                                                             GdaSqlBuilderId right_target_id,
                                                             GdaSqlSelectJoinType join_type,
                                                             GdaSqlBuilderId join_expr);
    void                gda_sql_builder_join_add_field      (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId join_id,
                                                             const gchar *field_name);
    void                gda_sql_builder_select_order_by     (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId expr_id,
                                                             gboolean asc,
                                                             const gchar *collation_name);
    void                gda_sql_builder_select_set_distinct (GdaSqlBuilder *builder,
                                                             gboolean distinct,
                                                             GdaSqlBuilderId expr_id);
    void                gda_sql_builder_select_set_limit    (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId limit_count_expr_id,
                                                             GdaSqlBuilderId limit_offest_expr_id);
    void                gda_sql_builder_select_set_having   (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId cond_id);
    void                gda_sql_builder_select_group_by     (GdaSqlBuilder *builder,
                                                             GdaSqlBuilderId expr_id);

    void                gda_sql_builder_compound_add_sub_select
                                                            (GdaSqlBuilder *builder,
                                                             GdaSqlStatement *sqlst);
    void                gda_sql_builder_compound_set_type   (GdaSqlBuilder *builder,
                                                             GdaSqlStatementCompoundType compound_type);

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

## Object Hierarchy

      GObject
       +----GdaSqlBuilder

## Properties

      "stmt-type"                GdaSqlStatementType   : Write / Construct Only

## 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 >= ##ageparam::int" 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.

## Details

### GdaSqlBuilder

    typedef struct _GdaSqlBuilder GdaSqlBuilder;

### GdaSqlBuilderId

    typedef guint GdaSqlBuilderId;

### 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`

`stmt_type` : | the type of statement to build
Returns : | the newly created object, or `NULL` if an error occurred (such as unsupported statement type)

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.

`builder` : | a GdaSqlBuilder object
`error` : | a place to store errors, or `NULL`
Returns : | a new GdaStatement object, or `NULL` if an error occurred

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.

`builder` : | a GdaSqlBuilder object
Returns : | a GdaSqlStatement pointer

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.

`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()`.

`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`

`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

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()`.

`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 reprenents a function applied to some arguments

`builder` : | a GdaSqlBuilder object
`func_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

`builder` : | a GdaSqlBuilder object
`func_name` : |
`args` : | an array of IDs representing the function's arguments
`args_size` : | `args`'s size
Returns : | the ID of the new expression, or 0 if there was an error

Since 4.2

### gda_sql_builder_add_id ()

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

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 `string` 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()`.

`builder` : | a GdaSqlBuilder object
`string` : | 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()`.

`builder` : | a GdaSqlBuilder object
`field_name` : | a field name
`table_name` : | a table name, or `NULL`
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. It is possible to customize how the value has to be interpreted by passing a specific GdaDataHandler object as `dh`.

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

`builder` : | a GdaSqlBuilder object
`dh` : | a GdaDataHandler to use, or `NULL`
`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. It is possible to customize how the value has to be interpreted by passing a specific GdaDataHandler object as `dh`.

`builder` : | a GdaSqlBuilder object
`dh` : | a GdaDataHandler to use, or `NULL`
`value` : | value to set the expression to, or `NULL` or a GDA_TYPE_NULL value to represent an SQL NULL
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

`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.

`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`.

`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
`then_array` : | an array containing each THEN expression ID, having at least `args_size` elements
`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.

`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 reprenents a condition (or operation).

`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 reprenents 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).

`builder` : | a GdaSqlBuilder object
`op` : | type of condition
`op_ids` : | an array of ID for the arguments (not `0`)
`op_ids_size` : |
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

`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

`builder` : | a GdaSqlBuilder object
`table_name` : | the name of the target table
`alias` : | the alias to give to the target, or `NULL`
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.

`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`
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()`.

`builder` : | a GdaSqlBuilder object
`field_name` : | a field name
`table_name` : | a table name, or `NULL`
`alias` : | an alias (eg. for the "AS" clause), or `NULL`
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`.

`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 joins in a SELECT statement to make its condition on the field which name is `field_name`

`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`)

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.

`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`

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>...").

`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_offest_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.

`builder` : | a GdaSqlBuilder object
`limit_count_expr_id` : | the ID of the LIMIT expression, or `0`
`limit_offest_expr_id` : |

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

`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

`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

`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

`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.

`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`.

`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

## Property Details

### The `"stmt-type"` property

      "stmt-type"                GdaSqlStatementType   : Write / Construct Only

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

Default value: GDA_SQL_STATEMENT_UNKNOWN