Gda.SqlBuilder¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
object |
r |
Class Details¶
- class Gda.SqlBuilder(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- classmethod new(stmt_type)¶
- Parameters:
stmt_type (
Gda.SqlStatementType
) – the type of statement to build- Returns:
the newly created object, or
None
if an error occurred (such as unsupported statement type)- Return type:
Create a new
Gda.SqlBuilder
object to buildGda.Statement
orGda.SqlStatement
objects of type stmt_typeNew in version 4.2.
- add_case(test_expr, else_expr, when_array, then_array)¶
- Parameters:
test_expr (
int
) – the expression ID representing the test of the CASE, or %0else_expr (
int
) – the expression ID representing the ELSE expression, or %0when_array ([
int
]) – an array containing each WHEN expression ID, having at least args_size elementsthen_array ([
int
]) – an array containing each THEN expression ID, having at least args_size elements
- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
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.
New in version 4.2.
- add_cond(op, op1, op2, op3)¶
- Parameters:
op (
Gda.SqlOperatorType
) – type of conditionop1 (
int
) – the ID of the 1st argument (not 0)op2 (
int
) – the ID of the 2nd argument (may be %0 if op needs only one operand)op3 (
int
) – 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
- Return type:
Builds a new expression which represents a condition (or operation).
New in version 4.2.
- add_cond_v(op, op_ids)¶
- Parameters:
op (
Gda.SqlOperatorType
) – type of conditionop_ids ([
int
]) – an array of ID for the arguments (not %0)
- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
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.SqlOperatorType.AND
and there is in fact only one operand).New in version 4.2.
- add_expr_value(dh, value)¶
- Parameters:
dh (
Gda.DataHandler
orNone
) – deprecated useless argument, just passNone
value (
GObject.Value
orNone
) – value to set the expression to, orNone
or a GDA_TYPE_NULL value to represent an SQLNone
- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
Defines an expression in self 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
Gda.DataHandler
object as dh. This feature is very rarely used and the dh argument should generally beNone
.New in version 4.2.
- add_field_id(field_name, table_name)¶
- Parameters:
- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
Defines an expression representing a field in self, which may be reused to build other parts of a statement, for instance as a parameter to
Gda.SqlBuilder.add_cond
() orGda.SqlBuilder.add_field_value_id
().Calling this with a
None
table_name is equivalent to callingGda.SqlBuilder.add_id
().For SELECT queries, see
Gda.SqlBuilder.select_add_field
().New in version 4.2.
- add_field_value_as_gvalue(field_name, value)¶
- Parameters:
field_name (
str
) – a field namevalue (
GObject.Value
orNone
) – value to set the field to, orNone
or a GDA_TYPE_NULL value to represent an SQLNone
Valid only for: INSERT, UPDATE statements.
Specifies that the field represented by field_name will be set to the value identified by value
New in version 4.2.
- add_field_value_id(field_id, value_id)¶
- Parameters:
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.SqlBuilder.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.SqlBuilder.add_field_value_as_gvalue
().New in version 4.2.
- add_function(func_name, args)¶
- Parameters:
- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
Builds a new expression which represents a function applied to some arguments
New in version 4.2.
- add_id(str)¶
- Parameters:
str (
str
) – a string- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
Defines an expression representing an identifier in self, which may be reused to build other parts of a statement, for instance as a parameter to
Gda.SqlBuilder.add_cond
() orGda.SqlBuilder.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.SqlBuilder.add_field_id
().New in version 4.2.
- add_param(param_name, type, nullok)¶
- Parameters:
param_name (
str
) – parameter’s nametype (
GObject.GType
) – parameter’s type
- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
Defines a parameter in self 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
New in version 4.2.
- compound_add_sub_select_from_builder(subselect)¶
- Parameters:
subselect (
Gda.SqlBuilder
) – aGda.SqlBuilder
, which has to be a SELECT or compound SELECT. This will be copied.
Add a sub select to a COMPOUND statement
New in version 4.2.
- compound_set_type(compound_type)¶
- Parameters:
compound_type (
Gda.SqlStatementCompoundType
) – a type of compound
Changes the type of compound which self is making, for a COMPOUND statement
New in version 4.2.
- get_statement()¶
- Raises:
- Returns:
a new
Gda.Statement
object, orNone
if an error occurred- Return type:
Creates a new
Gda.Statement
statement from self's contents.New in version 4.2.
- import_expression_from_builder(query, expr_id)¶
- Parameters:
query (
Gda.SqlBuilder
) – aGda.SqlBuilder
object to get expression fromexpr_id (
int
) – a #GdaSqlBuilderId of the expression in query
- Returns:
the ID of the new expression, or %0 if there was an error
- Return type:
Imports the an expression located in query into self.
New in version 4.2.
- join_add_field(join_id, field_name)¶
- Parameters:
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.
New in version 4.2.
- select_add_field(field_name, table_name, alias)¶
- Parameters:
- Returns:
the ID of the added field, or %0 if there was an error
- Return type:
Valid only for: SELECT statements.
Add a selected selected item to the SELECT statement.
For non-SELECT statements, see
Gda.SqlBuilder.add_field_id
().New in version 4.2.
- select_add_target(table_name, alias)¶
- Parameters:
- Returns:
the ID of the new target, or %0 if there was an error
- Return type:
Adds a new target to a SELECT statement
New in version 4.2.
- select_add_target_id(table_id, alias)¶
- Parameters:
- Returns:
the ID of the new (or existing) target, or %0 if there was an error
- Return type:
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.
New in version 4.2.
- select_group_by(expr_id)¶
- Parameters:
expr_id (
int
) – the ID of the expression to set use in the GROUP BY clause, or 0 to unset any previous GROUP BY clause
Valid only for: SELECT statements
Adds the expr_id expression to the GROUP BY clause’s expressions list
New in version 4.2.
- select_order_by(expr_id, asc, collation_name)¶
- Parameters:
Adds a new ORDER BY expression to a SELECT statement.
New in version 4.2.
- select_set_distinct(distinct, expr_id)¶
- Parameters:
Defines (if distinct is
True
) or removes (if distinct isFalse
) 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>…”).New in version 4.2.
- select_set_having(cond_id)¶
- Parameters:
cond_id (
int
) – the ID of the expression to set as HAVING condition, or 0 to unset any previous HAVING condition
Valid only for: SELECT statements
Sets the HAVING condition of the statement
New in version 4.2.
- select_set_limit(limit_count_expr_id, limit_offset_expr_id)¶
- Parameters:
If limit_count_expr_id is not %0, defines the maximum number of rows in the
Gda.DataModel
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.
New in version 4.2.