Gda.Connection¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
Authentication string to use |
||
r/w |
Connection string to use |
||
r/w |
DSN to use |
||
r/w |
Number of history events to keep in memory |
||
r/w |
Artificially slows down the execution of queries |
||
r/w |
Computes execution delay for each executed statement |
||
r/w |
Determines if the connection acts as a thread wrapper around another connection, making it completely thread safe |
||
r/w |
|
||
r/w |
Make the connection set up a monitoring function in the mainloop to monitor the wrapped connection |
||
r/w |
Provider to use |
||
r/w |
Unique |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Gets emitted when the connection to the database has been closed |
|
Gets emitted when the connection has been opened to the database |
|
Gets emitted when the connection to the database is about to be closed |
|
Gets emitted when the DSN used by cnc has been changed |
|
Gets emitted whenever a connection event occurs. |
|
Gets emitted when the transaction status of cnc has changed (a transaction has been started, rolled back, a savepoint added,…) |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
object |
r |
Class Details¶
- class Gda.Connection(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- classmethod new_from_dsn(dsn, auth_string, options)¶
- Parameters:
dsn (
str
) – data source name.options (
Gda.ConnectionOptions
) – options for the connection (seeGda.ConnectionOptions
).
- Raises:
- Returns:
a new
Gda.Connection
if connection opening was successful orNone
if there was an error.- Return type:
This function is similar to
Gda.Connection.open_from_dsn
(), except it does not actually open the connection, you have to open it usingGda.Connection.open
().New in version 5.0.2.
- classmethod new_from_string(provider_name, cnc_string, auth_string, options)¶
- Parameters:
provider_name (
str
orNone
) – provider ID to connect to, orNone
cnc_string (
str
) – connection string.options (
Gda.ConnectionOptions
) – options for the connection (seeGda.ConnectionOptions
).
- Raises:
- Returns:
a new
Gda.Connection
if connection opening was successful orNone
if there was an error.- Return type:
This function is similar to
Gda.Connection.open_from_string
(), except it does not actually open the connection, you have to open it usingGda.Connection.open
().New in version 5.0.2.
- classmethod open_from_dsn(dsn, auth_string, options)¶
- Parameters:
dsn (
str
) – data source name.options (
Gda.ConnectionOptions
) – options for the connection (seeGda.ConnectionOptions
).
- Raises:
- Returns:
a new
Gda.Connection
if connection opening was successful orNone
if there was an error.- Return type:
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 useGda.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, seeGda.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 (useGda.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 theGda.ConfigError
error codes).
- classmethod open_from_string(provider_name, cnc_string, auth_string, options)¶
- Parameters:
provider_name (
str
orNone
) – provider ID to connect to, orNone
cnc_string (
str
) – connection string.options (
Gda.ConnectionOptions
) – options for the connection (seeGda.ConnectionOptions
).
- Raises:
- Returns:
a new
Gda.Connection
if connection opening was successful orNone
if there was an error.- Return type:
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 isNone
then this provider will be used). Note that if provided, <username>, <password> and <provider> must be encoded as per RFC 1738, seeGda.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 (useGda.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 theGda.ConfigError
error codes).
- classmethod open_sqlite(directory, filename, auto_unlink)¶
- Parameters:
- Returns:
a new
Gda.Connection
, orNone
if an error occurred- Return type:
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>” formout_cnc_params (
str
) – a place to store the new string containing the <connection_params> partout_provider (
str
) – a place to store the new string containing the <provider> partout_username (
str
) – a place to store the new string containing the <username> partout_password (
str
orNone
) – a place to store the new string containing the <password> part, orNone
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:
gda_stmt (
Gda.Statement
) – aGda.Statement
objectprepared_stmt (
Gda.PStmt
) – a prepared statement object (as aGda.PStmt
object, or more likely a descendant)
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:
- Raises:
- Returns:
True
if no error occurred- Return type:
Adds a SAVEPOINT named name.
- async_cancel(task_id)¶
- Parameters:
task_id (
int
) – a task ID returned byGda.Connection.async_statement_execute
()- Raises:
- Returns:
True
if no error occurred- Return type:
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 returnsFalse
, 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 byGda.Connection.async_statement_execute
()- Raises:
- Returns:
a
GObject.Object
, orNone
if an error occurred- 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 returnNone
(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:
stmt (
Gda.Statement
) – aGda.Statement
objectparams (
Gda.Set
orNone
) – aGda.Set
object (which can be obtained usingGda.Statement.get_parameters
()), orNone
model_usage (
Gda.StatementModelUsage
) – in the case where stmt is a SELECT statement, specifies how the returned data model will be usedcol_types ([
GObject.GType
] orNone
) – an array ofGObject.GType
to request each returnedGda.DataModel
's column’sGObject.GType
, terminated with theGObject.TYPE_NONE
need_last_insert_row (
bool
) –True
if the values of the last interted row must be computed
- Raises:
- 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:
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 useGda.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:
batch (
Gda.Batch
) – aGda.Batch
object which contains all the statements to executeparams (
Gda.Set
orNone
) – aGda.Set
object (which can be obtained usingGda.Batch.get_parameters
()), orNone
model_usage (
Gda.StatementModelUsage
) – specifies how the returned data model(s) will be used, as aGda.StatementModelUsage
enum
- Raises:
- Returns:
a new list of
GObject.Object
objects- Return type:
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 oneGObject.Object
for each statement; seeGda.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:
name (
str
orNone
) – the name of the transation to start, orNone
level (
Gda.TransactionIsolation
) – the requested transaction level (Gda.TransactionIsolation.UNKNOWN
if not specified)
- Raises:
- Returns:
True
if the transaction was started successfully,False
otherwise.- Return type:
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
orNone
) – the name of the transation to commit, orNone
- Raises:
- Returns:
True
if the transaction was finished successfully,False
otherwise.- Return type:
Commits the given transaction to the backend database. You need to call
Gda.Connection.begin_transaction
() first.
- create_operation(type, options)¶
- Parameters:
type (
Gda.ServerOperationType
) – the type of operation requested
- Raises:
- Returns:
a new
Gda.ServerOperation
object, orNone
in the connection’s provider does not support the type type of operation or if an error occurred- Return type:
Creates a new
Gda.ServerOperation
object which can be modified in order to perform the type type of action. It is a wrapper around theGda.ServerProvider.create_operation
() method.
- create_parser()¶
- Returns:
a new
Gda.SqlParser
object, orNone
- Return type:
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, thenNone
is returned, and a general SQL parser can be obtained usingGda.SqlParser.new
().
- del_prepared_statement(gda_stmt)¶
- Parameters:
gda_stmt (
Gda.Statement
) – aGda.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 updatedcondition_column_name (
str
) – the name of the column to used in the WHERE condition clausecondition_value (
GObject.Value
) – the condition_column_type'sGObject.GType
- Raises:
- Returns:
- Return type:
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:
- Raises:
- Returns:
True
if no error occurred- Return type:
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:
- Returns:
the number of rows affected or -1, or -2
- Return type:
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:
- Returns:
a new
Gda.DataModel
if successful,None
otherwise- Return type:
Execute a SQL SELECT command over an opened connection.
New in version 4.2.3.
- get_authentication()¶
- Returns:
the user name.
- Return type:
Gets the user name used to open this connection.
- get_cnc_string()¶
- Returns:
the connection string used when opening the connection.
- Return type:
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:
- 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_events()¶
- Returns:
a
GLib.List
ofGda.ConnectionEvent
objects (the list should not be modified)- Return type:
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:
Get or initializes the
Gda.MetaStore
associated to self
- get_meta_store_data_v(meta_type, filters)¶
- Parameters:
meta_type (
Gda.ConnectionMetaType
) – describes which data to get.filters ([
Gda.Holder
]) – aGLib.List
ofGda.Holder
objects
- Raises:
- Returns:
a
Gda.DataModel
containing the data required. The caller is responsible for freeing the returned model usingGObject.Object.unref
().- Return type:
see #gda_connection_get_meta_store_data
- get_options()¶
- Returns:
the connection options.
- Return type:
Gets the
Gda.ConnectionOptions
used to open this connection.
- get_prepared_statement(gda_stmt)¶
- Parameters:
gda_stmt (
Gda.Statement
) – aGda.Statement
object- Returns:
the prepared statement, or
None
if no association exists- Return type:
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
(NEVERNone
)- Return type:
Gets a pointer to the
Gda.ServerProvider
object used to access the database
- get_provider_name()¶
- Returns:
a non modifiable string
- Return type:
Gets the name (identifier) of the database provider used by self
- get_transaction_status()¶
- Returns:
a
Gda.TransactionStatus
object, orNone
- Return type:
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:
table (
str
) – table’s name to insert intovalues ([
GObject.Value
]) – a list of values (asGObject.Value
)
- Raises:
- Returns:
- Return type:
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()¶
-
Checks whether a connection is open or not.
- open()¶
- Raises:
- Returns:
- Return type:
Tries to open the connection.
- parse_sql_string(sql)¶
- Parameters:
- Raises:
- Returns:
a
Gda.Statement
representing the SQL command, orNone
if an error occurred- 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
) – aGda.ServerOperation
object- Raises:
- Returns:
True
if no error occurred- Return type:
Performs the operation described by op (which should have been created using
Gda.Connection.create_operation
()). It is a wrapper around theGda.ServerProvider.perform_operation
() method.
- point_available_event(type)¶
- Parameters:
type (
Gda.ConnectionEventType
) – aGda.ConnectionEventType
- Returns:
a pointer to the next available connection event, or
None
if event should be ignored- Return type:
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:
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:
rstmt (
Gda.RepetitiveStatement
) – aGda.RepetitiveStatement
objectmodel_usage (
Gda.StatementModelUsage
) – specifies how the returned data model will be used as aGda.StatementModelUsage
enumcol_types ([
GObject.GType
] orNone
) – an array ofGObject.GType
to request each returnedGda.DataModel
's column’sGObject.GType
, seeGda.Connection.statement_execute_select_full
() for more informationstop_on_error (
bool
) – set toTrue
if the method has to stop on the first error.
- Raises:
- Returns:
a new list of
GObject.Object
pointers (seeGda.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 isFalse
, then the list may contain someNone
pointers which refer to statements which failed to execute.- Return type:
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 isFalse
, then it may contain the last error which occurred.New in version 4.2.
- rollback_savepoint(name)¶
- Parameters:
- Raises:
- Returns:
True
if no error occurred- Return type:
Rollback all the modifications made after the SAVEPOINT named name.
- rollback_transaction(name)¶
- Parameters:
name (
str
orNone
) – the name of the transation to commit, orNone
- Raises:
- Returns:
- Return type:
Rollbacks the given transaction. This means that all changes made to the underlying data source since the last call to
Gda.Connection.begin_transaction
() orGda.Connection.commit_transaction
() will be discarded.
- statement_execute(stmt, params, model_usage)¶
- Parameters:
stmt (
Gda.Statement
) – aGda.Statement
objectparams (
Gda.Set
orNone
) – aGda.Set
object (which can be obtained usingGda.Statement.get_parameters
()), orNone
model_usage (
Gda.StatementModelUsage
) – in the case where stmt is a SELECT statement, specifies how the returned data model will be used
- Raises:
- Returns:
a
GObject.Object
, orNone
if an error occurred- 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:
a
Gda.DataSelect
object (which is also aGda.DataModel
) if stmt is a SELECT statement (usually aGda.SqlStatementType.SELECT
, seeGda.SqlStatementType
) containing the results of the SELECT. The resulting data model is by default read only, but modifications can be enabled, see theGda.DataSelect
's documentation for more information.a
Gda.Set
for any other SQL statement which correctly executed. In this case (if the provider supports it), then theGda.Set
may contain value holders named:a (
int
)Gda.Holder
named “IMPACTED_ROWS”a (
GObject.Object
)Gda.Holder
named “EVENT” which contains aGda.ConnectionEvent
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 newGda.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 aGda.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 returnNone
.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 returnNone
, unless the model_usage has theGda.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 theGda.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 theGda.DataSelect
'sauto-reset
property for more information. Note4: if model_usage does not contain theGda.StatementModelUsage.RANDOM_ACCESS
orGda.StatementModelUsage.CURSOR_FORWARD
flags, then the default will be to return a random access data modelNote5: 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:
stmt (
Gda.Statement
) – aGda.Statement
object.params (
Gda.Set
orNone
) – aGda.Set
object (which can be obtained usingGda.Statement.get_parameters
()), orNone
- Raises:
- Returns:
the number of rows affected (>=0) or -1 or -2
- Return type:
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 theGda.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:
stmt (
Gda.Statement
) – aGda.Statement
object.params (
Gda.Set
orNone
) – aGda.Set
object (which can be obtained usingGda.Statement.get_parameters
()), orNone
- Raises:
- Returns:
a
Gda.DataModel
containing the data returned by the data source, orNone
if an error occurred- Return type:
Executes a selection command on the given connection.
This function returns a
Gda.DataModel
resulting from the SELECT statement, orNone
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:
stmt (
Gda.Statement
) – aGda.Statement
object.params (
Gda.Set
orNone
) – aGda.Set
object (which can be obtained usingGda.Statement.get_parameters
()), orNone
model_usage (
Gda.StatementModelUsage
) – specifies how the returned data model will be used as aGda.StatementModelUsage
enumcol_types ([
GObject.GType
] orNone
) – an array ofGObject.GType
to request each returnedGda.DataModel
's column’sGObject.GType
, terminated with theGObject.TYPE_NONE
value. Any value left to 0 will make the database provider determine the realGObject.GType
. col_types can also beNone
if no column type is specified.
- Raises:
- Returns:
a
Gda.DataModel
containing the data returned by the data source, orNone
if an error occurred- Return type:
Executes a selection command on the given connection.
This function returns a
Gda.DataModel
resulting from the SELECT statement, orNone
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
) – aGda.Statement
object- Raises:
- Returns:
True
if no error occurred.- Return type:
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 whenGda.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:
stmt (
Gda.Statement
) – aGda.Statement
objectparams (
Gda.Set
orNone
) – aGda.Set
object (which can be obtained usingGda.Statement.get_parameters
()), orNone
flags (
Gda.StatementSqlFlag
) – SQL rendering flags, asGda.StatementSqlFlag
OR’ed values
- Raises:
- 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:
- Return type:
Asks the underlying provider for if a specific feature is supported.
- update_meta_store(context)¶
- Parameters:
context (
Gda.MetaContext
orNone
) – description of which part of self's associatedGda.MetaStore
should be updated, orNone
- Raises:
- Returns:
True
if no error occurred- Return type:
Updates self's associated
Gda.MetaStore
. If context is notNone
, then only the parts described by context will be updated, and if it isNone
, 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 theGda.MetaStore
has adopted regarding case sensitivity, usingGda.Connection.quote_sql_identifier
() orGda.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 updatedcondition_column_name (
str
) – the name of the column to used in the WHERE condition clausecondition_value (
GObject.Value
) – the condition_column_type'sGObject.GType
values ([
GObject.Value
]) – a list of values (asGObject.Value
)
- Raises:
- Returns:
- Return type:
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:
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:
- 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:
- 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:
- 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:
- 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:
- Parameters:
connection (
Gda.Connection
) – The object which received the signalevent (
Gda.ConnectionEvent
) – aGda.ConnectionEvent
object
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:
- 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¶
-
Authentication string to use
- Gda.Connection.props.cnc_string¶
-
Connection string to use
- Gda.Connection.props.dsn¶
-
DSN to use
- Gda.Connection.props.events_history_size¶
-
Defines the number of
Gda.ConnectionEvent
objects kept in memory which can be fetched usingGda.Connection.get_events
().New in version 4.2.
- Gda.Connection.props.execution_slowdown¶
-
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¶
-
Computes execution times for each statement executed.
New in version 4.2.9.
- Gda.Connection.props.is_wrapper¶
-
This property, if set to
True
, specifies that the connection is not a real connection, but rather aGda.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:
- Default Value:
- Flags:
Gda.MetaStore
used by the connection
- Gda.Connection.props.monitor_wrapped_in_mainloop¶
-
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:
- Default Value:
- Flags:
Provider to use