Top |
Misc API for database providersMisc API for database providers — Methods dedicated to implementing providers |
The methods mentioned in this section are reserved for database providers implementations and should not bu used by developers outside that scope.
GdaServerOperation * gda_server_operation_new (GdaServerOperationType op_type
,const gchar *xml_file
);
IMPORTANT NOTE: Using this funtion is not the recommended way of creating a GdaServerOperation object, the
correct way is to use gda_server_provider_create_operation()
; this method is reserved for the database provider's
implementation.
Creates a new GdaServerOperation object from the xml_file
specifications
The xml_file
must respect the DTD described in the "libgda-server-operation.dtd" file: its top
node must be a <serv_op> tag.
GdaSqlParser *
gda_server_provider_internal_get_parser
(GdaServerProvider *prov
);
This is a factory method to get a unique instance of a GdaSqlParser object for each GdaServerProvider object Don't unref it.
gboolean gda_server_provider_perform_operation_default (GdaServerProvider *provider
,GdaConnection *cnc
,GdaServerOperation *op
,GError **error
);
Performs the operation described by op
, using the SQL from the rendering of the operation
provider |
a GdaServerProvider object |
|
cnc |
a GdaConnection object which will be used to perform an action, or |
[allow-none] |
op |
a GdaServerOperation object |
|
error |
a place to store an error, or |
GdaDataHandler * gda_server_provider_get_data_handler_default (GdaServerProvider *provider
,GdaConnection *cnc
,GType type
,const gchar *dbms_type
);
gda_server_provider_get_data_handler_default
has been deprecated since version 5.2 and should not be used in newly-written code.
use gda_server_provider_handler_use_default()
instead
Provides the implementation when the default Libgda's data handlers must be used
provider |
a server provider. |
|
cnc |
a GdaConnection object, or |
[allow-none] |
type |
a GType |
|
dbms_type |
a DBMS type definition |
GdaDataHandler * gda_server_provider_handler_use_default (GdaServerProvider *provider
,GType type
);
Reserved to database provider's implementations. This method defines a default data handler for
provider
, and returns that GdaDataHandler.
[skip]
Since: 5.2
GdaDataHandler * gda_server_provider_handler_find (GdaServerProvider *prov
,GdaConnection *cnc
,GType g_type
,const gchar *dbms_type
);
Reserved to database provider's implementations: get the GdaDataHandler associated to prov
for connection cnc
. You probably want to use gda_server_provider_get_data_handler_g_type()
.
void gda_server_provider_handler_declare (GdaServerProvider *prov
,GdaDataHandler *dh
,GdaConnection *cnc
,GType g_type
,const gchar *dbms_type
);
gchar * gda_server_provider_find_file (GdaServerProvider *prov
,const gchar *inst_dir
,const gchar *filename
);
Finds the location of a filename
. This function should only be used by database provider's
implementations
gchar * gda_server_provider_load_file_contents (const gchar *inst_dir
,const gchar *data_dir
,const gchar *filename
);
Loads and returns the contents of filename
, which is searched in several places
This function should only be used by database provider's
implementations
inst_dir |
directory where the database provider has been installed |
|
data_dir |
DATA directory to look for ($prefix/share) |
|
filename |
name of the file to load |
void gda_connection_internal_set_provider_data (GdaConnection *cnc
,gpointer data
,GDestroyNotify destroy_func
);
Note: calling this function more than once will not make it call destroy_func
on any previously
set opaque data
, you'll have to do it yourself.
[skip]
cnc |
a GdaConnection object |
|
data |
an opaque structure, known only to the provider for which |
|
destroy_func |
function to call when the connection closes and |
gpointer
gda_connection_internal_get_provider_data
(GdaConnection *cnc
);
Get the opaque pointer previously set using gda_connection_internal_set_provider_data()
.
If it's not set, then add a connection event and returns NULL
[skip]
the pointer to the opaque structure set using gda_connection_internal_set_provider_data()
, or NULL
.
gpointer gda_connection_internal_get_provider_data_error (GdaConnection *cnc
,GError **error
);
Get the opaque pointer previously set using gda_connection_internal_set_provider_data()
.
If it's not set, then add a connection event and returns NULL
[skip]
the pointer to the opaque structure set using gda_connection_internal_set_provider_data()
, or NULL
.
Since: 5.0.2
void gda_connection_add_event (GdaConnection *cnc
,GdaConnectionEvent *event
);
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!
cnc |
a GdaConnection object. |
|
event |
is stored internally, so you don't need to unref it. |
[transfer full] |
GdaConnectionEvent * gda_connection_add_event_string (GdaConnection *cnc
,const gchar *str
,...
);
Adds a new error to the given connection object. This is just a convenience function that simply creates a GdaConnectionEvent and then calls gda_server_connection_add_error.
[skip]
cnc |
a GdaConnection object. |
|
str |
a format string (see the printf(3) documentation). |
|
... |
the arguments to insert in the error message. |
a new GdaConnectionEvent object, however the caller does not hold a reference to the returned object, and if need be the caller must call g_object_ref()
on it.
void
gda_connection_clear_events_list (GdaConnection *cnc
);
This function lets you clear the list of GdaConnectionEvent's of the given connection.
void gda_connection_event_set_event_type (GdaConnectionEvent *event
,GdaConnectionEventType type
);
Sets event
's severity (from a simple notice to a fatal event)
This function should not be called directly.
void gda_connection_event_set_description (GdaConnectionEvent *event
,const gchar *description
);
Sets event
's description
. This function should not be called directly.
event |
||
description |
a description, or |
[allow-none] |
void gda_connection_event_set_code (GdaConnectionEvent *event
,glong code
);
Sets event
's code: the code is specific to the provider being used.
If you want to have a common understanding of the event codes, use
gda_connection_event_get_gda_code()
instead.
This function should not be called directly
void gda_connection_event_set_gda_code (GdaConnectionEvent *event
,GdaConnectionEventCode code
);
Sets event
's gda code: that code is standardized by the libgda
library. If you want to specify the corresponding provider specific code,
use gda_connection_event_get_code()
or gda_connection_event_get_sqlstate()
instead.
This function should not be called directly
void gda_connection_event_set_source (GdaConnectionEvent *event
,const gchar *source
);
Sets event
's source
; this function should not be called directly
void gda_connection_event_set_sqlstate (GdaConnectionEvent *event
,const gchar *sqlstate
);
Changes the SQLSTATE code of event
, this function should not be called directly
Sets event
's SQL state.
void gda_connection_add_prepared_statement (GdaConnection *cnc
,GdaStatement *gda_stmt
,GdaPStmt *prepared_stmt
);
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
.
cnc |
a GdaConnection object |
|
gda_stmt |
a GdaStatement object |
|
prepared_stmt |
a prepared statement object (as a GdaPStmt object, or more likely a descendant) |
void gda_connection_del_prepared_statement (GdaConnection *cnc
,GdaStatement *gda_stmt
);
Removes any prepared statement associated to gda_stmt
in cnc
: this undoes what
gda_connection_add_prepared_statement()
does.
GdaPStmt * gda_connection_get_prepared_statement (GdaConnection *cnc
,GdaStatement *gda_stmt
);
Retrieves a pointer to an object representing a prepared statement for gda_stmt
within cnc
. The
association must have been done using gda_connection_add_prepared_statement()
.
void gda_connection_internal_transaction_started (GdaConnection *cnc
,const gchar *parent_trans
,const gchar *trans_name
,GdaTransactionIsolation isol_level
);
Internal functions to be called by database providers when a transaction has been started to keep track of the transaction status of the connection.
Note: this function should not be called if gda_connection_internal_statement_executed()
has already been called because a statement's execution was necessary to perform
the action.
[skip]
cnc |
||
parent_trans |
name of the parent transaction, or |
[allow-none] |
trans_name |
transaction's name, or |
|
isol_level |
isolation level. |
void gda_connection_internal_transaction_rolledback (GdaConnection *cnc
,const gchar *trans_name
);
Internal functions to be called by database providers when a transaction has been rolled back to keep track of the transaction status of the connection
Note: this function should not be called if gda_connection_internal_statement_executed()
has already been called because a statement's execution was necessary to perform
the action.
[skip]
void gda_connection_internal_transaction_committed (GdaConnection *cnc
,const gchar *trans_name
);
Internal functions to be called by database providers when a transaction has been committed to keep track of the transaction status of the connection
Note: this function should not be called if gda_connection_internal_statement_executed()
has already been called because a statement's execution was necessary to perform
the action.
[skip]
void gda_connection_internal_statement_executed (GdaConnection *cnc
,GdaStatement *stmt
,GdaSet *params
,GdaConnectionEvent *error
);
Internal functions to be called by database providers when a statement has been executed to keep track of the transaction status of the connection
[skip]
cnc |
||
stmt |
a GdaStatement which has been executed |
|
params |
execution's parameters. |
[allow-none] |
error |
a GdaConnectionEvent if the execution failed, or |
void gda_connection_internal_savepoint_added (GdaConnection *cnc
,const gchar *parent_trans
,const gchar *svp_name
);
Internal functions to be called by database providers when a savepoint has been added to keep track of the transaction status of the connection
Note: this function should not be called if gda_connection_internal_statement_executed()
has already been called because a statement's execution was necessary to perform
the action.
[skip]
cnc |
||
parent_trans |
name of the parent transaction, or |
[allow-none] |
svp_name |
savepoint's name, or |
void gda_connection_internal_savepoint_rolledback (GdaConnection *cnc
,const gchar *svp_name
);
Internal functions to be called by database providers when a savepoint has been rolled back to keep track of the transaction status of the connection
Note: this function should not be called if gda_connection_internal_statement_executed()
has already been called because a statement's execution was necessary to perform
the action.
[skip]
void gda_connection_internal_savepoint_removed (GdaConnection *cnc
,const gchar *svp_name
);
Internal functions to be called by database providers when a savepoint has been removed to keep track of the transaction status of the connection
Note: this function should not be called if gda_connection_internal_statement_executed()
has already been called because a statement's execution was necessary to perform
the action.
[skip]
void gda_connection_internal_change_transaction_state (GdaConnection *cnc
,GdaTransactionStatusState newstate
);
Internal function to be called by database providers to force a transaction status change.
[skip]
void
gda_connection_internal_reset_transaction_status
(GdaConnection *cnc
);
Internal function to be called by database providers to reset the transaction status.
[skip]
GdaConnection * gda_connection_open_sqlite (const gchar *directory
,const gchar *filename
,gboolean auto_unlink
);
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.
directory |
the directory the database file will be in, or |
[allow-none] |
filename |
the database file name |
|
auto_unlink |
if |
gboolean gda_meta_store_modify (GdaMetaStore *store
,const gchar *table_name
,GdaDataModel *new_data
,const gchar *condition
,GError **error
,...
);
Propagates an update to store
, the update's contents is represented by new_data
, this function is
primarily reserved to database providers.
For example tell store
to update its list of tables, new_data
should contain the same columns as the "_tables"
table of store
, and contain one row per table in the store; there should not be any more argument after the error
argument.
Now, to update only one table, the new_data
data model should have one row for the table to update (or no row
at all if the table does not exist anymore), and have values for the primary key of the "_tables" table of
store
, namely "table_catalog", "table_schema" and "table_name".
[skip]
store |
a GdaMetaStore object |
|
table_name |
the name of the table to modify within |
|
new_data |
a GdaDataModel containing the new data to set in |
[nullable] |
condition |
SQL expression (which may contain variables) defining the rows which are being obsoleted by |
[nullable] |
error |
a place to store errors, or |
[nullable] |
... |
a list of (variable name (gchar *), GValue *value) terminated with NULL, representing values for all the
variables mentioned in |
gboolean gda_meta_store_modify_v (GdaMetaStore *store
,const gchar *table_name
,GdaDataModel *new_data
,const gchar *condition
,gint nvalues
,const gchar **value_names
,const GValue **values
,GError **error
);
Propagates an update to store
, the update's contents is represented by new_data
, this function is
primarily reserved to database providers.
[rename-to gda_meta_store_modify]
store |
a GdaMetaStore object |
|
table_name |
the name of the table to modify within |
|
new_data |
a GdaDataModel containing the new data to set in |
[nullable] |
condition |
SQL expression (which may contain variables) defining the rows which are being obsoleted by |
[nullable] |
nvalues |
number of values in |
|
value_names |
names of values. |
[array length=nvalues] |
values |
values. |
[array length=nvalues] |
error |
a place to store errors, or |
[nullable] |
Since: 4.2.6
gboolean gda_meta_store_modify_with_context (GdaMetaStore *store
,GdaMetaContext *context
,GdaDataModel *new_data
,GError **error
);
Propagates an update to store
, the update's contents is represented by new_data
, this function is
primarily reserved to database providers.
store |
a GdaMetaStore object |
|
context |
a GdaMetaContext context describing what to modify in |
[transfer none] |
new_data |
a GdaDataModel containing the new data to set in |
[transfer none][nullable] |
error |
a place to store errors, or |
void gda_meta_store_set_identifiers_style (GdaMetaStore *store
,GdaSqlIdentifierStyle style
);
Specifies how store
must handle SQL identifiers it has to store. This method is mainly used by
database providers.
Since: 4.2
void gda_meta_store_set_reserved_keywords_func (GdaMetaStore *store
,GdaSqlReservedKeywordsFunc func
);
Specifies a function which store
will use to determine if a keyword is an SQL reserved
keyword or not.
This method is mainly used by database providers.
store |
a GdaMetaStore object |
|
func |
a GdaSqlReservedKeywordsFunc function, or |
[nullable][scope call] |
Since: 4.2
gboolean gda_compute_dml_statements (GdaConnection *cnc
,GdaStatement *select_stmt
,gboolean require_pk
,GdaStatement **insert_stmt
,GdaStatement **update_stmt
,GdaStatement **delete_stmt
,GError **error
);
Creates an INSERT, an UPDATE and a DELETE statement from a SELECT statement
using the database metadata available in cnc
's meta store. Each statements are computed only if
the corresponding place to store the created statement is not NULL
.
cnc |
||
select_stmt |
a SELECT GdaStatement (compound statements not handled) |
|
require_pk |
TRUE if the created statement have to use a primary key |
|
insert_stmt |
a place to store the created INSERT statement, or |
[nullable][transfer full] |
update_stmt |
a place to store the created UPDATE statement, or |
[nullable][transfer full] |
delete_stmt |
a place to store the created DELETE statement, or |
[nullable][transfer full] |
error |
a place to store errors, or |
[nullable] |
GdaSqlStatement * gda_compute_select_statement_from_update (GdaStatement *update_stmt
,GError **error
);
Computes a SELECT statement which selects all the rows the update_stmt
would update. Beware
however that this GdaSqlStatement does not select anything (ie it would be rendered as "SELECT FROM ... WHERE ...")
and before being usable, one needs to add some fields to actually select.
[skip]
GdaSqlStatement * gda_rewrite_sql_statement_for_null_parameters (GdaSqlStatement *sqlst
,GdaSet *params
,gboolean *out_modified
,GError **error
);
Modifies sqlst
to take into account any parameter which might be NULL
: if sqlst
contains the
equivalent of "xxx = <parameter definition>" and if that parameter is in params
and
its value is of type GDA_TYPE_NUL, then that part is replaced with "xxx IS NULL". It also
handles the "xxx IS NOT NULL" transformation.
If out_modified
is not NULL
, then it will be set to TRUE
if sqlst
has been modified
by this function, and to FALSE
otherwise.
This function is used by provider's implementations to make sure one can use parameters with NULL values in statements without having to rewrite statements, as database usually don't consider that "xxx = NULL" is the same as "xxx IS NULL" when using parameters.
[skip]
sqlst |
[transfer full] | |
params |
a GdaSet to be used as parameters when executing |
|
out_modified |
a place to store the boolean which tells if |
[nullable] |
error |
a place to store errors, or |
Since: 4.2.9
gboolean gda_rewrite_statement_for_null_parameters (GdaStatement *stmt
,GdaSet *params
,GdaStatement **out_stmt
,GError **error
);
Modifies stmt
to take into account any parameter which might be NULL
: if stmt
contains the
equivalent of "xxx = <parameter definition>" and if that parameter is in params
and
its value is of type GDA_TYPE_NUL, then that part is replaced with "xxx IS NULL". It also
handles the "xxx IS NOT NULL" transformation.
For example the following SELECT:
SELECT * FROM data WHERE id = ##id::int::null AND name = ##name::string
in case the "id" parameter is set to NULL, is converted to:
SELECT * FROM data WHERE id IS NULL AND name = ##name::string
if out_stmt
is not NULL
, then it will contain:
This function is used by provider's implementations to make sure one can use parameters with NULL values in statements without having to rewrite statements, as database usually don't consider that "xxx = NULL" is the same as "xxx IS NULL" when using parameters.
stmt |
a GdaStatement. |
[transfer none] |
params |
a GdaSet to be used as parameters when executing |
|
out_stmt |
a place to store the new GdaStatement, or |
[transfer full][nullable] |
error |
a place to store errors, or |
Since: 4.2.9
GdaSqlExpr * gda_compute_unique_table_row_condition (GdaSqlStatementSelect *stsel
,GdaMetaTable *mtable
,gboolean require_pk
,GError **error
);
Computes a GdaSqlExpr expression which can be used in the WHERE clause of an UPDATE
or DELETE statement when a row from the result of the stsel
statement has to be modified.
[skip]
stsel |
a GdaSqlSelectStatement |
|
mtable |
||
require_pk |
set to TRUE if a primary key ir required |
|
error |
a place to store errors, or |
GdaSqlExpr * gda_compute_unique_table_row_condition_with_cnc (GdaConnection *cnc
,GdaSqlStatementSelect *stsel
,GdaMetaTable *mtable
,gboolean require_pk
,GError **error
);
Computes a GdaSqlExpr expression which can be used in the WHERE clause of an UPDATE
or DELETE statement when a row from the result of the stsel
statement has to be modified.
If require_pk
is TRUE
then this function will return a non NULL
GdaSqlExpr only if it can
use a primary key of mtable
. If require_pk
is FALSE
, then it will try to use a primary key of mtable
,
and if none is available, it will use all the columns of mtable
to compute a condition statement.
[skip]
cnc |
a GdaConnection, or |
[nullable] |
stsel |
a GdaSqlSelectStatement |
|
mtable |
||
require_pk |
set to |
|
error |
a place to store errors, or |
Since: 4.0.3
gboolean gda_sql_any_part_check_structure (GdaSqlAnyPart *node
,GError **error
);
Checks for any error in node
's structure to make sure it is valid. This
is the same as gda_sql_statement_check_structure()
but for individual GdaSqlAnyPart
parts. This function is mainly for database provider's implementations
GdaSqlStatement * gda_statement_rewrite_for_default_values (GdaStatement *stmt
,GdaSet *params
,gboolean remove
,GError **error
);
Rewrites stmt
and creates a new GdaSqlStatement where all the variables which are to a DEFAULT value
(as returned by gda_holder_value_is_default()
) are either removed from the statement (if remove
is TRUE
) or replaced by the "DEFAULT" keyword (if remove
is FALSE
).
This function is only useful for database providers' implementations which have to deal with default
values when executing statements, and is only relevant in the case of INSERT or UPDATE statements
(in the latter case an error is returned if remove
is TRUE
).
For example the
INSERT INTO mytable (id, name) VALUES (23, ##name::string)
is re-written into
INSERT INTO mytable (id, name) VALUES (23, DEFAULT)
if remove
is FALSE
and into
INSERT INTO mytable (id) VALUES (23)
if remove
is TRUE
.
[skip]
stmt |
a GdaStatement object |
|
params |
a GdaSet containing the variable's values to be bound when executing |
|
remove |
set to |
|
error |
a place to store errors, or |
Since: 4.2
gchar *
gda_sql_identifier_force_quotes (const gchar *str
);
Add double quotes around the str
identifier. This function is normally used only by database provider's
implementation. Any double quote character is replaced by two double quote characters.
For other uses, see gda_sql_identifier_quote()
.
Since: 5.0
gchar *
gda_sql_identifier_prepare_for_compare
(gchar *str
);
Prepares str
to be compared:
if surrounded by double quotes or single quotes, then just remove the quotes
otherwise convert to lower case
The quoted string:
must start and finish with the same single or double quotes character
can contain the delimiter character (the single or double quotes) in the string if every instance of it is preceeded with a backslash character or with the delimiter character itself
This function is normally used only by database provider's implementation.
WARNING: str
must NOT be a composed identifier (<part1>."<part2>" for example)
Since: 5.0
Specifies how SQL identifiers are represented by a specific database
case insensitive SQL identifiers are represented in lower case (meaning that any SQL identifier which has a non lower case character is case sensitive) |
||
case insensitive SQL identifiers are represented in upper case (meaning that any SQL identifier which has a non upper case character is case sensitive) |