Gda.DataSelect

g GObject.GInterface GObject.GInterface Gda.DataModel Gda.DataModel GObject.GInterface->Gda.DataModel GObject.Object GObject.Object Gda.DataSelect Gda.DataSelect GObject.Object->Gda.DataSelect Gda.DataModel->Gda.DataSelect

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gda.DataModel (43)

Structs:

GObject.ObjectClass (5)

class

error_quark ()

compute_columns_attributes ()

compute_modification_statements ()

compute_modification_statements_ext (cond_type)

compute_row_selection_condition ()

get_connection ()

prepare_for_offline ()

rerun ()

set_modification_statement (mod_stmt)

set_modification_statement_sql (sql)

set_row_selection_condition_sql (sql_where)

Virtual Methods

Inherited:

GObject.Object (7), Gda.DataModel (27)

do_fetch_at (prow, rownum)

do_fetch_nb_rows ()

do_fetch_next (prow, rownum)

do_fetch_prev (prow, rownum)

do_fetch_random (prow, rownum)

do_store_all ()

Properties

Name

Type

Flags

Short Description

auto-reset

bool

r/w

Automatically re-run the SELECT statement if any parameter has changed since it was first executed

connection

Gda.Connection

r/w/co

Connection from which this data model is created

delete-stmt

Gda.Statement

r/w

DELETE Statement to be executed to remove data

exec-params

Gda.Set

r/w/co

Gda.Set used when the SELECT statement was executed

execution-delay

float

r/w

insert-stmt

Gda.Statement

r/w

INSERT Statement to be executed to add data

model-usage

int

r/w/co

Determines how the data model may be used

prepared-stmt

Gda.PStmt

r/w

Associated prepared statement (for internal usage)

select-stmt

Gda.Statement

r

SELECT statement which was executed to yield to the data model

store-all-rows

bool

r/w

Tells if model has analyzed all the rows

update-stmt

Gda.Statement

r/w

UPDATE Statement to be executed to update data

Signals

Inherited:

GObject.Object (1), Gda.DataModel (6)

Fields

Inherited:

GObject.Object (1), Gda.DataModel (6)

Name

Type

Access

Description

advertized_nrows

int

r

nb_stored_rows

int

r

object

GObject.Object

r

prep_stmt

Gda.PStmt

r

Class Details

class Gda.DataSelect(**kwargs)
Bases:

GObject.Object, Gda.DataModel

Abstract:

Yes

Structure:

Gda.DataSelectClass

classmethod error_quark()
Return type:

int

compute_columns_attributes()
Raises:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

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:

GLib.Error

Returns:

True if no error occurred. If False is returned, then some modification statement may still have been computed

Return type:

bool

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 unset

This function is similar to calling Gda.DataSelect.compute_modification_statements_ext() with cond_type set to Gda.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:

GLib.Error

Returns:

True if no error occurred. If False is returned, then some modification statement may still have been computed

Return type:

bool

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 unset

New in version 4.2.9.

compute_row_selection_condition()
Raises:

GLib.Error

Returns:

True if no error occurred.

Return type:

bool

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, or None

Return type:

Gda.Connection

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:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

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:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

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) – a Gda.Statement (INSERT, UPDATE or DELETE)

Raises:

GLib.Error

Returns:

True if no error occurred.

Return type:

bool

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)
Parameters:

sql (str) – an SQL text

Raises:

GLib.Error

Returns:

True if no error occurred.

Return type:

bool

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:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

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 NOT None, 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_at(prow, rownum) virtual
Parameters:
Return type:

bool

do_fetch_nb_rows() virtual
Return type:

int

do_fetch_next(prow, rownum) virtual
Parameters:
Return type:

bool

do_fetch_prev(prow, rownum) virtual
Parameters:
Return type:

bool

do_fetch_random(prow, rownum) virtual
Parameters:
Return type:

bool

do_store_all() virtual
Return type:

bool

Property Details

Gda.DataSelect.props.auto_reset
Name:

auto-reset

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Automatically re-run the SELECT statement if any parameter has changed since it was first executed

Gda.DataSelect.props.connection
Name:

connection

Type:

Gda.Connection

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Connection from which this data model is created

Gda.DataSelect.props.delete_stmt
Name:

delete-stmt

Type:

Gda.Statement

Default Value:

None

Flags:

READABLE, WRITABLE

DELETE Statement to be executed to remove data

Gda.DataSelect.props.exec_params
Name:

exec-params

Type:

Gda.Set

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Gda.Set used when the SELECT statement was executed

Gda.DataSelect.props.execution_delay
Name:

execution-delay

Type:

float

Default Value:

0.0

Flags:

READABLE, WRITABLE

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:

Gda.Statement

Default Value:

None

Flags:

READABLE, WRITABLE

INSERT Statement to be executed to add data

Gda.DataSelect.props.model_usage
Name:

model-usage

Type:

int

Default Value:

1

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Determines how the data model may be used

Gda.DataSelect.props.prepared_stmt
Name:

prepared-stmt

Type:

Gda.PStmt

Default Value:

None

Flags:

READABLE, WRITABLE

Associated prepared statement (for internal usage)

Gda.DataSelect.props.select_stmt
Name:

select-stmt

Type:

Gda.Statement

Default Value:

None

Flags:

READABLE

SELECT statement which was executed to yield to the data model

Gda.DataSelect.props.store_all_rows
Name:

store-all-rows

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Tells if model has analyzed all the rows

Gda.DataSelect.props.update_stmt
Name:

update-stmt

Type:

Gda.Statement

Default Value:

None

Flags:

READABLE, WRITABLE

UPDATE Statement to be executed to update data