GdaDataModelQuery

GdaDataModelQuery — An implementation of GdaDataModel based on a SELECT query

Functions

Properties

GdaQuery * delete-query Read / Write
GdaQuery * insert-query Read / Write
GdaQuery * query Read / Write / Construct Only
GdaQuery * update-query Read / Write
gboolean use-transaction Read / Write / Construct

Types and Values

Object Hierarchy

    GObject
    ╰── GdaObject
        ╰── GdaDataModelQuery

Implemented Interfaces

GdaDataModelQuery implements GdaDataModel.

Description

The GdaDataModelQuery data model simply stores the values returned by a SELECT query. The connection used to execute the SELECT query (given when the object is constructed) is the same as the one provided th the GdaDict object to which the query relates.

Functions

gda_data_model_query_new ()

GdaDataModel *
gda_data_model_query_new (GdaQuery *query);

Creates a new GdaDataModel object using the data returned by the execution of the query SELECT query.

Parameters

query

a SELECT query

 

Returns

a pointer to the newly created GdaDataModel.


gda_data_model_query_get_parameter_list ()

GdaParameterList *
gda_data_model_query_get_parameter_list
                               (GdaDataModelQuery *model);

If some parameters are required to execute the SELECT query used in the model data model, then returns the GdaParameterList used; otherwise does nothing and returns NULL.

Parameters

model

a GdaDataModelQuery data model

 

Returns

a GdaParameterList object, or NULL


gda_data_model_query_refresh ()

gboolean
gda_data_model_query_refresh (GdaDataModelQuery *model,
                              GError **error);

(Re)-runs the SELECT query to update the contents of model

Parameters

model

a GdaDataModelQuery data model

 

error

a place to store errors, or NULL

 

Returns

TRUE if no error occurred


gda_data_model_query_set_modification_query ()

gboolean
gda_data_model_query_set_modification_query
                               (GdaDataModelQuery *model,
                                const gchar *query,
                                GError **error);

Sets the modification query to be used by model to actually perform any change to the dataset in the database.

The provided query (the query SQL) must be either a INSERT, UPDATE or DELETE query. It can contain parameters, and the parameters named '[+-]<num>' will be replaced when the query is run:

  • a parameter named +<num> will take the new value set at the <num>th column in model

  • a parameter named -<num> will take the old value set at the <num>th column in model

Please note that the "+0" and "-0" parameters names are valid and will respectively take the new and old values of the first column of model .

Examples of queries are: "INSERT INTO orders (customer, creation_date, delivery_before, delivery_date) VALUES (## / *name:'Customer' type:integer* /, date('now'), ## / *name:"+2" type:date nullok:TRUE * /, NULL)", "DELETE FROM orders WHERE id = ## / *name:"-0" type:integer* /" and "UPDATE orders set id=## / *name:"+0" type:integer* /, delivery_before=## / *name:"+2" type:date nullok:TRUE* /, delivery_date=## / *name:"+3" type:date nullok:TRUE* / WHERE id=## / *name:"-0" type:integer* /"

Parameters

model

a GdaDataModelQuery data model

 

query

the SQL code for a query

 

error

a place to store errors, or NULL

 

Returns

TRUE if no error occurred.


gda_data_model_query_compute_modification_queries ()

gboolean
gda_data_model_query_compute_modification_queries
                               (GdaDataModelQuery *model,
                                const gchar *target,
                                GdaDataModelQueryOptions options,
                                GError **error);

Try to compute the INSERT, DELETE and UPDATE queries; any previous modification query will be discarded.

If specified, the table which will be updated is the one represented by the target .

If target is NULL, then an error will be returned if model 's SELECT query has more than one target.

Parameters

model

a GdaDataModelQuery object

 

target

the target table to modify, or NULL

 

options

options to specify how the queries must be built in some special cases

 

error

a place to store errors or NULL

 

Returns

TRUE if the INSERT, DELETE and UPDATE queries have been computed.

Types and Values

struct GdaDataModelQuery

struct GdaDataModelQuery;


struct GdaDataModelQueryClass

struct GdaDataModelQueryClass {
	GdaObjectClass             parent_class;
};


GdaDataModelQueryPrivate

typedef struct _GdaDataModelQueryPrivate GdaDataModelQueryPrivate;

Property Details

The “delete-query” property

  “delete-query”             GdaQuery *

DELETE Query to be executed to remove data.

Flags: Read / Write


The “insert-query” property

  “insert-query”             GdaQuery *

INSERT Query to be executed to add data.

Flags: Read / Write


The “query” property

  “query”                    GdaQuery *

SELECT Query to be executed to populate the model with data.

Flags: Read / Write / Construct Only


The “update-query” property

  “update-query”             GdaQuery *

UPDATE Query to be executed to update data.

Flags: Read / Write


The “use-transaction” property

  “use-transaction”          gboolean

Run modification queries within a transaction.

Flags: Read / Write / Construct

Default value: FALSE