![]() |
![]() |
![]() |
GNOME Data Access 4.0 manual | ![]() |
---|---|---|---|---|
GdaDataModelQuery; enum GdaDataModelQueryError; GdaDataModelQueryClass; GdaDataModelQueryPrivate; GdaDataModelQuery* gda_data_model_query_new (GdaConnection *cnc, GdaStatement *select_stmt, GdaSet *params); gboolean gda_data_model_query_refresh (GdaDataModelQuery *model, GError **error); gboolean gda_data_model_query_set_row_selection_condition (GdaDataModelQuery *model, GdaSqlExpr *expr, GError **error); gboolean gda_data_model_query_set_row_selection_condition_sql (GdaDataModelQuery *model, const gchar *sql_where, GError **error); gboolean gda_data_model_query_compute_row_selection_condition (GdaDataModelQuery *model, GError **error); gboolean gda_data_model_query_set_modification_statement (GdaDataModelQuery *model, GdaStatement *mod_stmt, GError **error); gboolean gda_data_model_query_set_modification_statement_sql (GdaDataModelQuery *model, const gchar *sql, GError **error); gboolean gda_data_model_query_compute_modification_statements (GdaDataModelQuery *model, GError **error);
"connection" GdaConnection* : Read / Write / Construct Only "exec-params" GdaSet* : Read / Write / Construct Only "statement" GdaStatement* : Read / Write / Construct Only
The GdaDataModelQuery data model executes a SELECT statement and acts as a thin wrapper around the resulting GdaDataModel. The benefits of using a GdaDataModelQuery object are:
The data model can re-execute the SELECT statement anytime to have some up-to-date data (appearing in the same data model instead of one new data model object everytime the SELECT statement is executed)
If the statement needs some parameters, then anytime a parameter is changed, the SELECT statement is re-executed with the new paramet's values
The GdaDataModelQuery data model can be modified, the same rules as for the GdaDataSelect object apply.
If multiple modifications are to be done, then it can perform them in a transaction
typedef enum { GDA_DATA_MODEL_QUERY_SELECT_STATEMENT_ERROR, GDA_DATA_MODEL_QUERY_CONNECTION_ERROR } GdaDataModelQueryError;
GdaDataModelQuery* gda_data_model_query_new (GdaConnection *cnc, GdaStatement *select_stmt, GdaSet *params);
Creates a new GdaDataModel object using the data returned by the execution of the
select_stmt
SELECT statement.
Note: if select_stmt
contains one or more parameters, then params
should not be NULL
otherwise
the resulting object will never contain anything and will be unuseable as the SELECT statement
will never be successfully be executed.
|
a GdaConnection object |
|
a SELECT statement |
|
a GdaSet object containing select_stmt 's execution parameters (see gda_statement_get_parameters() ), or NULL
|
Returns : |
a pointer to the newly created GdaDataModel. |
gboolean gda_data_model_query_refresh (GdaDataModelQuery *model, GError **error);
(Re)-runs the SELECT query to update the contents of model
|
a GdaDataModelQuery data model |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred |
gboolean gda_data_model_query_set_row_selection_condition (GdaDataModelQuery *model, GdaSqlExpr *expr, GError **error);
Offers the same features as gda_data_model_query_set_row_selection_condition_sql()
but using a GdaSqlExpr
structure instead of an SQL syntax.
|
a GdaDataSelect data model |
|
a GdaSqlExpr expression |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred |
gboolean gda_data_model_query_set_row_selection_condition_sql (GdaDataModelQuery *model, const gchar *sql_where, GError **error);
Specifies the SQL condition corresponding to the WHERE part of a SELECT statement which would return only 1 row (the expression of the primary key).
For example for a table created as "CREATE TABLE mytable (part1 int NOT NULL, part2 string NOT NULL,
name string, PRIMARY KEY (part1, part2))", and if pmodel
corresponds to the execution of the
"SELECT name, part1, part2 FROM mytable", then the sensible value for sql_where
would be
"part1 = ##-1::int AND part2 = ##-2::string" because the values of the 'part1' field are located
in pmodel
's column number 1 and the values of the 'part2' field are located
in pmodel
's column number 2 and the primary key is composed of (part1, part2).
For more information about the syntax of the parameters (named "##-1::int" for example), see the
GdaSqlParser documentation, and
gda_data_model_query_set_modification_statement()
.
|
a GdaDataSelect data model |
|
an SQL condition (withouth the WHERE keyword) |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred |
gboolean gda_data_model_query_compute_row_selection_condition (GdaDataModelQuery *model, GError **error);
Offers the same features as gda_data_model_query_set_row_selection_condition()
but the expression
is computed from the meta data associated to the connection being used when model
was created.
NOTE1: make sure the meta data associated to the connection is up to date before using this
method, see gda_connection_update_meta_store()
.
NOTE2: if the SELECT statement from which model
has been created uses more than one table, or
if the table used does not have any primary key, then this method will fail
|
a GdaDataSelect object |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred. |
gboolean gda_data_model_query_set_modification_statement (GdaDataModelQuery *model, GdaStatement *mod_stmt, GError **error);
Informs model
that it should allow modifications to the data in some columns and some rows
using mod_stmt
to propagate those modifications into the database.
If mod_stmt
is:
an UPDATE statement, then all the rows in model
will be modifyable
a DELETE statement, then it will be possible to delete rows in model
in INSERT statement, then it will be possible to add some rows to model
any other statement, then this method will return an error
This method can be called several times to specify different types of modification.
If mod_stmt
is an UPDATE or DELETE statement then it should have a WHERE part which identifies
a unique row in model
(please note that this property can't be checked but may result
in model
behaving in an unpredictable way).
NOTE1: However, if the gda_data_model_query_set_row_selection_condition()
or gda_data_model_query_set_row_selection_condition_sql()
have been successfully be called before, the WHERE
part of mod_stmt
WILL be modified to use the row selection condition specified through one of
these methods (please not that it is then possible to avoid specifying a WHERE part in mod_stmt
then).
NOTE2: if gda_data_model_query_set_row_selection_condition()
or gda_data_model_query_set_row_selection_condition_sql()
have not yet been successfully be called before, then
the WHERE part of mod_stmt
will be used as if one of these functions had been called.
|
a GdaDataSelect data model |
|
a GdaStatement (INSERT, UPDATE or DELETE) |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred. |
gboolean gda_data_model_query_set_modification_statement_sql (GdaDataModelQuery *model, const gchar *sql, GError **error);
Offers the same feature as gda_data_model_query_set_modification_statement()
but using an SQL statement
|
a GdaDataSelect data model |
|
an SQL text |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred. |
gboolean gda_data_model_query_compute_modification_statements (GdaDataModelQuery *model, GError **error);
Makes model
try to compute INSERT, UPDATE and DELETE statements to be used when modifying model
's contents.
Note: any modification statement set using gda_data_model_query_set_modification_statement()
will first be unset
|
a GdaDataSelect data model |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred. If FALSE is returned, then some modification statement may still have been computed |
"connection"
property"connection" GdaConnection* : Read / Write / Construct Only
Connection to use to execute statements.
"exec-params"
property"exec-params" GdaSet* : Read / Write / Construct Only
Parameters used with the SELECT statement.
"statement"
property"statement" GdaStatement* : Read / Write / Construct Only
SELECT statement to be executed to populate the model with data.