1 /*
2  * Copyright (C) 2000 Reinhard Müller <reinhard@src.gnome.org>
3  * Copyright (C) 2000 - 2002 Rodrigo Moya <rodrigo@gnome-db.org>
4  * Copyright (C) 2001 Carlos Perelló Marín <carlos@gnome-db.org>
5  * Copyright (C) 2001 - 2012 Vivien Malerba <malerba@gnome-db.org>
6  * Copyright (C) 2002 Gonzalo Paniagua Javier <gonzalo@src.gnome.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA  02110-1301, USA.
22  */
23 
24 #ifndef __GDA_VCONNECTION_DATA_MODEL_PRIVATE_H__
25 #define __GDA_VCONNECTION_DATA_MODEL_PRIVATE_H__
26 
27 G_BEGIN_DECLS
28 
29 typedef enum {
30 	PARAMS_INSERT,
31 	PARAMS_UPDATE,
32 	PARAMS_DELETE,
33 	PARAMS_NB
34 } ParamType;
35 
36 typedef struct GdaVConnectionTableData GdaVConnectionTableData;
37 typedef struct VContext VContext;
38 typedef struct ExecContext ExecContext;
39 typedef struct VirtualFilteredData VirtualFilteredData;
40 
41 struct VContext{
42 	GObject                 *context_object;
43 	GArray                  *context_data;
44 	GdaVConnectionTableData *vtable;
45 };
46 
47 struct ExecContext {
48 	VContext   *current_vcontext;
49 	GRecMutex  *mutex;
50 	GHashTable *hash; /* key = a GObject, value = a VContext where @context_object == key */
51 };
52 
53 /*
54  * This structure holds data to be used by a virtual cursor, for a specific filter,
55  * it keeps track of data which has been assigned a rowID
56  */
57 struct VirtualFilteredData {
58 	/* status */
59 	guint8 refcount;
60 	gboolean reuseable;
61 
62 	/* filter */
63 	int idxNum;
64 	char *idxStr;
65 	int argc;
66 	GValue **argv;
67 
68 	/* row numbers offset */
69 	guint32 rowid_offset;
70 
71 	/* data */
72 	GdaDataModel *model;
73 	GdaDataModelIter *iter; /* not NULL while nrows == -1 */
74 	GArray       *values_array;
75 	gint          ncols;
76 	gint          nrows; /* -1 until known */
77 };
78 
79 struct GdaVConnectionTableData {
80 	GdaVconnectionDataModelSpec *spec;
81 	GDestroyNotify               spec_free_func;
82 
83 	GdaDataModel                *real_model; /* data model really being used, a reference is kept */
84 	GList                       *columns;
85 	gchar                       *table_name;
86 	gchar                       *unique_name;
87 	gint                         n_columns;
88 
89 	GdaStatement                *modif_stmt[PARAMS_NB];
90 	GdaSet                      *modif_params[PARAMS_NB];
91 
92 	ExecContext                  context; /* not a pointer! */
93 };
94 
95 
96 void                     _gda_vconnection_virtual_filtered_data_unref (VirtualFilteredData *data);
97 
98 void                     _gda_vconnection_data_model_table_data_free (GdaVConnectionTableData *td);
99 
100 GdaVConnectionTableData *_gda_vconnection_get_table_data_by_name (GdaVconnectionDataModel *cnc, const gchar *table_name);
101 GdaVConnectionTableData *_gda_vconnection_get_table_data_by_model (GdaVconnectionDataModel *cnc, GdaDataModel *model);
102 GdaVConnectionTableData *_gda_vconnection_get_table_data_by_unique_name (GdaVconnectionDataModel *cnc, const gchar *unique_name);
103 
104 void                     _gda_vconnection_set_working_obj (GdaVconnectionDataModel *cnc, GObject *obj);
105 void                     _gda_vconnection_change_working_obj (GdaVconnectionDataModel *cnc, GObject *obj);
106 
107 G_END_DECLS
108 
109 #endif
110