GdaPModel

GdaPModel — Proposed base implementation for data models returned by the execution of a SELECT statement

Synopsis


#include <providers-support/gda-pmodel.h>


                    GdaPModel;
                    GdaPModelClass;
void                gda_pmodel_take_row                 (GdaPModel *model,
                                                         GdaPRow *row,
                                                         gint rownum);
GdaPRow*            gda_pmodel_get_stored_row           (GdaPModel *model,
                                                         gint rownum);
GdaConnection*      gda_pmodel_get_connection           (GdaPModel *model);
gboolean            gda_pmodel_set_modification_query   (GdaPModel *model,
                                                         GdaStatement *mod_stmt,
                                                         GError **error);
gboolean            gda_pmodel_compute_modification_queries
                                                        (GdaPModel *model,
                                                         const gchar *target,
                                                         gboolean use_all_fields_if_no_pk,
                                                         GError **error);

Description

This data model implements the GdaDataModel interface and is the proposed base object when database providers implement a data model returned when a SELECT statement has been executed.

Specifically it offers the following features:

  • Manages its list of GdaColumn using the list exported by the prepared statement object (GdaPStmt)

  • Allows random or cursor based access

  • Allows for efficient memory usage allowing the subclass to finely tune its memory usage

  • Will provide a generic mechanism for writable data models

See the Virtual methods for recordsets section for more information about how to implement the virtual methods.

Details

GdaPModel

typedef struct {
	GObject           object;
	GdaPModelPrivate *priv;
	/* read only information */
	GdaPStmt         *prep_stmt; /* use the "prepared-stmt" property to set this */
	gint              nb_stored_rows; /* number of GdaPRow objects currently stored */
	gint              advertized_nrows; /* set when the number of rows becomes known */
} GdaPModel;

GObject object; base object
GdaPModelPrivate *priv; private data
GdaPStmt *prep_stmt; SELECT prepared statement for which the execution gave this object
gint nb_stored_rows;
gint advertized_nrows; initially set to -1, set to a value >= 0 when the number of rows in the data model is known

GdaPModelClass

typedef struct {
	GObjectClass      parent_class;

	/* GDA_DATA_MODEL_ACCESS_RANDOM */
	gint             (*fetch_nb_rows) (GdaPModel *model);
	gboolean         (*fetch_random)  (GdaPModel *model, GdaPRow **prow, gint rownum, GError **error);
	gboolean         (*store_all)     (GdaPModel *model, GError **error);

	/* GDA_STATEMENT_MODEL_CURSOR_* */
	gboolean         (*fetch_next)    (GdaPModel *model, GdaPRow **prow, gint rownum, GError **error);
	gboolean         (*fetch_prev)    (GdaPModel *model, GdaPRow **prow, gint rownum, GError **error);
	gboolean         (*fetch_at)      (GdaPModel *model, GdaPRow **prow, gint rownum, GError **error);
} GdaPModelClass;

GObjectClass parent_class; parent object class
fetch_nb_rows () virtual method which must be implemented when access method is GDA_DATA_MODEL_ACCESS_RANDOM
fetch_random () virtual method which must be implemented when access method is GDA_DATA_MODEL_ACCESS_RANDOM
store_all ()
fetch_next () virtual method which must be implemented when access method is GDA_DATA_MODEL_ACCESS_CURSOR_FORWARD
fetch_prev () virtual method which must be implemented when access method is GDA_DATA_MODEL_ACCESS_CURSOR_BACKWARD
fetch_at () virtual method which can be implemented when access method is GDA_DATA_MODEL_ACCESS_CURSOR_FORWARD or GDA_DATA_MODEL_ACCESS_CURSOR_BACKWARD

gda_pmodel_take_row ()

void                gda_pmodel_take_row                 (GdaPModel *model,
                                                         GdaPRow *row,
                                                         gint rownum);

Stores row into model, externally advertized at row number rownum. The reference to row is stolen.

model : a GdaPModel data model
row : a GdaPRow row
rownum : "external" advertized row number

gda_pmodel_get_stored_row ()

GdaPRow*            gda_pmodel_get_stored_row           (GdaPModel *model,
                                                         gint rownum);

Get the GdaPRow object stored within model at row rownum

model : a GdaPModel data model
rownum : "external" advertized row number
Returns : the requested GdaPRow, or NULL if not found

gda_pmodel_get_connection ()

GdaConnection*      gda_pmodel_get_connection           (GdaPModel *model);

Get a pointer to the GdaConnection object which was used when model was created (and which may be used internally by model).

model : a GdaPModel data model
Returns : a pointer to the GdaConnection, or NULL

gda_pmodel_set_modification_query ()

gboolean            gda_pmodel_set_modification_query   (GdaPModel *model,
                                                         GdaStatement *mod_stmt,
                                                         GError **error);

Forces model to allow data modification using mod_stmt as the statement executed when the corresponding modification is requested

model : a GdaPModel data model
mod_stmt : a GdaStatement (INSERT, UPDATE or DELETE)
error : a place to store errors, or NULL
Returns : TRUE if no error occurred.

gda_pmodel_compute_modification_queries ()

gboolean            gda_pmodel_compute_modification_queries
                                                        (GdaPModel *model,
                                                         const gchar *target,
                                                         gboolean use_all_fields_if_no_pk,
                                                         GError **error);

Makes model try to compute INSERT, UPDATE and DELETE statements to be used when modifying model's contents

model : a GdaPModel data model
target : the name of the target to modify (a table name or alias)
use_all_fields_if_no_pk : set to TRUE if all fields must be used in the WHERE condition when no primary key exists
error : a place to store errors, or NULL
Returns : TRUE if no error occurred.