Gda.Connection

g GObject.GInterface GObject.GInterface Gda.Lockable Gda.Lockable GObject.GInterface->Gda.Lockable GObject.Object GObject.Object Gda.Connection Gda.Connection GObject.Object->Gda.Connection Gda.Lockable->Gda.Connection

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gda.Lockable (3)

Structs:

GObject.ObjectClass (5)

class

error_quark ()

class

new_from_dsn (dsn, auth_string, options)

class

new_from_string (provider_name, cnc_string, auth_string, options)

class

open_from_dsn (dsn, auth_string, options)

class

open_from_string (provider_name, cnc_string, auth_string, options)

class

open_sqlite (directory, filename, auto_unlink)

class

string_split (string, out_cnc_params, out_provider, out_username, out_password)

add_event (event)

add_prepared_statement (gda_stmt, prepared_stmt)

add_savepoint (name)

async_cancel (task_id)

async_fetch_result (task_id)

async_statement_execute (stmt, params, model_usage, col_types, need_last_insert_row)

batch_execute (batch, params, model_usage)

begin_transaction (name, level)

clear_events_list ()

close ()

close_no_warning ()

commit_transaction (name)

create_operation (type, options)

create_parser ()

del_prepared_statement (gda_stmt)

delete_row_from_table (table, condition_column_name, condition_value)

delete_savepoint (name)

execute_non_select_command (sql)

execute_select_command (sql)

get_authentication ()

get_cnc_string ()

get_date_format ()

get_dsn ()

get_events ()

get_meta_store ()

get_meta_store_data_v (meta_type, filters)

get_options ()

get_prepared_statement (gda_stmt)

get_provider ()

get_provider_name ()

get_transaction_status ()

insert_row_into_table_v (table, col_names, values)

is_opened ()

open ()

parse_sql_string (sql)

perform_operation (op)

point_available_event (type)

quote_sql_identifier (id)

repetitive_statement_execute (rstmt, model_usage, col_types, stop_on_error)

rollback_savepoint (name)

rollback_transaction (name)

statement_execute (stmt, params, model_usage)

statement_execute_non_select (stmt, params)

statement_execute_select (stmt, params)

statement_execute_select_full (stmt, params, model_usage, col_types)

statement_prepare (stmt)

statement_to_sql (stmt, params, flags)

supports_feature (feature)

update_meta_store (context)

update_row_in_table_v (table, condition_column_name, condition_value, col_names, values)

value_to_sql_string (from_)

Virtual Methods

Inherited:

GObject.Object (7), Gda.Lockable (3)

do_conn_closed ()

do_conn_opened ()

do_conn_to_close ()

do_dsn_changed ()

do_error (error)

do_transaction_status_changed ()

Properties

Name

Type

Flags

Short Description

auth-string

str

r/w

Authentication string to use

cnc-string

str

r/w

Connection string to use

dsn

str

r/w

DSN to use

events-history-size

int

r/w

Number of history events to keep in memory

execution-slowdown

int

r/w

Artificially slows down the execution of queries

execution-timer

bool

r/w

Computes execution delay for each executed statement

is-wrapper

bool

r/w

Determines if the connection acts as a thread wrapper around another connection, making it completely thread safe

meta-store

Gda.MetaStore

r/w

Gda.MetaStore used by the connection

monitor-wrapped-in-mainloop

bool

r/w

Make the connection set up a monitoring function in the mainloop to monitor the wrapped connection

provider

Gda.ServerProvider

r/w

Provider to use

thread-owner

int

r/w

Unique GLib.Thread from which the connection will be available.This should only be modified by the database providers’ implementation

Signals

Inherited:

GObject.Object (1)

Name

Short Description

conn-closed

Gets emitted when the connection to the database has been closed

conn-opened

Gets emitted when the connection has been opened to the database

conn-to-close

Gets emitted when the connection to the database is about to be closed

dsn-changed

Gets emitted when the DSN used by cnc has been changed

error

Gets emitted whenever a connection event occurs.

transaction-status-changed

Gets emitted when the transaction status of cnc has changed (a transaction has been started, rolled back, a savepoint added,…)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

object

GObject.Object

r

Class Details

class Gda.Connection(**kwargs)
Bases:

GObject.Object, Gda.Lockable

Abstract:

No

Structure:

Gda.ConnectionClass

classmethod error_quark()
Return type:

int

classmethod new_from_dsn(dsn, auth_string, options)
Parameters:
Raises:

GLib.Error

Returns:

a new Gda.Connection if connection opening was successful or None if there was an error.

Return type:

Gda.Connection

This function is similar to Gda.Connection.open_from_dsn(), except it does not actually open the connection, you have to open it using Gda.Connection.open().

New in version 5.0.2.

classmethod new_from_string(provider_name, cnc_string, auth_string, options)
Parameters:
Raises:

GLib.Error

Returns:

a new Gda.Connection if connection opening was successful or None if there was an error.

Return type:

Gda.Connection

This function is similar to Gda.Connection.open_from_string(), except it does not actually open the connection, you have to open it using Gda.Connection.open().

New in version 5.0.2.

classmethod open_from_dsn(dsn, auth_string, options)
Parameters:
Raises:

GLib.Error

Returns:

a new Gda.Connection if connection opening was successful or None if there was an error.

Return type:

Gda.Connection

This function is the way of opening database connections with libgda, using a pre-defined data source (DSN), see Gda.Config.define_dsn() for more information about how to define a DSN. If you don’t want to define a DSN, it is possible to use Gda.Connection.open_from_string() instead of this method.

The dsn string must have the following format: “[<username>[:<password>]@]<DSN>” (if <username> and/or <password> are provided, and auth_string is None, then these username and passwords will be used). Note that if provided, <username> and <password> must be encoded as per RFC 1738, see Gda.rfc1738_encode() for more information.

The auth_string can contain the authentication information for the server to accept the connection. It is a string containing semi-colon seperated named value, usually like “USERNAME=…;PASSWORD=…” where the … are replaced by actual values. Note that each name and value must be encoded as per RFC 1738, see Gda.rfc1738_encode() for more information.

The actual named parameters required depend on the provider being used, and that list is available as the auth_params member of the Gda.ProviderInfo structure for each installed provider (use Gda.Config.get_provider_info() to get it). Also one can use the “gda-sql-5.0 -L” command to list the possible named parameters.

This method may fail with a GDA_CONNECTION_ERROR domain error (see the Gda.ConnectionError error codes) or a %GDA_CONFIG_ERROR domain error (see the Gda.ConfigError error codes).

classmethod open_from_string(provider_name, cnc_string, auth_string, options)
Parameters:
Raises:

GLib.Error

Returns:

a new Gda.Connection if connection opening was successful or None if there was an error.

Return type:

Gda.Connection

Opens a connection given a provider ID and a connection string. This allows applications to open connections without having to create a data source (DSN) in the configuration. The format of cnc_string is similar to PostgreSQL and MySQL connection strings. It is a semicolumn-separated series of <key>=<value> pairs, where each key and value are encoded as per RFC 1738, see Gda.rfc1738_encode() for more information.

The possible keys depend on the provider, the “gda-sql-5.0 -L” command can be used to list the actual keys for each installed database provider.

For example the connection string to open an SQLite connection to a database file named “my_data.db” in the current directory would be “DB_DIR=.;DB_NAME=my_data”.

The cnc_string string must have the following format: “’<provider>:// [<username>[:<password>]’@]<connection_params>” (if <username> and/or <password> are provided, and auth_string is None, then these username and passwords will be used, and if <provider> is provided and provider_name is None then this provider will be used). Note that if provided, <username>, <password> and <provider> must be encoded as per RFC 1738, see Gda.rfc1738_encode() for more information.

The auth_string must contain the authentication information for the server to accept the connection. It is a string containing semi-colon seperated named values, usually like “USERNAME=…;PASSWORD=…” where the … are replaced by actual values. Note that each name and value must be encoded as per RFC 1738, see Gda.rfc1738_encode() for more information.

The actual named parameters required depend on the provider being used, and that list is available as the auth_params member of the Gda.ProviderInfo structure for each installed provider (use Gda.Config.get_provider_info() to get it). Similarly to the format of the connection string, use the “gda-sql-5.0 -L” command to list the possible named parameters.

Additionally, it is possible to have the connection string respect the “<provider_name>://<real cnc string>” format, in which case the provider name and the real connection string will be extracted from that string (note that if provider_name is not None then it will still be used as the provider ID).\

This method may fail with a GDA_CONNECTION_ERROR domain error (see the Gda.ConnectionError error codes) or a %GDA_CONFIG_ERROR domain error (see the Gda.ConfigError error codes).

classmethod open_sqlite(directory, filename, auto_unlink)
Parameters:
  • directory (str or None) – the directory the database file will be in, or None for the default TMP directory

  • filename (str) – the database file name

  • auto_unlink (bool) – if True, then the database file will be removed afterwards

Returns:

a new Gda.Connection, or None if an error occurred

Return type:

Gda.Connection

Opens an SQLite connection even if the SQLite provider is not installed, to be used by database providers which need a temporary database to store some information.

classmethod string_split(string, out_cnc_params, out_provider, out_username, out_password)
Parameters:
  • string (str) – a string in the “’<provider>:// [<username>[:<password>]’@]<connection_params>” form

  • out_cnc_params (str) – a place to store the new string containing the <connection_params> part

  • out_provider (str) – a place to store the new string containing the <provider> part

  • out_username (str) – a place to store the new string containing the <username> part

  • out_password (str or None) – a place to store the new string containing the <password> part, or None

Extract the provider, connection parameters, username and password from string. in string, the various parts are strings which are expected to be encoded using an RFC 1738 compliant encoding. If they are specified, the returned provider, username and password strings are correctly decoded.

For example all the following connection strings:

PostgreSQL://meme:pass@DB_NAME=mydb;HOST=server
PostgreSQL://meme@DB_NAME=mydb;HOST=server;PASSWORD=pass
PostgreSQL://meme@DB_NAME=mydb;PASSWORD=pass;HOST=server
PostgreSQL://meme@PASSWORD=pass;DB_NAME=mydb;HOST=server
PostgreSQL://DB_NAME=mydb;HOST=server;USERNAME=meme;PASSWORD=pass
PostgreSQL://DB_NAME=mydb;HOST=server;PASSWORD=pass;USERNAME=meme
PostgreSQL://DB_NAME=mydb;USERNAME=meme;PASSWORD=pass;HOST=server
PostgreSQL://PASSWORD=pass;USERNAME=meme;DB_NAME=mydb;HOST=server
PostgreSQL://:pass@USERNAME=meme;DB_NAME=mydb;HOST=server
PostgreSQL://:pass@DB_NAME=mydb;HOST=server;USERNAME=meme

will return the following new strings (double quotes added here to delimit strings):

out_cnc_params: "DB_NAME=mydb;HOST=server"
out_provider: "PostgreSQL"
out_username: "meme"
out_password: "pass"
add_event(event)
Parameters:

event (Gda.ConnectionEvent) – is stored internally, so you don’t need to unref it.

Adds an event to the given connection. This function is usually called by providers, to inform clients of events that happened during some operation.

As soon as a provider (or a client, it does not matter) calls this function with an event object which is an error, the connection object emits the “error” signal, to which clients can connect to be informed of events.

WARNING: the reference to the event object is stolen by this function!

add_prepared_statement(gda_stmt, prepared_stmt)
Parameters:

Declares that prepared_stmt is a prepared statement object associated to gda_stmt within the connection (meaning the connection increments the reference counter of prepared_stmt).

If gda_stmt changes or is destroyed, the the association will be lost and the connection will lose the reference it has on prepared_stmt.

add_savepoint(name)
Parameters:

name (str or None) – name of the savepoint to add

Raises:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

Adds a SAVEPOINT named name.

async_cancel(task_id)
Parameters:

task_id (int) – a task ID returned by Gda.Connection.async_statement_execute()

Raises:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

Requests that a task be cancelled. This operation may of may not have any effect depending on the task’s status, even if it returns True. If it returns False, then the task has not been cancelled.

New in version 4.2.

async_fetch_result(task_id)
Parameters:

task_id (int) – a task ID returned by Gda.Connection.async_statement_execute()

Raises:

GLib.Error

Returns:

a GObject.Object, or None if an error occurred

last_insert_row:

a place to store a new Gda.Set object which contains the values of the last inserted row, or None

Return type:

(GObject.Object, last_insert_row: Gda.Set)

Use this method to obtain the result of the execution of a statement which has been executed asynchronously by calling Gda.Connection.async_statement_execute(). This function is non locking and will return None (and no error will be set) if the statement has not been executed yet.

If the statement has been executed, this method returns the same value as Gda.Connection.statement_execute() would have if the statement had been executed synchronously.

New in version 4.2.

async_statement_execute(stmt, params, model_usage, col_types, need_last_insert_row)
Parameters:
Raises:

GLib.Error

Returns:

a task ID, or 0 if an error occurred (not an error regarding stmt itself as its execution has not yet started but any other error)

Return type:

int

This method is similar to Gda.Connection.statement_execute() but is asynchronous as it method returns immediately with a task ID. It’s up to the caller to use Gda.Connection.async_fetch_result() regularly to check if the statement’s execution is finished.

It is possible to call the method several times to request several statements to be executed asynchronously, the statements will be executed in the order in which they were requested.

The parameters, if present, are copied and can be discarded or modified before the statement is actually executed. The stmt object is not copied but simply referenced (for performance reasons), and if it is modified before it is actually executed, then its execution will not occur. It is however safe to call GObject.Object.unref() on it if it’s not needed anymore.

The execution failure of any statement has no impact on the execution of other statements except for example if the connection has a transaction started and the failure invalidates the transaction (as decided by the database server).

Note that for asynchronous calls to succeed, it is gererally necessary to specify the Gda.ConnectionOptions.THREAD_ISOLATED flag when opening the connection to be sure it is opened in a separate thread in which asynchronous calls are made (failing to use this flag make the asynchronous call dependant on the database provider implementation and at the moment none support this feature).

New in version 4.2.

batch_execute(batch, params, model_usage)
Parameters:
Raises:

GLib.Error

Returns:

a new list of GObject.Object objects

Return type:

[GObject.Object]

Executes all the statements contained in batch (in the order in which they were added to batch), and returns a list of GObject.Object objects, at most one GObject.Object for each statement; see Gda.Connection.statement_execute() for details about the returned objects.

If one of the statement fails, then none of the subsequent statement will be executed, and the method returns the list of GObject.Object created by the correct execution of the previous statements. If a transaction is required, then it should be started before calling this method.

begin_transaction(name, level)
Parameters:
Raises:

GLib.Error

Returns:

True if the transaction was started successfully, False otherwise.

Return type:

bool

Starts a transaction on the data source, identified by the name parameter.

Before starting a transaction, you can check whether the underlying provider does support transactions or not by using the Gda.Connection.supports_feature() function.

clear_events_list()

This function lets you clear the list of Gda.ConnectionEvent's of the given connection.

close()

Closes the connection to the underlying data source, but first emits the “conn-to-close” signal.

close_no_warning()

Closes the connection to the underlying data source, without emiting any warning signal.

commit_transaction(name)
Parameters:

name (str or None) – the name of the transation to commit, or None

Raises:

GLib.Error

Returns:

True if the transaction was finished successfully, False otherwise.

Return type:

bool

Commits the given transaction to the backend database. You need to call Gda.Connection.begin_transaction() first.

create_operation(type, options)
Parameters:
Raises:

GLib.Error

Returns:

a new Gda.ServerOperation object, or None in the connection’s provider does not support the type type of operation or if an error occurred

Return type:

Gda.ServerOperation

Creates a new Gda.ServerOperation object which can be modified in order to perform the type type of action. It is a wrapper around the Gda.ServerProvider.create_operation() method.

create_parser()
Returns:

a new Gda.SqlParser object, or None

Return type:

Gda.SqlParser

Creates a new parser object able to parse the SQL dialect understood by self. If the Gda.ServerProvider object internally used by self does not have its own parser, then None is returned, and a general SQL parser can be obtained using Gda.SqlParser.new().

del_prepared_statement(gda_stmt)
Parameters:

gda_stmt (Gda.Statement) – a Gda.Statement object

Removes any prepared statement associated to gda_stmt in self: this undoes what Gda.Connection.add_prepared_statement() does.

delete_row_from_table(table, condition_column_name, condition_value)
Parameters:
  • table (str) – the table’s name with the row’s values to be updated

  • condition_column_name (str) – the name of the column to used in the WHERE condition clause

  • condition_value (GObject.Value) – the condition_column_type's GObject.GType

Raises:

GLib.Error

Returns:

True if no error occurred, False otherwise

Return type:

bool

This is a convenience function, which creates a DELETE statement and executes it using the values provided. It internally relies on variables which makes it immune to SQL injection problems.

The equivalent SQL command is: DELETE FROM <table> WHERE <condition_column_name> = <condition_value>.

New in version 4.2.3.

delete_savepoint(name)
Parameters:

name (str or None) – name of the savepoint to delete

Raises:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

Delete the SAVEPOINT named name when not used anymore.

execute_non_select_command(sql)
Parameters:

sql (str) – a query statement that must not begin with “SELECT”

Raises:

GLib.Error

Returns:

the number of rows affected or -1, or -2

Return type:

int

This is a convenience function to execute a SQL command over the opened connection. For the returned value, see Gda.Connection.statement_execute_non_select()’s documentation.

New in version 4.2.3.

execute_select_command(sql)
Parameters:

sql (str) – a query statement that must begin with “SELECT”

Raises:

GLib.Error

Returns:

a new Gda.DataModel if successful, None otherwise

Return type:

Gda.DataModel

Execute a SQL SELECT command over an opened connection.

New in version 4.2.3.

get_authentication()
Returns:

the user name.

Return type:

str

Gets the user name used to open this connection.

get_cnc_string()
Returns:

the connection string used when opening the connection.

Return type:

str

Gets the connection string used to open this connection.

The connection string is the string sent over to the underlying database provider, which describes the parameters to be used to open a connection on the underlying data source.

get_date_format()
Raises:

GLib.Error

Returns:

True if no error occurred

out_first:

the place to store the first part of the date, or None

out_second:

the place to store the second part of the date, or None

out_third:

the place to store the third part of the date, or None

out_sep:

the place to store the separator (used between year, month and day parts) part of the date, or None

Return type:

(bool, out_first: GLib.DateDMY, out_second: GLib.DateDMY, out_third: GLib.DateDMY, out_sep: str)

This function allows you to determine the actual format for the date values.

New in version 5.2.

get_dsn()
Returns:

the data source name the connection object is connected to.

Return type:

str

get_events()
Returns:

a GLib.List of Gda.ConnectionEvent objects (the list should not be modified)

Return type:

[Gda.ConnectionEvent]

Retrieves a list of the last errors occurred during the connection. The returned list is chronologically ordered such as that the most recent event is the Gda.ConnectionEvent of the first node.

Warning: the self object may change the list if connection events occur

get_meta_store()
Returns:

a Gda.MetaStore object

Return type:

Gda.MetaStore

Get or initializes the Gda.MetaStore associated to self

get_meta_store_data_v(meta_type, filters)
Parameters:
Raises:

GLib.Error

Returns:

a Gda.DataModel containing the data required. The caller is responsible for freeing the returned model using GObject.Object.unref().

Return type:

Gda.DataModel

see #gda_connection_get_meta_store_data

get_options()
Returns:

the connection options.

Return type:

Gda.ConnectionOptions

Gets the Gda.ConnectionOptions used to open this connection.

get_prepared_statement(gda_stmt)
Parameters:

gda_stmt (Gda.Statement) – a Gda.Statement object

Returns:

the prepared statement, or None if no association exists

Return type:

Gda.PStmt

Retrieves a pointer to an object representing a prepared statement for gda_stmt within self. The association must have been done using Gda.Connection.add_prepared_statement().

get_provider()
Returns:

the Gda.ServerProvider (NEVER None)

Return type:

Gda.ServerProvider

Gets a pointer to the Gda.ServerProvider object used to access the database

get_provider_name()
Returns:

a non modifiable string

Return type:

str

Gets the name (identifier) of the database provider used by self

get_transaction_status()
Returns:

a Gda.TransactionStatus object, or None

Return type:

Gda.TransactionStatus

Get the status of self regarding transactions. The returned object should not be modified or destroyed; however it may be modified or destroyed by the connection itself.

If None is returned, then no transaction has been associated with self

insert_row_into_table_v(table, col_names, values)
Parameters:
Raises:

GLib.Error

Returns:

True if no error occurred, False otherwise

Return type:

bool

col_names and values must have length (>= 1).

This is a convenience function, which creates an INSERT statement and executes it using the values provided. It internally relies on variables which makes it immune to SQL injection problems.

The equivalent SQL command is: INSERT INTO <table> (<column_name> [,…]) VALUES (<column_name> = <new_value> [,…]).

New in version 4.2.3.

is_opened()
Returns:

True if the connection is open, False if it’s not.

Return type:

bool

Checks whether a connection is open or not.

open()
Raises:

GLib.Error

Returns:

True if the connection is opened, and False otherwise.

Return type:

bool

Tries to open the connection.

parse_sql_string(sql)
Parameters:

sql (str) – an SQL command to parse, not None

Raises:

GLib.Error

Returns:

a Gda.Statement representing the SQL command, or None if an error occurred

params:

a place to store a new Gda.Set, for parameters used in SQL command, or None

Return type:

(Gda.Statement, params: Gda.Set)

This function helps to parse a SQL string which uses parameters and store them at params.

New in version 4.2.3.

perform_operation(op)
Parameters:

op (Gda.ServerOperation) – a Gda.ServerOperation object

Raises:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

Performs the operation described by op (which should have been created using Gda.Connection.create_operation()). It is a wrapper around the Gda.ServerProvider.perform_operation() method.

point_available_event(type)
Parameters:

type (Gda.ConnectionEventType) – a Gda.ConnectionEventType

Returns:

a pointer to the next available connection event, or None if event should be ignored

Return type:

Gda.ConnectionEvent

Use this method to get a pointer to the next available connection event which can then be customized and taken into account using Gda.Connection.add_event().

New in version 4.2.

quote_sql_identifier(id)
Parameters:

id (str) – an SQL identifier

Returns:

a new string, to free with GLib.free() once not needed anymore

Return type:

str

Use this method to get a correctly quoted (if necessary) SQL identifier which can be used in SQL statements, from id. If id is already correctly quoted for self, then a copy of id may be returned.

This method may add double quotes (or other characters) around id:

  • if id is a reserved SQL keyword (such as SELECT, INSERT, …)

  • if id contains non allowed characters such as spaces, or if it starts with a digit

  • in any other event as necessary for self, depending on the the options passed when opening the self connection, and specifically the ‘GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE [GDA-CONNECTION-OPTIONS-SQL-IDENTIFIERS-CASE-SENSITIVE:CAPS]’ option.

One can safely pass an already quoted id to this method, either with quoting characters allowed by self or using the double quote (”) character.

New in version 4.0.3.

repetitive_statement_execute(rstmt, model_usage, col_types, stop_on_error)
Parameters:
Raises:

GLib.Error

Returns:

a new list of GObject.Object pointers (see Gda.Connection.statement_execute() for more information about what they represent), one for each actual execution of the statement upon which rstmt is built. If stop_on_error is False, then the list may contain some None pointers which refer to statements which failed to execute.

Return type:

[GObject.Object]

Executes the statement upon which rstmt is built. Note that as several statements can actually be executed by this method, it is recommended to be within a transaction.

If error is not None and stop_on_error is False, then it may contain the last error which occurred.

New in version 4.2.

rollback_savepoint(name)
Parameters:

name (str or None) – name of the savepoint to rollback to

Raises:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

Rollback all the modifications made after the SAVEPOINT named name.

rollback_transaction(name)
Parameters:

name (str or None) – the name of the transation to commit, or None

Raises:

GLib.Error

Returns:

True if the operation was successful, False otherwise.

Return type:

bool

Rollbacks the given transaction. This means that all changes made to the underlying data source since the last call to Gda.Connection.begin_transaction() or Gda.Connection.commit_transaction() will be discarded.

statement_execute(stmt, params, model_usage)
Parameters:
Raises:

GLib.Error

Returns:

a GObject.Object, or None if an error occurred

last_insert_row:

a place to store a new Gda.Set object which contains the values of the last inserted row, or None

Return type:

(GObject.Object, last_insert_row: Gda.Set)

Executes stmt.

As stmt can, by design (and if not abused), contain only one SQL statement, the return object will either be:

If last_insert_row is not None and stmt is an INSERT statement, then it will contain (if the provider used by self supports it) a new Gda.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 Gda.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 %GDA_SERVER_PROVIDER_ERROR domain error (see the Gda.ServerProviderError error codes).

Note1: If stmt is a SELECT statement which has some parameters and if params is None, then the statement can’t be executed and this method will return None.

Note2: If stmt is a SELECT statement which has some parameters and if params is not None but contains some invalid parameters, then the statement can’t be executed and this method will return None, unless the model_usage has the Gda.StatementModelUsage.ALLOW_NOPARAM flag.

Note3: If stmt is a SELECT statement which has some parameters and if params is not None but contains some invalid parameters and if model_usage has the Gda.StatementModelUsage.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 Gda.DataSelect's

auto-reset property for more information. Note4: if model_usage does not contain the Gda.StatementModelUsage.RANDOM_ACCESS or Gda.StatementModelUsage.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) [gen:blobs]’ for more information. Also see the ‘provider’s limitations [limitations]’, and the

‘Advanced GdaDataSelect usage [data-select]’ sections.

statement_execute_non_select(stmt, params)
Parameters:
Raises:

GLib.Error

Returns:

the number of rows affected (>=0) or -1 or -2

last_insert_row:

a place to store a new Gda.Set object which contains the values of the last inserted row, or None

Return type:

(int, last_insert_row: Gda.Set)

Executes a non-selection statement on the given connection.

This function returns the number of rows affected by the execution of stmt, or -1 if an error occurred, or -2 if the connection’s provider does not return the number of rows affected.

This function is just a convenience function around the Gda.Connection.statement_execute() function. See the documentation of the Gda.Connection.statement_execute() for information about the params list of parameters.

See Gda.Connection.statement_execute() form more information about last_insert_row.

statement_execute_select(stmt, params)
Parameters:
Raises:

GLib.Error

Returns:

a Gda.DataModel containing the data returned by the data source, or None if an error occurred

Return type:

Gda.DataModel

Executes a selection command on the given connection.

This function returns a Gda.DataModel resulting from the SELECT statement, or None if an error occurred.

This function is just a convenience function around the Gda.Connection.statement_execute() function.

See the documentation of the Gda.Connection.statement_execute() for information about the params list of parameters.

statement_execute_select_full(stmt, params, model_usage, col_types)
Parameters:
Raises:

GLib.Error

Returns:

a Gda.DataModel containing the data returned by the data source, or None if an error occurred

Return type:

Gda.DataModel

Executes a selection command on the given connection.

This function returns a Gda.DataModel resulting from the SELECT statement, or None if an error occurred.

This function is just a convenience function around the Gda.Connection.statement_execute() function.

See the documentation of the Gda.Connection.statement_execute() for information about the params list of parameters.

statement_prepare(stmt)
Parameters:

stmt (Gda.Statement) – a Gda.Statement object

Raises:

GLib.Error

Returns:

True if no error occurred.

Return type:

bool

Ask the database accessed through the self connection to prepare the usage of stmt. This is only useful if stmt will be used more than once (however some database providers may always prepare statements before executing them).

This function is also useful to make sure stmt is fully understood by the database before actually executing it.

Note however that it is also possible that Gda.Connection.statement_prepare() fails when Gda.Connection.statement_execute() does not fail (this will usually be the case with statements such as “SELECT * FROM ##tablename::string” because database usually don’t allow variables to be used in place of a table name).

statement_to_sql(stmt, params, flags)
Parameters:
Raises:

GLib.Error

Returns:

a new string, or None if an error occurred

params_used:

a place to store the list of individual Gda.Holder objects within params which have been used

Return type:

(str, params_used: [Gda.Holder])

Renders stmt as an SQL statement, adapted to the SQL dialect used by self

supports_feature(feature)
Parameters:

feature (Gda.ConnectionFeature) – feature to ask for.

Returns:

True if the provider supports it, False if not.

Return type:

bool

Asks the underlying provider for if a specific feature is supported.

update_meta_store(context)
Parameters:

context (Gda.MetaContext or None) – description of which part of self's associated Gda.MetaStore should be updated, or None

Raises:

GLib.Error

Returns:

True if no error occurred

Return type:

bool

Updates self's associated Gda.MetaStore. If context is not None, then only the parts described by context will be updated, and if it is None, then the complete meta store will be updated. Detailed explanations follow:

In order to keep the meta store’s contents in a consistent state, the update process involves updating the contents of all the tables related to one where the contents change. For example the “_columns” table (which lists all the columns of a table) depends on the “_tables” table (which lists all the tables in a schema), so if a row is added, removed or modified in the “_tables”, then the “_columns” table’s contents needs to be updated as well regarding that row.

If context is None, then the update process will simply overwrite any data that was present in all the meta store’s tables with new (up to date) data even if nothing has changed, without having to build the tables’ dependency tree. This is the recommended way of proceeding when dealing with a meta store which might be outdated.

On the other hand, if context is not None, then a tree of the dependencies has to be built (depending on context) and only some parts of the meta store are updated following that dependencies tree. Specifying a context may be useful for example in the following situations:

  • One knows that a database object has changed (for example a table created), and may use the context to request that only the information about that table be updated

  • One is only interested in the list of views, and may request that only the information about views may be updated

When context is not None, and contains specified SQL identifiers (for example the “table_name” of the “_tables” table), then each SQL identifier has to match the convention the Gda.MetaStore has adopted regarding case sensitivity, using Gda.Connection.quote_sql_identifier() or Gda.MetaStore.sql_identifier_quote().

see the ‘meta data section about SQL identifiers [information_schema:sql_identifiers]’ for more information, and the documentation about the Gda.sql_identifier_quote() function which will be most useful.

Note however that usually more information will be updated than strictly requested by the context argument.

For more information, see the ‘Database structure [information_schema]’ section, and the ‘Update the meta data about a table [howto-meta2]’ howto.

update_row_in_table_v(table, condition_column_name, condition_value, col_names, values)
Parameters:
  • table (str) – the table’s name with the row’s values to be updated

  • condition_column_name (str) – the name of the column to used in the WHERE condition clause

  • condition_value (GObject.Value) – the condition_column_type's GObject.GType

  • col_names ([str]) – a list of column names (as const str *)

  • values ([GObject.Value]) – a list of values (as GObject.Value)

Raises:

GLib.Error

Returns:

True if no error occurred, False otherwise

Return type:

bool

col_names and values must have length (>= 1).

This is a convenience function, which creates an UPDATE statement and executes it using the values provided. It internally relies on variables which makes it immune to SQL injection problems.

The equivalent SQL command is: UPDATE <table> SET <column_name> = <new_value> [,…] WHERE <condition_column_name> = <condition_value>.

New in version 4.2.3.

value_to_sql_string(from_)
Parameters:

from (GObject.Value) – GObject.Value to convert from

Returns:

escaped and quoted value or None if not supported.

Return type:

str

Produces a fully quoted and escaped string from a GObject.Value

do_conn_closed() virtual
do_conn_opened() virtual
do_conn_to_close() virtual
do_dsn_changed() virtual
do_error(error) virtual
Parameters:

error (Gda.ConnectionEvent) –

do_transaction_status_changed() virtual

Signal Details

Gda.Connection.signals.conn_closed(connection)
Signal Name:

conn-closed

Flags:

RUN_LAST

Parameters:

connection (Gda.Connection) – The object which received the signal

Gets emitted when the connection to the database has been closed

Gda.Connection.signals.conn_opened(connection)
Signal Name:

conn-opened

Flags:

RUN_FIRST

Parameters:

connection (Gda.Connection) – The object which received the signal

Gets emitted when the connection has been opened to the database

Gda.Connection.signals.conn_to_close(connection)
Signal Name:

conn-to-close

Flags:

RUN_FIRST

Parameters:

connection (Gda.Connection) – The object which received the signal

Gets emitted when the connection to the database is about to be closed

Gda.Connection.signals.dsn_changed(connection)
Signal Name:

dsn-changed

Flags:

RUN_LAST

Parameters:

connection (Gda.Connection) – The object which received the signal

Gets emitted when the DSN used by cnc has been changed

Gda.Connection.signals.error(connection, event)
Signal Name:

error

Flags:

RUN_LAST

Parameters:

Gets emitted whenever a connection event occurs. Check the nature of event to see if it’s an error or a simple notification

Gda.Connection.signals.transaction_status_changed(connection)
Signal Name:

transaction-status-changed

Flags:

RUN_LAST

Parameters:

connection (Gda.Connection) – The object which received the signal

Gets emitted when the transaction status of cnc has changed (a transaction has been started, rolled back, a savepoint added,…)

Property Details

Gda.Connection.props.auth_string
Name:

auth-string

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE

Authentication string to use

Gda.Connection.props.cnc_string
Name:

cnc-string

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE

Connection string to use

Gda.Connection.props.dsn
Name:

dsn

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE

DSN to use

Gda.Connection.props.events_history_size
Name:

events-history-size

Type:

int

Default Value:

5

Flags:

READABLE, WRITABLE

Defines the number of Gda.ConnectionEvent objects kept in memory which can be fetched using Gda.Connection.get_events().

New in version 4.2.

Gda.Connection.props.execution_slowdown
Name:

execution-slowdown

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

Artificially slows down the execution of queries. This property can be used to debug some problems. If non zero, this value is the number of microseconds waited before actually executing each query.

New in version 5.2.0.

Gda.Connection.props.execution_timer
Name:

execution-timer

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Computes execution times for each statement executed.

New in version 4.2.9.

Gda.Connection.props.is_wrapper
Name:

is-wrapper

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

This property, if set to True, specifies that the connection is not a real connection, but rather a Gda.Connection object which “proxies” all the calls to another connection which executes in a sub thread.

Note: this property is used internally by Libgda and should not be directly used by any programs. Setting this property has no effect, reading it is supported, though.

New in version 4.2.

Gda.Connection.props.meta_store
Name:

meta-store

Type:

Gda.MetaStore

Default Value:

None

Flags:

READABLE, WRITABLE

Gda.MetaStore used by the connection

Gda.Connection.props.monitor_wrapped_in_mainloop
Name:

monitor-wrapped-in-mainloop

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Useful only when there is a mainloop and when the connection acts as a thread wrapper around another connection, it sets up a timeout to handle signals coming from the wrapped connection.

If the connection is not a thread wrapper, then this property has no effect.

New in version 4.2.

Gda.Connection.props.provider
Name:

provider

Type:

Gda.ServerProvider

Default Value:

None

Flags:

READABLE, WRITABLE

Provider to use

Gda.Connection.props.thread_owner
Name:

thread-owner

Type:

int

Default Value:

None

Flags:

READABLE, WRITABLE

Unique GLib.Thread from which the connection will be available.This should only be modified by the database providers’ implementation