statement_execute
Description:
Executes stmt
.
As stmt
can, by design (and if not abused), contain only one SQL statement, the return object will either be:
- a DataSelect object (which is also a
DataModel) if
stmt
is a SELECT statement (usually a GDA_SQL_STATEMENT_SELECT, see SqlStatementType) containing the results of the SELECT. The resulting data model is by default read only, but modifications can be enabled, see the DataSelect's documentation for more information. - a Set for any other SQL statement which correctly executed. In this case (if the
provider supports it), then the Set may contain value holders named:
- a (gint) Holder named "IMPACTED_ROWS"
- a (GObject) Holder named "EVENT" which contains a ConnectionEvent
If last_insert_row
is not null
and stmt
is an INSERT statement, then it will contain (if the provider
used by this supports it) a new Set object composed of
value holders named "+<column number>" starting at column 0 which contain the actual inserted values. For example if a table is composed
of an 'id' column which is auto incremented and a 'name' column then the execution of a "INSERT INTO mytable (name) VALUES ('joe')" query will
return a Set with two holders:
- one with the '+0' ID which may for example contain 1 (note that its "name" property should be "id")
- one with the '+1' ID which will contain 'joe' (note that its "name" property should be "name")
This method may fail with a ServerProviderError domain error (see the ServerProviderError error codes).
Note1: If stmt
is a SELECT statement which has some parameters and if params
is null
, then the statement
can't be executed and this method will return null
.
Note2: If stmt
is a SELECT statement which has some parameters and if params
is not null
but contains
some invalid parameters, then the statement can't be executed and this method will return null
, unless the model_usage
has the GDA_STATEMENT_MODEL_ALLOW_NOPARAM flag.
Note3: If stmt
is a SELECT statement which has some parameters and if params
is not null
but contains
some invalid parameters and if model_usage
has the GDA_STATEMENT_MODEL_ALLOW_NOPARAM flag, then the returned data model will
contain no row but will have all the correct columns (even though some of the columns might report as GDA_TYPE_NULL). In this case, if (after
this method call) any of params
' parameters change then the resulting data model will re-run itself, see the GdaDataSelect's
auto-reset property for more information.
Note4: if model_usage
does not contain the GDA_STATEMENT_MODEL_RANDOM_ACCESS or GDA_STATEMENT_MODEL_CURSOR_FORWARD flags, then the
default will be to return a random access data model
Note5: If stmt
is a SELECT statement which returns blob values (of type GDA_TYPE_BLOB
), then an implicit transaction
will have been started by the database provider, and it's up to the caller to close the transaction (which will then be locked) once all the
blob ressources have been liberated (when the returned data model is destroyed). See the section about Binary large objects (BLOBs) for
more information.
Also see the provider's limitations, and the Advanced GdaDataSelect usage sections.
Parameters:
this | |
stmt |
a Statement object |
model_usage |
in the case where |
last_insert_row |
a place to store a new Set object which contains the values of the last inserted
row, or |
params |
a Set object (which can be obtained using
get_parameters), or |
Returns:
a Object, or |