libgdamm
4.99.7
|
SqlBuilder can be used to build a Statement from its structural description, much in the same way a SqlParser can be used to build a Statement from a SQL string. More...
Public Types | |
typedef guint | Id |
Public Member Functions | |
virtual | ~SqlBuilder () |
GdaSqlBuilder* | gobj () |
Provides access to the underlying C GObject. More... | |
const GdaSqlBuilder* | gobj () const |
Provides access to the underlying C GObject. More... | |
GdaSqlBuilder* | gobj_copy () |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More... | |
Glib::RefPtr< Statement > | get_statement () const |
Creates a new Gda::Statement statement from builder's contents. More... | |
SqlStatement | get_sql_statement () const |
Creates a new Gda::SqlStatement structure from builder's contents. More... | |
Id | add_id (const Glib::ustring& 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 add_cond() or add_field_value_id(). More... | |
Id | add_field_id (const Glib::ustring& field_name, const Glib::ustring& table_name=Glib::ustring()) |
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 add_cond() or add_field_value_id(). More... | |
template<class ValueType > | |
Id | add_expr (const Glib::RefPtr< DataHandler >& dh, const ValueType& value) |
Defines an expression in Builder which may be reused to build other parts of a statement. More... | |
Id | add_expr_as_value (const Glib::RefPtr< DataHandler >& dh, const Value& value) |
Defines an expression in Builder which may be reused to build other parts of a statement. More... | |
template<class ValueType > | |
Id | add_expr (const ValueType& value) |
Defines an expression in Builder which may be reused to build other parts of a statement. More... | |
Id | add_expr_as_value (const Value& value) |
Defines an expression in Builder which may be reused to build other parts of a statement. More... | |
Id | add_param (const Glib::ustring& param_name, GType type, bool nullok=false) |
Defines a parameter which may be reused to build other parts of a statement. More... | |
Id | add_cond (SqlOperatorType op, Id op1, Id op2=0, Id op3=0) |
Builds a new expression which reprenents a condition (or operation). More... | |
Id | add_cond (SqlOperatorType op, const std::vector< Id >& op_ids) |
Builds a new expression which reprenents a condition (or operation). More... | |
Id | add_function (const Glib::ustring& function_name, const std::vector< Id >& args) |
Builds a new expression which represents a function applied to some arguments. More... | |
Id | add_function (const Glib::ustring& function_name, Id arg) |
Builds a new expression which represents a function applied to an argument. More... | |
Id | add_sub_select (const SqlStatement& sqlst) |
Adds an expression which is a subselect. More... | |
Id | select_add_field (const Glib::ustring& field_name, const Glib::ustring& table_name, const Glib::ustring& alias=Glib::ustring()) |
Valid only for: SELECT statements. More... | |
Id | select_add_target (const Glib::ustring& table_name, const Glib::ustring& alias=Glib::ustring()) |
Adds a new target to a SELECT statement. More... | |
Id | select_add_target_id (Id table_id, const Glib::ustring& alias=Glib::ustring()) |
Adds a new target to a SELECT statement. More... | |
Id | select_join_targets (Id left_target_id, Id right_target_id, SqlSelectJoinType join_type, Id join_expr=0) |
Joins two targets in a SELECT statement. More... | |
void | join_add_field (Id join_id, const Glib::ustring& 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. More... | |
void | select_order_by (Id expr_id, bool asc=true, const Glib::ustring& collation_name=Glib::ustring()) |
Adds a new ORDER BY expression to a SELECT statement. More... | |
void | select_set_distinct (bool distinct=true) |
Adds or removes a DISTINCT clause for a SELECT statement. More... | |
void | select_set_distinct (bool distinct, Id expr_id) |
Defines (if distinct is true ) or removes (if distinct is false ) a DISTINCT clause for a SELECT statement. More... | |
void | select_set_limit (Id limit_count, Id offset=0) |
Defines the maximum number of rows in the DataModel resulting from the execution of the built statement. More... | |
void | select_set_limit_id (Id limit_count_expr_id, Id limit_offest_expr_id=0) |
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. More... | |
void | select_set_having (Id cond_id) |
Valid only for: SELECT statements. More... | |
void | select_group_by (Id expr_id) |
Valid only for: SELECT statements. More... | |
void | set_table (const Glib::ustring& table_name) |
Valid only for: INSERT, UPDATE, DELETE statements. More... | |
void | set_where (Id cond_id) |
Valid only for: UPDATE, DELETE, SELECT statements. More... | |
void | add_field_value_id (Id field_id, Id value_id=0) |
Valid only for: INSERT, UPDATE, SELECT statements. More... | |
template<class ValueType > | |
void | add_field_value (const Glib::ustring& field_name, const ValueType& value) |
Specifies that the field represented by field_name will be set to the value. More... | |
void | add_field_value_as_value (const Glib::ustring& field_name, const Value& value) |
Valid only for: INSERT, UPDATE statements. More... | |
void | compound_add_sub_select (const SqlStatement& sqlst) |
Add a sub select to a COMPOUND statement. More... | |
SqlExpr | export_expression (Id id) const |
Exports a part managed by builder as a new Gda::SqlExpr, which can represent any expression in a statement. More... | |
Id | import_expression (const SqlExpr& expr) |
Imports the expression. More... | |
Static Public Member Functions | |
static GType | get_type () |
Get the GType for this class, for use with the underlying GObject type system. More... | |
static Glib::RefPtr< SqlBuilder > | create (SqlStatementType type) |
Protected Member Functions | |
SqlBuilder (SqlStatementType type) | |
Related Functions | |
(Note that these are not member functions.) | |
Glib::RefPtr < Gnome::Gda::SqlBuilder > | wrap (GdaSqlBuilder* object, bool take_copy=false) |
A Glib::wrap() method for this object. More... | |
SqlBuilder can be used to build a Statement from its structural description, much in the same way a SqlParser can be used to build a Statement from a SQL string.
You may, for instance, pass the SqlBuilder directly to Connection::statement_execute_select_builder() or Connection::statement_execute_non_select_builder(). Or you may instead call get_statement() and use the resulting SqlStatement.
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 SqlBuilder object, and each is identified using a single ID. That ID is dynamically allocated by the object.
This simple example builds the equivalent of this SQL query: "SELECT employees.name_first, employees.name_last FROM employees WHERE employees.employee_id = 123".
Note that, in this simple example, it's not necessary to specify the extra "employees" table name parameter to select_add_field() and add_field_id(), though it's often a good idea to avoid ambiguity in larger queries.
typedef guint Gnome::Gda::SqlBuilder::Id |
|
virtual |
|
protected |
Id Gnome::Gda::SqlBuilder::add_cond | ( | SqlOperatorType | op, |
Id | op1, | ||
Id | op2 = 0 , |
||
Id | op3 = 0 |
||
) |
Builds a new expression which reprenents a condition (or operation).
op | Type of condition |
op1 | The ID of the 1st argument (not 0) |
op2 | The ID of the 2st argument (maybe 0 if op only requires one argument) |
op3 | The ID of the 3st argument (maybe 0 if op only requires one or two arguments) |
Id Gnome::Gda::SqlBuilder::add_cond | ( | SqlOperatorType | op, |
const std::vector< Id >& | op_ids | ||
) |
Builds a new expression which reprenents a condition (or operation).
op | Type of condition |
op_ids,: | list of IDs of the operands of the condition |
Id Gnome::Gda::SqlBuilder::add_expr | ( | const Glib::RefPtr< DataHandler >& | dh, |
const ValueType & | value | ||
) |
Defines an expression in Builder which may be reused to build other parts of a statement.
dh | The datahandler to use |
value,: | value to set the expression to |
See expr() except that no custom datahandler is given
Id Gnome::Gda::SqlBuilder::add_expr | ( | const ValueType & | value | ) |
Defines an expression in Builder which may be reused to build other parts of a statement.
value,: | value to set the expression to |
See expr() except that no custom datahandler is given
Id Gnome::Gda::SqlBuilder::add_expr_as_value | ( | const Glib::RefPtr< DataHandler >& | dh, |
const Value& | value | ||
) |
Defines an expression in Builder which may be reused to build other parts of a statement.
dh | The datahandler to use |
value,: | value to set the expression to |
See expr() except that no custom datahandler is given
Defines an expression in Builder which may be reused to build other parts of a statement.
value,: | value to set the expression to |
See expr() except that no custom datahandler is given
Id Gnome::Gda::SqlBuilder::add_field_id | ( | const Glib::ustring & | field_name, |
const Glib::ustring & | table_name = Glib::ustring() |
||
) |
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 add_cond() or add_field_value_id().
Calling this with a 0
table_name is equivalent to calling add_id().
For SELECT queries, see select_add_field().
field_name | A field name. |
table_name | A table name, or 0 . |
void Gnome::Gda::SqlBuilder::add_field_value | ( | const Glib::ustring & | field_name, |
const ValueType & | value | ||
) |
Specifies that the field represented by field_name will be set to the value.
See gadd_expr() for more information. This is valid only for INSERT and UPDATE statements.
field_name A field name.
value | The value to set the field to. |
void Gnome::Gda::SqlBuilder::add_field_value_as_value | ( | const Glib::ustring & | field_name, |
const Value& | value | ||
) |
Valid only for: INSERT, UPDATE statements.
Specifies that the field represented by field_name will be set to the value identified by value
field_name | A field name. |
value | Value to set the field to, or 0 or a GDA_TYPE_0 value to represent an SQL 0 . |
Valid only for: INSERT, UPDATE, SELECT statements.
See also add_field_value() and add_field_value_as_gvalue().
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. |
Id Gnome::Gda::SqlBuilder::add_function | ( | const Glib::ustring & | function_name, |
const std::vector< Id >& | args | ||
) |
Builds a new expression which represents a function applied to some arguments.
function_name | The name of the function to embed (e.g. MAX, MIN, ...) |
args,: | list of ids of the arguments to the function |
Id Gnome::Gda::SqlBuilder::add_function | ( | const Glib::ustring & | function_name, |
Id | arg | ||
) |
Builds a new expression which represents a function applied to an argument.
function_name | The name of the function to embed (e.g. MAX, MIN, ...) |
arg,: | The ids of the argument to the function |
Id Gnome::Gda::SqlBuilder::add_id | ( | const Glib::ustring & | 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 add_cond() or 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 add_field_id().
string | A string. |
Id Gnome::Gda::SqlBuilder::add_param | ( | const Glib::ustring & | param_name, |
GType | type, | ||
bool | nullok = false |
||
) |
Defines a parameter which may be reused to build other parts of a statement.
param_name: name of the parameter : GType of the parameter True if the parameter can be set to NULL |
Id Gnome::Gda::SqlBuilder::add_sub_select | ( | const SqlStatement& | sqlst | ) |
Adds an expression which is a subselect.
sqlst | A SqlStatement, which must be a SELECT or compound SELECT. |
void Gnome::Gda::SqlBuilder::compound_add_sub_select | ( | const SqlStatement& | sqlst | ) |
Add a sub select to a COMPOUND statement.
sqlst | A pointer to a Gda::SqlStatement, which has to be a SELECT or compound SELECT. This will be copied. |
|
static |
Exports a part managed by builder as a new Gda::SqlExpr, which can represent any expression in a statement.
id | The ID of the expression to be exported, (must be a valid ID in builder, not %0). |
0
. SqlStatement Gnome::Gda::SqlBuilder::get_sql_statement | ( | ) | const |
Creates a new Gda::SqlStatement 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.
Glib::RefPtr<Statement> Gnome::Gda::SqlBuilder::get_statement | ( | ) | const |
Creates a new Gda::Statement statement from builder's contents.
0
if an error occurred.
|
static |
Get the GType for this class, for use with the underlying GObject type system.
|
inline |
Provides access to the underlying C GObject.
|
inline |
Provides access to the underlying C GObject.
GdaSqlBuilder* Gnome::Gda::SqlBuilder::gobj_copy | ( | ) |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
Imports the expression.
expr | A SqlExpr obtained using export_expression(). |
void Gnome::Gda::SqlBuilder::join_add_field | ( | Id | join_id, |
const Glib::ustring & | 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.
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 0 ). |
Id Gnome::Gda::SqlBuilder::select_add_field | ( | const Glib::ustring & | field_name, |
const Glib::ustring & | table_name, | ||
const Glib::ustring & | alias = Glib::ustring() |
||
) |
Valid only for: SELECT statements.
Add a selected selected item to the SELECT statement.
For non-SELECT statements, see add_field_id().
field_name | A field name. |
table_name | A table name, or 0 . |
alias | An alias (eg. for the "AS" clause), or 0 . |
Id Gnome::Gda::SqlBuilder::select_add_target | ( | const Glib::ustring & | table_name, |
const Glib::ustring & | alias = Glib::ustring() |
||
) |
Adds a new target to a SELECT statement.
table_id | The ID of the expression holding a table reference. |
alias | The alias to give to the target. |
Id Gnome::Gda::SqlBuilder::select_add_target_id | ( | Id | table_id, |
const Glib::ustring & | alias = Glib::ustring() |
||
) |
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.
table_id | The ID of the expression holding a table reference (not %0). |
alias | The alias to give to the target, or 0 . |
void Gnome::Gda::SqlBuilder::select_group_by | ( | Id | expr_id | ) |
Valid only for: SELECT statements.
Adds the expr_id expression to the GROUP BY clause's expressions list
expr_id | The ID of the expression to set use in the GROUP BY clause, or 0 to unset any previous GROUP BY clause. |
Id Gnome::Gda::SqlBuilder::select_join_targets | ( | Id | left_target_id, |
Id | right_target_id, | ||
SqlSelectJoinType | join_type, | ||
Id | join_expr = 0 |
||
) |
Joins two targets in a SELECT statement.
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 |
void Gnome::Gda::SqlBuilder::select_order_by | ( | Id | expr_id, |
bool | asc = true , |
||
const Glib::ustring & | collation_name = Glib::ustring() |
||
) |
Adds a new ORDER BY expression to a SELECT statement.
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 0 . |
void Gnome::Gda::SqlBuilder::select_set_distinct | ( | bool | distinct = true | ) |
Adds or removes a DISTINCT clause for a SELECT statement.
distinct | Whether a DISTINCT clause should be in the SELECT statement. |
void Gnome::Gda::SqlBuilder::select_set_distinct | ( | bool | distinct, |
Id | 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>...").
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 . |
void Gnome::Gda::SqlBuilder::select_set_having | ( | Id | cond_id | ) |
Valid only for: SELECT statements.
Sets the HAVING condition of the statement
cond_id | The ID of the expression to set as HAVING condition, or 0 to unset any previous HAVING condition. |
Defines the maximum number of rows in the DataModel resulting from the execution of the built statement.
limit_count | The number of rows that should be returned. |
The | offset of the first row that should appear in the result. (note that this feature may not be supported by all the database providers.) |
void Gnome::Gda::SqlBuilder::select_set_limit_id | ( | Id | limit_count_expr_id, |
Id | limit_offest_expr_id = 0 |
||
) |
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.
limit_count_expr_id | The ID of the LIMIT expression, or %0. |
limit_offset_expr_id | The ID of the OFFSET expression, or %0. |
void Gnome::Gda::SqlBuilder::set_table | ( | const Glib::ustring & | table_name | ) |
Valid only for: INSERT, UPDATE, DELETE statements.
Sets the name of the table on which the built statement operates.
table_name | A table name. |
void Gnome::Gda::SqlBuilder::set_where | ( | Id | cond_id | ) |
Valid only for: UPDATE, DELETE, SELECT statements.
Sets the WHERE condition of the statement
cond_id | The ID of the expression to set as WHERE condition, or 0 to unset any previous WHERE condition. |
|
related |
A Glib::wrap() method for this object.
object | The C instance. |
take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref. |