1 /*
2 * Copyright (C) 2008 - 2012 Vivien Malerba <malerba@gnome-db.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <string.h>
21 #include "gda-firebird.h"
22 #include "gda-firebird-meta.h"
23 #include "gda-firebird-provider.h"
24 #include <libgda/gda-meta-store.h>
25 #include <libgda/sql-parser/gda-sql-parser.h>
26 #include <glib/gi18n-lib.h>
27 #include <libgda/gda-server-provider-extra.h>
28 #include <libgda/providers-support/gda-meta-column-types.h>
29 #include <libgda/gda-connection-private.h>
30 #include <libgda/gda-data-model-array.h>
31 #include <libgda/gda-set.h>
32 #include <libgda/gda-holder.h>
33 #include <libgda/gda-debug-macros.h>
34
35 //static gboolean append_a_row (GdaDataModel *to_model, GError **error, gint nb, ...);
36
37 /*
38 * predefined statements' IDs
39 */
40 typedef enum {
41 I_STMT_CATALOG,
42
43 I_STMT_SCHEMAS,
44
45 I_STMT_SCHEMAS_ALL,
46
47 I_STMT_SCHEMA_NAMED,
48
49 I_STMT_TABLES_ALL,
50
51 I_STMT_TABLES,
52
53 I_STMT_TABLE_NAMED,
54
55 I_STMT_VIEWS_ALL,
56
57 I_STMT_VIEWS,
58
59 I_STMT_VIEW_NAMED,
60
61 I_STMT_COLUMNS_OF_TABLE,
62
63 I_STMT_COLUMNS_ALL,
64
65 I_STMT_CHARACTER_SETS,
66
67 I_STMT_CHARACTER_SETS_ALL,
68
69 I_STMT_VIEWS_COLUMNS ,
70 I_STMT_VIEWS_COLUMNS_ALL,
71
72 I_STMT_TABLES_CONSTRAINTS,
73 I_STMT_TABLES_CONSTRAINTS_ALL,
74 I_STMT_TABLES_CONSTRAINTS_NAMED,
75 I_STMT_REF_CONSTRAINTS,
76 I_STMT_REF_CONSTRAINTS_ALL,
77
78 I_STMT_KEY_COLUMN_USAGE,
79 I_STMT_KEY_COLUMN_USAGE_ALL,
80
81 //I_STMT_TRIGGERS,
82 //I_STMT_TRIGGERS_ALL,
83
84 //I_STMT_ROUTINES,
85 //I_STMT_ROUTINES_ALL,
86 //I_STMT_ROUTINES_ONE,
87 //I_STMT_ROUTINES_PAR_ALL,
88 //I_STMT_ROUTINES_PAR,
89
90 I_STMT_INDEXES_ALL,
91 I_STMT_INDEXES_TABLE,
92 I_STMT_INDEXES_ONE,
93 I_STMT_INDEX_COLUMNS_ALL,
94 I_STMT_INDEX_COLUMNS_NAMED
95
96 } InternalStatementItem;
97
98
99 /*
100 * predefined statements' SQL
101 */
102 #define CATALOG_NAME "'firebird'"
103 #define SCHEMA_NAME "'SYS'"
104
105 static gchar *internal_sql[] = {
106 /* I_STMT_CATALOG */
107 "SELECT " CATALOG_NAME " FROM RDB$DATABASE",
108
109 /* I_STMT_SCHEMAS */
110 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, NULL, 1 AS schema_internal FROM RDB$DATABASE",
111
112 /* I_STMT_SCHEMAS_ALL */
113 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, NULL, 1 AS schema_internal FROM RDB$DATABASE",
114
115 /* I_STMT_SCHEMA_NAMED */
116 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, NULL, 1 AS schema_internal FROM RDB$DATABASE",
117
118 /* I_STMT_TABLES_ALL */
119 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, (RDB$RELATION_NAME), 'BASE TABLE', 1, RDB$RELATION_NAME, TRIM(RDB$RELATION_NAME) AS short_name, TRIM(RDB$OWNER_NAME) || '.' || (TRIM(RDB$RELATION_NAME)) AS table_full_name, TRIM(RDB$OWNER_NAME) FROM RDB$RELATIONS WHERE (RDB$SYSTEM_FLAG = 0) AND (RDB$RELATION_NAME NOT IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS))",
120
121 /* I_STMT_TABLES */
122 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, (RDB$RELATION_NAME), 'BASE TABLE', 1, RDB$RELATION_NAME, TRIM(RDB$RELATION_NAME) AS short_name, TRIM(RDB$OWNER_NAME) || '.' || (TRIM(RDB$RELATION_NAME)) AS table_full_name, TRIM(RDB$OWNER_NAME) FROM RDB$RELATIONS WHERE (RDB$SYSTEM_FLAG = 0) AND (RDB$RELATION_NAME NOT IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS))",
123
124 /* I_STMT_TABLE_NAMED */
125 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, (RDB$RELATION_NAME), 'BASE TABLE', 1, RDB$RELATION_NAME, TRIM(RDB$RELATION_NAME) AS short_name, TRIM(RDB$OWNER_NAME) || '.' || (TRIM(RDB$RELATION_NAME)) AS table_full_name, TRIM(RDB$OWNER_NAME) FROM RDB$RELATIONS WHERE (RDB$SYSTEM_FLAG = 0) AND (RDB$RELATION_NAME NOT IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS)) AND (TRIM(RDB$RELATION_NAME)) = ##tblname::string",
126
127 /* I_STMT_VIEWS_ALL */
128 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, (RDB$RELATION_NAME), NULL, NULL, 0 FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG = 0 AND RDB$RELATION_NAME IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS)",
129
130 /* I_STMT_VIEWS */
131 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, (RDB$RELATION_NAME), NULL, NULL, 0 FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG = 0 AND RDB$RELATION_NAME IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS)",
132
133 /* I_STMT_VIEW_NAMED */
134 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, ((RDB$RELATION_NAME)), NULL, NULL, 0, 0 FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG = 0 AND RDB$RELATION_NAME IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS) AND (TRIM(RDB$RELATION_NAME)) = ##tblname::string",
135
136 /* I_STMT_COLUMNS_OF_TABLE */
137 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, (RF.RDB$RELATION_NAME), (RF.RDB$FIELD_NAME) AS column_name, RF.RDB$FIELD_POSITION AS ordinal_position, RF.RDB$DEFAULT_VALUE AS column_default, RF.RDB$NULL_FLAG AS is_nullable, LOWER(TRIM(T.RDB$TYPE_NAME)) AS data_type, NULL, 'gchararray', F.RDB$CHARACTER_LENGTH AS character_maximum_length, F.RDB$FIELD_LENGTH AS character_octet_length, F.RDB$FIELD_PRECISION AS numeric_precision, F.RDB$FIELD_SCALE AS numeric_scale, NULL, NULL AS CHAR_SET_CAT, NULL AS CHAR_SET_SCHEMA, NULL AS CHAR_SET_NAME, NULL AS COLLATION_CAT, NULL AS COLLATION_NAME, NULL, NULL AS Extra, RF.RDB$UPDATE_FLAG as is_updatable, '' as column_comment FROM RDB$RELATION_FIELDS AS RF INNER JOIN RDB$RELATIONS R ON R.RDB$RELATION_NAME = RF.RDB$RELATION_NAME INNER JOIN RDB$FIELDS AS F ON ((F.RDB$FIELD_NAME = RF.RDB$FIELD_SOURCE)) INNER JOIN RDB$TYPES AS T ON (((T.RDB$TYPE = F.RDB$FIELD_TYPE) AND (T.RDB$FIELD_NAME = 'RDB$FIELD_TYPE'))) WHERE RF.RDB$SYSTEM_FLAG = 0 AND R.RDB$RELATION_NAME NOT IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS) AND (RF.RDB$RELATION_NAME) = ##tblname::string ORDER BY RF.RDB$RELATION_NAME ASC, RDB$FIELD_POSITION ASC",
138
139 /* I_STMT_COLUMNS_ALL */
140 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS schema_name, (RF.RDB$RELATION_NAME), (RF.RDB$FIELD_NAME) AS column_name, RF.RDB$FIELD_POSITION AS ordinal_position, RF.RDB$DEFAULT_VALUE AS column_default, RF.RDB$NULL_FLAG AS is_nullable, LOWER(TRIM(T.RDB$TYPE_NAME)) AS data_type, NULL, 'gchararray', F.RDB$CHARACTER_LENGTH AS character_maximum_length, F.RDB$FIELD_LENGTH AS character_octet_length, F.RDB$FIELD_PRECISION AS numeric_precision, F.RDB$FIELD_SCALE AS numeric_scale, NULL, NULL AS CHAR_SET_CAT, NULL AS CHAR_SET_SCHEMA, NULL AS CHAR_SET_NAME, NULL AS COLLATION_CAT, NULL AS COLLATION_NAME, NULL, NULL AS Extra, RF.RDB$UPDATE_FLAG as is_updatable, '' as column_comment FROM RDB$RELATION_FIELDS AS RF INNER JOIN RDB$RELATIONS R ON R.RDB$RELATION_NAME = RF.RDB$RELATION_NAME INNER JOIN RDB$FIELDS AS F ON ((F.RDB$FIELD_NAME = RF.RDB$FIELD_SOURCE)) INNER JOIN RDB$TYPES AS T ON (((T.RDB$TYPE = F.RDB$FIELD_TYPE) AND (T.RDB$FIELD_NAME = 'RDB$FIELD_TYPE'))) WHERE RF.RDB$SYSTEM_FLAG = 0 AND R.RDB$RELATION_NAME NOT IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS) ORDER BY RF.RDB$RELATION_NAME ASC, RDB$FIELD_POSITION ASC",
141
142 /* I_STMT_CHARACTER_SETS */
143 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS character_set_schema, RDB$CHARACTER_SET_NAME, RDB$DEFAULT_COLLATE_NAME, RDB$DEFAULT_COLLATE_NAME, RDB$DEFAULT_COLLATE_NAME, NULL, RDB$CHARACTER_SET_NAME, RDB$CHARACTER_SET_NAME FROM RDB$CHARACTER_SETS WHERE RDB$CHARACTER_SET_NAME = ##char_set_name::string",
144
145 /* I_STMT_CHARACTER_SETS_ALL */
146 "SELECT " CATALOG_NAME " AS catalog_name, " SCHEMA_NAME " AS character_set_schema, RDB$CHARACTER_SET_NAME, RDB$DEFAULT_COLLATE_NAME, RDB$DEFAULT_COLLATE_NAME, RDB$DEFAULT_COLLATE_NAME, NULL, RDB$CHARACTER_SET_NAME, RDB$CHARACTER_SET_NAME FROM RDB$CHARACTER_SETS",
147
148 /* I_STMT_VIEWS_COLUMNS */
149 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", (RDB$RELATION_NAME), " CATALOG_NAME ", " SCHEMA_NAME ", (RDB$RELATION_NAME), RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$SYSTEM_FLAG = 0 AND RDB$RELATION_NAME IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS) AND TRIM(RDB$RELATION_NAME) = ##tblname::string",
150
151 /* I_STMT_VIEWS_COLUMNS_ALL */
152 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", (RDB$RELATION_NAME), " CATALOG_NAME ", " SCHEMA_NAME ", (RDB$RELATION_NAME), RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$SYSTEM_FLAG = 0 AND RDB$RELATION_NAME IN (SELECT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS)",
153
154 /* I_STMT_TABLES_CONSTRAINTS */
155 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", RDB$CONSTRAINT_NAME, " CATALOG_NAME ", " SCHEMA_NAME ", TRIM(RDB$RELATION_NAME), RDB$CONSTRAINT_TYPE, NULL, CASE WHEN RDB$DEFERRABLE = 'YES' THEN 1 ELSE 0 END, CASE WHEN RDB$INITIALLY_DEFERRED = 'YES' THEN 1 ELSE 0 END FROM RDB$RELATION_CONSTRAINTS WHERE TRIM(RDB$RELATION_NAME) = ##tblname::string",
156
157 /* I_STMT_TABLES_CONSTRAINTS_ALL */
158 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", RDB$CONSTRAINT_NAME, " CATALOG_NAME ", " SCHEMA_NAME ", RDB$RELATION_NAME, RDB$CONSTRAINT_TYPE, NULL, CASE WHEN RDB$DEFERRABLE = 'YES' THEN 1 ELSE 0 END, CASE WHEN RDB$INITIALLY_DEFERRED = 'YES' THEN 1 ELSE 0 END FROM RDB$RELATION_CONSTRAINTS",
159
160 /* I_STMT_TABLES_CONSTRAINTS_NAMED */
161 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", RDB$CONSTRAINT_NAME, " CATALOG_NAME ", " SCHEMA_NAME ", RDB$RELATION_NAME, RDB$CONSTRAINT_TYPE, NULL, CASE WHEN RDB$DEFERRABLE = 'YES' THEN 1 ELSE 0 END, CASE WHEN RDB$INITIALLY_DEFERRED = 'YES' THEN 1 ELSE 0 END FROM RDB$RELATION_CONSTRAINTS WHERE TRIM(RDB$RELATION_NAME) = ##tblname::string AND RDB$CONSTRAINT_NAME = ##constraint_name::string",
162
163 /* I_STMT_REF_CONSTRAINTS */
164 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", TRIM(R1.RDB$RELATION_NAME), C.RDB$CONSTRAINT_NAME, " CATALOG_NAME ", " SCHEMA_NAME ", TRIM(R2.RDB$RELATION_NAME), C.RDB$CONST_NAME_UQ, RDB$MATCH_OPTION, RDB$UPDATE_RULE, RDB$DELETE_RULE FROM RDB$REF_CONSTRAINTS C INNER JOIN RDB$RELATION_CONSTRAINTS R1 ON R1.RDB$CONSTRAINT_NAME = C.RDB$CONSTRAINT_NAME INNER JOIN RDB$RELATION_CONSTRAINTS R2 ON R2.RDB$CONSTRAINT_NAME = C.RDB$CONST_NAME_UQ WHERE TRIM(R1.RDB$RELATION_NAME) = ##tblname::string AND C.RDB$CONSTRAINT_NAME = ##constraint_name::string",
165
166 /* I_STMT_REF_CONSTRAINTS_ALL */
167 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", TRIM(R1.RDB$RELATION_NAME), C.RDB$CONSTRAINT_NAME, " CATALOG_NAME ", " SCHEMA_NAME ", TRIM(R2.RDB$RELATION_NAME), C.RDB$CONST_NAME_UQ, RDB$MATCH_OPTION, RDB$UPDATE_RULE, RDB$DELETE_RULE FROM RDB$REF_CONSTRAINTS C INNER JOIN RDB$RELATION_CONSTRAINTS R1 ON R1.RDB$CONSTRAINT_NAME = C.RDB$CONSTRAINT_NAME INNER JOIN RDB$RELATION_CONSTRAINTS R2 ON R2.RDB$CONSTRAINT_NAME = C.RDB$CONST_NAME_UQ",
168
169 /* I_STMT_KEY_COLUMN_USAGE */
170 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", TRIM(r.RDB$RELATION_NAME), r.rdb$constraint_name, i.rdb$field_name, i.RDB$FIELD_POSITION FROM rdb$relation_constraints r INNER JOIN rdb$index_segments i ON r.rdb$index_name = i.rdb$index_name WHERE (r.rdb$constraint_type='PRIMARY KEY') AND TRIM(r.RDB$RELATION_NAME) = ##tblname::string AND r.rdb$constraint_name = ##constraint_name::string",
171
172 /* I_STMT_KEY_COLUMN_USAGE_ALL */
173 "SELECT " CATALOG_NAME ", " SCHEMA_NAME ", TRIM(r.RDB$RELATION_NAME), r.rdb$constraint_name, i.rdb$field_name, i.RDB$FIELD_POSITION FROM rdb$relation_constraints r INNER JOIN rdb$index_segments i ON r.rdb$index_name = i.rdb$index_name WHERE (r.rdb$constraint_type='PRIMARY KEY') ORDER BY r.rdb$constraint_name, i.rdb$field_position",
174
175 /* I_STMT_TRIGGERS */
176 //"SELECT " CATALOG_NAME " AS trigger_catalog, trigger_schema, trigger_name, event_manipulation, " CATALOG_NAME " AS event_object_catalog, event_object_schema, event_object_table, action_statement, action_orientation, action_timing, NULL, trigger_name, trigger_name FROM INFORMATION_SCHEMA.triggers WHERE trigger_schema = ##schema::string AND trigger_name = ##name::string",
177
178 /* I_STMT_TRIGGERS_ALL */
179 //"SELECT " CATALOG_NAME " AS trigger_catalog, trigger_schema, trigger_name, event_manipulation, " CATALOG_NAME " AS event_object_catalog, event_object_schema, event_object_table, action_statement, action_orientation, action_timing, NULL, trigger_name, trigger_name FROM INFORMATION_SCHEMA.triggers",
180
181 /* I_STMT_ROUTINES_ALL */
182 //"SELECT " CATALOG_NAME " AS specific_catalog, routine_schema AS specific_schema, routine_name AS specific_name, " CATALOG_NAME " AS routine_catalog, routine_schema, routine_name, routine_type, dtd_identifier AS return_type, FALSE AS returns_set, 0 AS nb_args, routine_body, routine_definition, external_name, external_language, parameter_style, CASE is_deterministic WHEN 'YES' THEN TRUE ELSE FALSE END AS is_deterministic, sql_data_access, FALSE AS is_null_call, routine_comment, routine_name, routine_name, definer FROM INFORMATION_SCHEMA.routines",
183
184 /* I_STMT_ROUTINES */
185 //"SELECT " CATALOG_NAME " AS specific_catalog, routine_schema AS specific_schema, routine_name AS specific_name, " CATALOG_NAME " AS routine_catalog, routine_schema, routine_name, routine_type, dtd_identifier AS return_type, FALSE AS returns_set, 0 AS nb_args, routine_body, routine_definition, external_name, external_language, parameter_style, CASE is_deterministic WHEN 'YES' THEN TRUE ELSE FALSE END AS is_deterministic, sql_data_access, FALSE AS is_null_call, routine_comment, routine_name, routine_name, definer FROM INFORMATION_SCHEMA.routines WHERE routine_schema = ##schema::string",
186
187 /* I_STMT_ROUTINES_ONE */
188 //"SELECT " CATALOG_NAME " AS specific_catalog, routine_schema AS specific_schema, routine_name AS specific_name, " CATALOG_NAME " AS routine_catalog, routine_schema, routine_name, routine_type, dtd_identifier AS return_type, FALSE AS returns_set, 0 AS nb_args, routine_body, routine_definition, external_name, external_language, parameter_style, CASE is_deterministic WHEN 'YES' THEN TRUE ELSE FALSE END AS is_deterministic, sql_data_access, FALSE AS is_null_call, routine_comment, routine_name, routine_name, definer FROM INFORMATION_SCHEMA.routines WHERE routine_schema = ##schema::string AND routine_name = ##name::string",
189
190 /* I_STMT_ROUTINES_PAR_ALL */
191 //"SELECT " CATALOG_NAME " AS specific_catalog, routine_schema AS specific_schema, routine_name AS specific_name, " CATALOG_NAME " AS routine_catalog, routine_schema, routine_name, routine_type, dtd_identifier AS return_type, FALSE AS returns_set, 0 AS nb_args, routine_body, routine_definition, external_name, external_language, parameter_style, CASE is_deterministic WHEN 'YES' THEN TRUE ELSE FALSE END AS is_deterministic, sql_data_access, FALSE AS is_null_call, routine_comment, routine_name, routine_name, definer FROM INFORMATION_SCHEMA.routines",
192
193 /* I_STMT_ROUTINES_PAR */
194 //"SELECT " CATALOG_NAME " AS specific_catalog, routine_schema AS specific_schema, routine_name AS specific_name, " CATALOG_NAME " AS routine_catalog, routine_schema, routine_name, routine_type, dtd_identifier AS return_type, FALSE AS returns_set, 0 AS nb_args, routine_body, routine_definition, external_name, external_language, parameter_style, CASE is_deterministic WHEN 'YES' THEN TRUE ELSE FALSE END AS is_deterministic, sql_data_access, FALSE AS is_null_call, routine_comment, routine_name, routine_name, definer FROM INFORMATION_SCHEMA.routines WHERE routine_schema = ##schema::string AND routine_name = ##name::string",
195
196 /* I_STMT_INDEXES_ALL */
197 "SELECT DISTINCT " CATALOG_NAME ", " SCHEMA_NAME ", INDEX_NAME, " CATALOG_NAME ", TABLE_SCHEMA, TABLE_NAME, NOT NON_UNIQUE, NULL, INDEX_TYPE, NULL, NULL, COMMENT FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_NAME <> 'PRIMARY'",
198
199 /* I_STMT_INDEXES_TABLE */
200 "SELECT DISTINCT " CATALOG_NAME ", " SCHEMA_NAME ", INDEX_NAME, " CATALOG_NAME ", TABLE_SCHEMA, TABLE_NAME, NOT NON_UNIQUE, NULL, INDEX_TYPE, NULL, NULL, COMMENT FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_NAME <> 'PRIMARY' AND TABLE_SCHEMA = ##schema::string AND TABLE_NAME = ##name::string",
201
202 /* I_STMT_INDEXES_ONE */
203 "SELECT DISTINCT " CATALOG_NAME ", INDEX_SCHEMA, INDEX_NAME, " CATALOG_NAME ", TABLE_SCHEMA, TABLE_NAME, NOT NON_UNIQUE, NULL, INDEX_TYPE, NULL, NULL, COMMENT FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_NAME <> 'PRIMARY' AND TABLE_SCHEMA = ##schema::string AND TABLE_NAME = ##name::string AND INDEX_NAME = ##name2::string",
204
205 /* I_STMT_INDEX_COLUMNS_ALL */
206 "SELECT DISTINCT " CATALOG_NAME ", INDEX_SCHEMA, INDEX_NAME, " CATALOG_NAME ", TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_NAME, SEQ_IN_INDEX FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_NAME <> 'PRIMARY' ORDER BY INDEX_SCHEMA, INDEX_NAME, SEQ_IN_INDEX",
207
208 /* I_STMT_INDEX_COLUMNS_NAMED */
209 "SELECT DISTINCT " CATALOG_NAME ", INDEX_SCHEMA, INDEX_NAME, " CATALOG_NAME ", TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_NAME, SEQ_IN_INDEX FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_NAME <> 'PRIMARY' AND TABLE_SCHEMA = ##schema::string AND TABLE_NAME = ##name::string AND INDEX_NAME = ##name2::string ORDER BY INDEX_SCHEMA, INDEX_NAME, SEQ_IN_INDEX"
210
211 };
212
213
214 /*
215 * global static values, and
216 * predefined statements' GdaStatement, all initialized in _gda_postgres_provider_meta_init()
217 */
218 static GMutex init_mutex;
219 static GdaStatement **internal_stmt = NULL;
220 static GdaSqlParser *internal_parser = NULL;
221 static GdaSet *i_set = NULL;
222
223 /* TO_ADD: other static values */
224
225
226 /*
227 * Meta initialization
228 */
229 void
_gda_firebird_provider_meta_init(GdaServerProvider * provider)230 _gda_firebird_provider_meta_init (GdaServerProvider *provider)
231 {
232 g_mutex_lock (&init_mutex);
233
234 if (!internal_stmt) {
235 InternalStatementItem i;
236 internal_parser = gda_server_provider_internal_get_parser (provider);
237 internal_stmt = g_new0 (GdaStatement *, sizeof (internal_sql) / sizeof (gchar*));
238 for (i = I_STMT_CATALOG; i < sizeof (internal_sql) / sizeof (gchar*); i++) {
239 internal_stmt[i] = gda_sql_parser_parse_string (internal_parser, internal_sql[i], NULL, NULL);
240 if (!internal_stmt[i])
241 g_error ("Could not parse internal statement: %s\n", internal_sql[i]);
242 }
243
244 /* initialize static values here */
245 i_set = gda_set_new_inline (5, "tblname", G_TYPE_STRING, "",
246 "schema", G_TYPE_STRING, "",
247 "constraint_name", G_TYPE_STRING, "",
248 "field_name", G_TYPE_STRING, ""
249 , "char_set_name", G_TYPE_STRING, "");
250
251 /* initialize static values here */
252 /*
253 i_set = gda_set_new_inline (3, "name", G_TYPE_STRING, "",
254 "schema", G_TYPE_STRING, "",
255 "name2", G_TYPE_STRING, ""); */
256
257 }
258
259 g_mutex_unlock (&init_mutex);
260 }
261
262 gboolean
_gda_firebird_meta__info(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)263 _gda_firebird_meta__info (GdaServerProvider *prov, GdaConnection *cnc,
264 GdaMetaStore *store, GdaMetaContext *context, GError **error)
265 {
266 GdaDataModel *model;
267 gboolean retval;
268 //WHERE_AM_I;
269 model = gda_connection_statement_execute_select_full (cnc
270 , internal_stmt[I_STMT_CATALOG]
271 , NULL
272 , GDA_DATA_MODEL_ACCESS_RANDOM
273 , _col_types_information_schema_catalog_name
274 , error);
275 if (!model)
276 return FALSE;
277
278 gda_meta_store_set_identifiers_style (store, GDA_SQL_IDENTIFIERS_UPPER_CASE);
279 retval = gda_meta_store_modify_with_context (store, context, model, error);
280 g_object_unref (model);
281 if (!retval){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
282
283 return retval;
284 }
285
286 gboolean
_gda_firebird_meta__btypes(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)287 _gda_firebird_meta__btypes (GdaServerProvider *prov, GdaConnection *cnc,
288 GdaMetaStore *store, GdaMetaContext *context, GError **error)
289 {
290 //WHERE_AM_I;
291 typedef struct
292 {
293 gchar *tname;
294 gchar *gtype;
295 gchar *comments;
296 gchar *synonyms;
297 } BuiltinDataType;
298
299 BuiltinDataType data_types[] = {
300 { "CHAR"
301 , "gchararray"
302 , "A fixed-length string that is always right-padded with spaces to the specified length when stored. M represents the column length in characters. The range of M is 0 to 255. If M is omitted, the length is 1."
303 , "" }
304 , { "VARCHAR"
305 , "gchararray"
306 , "A variable-length string. M represents the maximum column length in characters. In MySQL 5.0, the range of M is 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in MySQL 5.0.3 and later. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. For example, utf8 characters can require up to three bytes per character, so a VARCHAR column that uses the utf8 character set can be declared to be a maximum of 21,844 characters."
307 , "" }
308
309 , { "DATE"
310 , "GDate"
311 , "A date. The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format, but allows assignment of values to DATE columns using either strings or numbers."
312 , "" }
313 , { "TIME"
314 , "GdaTime"
315 , "A time. The range is '-838:59:59' to '838:59:59'. MySQL displays TIME values in 'HH:MM:SS' format, but allows assignment of values to TIME columns using either strings or numbers."
316 , "" }
317
318 , { "TIMESTAMP"
319 , "GdaTimestamp"
320 , "A timestamp. The range is '1970-01-01 00:00:01' UTC to partway through the year 2038. TIMESTAMP values are stored as the number of seconds since the epoch ('1970-01-01 00:00:00' UTC). A TIMESTAMP cannot represent the value '1970-01-01 00:00:00' because that is equivalent to 0 seconds from the epoch and the value 0 is reserved for representing '0000-00-00 00:00:00', the \"zero\" TIMESTAMP value."
321 , "" }
322
323 , { "SMALLINT"
324 , "gint"
325 , "A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535."
326 , "" }
327 , { "INTEGER"
328 , "gint"
329 , "A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295."
330 , "INTEGER" }
331 , { "DECIMAL"
332 , "GdaNumeric"
333 , "A packed \"exact\" fixed-point number. M is the total number of digits (the precision) and D is the number of digits after the decimal point (the scale). The decimal point and (for negative numbers) the \"-\" sign are not counted in M. If D is 0, values have no decimal point or fractional part. The maximum number of digits (M) for DECIMAL is 65 (64 from 5.0.3 to 5.0.5). The maximum number of supported decimals (D) is 30. If D is omitted, the default is 0. If M is omitted, the default is 10."
334 , "DEC" }
335 , { "DOUBLE"
336 , "gdouble"
337 , "A normal-size (double-precision) floating-point number. Allowable values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308. These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system."
338 , "DOUBLE PRECISION" }
339
340 , { "FLOAT"
341 , "gfloat"
342 , "A small (single-precision) floating-point number. Allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system."
343 , "" }
344 , { "NUMERIC"
345 , "GdaNumeric"
346 , "A BLOB column with a maximum length of 4,294,967,295 or 4GB (232 - 1) bytes. The effective maximum length of LONGBLOB columns depends on the configured maximum packet size in the client/server protocol and available memory. Each LONGBLOB value is stored using a four-byte length prefix that indicates the number of bytes in the value."
347 , "" }
348 , { "INT64"
349 , "gint64"
350 , "A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615."
351 , "" }
352 , { "BIGINT"
353 , "gint64"
354 , "A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615."
355 , "" }
356
357 , { "BLOB"
358 , "GdaBinary"
359 , "A BLOB column with a maximum length of 65,535 (216 - 1) bytes. Each BLOB value is stored using a two-byte length prefix that indicates the number of bytes in the value."
360 , "" }
361
362 };
363
364 GdaDataModel *model;
365 gboolean retval = TRUE;
366
367 model = gda_meta_store_create_modify_data_model (store, context->table_name);
368 if (model == NULL)
369 retval = FALSE;
370 else {
371 gsize i;
372 for (i = 0; i < sizeof(data_types) / sizeof(BuiltinDataType); ++i) {
373 BuiltinDataType *data_type = &(data_types[i]);
374 GList *values = NULL;
375 GValue *tmp_value = NULL;
376
377 g_value_set_string (tmp_value = gda_value_new (G_TYPE_STRING), data_type->tname);
378 values = g_list_append (values, tmp_value);
379
380 g_value_set_string (tmp_value = gda_value_new (G_TYPE_STRING), data_type->tname);
381 values = g_list_append (values, tmp_value);
382
383 g_value_set_string (tmp_value = gda_value_new (G_TYPE_STRING), data_type->gtype);
384 values = g_list_append (values, tmp_value);
385
386 g_value_set_string (tmp_value = gda_value_new (G_TYPE_STRING), data_type->comments);
387 values = g_list_append (values, tmp_value);
388
389 if (data_type->synonyms && *(data_type->synonyms))
390 g_value_set_string (tmp_value = gda_value_new (G_TYPE_STRING), data_type->synonyms);
391 else
392 tmp_value = gda_value_new_null ();
393 values = g_list_append (values, tmp_value);
394
395 g_value_set_boolean (tmp_value = gda_value_new (G_TYPE_BOOLEAN), FALSE);
396 values = g_list_append (values, tmp_value);
397
398 if (gda_data_model_append_values (model, values, NULL) < 0) {
399 retval = FALSE;
400 break;
401 }
402
403 g_list_foreach (values, (GFunc) gda_value_free, NULL);
404 g_list_free (values);
405 }
406
407 if (retval) {
408 //retval = gda_meta_store_modify (store, context->table_name, model, NULL, error, NULL);
409 retval = gda_meta_store_modify_with_context (store, context, model, error);
410 }
411 g_object_unref (G_OBJECT(model));
412 }
413 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
414
415 return retval;
416 }
417
418 gboolean
_gda_firebird_meta__udt(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)419 _gda_firebird_meta__udt (GdaServerProvider *prov, GdaConnection *cnc,
420 GdaMetaStore *store, GdaMetaContext *context, GError **error)
421 {
422 //WHERE_AM_I;
423
424 //TO_IMPLEMENT;
425 return TRUE;
426 }
427
428 gboolean
_gda_firebird_meta_udt(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * udt_catalog,const GValue * udt_schema)429 _gda_firebird_meta_udt (GdaServerProvider *prov, GdaConnection *cnc,
430 GdaMetaStore *store, GdaMetaContext *context, GError **error,
431 const GValue *udt_catalog, const GValue *udt_schema)
432 {
433 //GdaDataModel *model;
434 gboolean retval = TRUE;
435
436 //WHERE_AM_I;
437
438 /* set internal holder's values from the arguments */
439 gda_holder_set_value (gda_set_get_holder (i_set, "cat"), udt_catalog, error);
440 gda_holder_set_value (gda_set_get_holder (i_set, "schema"), udt_schema, error);
441
442 //TO_IMPLEMENT;
443 /* fill in @model, with something like:
444 * model = gda_connection_statement_execute_select (cnc, internal_stmt[I_STMT_UDT], i_set, error);
445 *
446 if (!model)
447 return FALSE;
448 retval = gda_meta_store_modify_with_context (store, context, model, error);
449 g_object_unref (model);
450 */
451 return retval;
452 }
453
454
455 gboolean
_gda_firebird_meta__udt_cols(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)456 _gda_firebird_meta__udt_cols (GdaServerProvider *prov, GdaConnection *cnc,
457 GdaMetaStore *store, GdaMetaContext *context, GError **error)
458 {
459 //WHERE_AM_I;
460
461 //TO_IMPLEMENT;
462 return TRUE;
463 }
464
465 gboolean
_gda_firebird_meta_udt_cols(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * udt_catalog,const GValue * udt_schema,const GValue * udt_name)466 _gda_firebird_meta_udt_cols (GdaServerProvider *prov, GdaConnection *cnc,
467 GdaMetaStore *store, GdaMetaContext *context, GError **error,
468 const GValue *udt_catalog, const GValue *udt_schema, const GValue *udt_name)
469 {
470 //WHERE_AM_I;
471
472 //TO_IMPLEMENT;
473 return TRUE;
474 }
475
476 gboolean
_gda_firebird_meta__enums(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)477 _gda_firebird_meta__enums (GdaServerProvider *prov, GdaConnection *cnc,
478 GdaMetaStore *store, GdaMetaContext *context, GError **error)
479 {
480 //WHERE_AM_I;
481
482 //TO_IMPLEMENT;
483 return TRUE;
484 }
485
486 gboolean
_gda_firebird_meta_enums(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * udt_catalog,const GValue * udt_schema,const GValue * udt_name)487 _gda_firebird_meta_enums (GdaServerProvider *prov, GdaConnection *cnc,
488 GdaMetaStore *store, GdaMetaContext *context, GError **error,
489 const GValue *udt_catalog, const GValue *udt_schema, const GValue *udt_name)
490 {
491 //WHERE_AM_I;
492
493 //TO_IMPLEMENT;
494 return TRUE;
495 }
496
497
498 gboolean
_gda_firebird_meta__domains(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)499 _gda_firebird_meta__domains (GdaServerProvider *prov, GdaConnection *cnc,
500 GdaMetaStore *store, GdaMetaContext *context, GError **error)
501 {
502 //WHERE_AM_I;
503
504 //TO_IMPLEMENT;
505 return TRUE;
506 }
507
508 gboolean
_gda_firebird_meta_domains(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * domain_catalog,const GValue * domain_schema)509 _gda_firebird_meta_domains (GdaServerProvider *prov, GdaConnection *cnc,
510 GdaMetaStore *store, GdaMetaContext *context, GError **error,
511 const GValue *domain_catalog, const GValue *domain_schema)
512 {
513 //WHERE_AM_I;
514
515 //TO_IMPLEMENT;
516 return TRUE;
517 }
518
519 gboolean
_gda_firebird_meta__constraints_dom(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)520 _gda_firebird_meta__constraints_dom (GdaServerProvider *prov, GdaConnection *cnc,
521 GdaMetaStore *store, GdaMetaContext *context, GError **error)
522 {
523 //WHERE_AM_I;
524
525 //TO_IMPLEMENT;
526 return TRUE;
527 }
528
529 gboolean
_gda_firebird_meta_constraints_dom(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * domain_catalog,const GValue * domain_schema,const GValue * domain_name)530 _gda_firebird_meta_constraints_dom (GdaServerProvider *prov, GdaConnection *cnc,
531 GdaMetaStore *store, GdaMetaContext *context, GError **error,
532 const GValue *domain_catalog, const GValue *domain_schema,
533 const GValue *domain_name)
534 {
535 //WHERE_AM_I;
536
537 //TO_IMPLEMENT;
538 return TRUE;
539 }
540
541 gboolean
_gda_firebird_meta__el_types(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)542 _gda_firebird_meta__el_types (GdaServerProvider *prov, GdaConnection *cnc,
543 GdaMetaStore *store, GdaMetaContext *context, GError **error)
544 {
545 //WHERE_AM_I;
546
547 //TO_IMPLEMENT;
548 return TRUE;
549 }
550
551 gboolean
_gda_firebird_meta_el_types(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * specific_name)552 _gda_firebird_meta_el_types (GdaServerProvider *prov, GdaConnection *cnc,
553 GdaMetaStore *store, GdaMetaContext *context, GError **error,
554 const GValue *specific_name)
555 {
556 //WHERE_AM_I;
557
558 //TO_IMPLEMENT;
559 return TRUE;
560 }
561
562 gboolean
_gda_firebird_meta__collations(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)563 _gda_firebird_meta__collations (GdaServerProvider *prov, GdaConnection *cnc,
564 GdaMetaStore *store, GdaMetaContext *context, GError **error)
565 {
566 //WHERE_AM_I;
567
568 //TO_IMPLEMENT;
569 return TRUE;
570 }
571
572 gboolean
_gda_firebird_meta_collations(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * collation_catalog,const GValue * collation_schema,const GValue * collation_name_n)573 _gda_firebird_meta_collations (GdaServerProvider *prov, GdaConnection *cnc,
574 GdaMetaStore *store, GdaMetaContext *context, GError **error,
575 const GValue *collation_catalog, const GValue *collation_schema,
576 const GValue *collation_name_n)
577 {
578 //WHERE_AM_I;
579
580 //TO_IMPLEMENT;
581 return TRUE;
582 }
583
584 gboolean
_gda_firebird_meta__character_sets(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)585 _gda_firebird_meta__character_sets (GdaServerProvider *prov, GdaConnection *cnc,
586 GdaMetaStore *store, GdaMetaContext *context, GError **error)
587 {
588 GdaDataModel *model;
589 gboolean retval;
590 //WHERE_AM_I;
591 model = gda_connection_statement_execute_select_full (cnc,
592 internal_stmt[I_STMT_CHARACTER_SETS_ALL],
593 NULL,
594 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
595 _col_types_character_sets,
596 error);
597 if (model == NULL)
598 retval = FALSE;
599 else {
600 retval = gda_meta_store_modify_with_context (store, context, model, error);
601 g_object_unref (G_OBJECT(model));
602 }
603 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
604
605 return retval;
606 }
607
608 gboolean
_gda_firebird_meta_character_sets(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * chset_catalog,const GValue * chset_schema,const GValue * chset_name_n)609 _gda_firebird_meta_character_sets (GdaServerProvider *prov, GdaConnection *cnc,
610 GdaMetaStore *store, GdaMetaContext *context, GError **error,
611 const GValue *chset_catalog, const GValue *chset_schema,
612 const GValue *chset_name_n)
613 {
614 GdaDataModel *model;
615 gboolean retval;
616 //WHERE_AM_I;
617
618 if (!gda_holder_set_value (gda_set_get_holder (i_set, "char_set_name"), chset_name_n, error))
619 return FALSE;
620
621 model = gda_connection_statement_execute_select_full (cnc,
622 internal_stmt[I_STMT_CHARACTER_SETS],
623 i_set,
624 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
625 _col_types_character_sets,
626 error);
627 if (model == NULL)
628 retval = FALSE;
629 else {
630 retval = gda_meta_store_modify_with_context (store, context, model, error);
631 g_object_unref (G_OBJECT(model));
632 }
633 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
634
635 return retval;
636
637 }
638
639 gboolean
_gda_firebird_meta__schemata(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)640 _gda_firebird_meta__schemata (GdaServerProvider *prov, GdaConnection *cnc,
641 GdaMetaStore *store, GdaMetaContext *context, GError **error)
642 {
643 GdaDataModel *model;
644 gboolean retval;
645 //WHERE_AM_I;
646 model = gda_connection_statement_execute_select_full (cnc,
647 internal_stmt[I_STMT_SCHEMAS_ALL],
648 NULL,
649 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
650 _col_types_schemata, error);
651 if (model == NULL)
652 retval = FALSE;
653 else {
654 retval = gda_meta_store_modify_with_context (store, context, model, error);
655 g_object_unref (G_OBJECT(model));
656 }
657 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
658
659 return retval;
660 }
661
662 gboolean
_gda_firebird_meta_schemata(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * catalog_name,const GValue * schema_name_n)663 _gda_firebird_meta_schemata (GdaServerProvider *prov, GdaConnection *cnc,
664 GdaMetaStore *store, GdaMetaContext *context, GError **error,
665 const GValue *catalog_name, const GValue *schema_name_n)
666 {
667 GdaDataModel *model;
668 gboolean retval;
669 //WHERE_AM_I;
670 if (!schema_name_n) {
671 model = gda_connection_statement_execute_select_full (cnc,
672 internal_stmt[I_STMT_SCHEMAS],
673 i_set,
674 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
675 _col_types_schemata,
676 error);
677 if (model == NULL)
678 retval = FALSE;
679 else {
680 retval = gda_meta_store_modify (store, context->table_name, model, NULL, error, NULL);
681 g_object_unref (G_OBJECT(model));
682 }
683 } else {
684 model = gda_connection_statement_execute_select_full (cnc,
685 internal_stmt[I_STMT_SCHEMA_NAMED],
686 i_set,
687 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
688 _col_types_schemata,
689 error);
690 if (model == NULL)
691 retval = FALSE;
692 else {
693 retval = gda_meta_store_modify (store, context->table_name, model,
694 "schema_name=##name::string",
695 error,
696 "schema", schema_name_n, NULL);
697 g_object_unref (G_OBJECT(model));
698 }
699 }
700 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
701 return retval;
702 }
703
704 gboolean
_gda_firebird_meta__tables_views(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)705 _gda_firebird_meta__tables_views (GdaServerProvider *prov, GdaConnection *cnc,
706 GdaMetaStore *store, GdaMetaContext *context, GError **error)
707 {
708 GdaDataModel *model_tables, *model_views;
709 gboolean retval;
710 //WHERE_AM_I;
711 /* Copy contents, just because we need to modify @context->table_name */
712 GdaMetaContext copy = *context;
713
714 model_tables = gda_connection_statement_execute_select_full (cnc,
715 internal_stmt[I_STMT_TABLES_ALL],
716 NULL,
717 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
718 _col_types_tables, error);
719 if (model_tables == NULL)
720 retval = FALSE;
721 else {
722 copy.table_name = "_tables";
723 retval = gda_meta_store_modify_with_context (store, ©, model_tables, error);
724 g_object_unref (G_OBJECT(model_tables));
725 if (retval == FALSE){g_print("\n\n***ERROR (_tables): \n\n");}
726 }
727
728 model_views = gda_connection_statement_execute_select_full (cnc,
729 internal_stmt[I_STMT_VIEWS_ALL],
730 NULL,
731 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
732 _col_types_views, error);
733 if (model_views == NULL)
734 retval = FALSE;
735 else {
736 copy.table_name = "_views";
737 retval = gda_meta_store_modify_with_context (store, ©, model_views, error);
738 g_object_unref (G_OBJECT(model_views));
739 }
740 if (retval == FALSE){g_print("\n\n***ERROR (_views): \n\n");}
741 return retval;
742 }
743
744 gboolean
_gda_firebird_meta_tables_views(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * table_catalog,const GValue * table_schema,const GValue * table_name_n)745 _gda_firebird_meta_tables_views (GdaServerProvider *prov, GdaConnection *cnc,
746 GdaMetaStore *store, GdaMetaContext *context, GError **error,
747 const GValue *table_catalog, const GValue *table_schema,
748 const GValue *table_name_n)
749 {
750 GdaDataModel *model_tables, *model_views;
751 gboolean retval;
752 //WHERE_AM_I;
753
754 FirebirdConnectionData *cdata;
755 cdata = (FirebirdConnectionData*) gda_connection_internal_get_provider_data_error (cnc, error);
756 if (!cdata)
757 return FALSE;
758
759 /* Copy contents, just because we need to modify @context->table_name */
760 GdaMetaContext copy = *context;
761
762 if (!table_name_n) {
763 model_tables = gda_connection_statement_execute_select_full (cnc,
764 internal_stmt[I_STMT_TABLES],
765 NULL,
766 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
767 _col_types_tables,
768 error);
769 if (model_tables == NULL)
770 retval = FALSE;
771 else {
772 copy.table_name = "_tables";
773 retval = gda_meta_store_modify_with_context (store, ©, model_tables, error);
774 g_object_unref (G_OBJECT (model_tables));
775 }
776
777 if (!retval)
778 return FALSE;
779
780 model_views = gda_connection_statement_execute_select_full (cnc,
781 internal_stmt[I_STMT_VIEWS],
782 NULL,
783 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
784 _col_types_views,
785 error);
786 if (model_views == NULL)
787 retval = FALSE;
788 else {
789 copy.table_name = "_views";
790 retval = gda_meta_store_modify_with_context (store, ©, model_views, error);
791 g_object_unref (G_OBJECT (model_views));
792 }
793
794 }
795 else {
796 g_print("got to the named portion\n");
797 if (!gda_holder_set_value (gda_set_get_holder (i_set, "tblname"), table_name_n, error))
798 return FALSE;
799
800 model_tables = gda_connection_statement_execute_select_full (cnc,
801 internal_stmt[I_STMT_TABLE_NAMED],
802 i_set,
803 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
804 _col_types_tables,
805 error);
806 if (model_tables == NULL)
807 retval = FALSE;
808 else {
809 copy.table_name = "_tables";
810 retval = gda_meta_store_modify_with_context (store, ©, model_tables, error);
811 g_object_unref (G_OBJECT(model_tables));
812 }
813
814 if (!retval)
815 return FALSE;
816
817 model_views = gda_connection_statement_execute_select_full (cnc,
818 internal_stmt[I_STMT_VIEW_NAMED],
819 i_set,
820 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
821 _col_types_views,
822 error);
823 if (model_views == NULL)
824 retval = FALSE;
825 else {
826 copy.table_name = "_views";
827 retval = gda_meta_store_modify_with_context (store, ©, model_views, error);
828 g_object_unref (G_OBJECT(model_views));
829 }
830 }
831 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
832
833 return retval;
834 }
835
836 /*
837 * map_mysql_type_to_gda:
838 * @value: a #GValue string.
839 *
840 * It maps a mysql type to a gda type. This means that when a
841 * mysql type is given, it will return its mapped gda type.
842 *
843 * Returns a newly created GValue string.
844 */
845 static inline GValue *
map_firebird_type_to_gda(const GValue * value)846 map_firebird_type_to_gda (const GValue *value)
847 {
848 const gchar *string = g_value_get_string (value);
849 GValue *newvalue;
850 const gchar *newstring;
851
852 if (strcmp (string, "blob") == 0)
853 newstring = "GdaBinary";
854 else
855 if (strcmp (string, "int64") == 0)
856 newstring = "gint64";
857 else
858 if (strcmp (string, "char") == 0)
859 newstring = "gchar";
860 else
861 if (strcmp (string, "date") == 0)
862 newstring = "GDate";
863 else
864 if (strcmp (string, "decimal") == 0)
865 newstring = "GdaNumeric";
866 else
867 if (strcmp (string, "numeric") == 0)
868 newstring = "GdaNumeric";
869 else
870 if (strcmp (string, "double") == 0)
871 newstring = "gdouble";
872 else
873 if (strcmp (string, "float") == 0)
874 newstring = "gfloat";
875 else
876 if (strcmp (string, "int") == 0)
877 newstring = "gint";
878 else
879 if (strcmp (string, "long") == 0)
880 newstring = "glong";
881 else
882 if (strcmp (string, "short") == 0)
883 newstring = "gint";
884 else
885 if (strcmp (string, "text") == 0)
886 newstring = "gchararray";
887 else
888 if (strcmp (string, "smallint") == 0)
889 newstring = "gint";
890 else
891 if (strcmp (string, "time") == 0)
892 newstring = "GdaTime";
893 else
894 if (strcmp (string, "timestamp") == 0)
895 newstring = "GdaTimestamp";
896 else
897 if (strcmp (string, "varchar") == 0)
898 newstring = "gchararray";
899 else
900 if (strcmp (string, "varying") == 0)
901 newstring = "gchararray";
902 else
903 {
904 g_print("Please report this bug. The following data-type is not supported in the library. %s\n", string);
905 newstring = "";
906 }
907 g_value_set_string (newvalue = gda_value_new (G_TYPE_STRING), newstring);
908
909 return newvalue;
910 }
911
912 gboolean
_gda_firebird_meta__columns(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)913 _gda_firebird_meta__columns (GdaServerProvider *prov, GdaConnection *cnc,
914 GdaMetaStore *store, GdaMetaContext *context, GError **error)
915 {
916 GdaDataModel *model, *proxy;
917 gboolean retval = TRUE;
918
919 //WHERE_AM_I;
920
921 /* Use a prepared statement for the "base" model. */
922 model = gda_connection_statement_execute_select_full (cnc,
923 internal_stmt[I_STMT_COLUMNS_ALL], NULL,
924 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
925 _col_types_columns, error);
926 if (model == NULL)
927 retval = FALSE;
928 else {
929 proxy = (GdaDataModel *) gda_data_proxy_new (model);
930 gda_data_proxy_set_sample_size ((GdaDataProxy *) proxy, 0);
931 gint n_rows = gda_data_model_get_n_rows (model);
932 gint i;
933 for (i = 0; i < n_rows; ++i) {
934 const GValue *value = gda_data_model_get_value_at (model, 7, i, error);
935 if (!value) {
936 retval = FALSE;
937 break;
938 }
939
940 GValue *newvalue = map_firebird_type_to_gda (value);
941
942 retval = gda_data_model_set_value_at (GDA_DATA_MODEL(proxy), 9, i, newvalue, error);
943 gda_value_free (newvalue);
944 if (!retval)
945 break;
946 }
947
948 if (retval) {
949 retval = gda_meta_store_modify_with_context (store, context, proxy, error);
950 if (!retval)
951 g_print("ERROR MESSAGE: \n\n%s\n\n", (*error)->message);
952 }
953
954 g_object_unref (G_OBJECT(proxy));
955 g_object_unref (G_OBJECT(model));
956 }
957 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
958
959 return retval;
960 }
961
962 gboolean
_gda_firebird_meta_columns(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * table_catalog,const GValue * table_schema,const GValue * table_name)963 _gda_firebird_meta_columns (GdaServerProvider *prov, GdaConnection *cnc,
964 GdaMetaStore *store, GdaMetaContext *context, GError **error,
965 const GValue *table_catalog, const GValue *table_schema,
966 const GValue *table_name)
967 {
968 GdaDataModel *model, *proxy;
969 gboolean retval = TRUE;
970 //WHERE_AM_I;
971 /* Use a prepared statement for the "base" model. */
972 const gchar *str;
973 str = g_value_get_string (table_name);
974 g_print("get columns for: %s\n", str);
975 if (!gda_holder_set_value (gda_set_get_holder (i_set, "tblname"), table_name, error))
976 return FALSE;
977
978 model = gda_connection_statement_execute_select_full (cnc,
979 internal_stmt[I_STMT_COLUMNS_OF_TABLE],
980 i_set,
981 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
982 _col_types_columns, error);
983 if (model == NULL)
984 retval = FALSE;
985 else {
986 proxy = (GdaDataModel *) gda_data_proxy_new (model);
987 gda_data_proxy_set_sample_size ((GdaDataProxy *) proxy, 0);
988 gint n_rows = gda_data_model_get_n_rows (model);
989 gint i;
990 for (i = 0; i < n_rows; ++i) {
991 const GValue *value = gda_data_model_get_value_at (model, 7, i, error);
992 if (!value) {
993 retval = FALSE;
994 break;
995 }
996
997 GValue *newvalue = map_firebird_type_to_gda (value);
998
999 retval = gda_data_model_set_value_at (GDA_DATA_MODEL(proxy), 9, i, newvalue, error);
1000 gda_value_free (newvalue);
1001 if (!retval)
1002 break;
1003 }
1004
1005 if (retval) {
1006 retval = gda_meta_store_modify (store, context->table_name, proxy,
1007 NULL,
1008 error,
1009 NULL);
1010
1011 /*
1012 retval = gda_meta_store_modify (store, context->table_name, proxy,
1013 "RF.RDB$RELATION_NAME = ##tblname::string",
1014 error,
1015 "tblname", table_name, NULL);
1016 */
1017 }
1018 g_object_unref (G_OBJECT(proxy));
1019 g_object_unref (G_OBJECT(model));
1020 }
1021 if (retval == FALSE){g_print("\n\n***ERROR (%s): %s\n\n", __FUNCTION__, (*error)->message);}
1022
1023 return retval;
1024 }
1025
1026 gboolean
_gda_firebird_meta__view_cols(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1027 _gda_firebird_meta__view_cols (GdaServerProvider *prov, GdaConnection *cnc,
1028 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1029 {
1030 //WHERE_AM_I;
1031
1032 GdaDataModel *model;
1033 gboolean retval;
1034
1035 model = gda_connection_statement_execute_select_full (cnc,
1036 internal_stmt[I_STMT_VIEWS_COLUMNS_ALL],
1037 NULL,
1038 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1039 _col_types_view_column_usage, error);
1040 if (model == NULL)
1041 retval = FALSE;
1042 else {
1043 retval = gda_meta_store_modify_with_context (store, context, model, error);
1044 g_object_unref (G_OBJECT(model));
1045 }
1046 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1047
1048 return retval;
1049 }
1050
1051 gboolean
_gda_firebird_meta_view_cols(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * view_catalog,const GValue * view_schema,const GValue * view_name)1052 _gda_firebird_meta_view_cols (GdaServerProvider *prov, GdaConnection *cnc,
1053 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1054 const GValue *view_catalog, const GValue *view_schema,
1055 const GValue *view_name)
1056 {
1057 GdaDataModel *model;
1058 gboolean retval;
1059 //WHERE_AM_I;
1060
1061 if (!gda_holder_set_value (gda_set_get_holder (i_set, "tblname"), view_name, error))
1062 return FALSE;
1063 model = gda_connection_statement_execute_select_full (cnc,
1064 internal_stmt[I_STMT_VIEWS_COLUMNS],
1065 i_set,
1066 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1067 _col_types_view_column_usage, error);
1068 if (model == NULL)
1069 retval = FALSE;
1070 else {
1071 retval = gda_meta_store_modify_with_context (store, context, model, error);
1072 g_object_unref (G_OBJECT(model));
1073 }
1074 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1075
1076 return retval;
1077 }
1078
1079 gboolean
_gda_firebird_meta__constraints_tab(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1080 _gda_firebird_meta__constraints_tab (GdaServerProvider *prov, GdaConnection *cnc,
1081 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1082 {
1083 //WHERE_AM_I;
1084 GdaDataModel *model;
1085 gboolean retval;
1086
1087 model = gda_connection_statement_execute_select_full (cnc,
1088 internal_stmt[I_STMT_TABLES_CONSTRAINTS_ALL],
1089 NULL,
1090 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1091 _col_types_table_constraints, error);
1092 if (model == NULL)
1093 retval = FALSE;
1094 else {
1095 retval = gda_meta_store_modify_with_context (store, context, model, error);
1096 g_object_unref (G_OBJECT(model));
1097 }
1098 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1099
1100 return retval;
1101
1102 }
1103
1104 gboolean
_gda_firebird_meta_constraints_tab(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * table_catalog,const GValue * table_schema,const GValue * table_name,const GValue * constraint_name_n)1105 _gda_firebird_meta_constraints_tab (GdaServerProvider *prov, GdaConnection *cnc,
1106 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1107 const GValue *table_catalog, const GValue *table_schema,
1108 const GValue *table_name, const GValue *constraint_name_n)
1109 {
1110 //WHERE_AM_I;
1111 return TRUE;
1112 GdaDataModel *model;
1113 gboolean retval;
1114
1115 if (!gda_holder_set_value (gda_set_get_holder (i_set, "tblname"), table_name, error))
1116 return FALSE;
1117 if (!constraint_name_n) {
1118 model = gda_connection_statement_execute_select_full (cnc,
1119 internal_stmt[I_STMT_TABLES_CONSTRAINTS],
1120 i_set,
1121 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1122 _col_types_table_constraints, error);
1123 if (model == NULL)
1124 retval = FALSE;
1125 else {
1126 retval = gda_meta_store_modify (store, context->table_name, model,
1127 "TRIM(RDB$RELATION_NAME) = ##tblname::string",
1128 error,
1129 "tblname", table_name, NULL);
1130 g_object_unref (G_OBJECT(model));
1131 }
1132 } else {
1133 if (!gda_holder_set_value (gda_set_get_holder (i_set, "constraint_name"), constraint_name_n, error))
1134 return FALSE;
1135 model = gda_connection_statement_execute_select_full (cnc,
1136 internal_stmt[I_STMT_TABLES_CONSTRAINTS_NAMED],
1137 i_set,
1138 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1139 _col_types_table_constraints, error);
1140 if (model == NULL)
1141 retval = FALSE;
1142 else {
1143 retval = gda_meta_store_modify (store, context->table_name, model,
1144 "TRIM(RDB$RELATION_NAME) = ##tblname::string AND RDB$CONSTRAINT_NAME = ##constraint_name::string",
1145 error,
1146 "tblname", table_name, "constraint_name", constraint_name_n, NULL);
1147 g_object_unref (G_OBJECT(model));
1148 }
1149 }
1150 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1151
1152 return retval;
1153 }
1154
1155 gboolean
_gda_firebird_meta__constraints_ref(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1156 _gda_firebird_meta__constraints_ref (GdaServerProvider *prov, GdaConnection *cnc,
1157 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1158 {
1159 //WHERE_AM_I;
1160 GdaDataModel *model;
1161 gboolean retval;
1162 model = gda_connection_statement_execute_select_full (cnc,
1163 internal_stmt[I_STMT_REF_CONSTRAINTS_ALL],
1164 NULL,
1165 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1166 _col_types_referential_constraints, error);
1167 if (model == NULL)
1168 retval = FALSE;
1169 else {
1170 retval = gda_meta_store_modify_with_context (store, context, model, error);
1171 g_object_unref (G_OBJECT(model));
1172 }
1173 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1174 return retval;
1175 }
1176
1177 gboolean
_gda_firebird_meta_constraints_ref(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * table_catalog,const GValue * table_schema,const GValue * table_name,const GValue * constraint_name)1178 _gda_firebird_meta_constraints_ref (GdaServerProvider *prov, GdaConnection *cnc,
1179 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1180 const GValue *table_catalog, const GValue *table_schema, const GValue *table_name,
1181 const GValue *constraint_name)
1182 {
1183 //WHERE_AM_I;
1184 GdaDataModel *model;
1185 gboolean retval = TRUE;
1186
1187 /* Use a prepared statement for the "base" model. */
1188
1189 if (!gda_holder_set_value (gda_set_get_holder (i_set, "tblname"), table_name, error))
1190 return FALSE;
1191 if (!gda_holder_set_value (gda_set_get_holder (i_set, "constraint_name"), constraint_name, error))
1192 return FALSE;
1193
1194 model = gda_connection_statement_execute_select_full (cnc,
1195 internal_stmt[I_STMT_REF_CONSTRAINTS],
1196 i_set,
1197 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1198 _col_types_referential_constraints, error);
1199 if (model == NULL)
1200 retval = FALSE;
1201 else {
1202 retval = gda_meta_store_modify (store, context->table_name, model,
1203 "TRIM(R1.RDB$RELATION_NAME) = ##tblname::string AND C.RDB$CONSTRAINT_NAME = ##constraint_name::string",
1204 error,
1205 "tblname", table_name, "constraint_name", constraint_name, NULL);
1206 g_object_unref (G_OBJECT(model));
1207
1208 }
1209 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1210 return retval;
1211 }
1212
1213 gboolean
_gda_firebird_meta__key_columns(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1214 _gda_firebird_meta__key_columns (GdaServerProvider *prov, GdaConnection *cnc,
1215 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1216 {
1217 //WHERE_AM_I;
1218 GdaDataModel *model;
1219 gboolean retval = TRUE;
1220
1221 model = gda_connection_statement_execute_select_full (cnc,
1222 internal_stmt[I_STMT_KEY_COLUMN_USAGE_ALL],
1223 NULL,
1224 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1225 _col_types_key_column_usage, error);
1226 if (model == NULL)
1227 retval = FALSE;
1228 else {
1229 retval = gda_meta_store_modify_with_context (store, context, model, error);
1230 g_object_unref (G_OBJECT(model));
1231 }
1232 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1233 return retval;
1234 }
1235
1236 gboolean
_gda_firebird_meta_key_columns(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * table_catalog,const GValue * table_schema,const GValue * table_name,const GValue * constraint_name)1237 _gda_firebird_meta_key_columns (GdaServerProvider *prov, GdaConnection *cnc,
1238 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1239 const GValue *table_catalog, const GValue *table_schema,
1240 const GValue *table_name, const GValue *constraint_name)
1241 {
1242 //WHERE_AM_I;
1243 GdaDataModel *model;
1244 gboolean retval = TRUE;
1245
1246 /* Use a prepared statement for the "base" model. */
1247
1248 if (!gda_holder_set_value (gda_set_get_holder (i_set, "tblname"), table_name, error))
1249 return FALSE;
1250 if (!gda_holder_set_value (gda_set_get_holder (i_set, "constraint_name"), constraint_name, error))
1251 return FALSE;
1252 model = gda_connection_statement_execute_select_full (cnc,
1253 internal_stmt[I_STMT_KEY_COLUMN_USAGE],
1254 i_set, GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1255 _col_types_key_column_usage,
1256 error);
1257 if (model == NULL)
1258 retval = FALSE;
1259 else {
1260 retval = gda_meta_store_modify (store, context->table_name, model,
1261 "TRIM(r.RDB$RELATION_NAME) = ##tblname::string AND r.rdb$constraint_name = ##constraint_name::string",
1262 error,
1263 "tblname", table_name, "constraint_name", constraint_name, NULL);
1264 g_object_unref (G_OBJECT(model));
1265 }
1266
1267 if (retval == FALSE){g_print("\n\n***ERROR: %s\n\n", (*error)->message);}
1268 return retval;
1269 }
1270
1271 gboolean
_gda_firebird_meta__check_columns(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1272 _gda_firebird_meta__check_columns (GdaServerProvider *prov, GdaConnection *cnc,
1273 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1274 {
1275 //WHERE_AM_I;
1276
1277 TO_IMPLEMENT;
1278 return TRUE;
1279 }
1280
1281 gboolean
_gda_firebird_meta_check_columns(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * table_catalog,const GValue * table_schema,const GValue * table_name,const GValue * constraint_name)1282 _gda_firebird_meta_check_columns (GdaServerProvider *prov, GdaConnection *cnc,
1283 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1284 const GValue *table_catalog, const GValue *table_schema,
1285 const GValue *table_name, const GValue *constraint_name)
1286 {
1287 //WHERE_AM_I;
1288 TO_IMPLEMENT;
1289 return TRUE;
1290 }
1291
1292 gboolean
_gda_firebird_meta__triggers(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1293 _gda_firebird_meta__triggers (GdaServerProvider *prov, GdaConnection *cnc,
1294 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1295 {
1296 //WHERE_AM_I;
1297
1298 /* GdaDataModel *model;
1299 gboolean retval;
1300
1301 model = gda_connection_statement_execute_select_full (cnc,
1302 internal_stmt[I_STMT_TRIGGERS_ALL],
1303 NULL,
1304 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1305 _col_types_triggers, error);
1306 if (model == NULL)
1307 retval = FALSE;
1308 else {
1309 retval = gda_meta_store_modify_with_context (store, context, model, error);
1310 g_object_unref (G_OBJECT(model));
1311 }
1312
1313 return retval;
1314 */
1315 TO_IMPLEMENT;
1316 return TRUE;
1317 }
1318
1319 gboolean
_gda_firebird_meta_triggers(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * table_catalog,const GValue * table_schema,const GValue * table_name)1320 _gda_firebird_meta_triggers (GdaServerProvider *prov, GdaConnection *cnc,
1321 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1322 const GValue *table_catalog, const GValue *table_schema,
1323 const GValue *table_name)
1324 {
1325 //WHERE_AM_I; return TRUE;
1326 /*
1327 GdaDataModel *model;
1328 gboolean retval;
1329
1330 if (!gda_holder_set_value (gda_set_get_holder (i_set, "schema"), table_schema, error))
1331 return FALSE;
1332 if (!gda_holder_set_value (gda_set_get_holder (i_set, "name"), table_name, error))
1333 return FALSE;
1334 model = gda_connection_statement_execute_select_full (cnc,
1335 internal_stmt[I_STMT_TRIGGERS],
1336 i_set,
1337 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1338 _col_types_triggers, error);
1339 if (model == NULL)
1340 retval = FALSE;
1341 else {
1342 retval = gda_meta_store_modify_with_context (store, context, model, error);
1343 g_object_unref (G_OBJECT(model));
1344
1345 }
1346
1347 return retval;
1348 */
1349 TO_IMPLEMENT;
1350 return TRUE;
1351 }
1352
1353 gboolean
_gda_firebird_meta__routines(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1354 _gda_firebird_meta__routines (GdaServerProvider *prov, GdaConnection *cnc,
1355 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1356 {
1357 //WHERE_AM_I; return TRUE;
1358 /*
1359 GdaDataModel *model;
1360 gboolean retval;
1361
1362 model = gda_connection_statement_execute_select_full (cnc,
1363 internal_stmt[I_STMT_ROUTINES_ALL],
1364 NULL,
1365 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1366 _col_types_routines, error);
1367 if (model == NULL)
1368 retval = FALSE;
1369 else {
1370 retval = gda_meta_store_modify_with_context (store, context, model, error);
1371 g_object_unref (G_OBJECT(model));
1372 }
1373
1374 return retval;
1375 */
1376 TO_IMPLEMENT;
1377 return TRUE;
1378 }
1379
1380 gboolean
_gda_firebird_meta_routines(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * routine_catalog,const GValue * routine_schema,const GValue * routine_name_n)1381 _gda_firebird_meta_routines (GdaServerProvider *prov, GdaConnection *cnc,
1382 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1383 const GValue *routine_catalog, const GValue *routine_schema,
1384 const GValue *routine_name_n)
1385 {
1386 //WHERE_AM_I; return TRUE;
1387 /*
1388 GdaDataModel *model;
1389 gboolean retval;
1390
1391 if (!gda_holder_set_value (gda_set_get_holder (i_set, "schema"), routine_schema, error))
1392 return FALSE;
1393 if (routine_name_n != NULL) {
1394 if (!gda_holder_set_value (gda_set_get_holder (i_set, "name"), routine_name_n, error))
1395 return FALSE;
1396 model = gda_connection_statement_execute_select_full (cnc,
1397 internal_stmt[I_STMT_ROUTINES_ONE],
1398 i_set,
1399 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1400 _col_types_routines, error);
1401 }
1402 else
1403 model = gda_connection_statement_execute_select_full (cnc,
1404 internal_stmt[I_STMT_ROUTINES],
1405 i_set,
1406 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1407 _col_types_routines, error);
1408 if (model == NULL)
1409 retval = FALSE;
1410 else {
1411 retval = gda_meta_store_modify_with_context (store, context, model, error);
1412 g_object_unref (G_OBJECT(model));
1413
1414 }
1415
1416 return retval;
1417 */
1418 TO_IMPLEMENT;
1419 return TRUE;
1420 }
1421
1422 gboolean
_gda_firebird_meta__routine_col(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1423 _gda_firebird_meta__routine_col (GdaServerProvider *prov, GdaConnection *cnc,
1424 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1425 {
1426 //WHERE_AM_I;
1427 TO_IMPLEMENT;
1428 return TRUE;
1429 }
1430
1431 gboolean
_gda_firebird_meta_routine_col(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * rout_catalog,const GValue * rout_schema,const GValue * rout_name)1432 _gda_firebird_meta_routine_col (GdaServerProvider *prov, GdaConnection *cnc,
1433 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1434 const GValue *rout_catalog, const GValue *rout_schema,
1435 const GValue *rout_name)
1436 {
1437 //WHERE_AM_I;
1438 TO_IMPLEMENT;
1439 return TRUE;
1440 }
1441
1442 gboolean
_gda_firebird_meta__routine_par(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1443 _gda_firebird_meta__routine_par (GdaServerProvider *prov, GdaConnection *cnc,
1444 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1445 {
1446 //WHERE_AM_I;
1447 TO_IMPLEMENT;
1448 return TRUE;
1449 }
1450
1451 gboolean
_gda_firebird_meta_routine_par(GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,const GValue * rout_catalog,const GValue * rout_schema,const GValue * rout_name)1452 _gda_firebird_meta_routine_par (GdaServerProvider *prov, GdaConnection *cnc,
1453 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1454 const GValue *rout_catalog, const GValue *rout_schema,
1455 const GValue *rout_name)
1456 {
1457 //WHERE_AM_I;
1458 TO_IMPLEMENT;
1459 return TRUE;
1460 }
1461
1462 gboolean
_gda_firebird_meta__indexes_tab(G_GNUC_UNUSED GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1463 _gda_firebird_meta__indexes_tab (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnection *cnc,
1464 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1465 {
1466 //WHERE_AM_I;
1467 TO_IMPLEMENT;
1468 return TRUE;
1469 /*
1470 GdaDataModel *model;
1471 gboolean retval;
1472
1473 model = gda_connection_statement_execute_select_full (cnc,
1474 internal_stmt[I_STMT_INDEXES_ALL],
1475 NULL,
1476 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1477 _col_types_table_indexes, error);
1478 if (model == NULL)
1479 retval = FALSE;
1480 else {
1481 retval = gda_meta_store_modify_with_context (store, context, model, error);
1482 g_object_unref (G_OBJECT(model));
1483 }
1484
1485 return retval;
1486 */
1487 }
1488
1489 gboolean
_gda_firebird_meta_indexes_tab(G_GNUC_UNUSED GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,G_GNUC_UNUSED const GValue * table_catalog,const GValue * table_schema,const GValue * table_name,const GValue * index_name_n)1490 _gda_firebird_meta_indexes_tab (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnection *cnc,
1491 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1492 G_GNUC_UNUSED const GValue *table_catalog, const GValue *table_schema,
1493 const GValue *table_name, const GValue *index_name_n)
1494 {
1495 //WHERE_AM_I;
1496 TO_IMPLEMENT;
1497 return TRUE;
1498 /*
1499 GdaDataModel *model;
1500 gboolean retval;
1501
1502 if (!gda_holder_set_value (gda_set_get_holder (i_set, "schema"), table_schema, error))
1503 return FALSE;
1504 if (!gda_holder_set_value (gda_set_get_holder (i_set, "name"), table_name, error))
1505 return FALSE;
1506 if (index_name_n) {
1507 if (!gda_holder_set_value (gda_set_get_holder (i_set, "name2"), index_name_n, error))
1508 return FALSE;
1509 model = gda_connection_statement_execute_select_full (cnc,
1510 internal_stmt[I_STMT_INDEXES_ONE],
1511 i_set,
1512 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1513 _col_types_table_indexes, error);
1514 }
1515 model = gda_connection_statement_execute_select_full (cnc,
1516 internal_stmt[I_STMT_INDEXES_TABLE],
1517 i_set,
1518 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1519 _col_types_table_indexes, error);
1520
1521 if (model == NULL)
1522 retval = FALSE;
1523 else {
1524 gda_meta_store_set_reserved_keywords_func (store,
1525 _gda_mysql_reuseable_get_reserved_keywords_func
1526 ((GdaProviderReuseable*) rdata));
1527 retval = gda_meta_store_modify_with_context (store, context, model, error);
1528 g_object_unref (G_OBJECT(model));
1529
1530 }
1531
1532 return retval;
1533 */
1534 }
1535
1536 gboolean
_gda_firebird_meta__index_cols(G_GNUC_UNUSED GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error)1537 _gda_firebird_meta__index_cols (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnection *cnc,
1538 GdaMetaStore *store, GdaMetaContext *context, GError **error)
1539 {
1540 //WHERE_AM_I; return TRUE;
1541 /*
1542 GdaDataModel *model;
1543 gboolean retval;
1544
1545 model = gda_connection_statement_execute_select_full (cnc,
1546 internal_stmt[I_STMT_INDEX_COLUMNS_ALL],
1547 NULL,
1548 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1549 _col_types_index_column_usage, error);
1550 if (model == NULL)
1551 retval = FALSE;
1552 else {
1553 retval = gda_meta_store_modify_with_context (store, context, model, error);
1554 g_object_unref (G_OBJECT(model));
1555 }
1556
1557 return retval;
1558 */
1559 TO_IMPLEMENT;
1560 return TRUE;
1561 }
1562
1563 gboolean
_gda_firebird_meta_index_cols(G_GNUC_UNUSED GdaServerProvider * prov,GdaConnection * cnc,GdaMetaStore * store,GdaMetaContext * context,GError ** error,G_GNUC_UNUSED const GValue * table_catalog,const GValue * table_schema,const GValue * table_name,const GValue * index_name)1564 _gda_firebird_meta_index_cols (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnection *cnc,
1565 GdaMetaStore *store, GdaMetaContext *context, GError **error,
1566 G_GNUC_UNUSED const GValue *table_catalog, const GValue *table_schema,
1567 const GValue *table_name, const GValue *index_name)
1568 {
1569 //WHERE_AM_I; return TRUE;
1570 /*
1571 GdaDataModel *model;
1572 gboolean retval;
1573
1574 if (!gda_holder_set_value (gda_set_get_holder (i_set, "name"), table_name, error))
1575 return FALSE;
1576 if (!gda_holder_set_value (gda_set_get_holder (i_set, "name2"), index_name, error))
1577 return FALSE;
1578 model = gda_connection_statement_execute_select_full (cnc,
1579 internal_stmt[I_STMT_INDEX_COLUMNS_NAMED],
1580 i_set,
1581 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
1582 _col_types_index_column_usage, error);
1583
1584 if (model == NULL)
1585 retval = FALSE;
1586 else {
1587 retval = gda_meta_store_modify_with_context (store, context, model, error);
1588 g_object_unref (G_OBJECT(model));
1589
1590 }
1591
1592 return retval;
1593 */
1594 TO_IMPLEMENT;
1595 return TRUE;
1596 }
1597
1598