Gda.DataSelect¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
Automatically re-run the SELECT statement if any parameter has changed since it was first executed |
||
r/w/co |
Connection from which this data model is created |
||
r/w |
DELETE Statement to be executed to remove data |
||
r/w/co |
|
||
r/w |
|||
r/w |
INSERT Statement to be executed to add data |
||
r/w/co |
Determines how the data model may be used |
||
r/w |
Associated prepared statement (for internal usage) |
||
r |
SELECT statement which was executed to yield to the data model |
||
r/w |
Tells if model has analyzed all the rows |
||
r/w |
UPDATE Statement to be executed to update data |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
advertized_nrows |
r |
||
nb_stored_rows |
r |
||
object |
r |
||
prep_stmt |
r |
Class Details¶
- class Gda.DataSelect(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
- compute_columns_attributes()¶
- Raises:
- Returns:
True
if no error occurred- Return type:
Computes correct attributes for each of self's columns, which includes the “NOT
None
" attribute, the default value, the precision and scale for numeric values.
- compute_modification_statements()¶
- Raises:
- Returns:
True
if no error occurred. IfFalse
is returned, then some modification statement may still have been computed- Return type:
Makes self try to compute INSERT, UPDATE and DELETE statements to be used when modifying self's contents. Note: any modification statement set using
Gda.DataSelect.set_modification_statement
() will first be unsetThis function is similar to calling
Gda.DataSelect.compute_modification_statements_ext
() with cond_type set toGda.DataSelectConditionType.PK
- compute_modification_statements_ext(cond_type)¶
- Parameters:
cond_type (
Gda.DataSelectConditionType
) – the type of condition for the modifications where one row only should be identified- Raises:
- Returns:
True
if no error occurred. IfFalse
is returned, then some modification statement may still have been computed- Return type:
Makes self try to compute INSERT, UPDATE and DELETE statements to be used when modifying self's contents. Note: any modification statement set using
Gda.DataSelect.set_modification_statement
() will first be unsetNew in version 4.2.9.
- compute_row_selection_condition()¶
- Raises:
- Returns:
True
if no error occurred.- Return type:
Offers the same features as gda_data_select_set_row_selection_condition() but the expression is computed from the meta data associated to the connection being used when self 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 self has been created uses more than one table, or if the table used does not have any primary key, then this method will fail
- get_connection()¶
- Returns:
a pointer to the
Gda.Connection
, orNone
- Return type:
Get a pointer to the
Gda.Connection
object which was used when self was created (and which may be used internally by self).
- prepare_for_offline()¶
- Raises:
- Returns:
True
if no error occurred- Return type:
Use this method to make sure all the data contained in the data model are stored on the client side (and that no subsquent call to the server will be necessary to access that data), at the cost of a higher memory consumption.
This method is useful in the following situations:
You need to disconnect from the server and continue to use the data in the data model
You need to make sure the data in the data model can be used even though the connection to the server may be used for other purposes (for example executing other queries)
Note that this method will fail if:
the data model contains any blobs (because blobs reading requires acces to the server); binary values are Ok, though.
the data model has been modified since it was created
New in version 5.2.0.
- rerun()¶
- Raises:
- Returns:
True
if no error occurred- Return type:
Requests that self be re-run to have an updated result. If an error occurs, then self will not be changed.
New in version 4.2.
- set_modification_statement(mod_stmt)¶
- Parameters:
mod_stmt (
Gda.Statement
) – aGda.Statement
(INSERT, UPDATE or DELETE)- Raises:
- Returns:
True
if no error occurred.- Return type:
Informs self 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 self will be writable
a DELETE statement, then it will be possible to delete rows in self
in INSERT statement, then it will be possible to add some rows to self
any other statement, then this method will return an error
This method can be called several times to specify different types of modification statements.
Each modification statement will be executed when one or more values are modified in the data model; each statement should then include variables which will be set to either the old value or the new value of a column at the specified modified row (but can also contain other variables). Each variable named as “+<number>” will be mapped to the new value of the number’th column (starting at 0), and each variable named as “-<number>” will be mapped to the old value of the number’th column.
Examples of the SQL equivalent of each statement are (for example if “mytable” has the “id” field as primary key, and if that field is auto incremented and if the data model is the result of executing “SELECT * from mytable”).
“INSERT INTO mytable (name) VALUES (##+1:py:func:::string<Gda.DataSelect.signals.string>)”: the column ID can not be set for new rows
“DELETE FROM mytable WHERE id=##-0:py:func:::int<Gda.DataSelect.signals.int>"
“UPDATE mytable SET name=##+1:py:func:::string<Gda.DataSelect.signals.string> WHERE id=##-0:py:func:::int<Gda.DataSelect.signals.int>": the column ID cannot be modified
Also see the
Gda.DataSelect.set_row_selection_condition_sql
() for more information about the WHERE part of the UPDATE and DELETE statement types.If mod_stmt is an UPDATE or DELETE statement then it should have a WHERE part which identifies a unique row in self (please note that this property can’t be checked but may result in self behaving in an unpredictable way).
NOTE1: However, if the gda_data_select_set_row_selection_condition() or
Gda.DataSelect.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_select_set_row_selection_condition() or
Gda.DataSelect.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.
- set_modification_statement_sql(sql)¶
-
Offers the same feature as
Gda.DataSelect.set_modification_statement
() but using an SQL statement.
- set_row_selection_condition_sql(sql_where)¶
- Parameters:
sql_where (
str
) – an SQL condition (without the WHERE keyword)- Raises:
- Returns:
True
if no error occurred- Return type:
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
None
, part2 string NOTNone
, 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:py:func:::int<Gda.DataSelect.signals.int> AND part2 = ##-2:py:func:::string<Gda.DataSelect.signals.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 <![CDATA[“##-1:py:func:::int<Gda.DataSelect.signals.int>"]]> for example), see the
‘GdaSqlParser [GdaSqlParser.description]’ documentation, and
Gda.DataSelect.set_modification_statement
().
- do_fetch_random(prow, rownum) virtual¶
Property Details¶
- Gda.DataSelect.props.auto_reset¶
-
Automatically re-run the SELECT statement if any parameter has changed since it was first executed
- Gda.DataSelect.props.connection¶
- Name:
connection
- Type:
- Default Value:
- Flags:
Connection from which this data model is created
- Gda.DataSelect.props.delete_stmt¶
- Name:
delete-stmt
- Type:
- Default Value:
- Flags:
DELETE Statement to be executed to remove data
- Gda.DataSelect.props.exec_params¶
- Name:
exec-params
- Type:
- Default Value:
- Flags:
Gda.Set
used when the SELECT statement was executed
- Gda.DataSelect.props.execution_delay¶
-
This property stores the execution delay which has been necessary to obtain the data
New in version 4.2.9.
- Gda.DataSelect.props.insert_stmt¶
- Name:
insert-stmt
- Type:
- Default Value:
- Flags:
INSERT Statement to be executed to add data
- Gda.DataSelect.props.model_usage¶
- Name:
model-usage
- Type:
- Default Value:
1
- Flags:
Determines how the data model may be used
- Gda.DataSelect.props.prepared_stmt¶
-
Associated prepared statement (for internal usage)
- Gda.DataSelect.props.select_stmt¶
- Name:
select-stmt
- Type:
- Default Value:
- Flags:
SELECT statement which was executed to yield to the data model
- Gda.DataSelect.props.store_all_rows¶
-
Tells if model has analyzed all the rows
- Gda.DataSelect.props.update_stmt¶
- Name:
update-stmt
- Type:
- Default Value:
- Flags:
UPDATE Statement to be executed to update data