gda 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90fd4381e4ad8e36706b5668d06a7aefd38bddb3
4
+ data.tar.gz: d4decc43386524ae4bb1b5f013b9c8e61284cf7d
5
+ SHA512:
6
+ metadata.gz: 1a1cff3f1c41b0797b0acfc4432e8bdee15f37dd3a82737f44f30a5b39480450065c8f3d6e52e54dcf8c443023683b1c76910d0ab64cd5d6b6ffb2ff337eb3f6
7
+ data.tar.gz: a46766066ba0905568447e5d2b0068299cd4693dccc578683b17593cbd5feba30af797c44459786a7fdf6e21d9415a61851aaa6b6700b6ce21d964fb5f80c854
@@ -0,0 +1,12 @@
1
+ require "autotest/restart"
2
+ require 'rbconfig'
3
+
4
+ Autotest.add_hook :initialize do |at|
5
+ at.find_directories = ARGV unless ARGV.empty?
6
+ at.testlib = "minitest/autorun"
7
+ end
8
+
9
+ Autotest.add_hook :run_command do |at|
10
+ at.unit_diff = 'cat'
11
+ system "ruby -S rake compile"
12
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2012-07-13
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,27 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ ext/gda/extconf.rb
7
+ ext/gda/gda.c
8
+ ext/gda/gda.h
9
+ ext/gda/gda_nodes.c
10
+ ext/gda/gda_nodes.h
11
+ ext/gda/gda_provider.c
12
+ ext/gda/gda_provider.h
13
+ ext/gda/gda_statement.c
14
+ ext/gda/gda_statement.h
15
+ lib/gda.rb
16
+ lib/gda/visitors/dot.rb
17
+ lib/gda/visitors/each.rb
18
+ lib/gda/visitors/max_depth.rb
19
+ lib/gda/visitors/visitor.rb
20
+ test/helper.rb
21
+ test/sqllog.sqlite3
22
+ test/test_dot_visitor.rb
23
+ test/test_gda.rb
24
+ test/test_max_depth.rb
25
+ test/test_node_attributes.rb
26
+ test/test_nodes.rb
27
+ test/test_statement.rb
@@ -0,0 +1,61 @@
1
+ = gda
2
+
3
+ * http://github.com/tenderlove/gda
4
+
5
+ == DESCRIPTION:
6
+
7
+ An SQL parser. Wraps libgda in a loving embrace to give you a ruby level SQL
8
+ parser.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Not done yet
13
+ * Do not use
14
+
15
+ == SYNOPSIS:
16
+
17
+ parser = GDA::SQL::Parser.new
18
+
19
+ stmt = parser.parse 'SELECT * FROM FOO WHERE 1 = 1 GROUP BY omg HAVING omg(id) < 2 ORDER BY foo, bar LIMIT 50 OFFSET 2'
20
+
21
+ stmt.ast.each do |node|
22
+ p node
23
+ end
24
+
25
+ puts stmt.ast.to_dot
26
+
27
+ == HACKING:
28
+
29
+ $ brew install libgda
30
+ $ gem install hoe rake-compiler
31
+ $ rake
32
+
33
+ == INSTALL:
34
+
35
+ * brew install libgda
36
+ * gem install gda
37
+
38
+ == LICENSE:
39
+
40
+ (The MIT License)
41
+
42
+ Copyright (c) 2012-2013 Aaron Patterson
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugins.delete :rubyforge
7
+ Hoe.plugin :minitest
8
+ Hoe.plugin :gemspec # `gem install hoe-gemspec`
9
+ Hoe.plugin :git # `gem install hoe-git`
10
+
11
+ Hoe.spec 'gda' do
12
+ developer('Aaron Patterson', 'tenderlove@ruby-lang.org')
13
+ self.readme_file = 'README.rdoc'
14
+ self.history_file = 'CHANGELOG.rdoc'
15
+ self.extra_rdoc_files = FileList['*.rdoc']
16
+
17
+ extra_dev_deps << ['rake-compiler', '>= 0.4.1']
18
+ extra_dev_deps << ['sqlite3']
19
+
20
+ self.spec_extras = {
21
+ :extensions => ["ext/gda/extconf.rb"],
22
+ :required_ruby_version => '>= 1.9.3'
23
+ }
24
+
25
+ require "rake/extensiontask"
26
+
27
+ Rake::ExtensionTask.new "gda", spec do |ext|
28
+ ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
29
+ end
30
+ end
31
+
32
+ task :test => :compile
33
+
34
+ # vim: syntax=ruby
@@ -0,0 +1,19 @@
1
+ require 'mkmf'
2
+
3
+ # :stopdoc:
4
+
5
+ ENV['PKG_CONFIG_PATH']= '/usr/local/Library/ENV/pkgconfig/mountain_lion'
6
+
7
+ dir_config 'libgda'
8
+
9
+ def asplode missing
10
+ abort "#{missing} is missing. Try 'brew install libgda'"
11
+ end
12
+
13
+ pkg_config 'libgda-5.0'
14
+ find_header('libgda/sql-parser/gda-sql-parser.h') || asplode("libgda")
15
+
16
+ create_makefile 'gda'
17
+
18
+
19
+ # :startdoc:
@@ -0,0 +1,99 @@
1
+ #include <gda.h>
2
+
3
+ VALUE mGDA;
4
+ VALUE mSQL;
5
+ VALUE cParser;
6
+
7
+ static VALUE allocate(VALUE klass)
8
+ {
9
+ GdaSqlParser * parser;
10
+
11
+ parser = gda_sql_parser_new();
12
+ return Data_Wrap_Struct(klass, NULL, g_object_unref, parser);
13
+ }
14
+
15
+ static VALUE parse(VALUE self, VALUE sql)
16
+ {
17
+ GdaSqlParser * parser;
18
+ GdaStatement * stmt;
19
+ GError * error;
20
+ const gchar * rest;
21
+
22
+ Data_Get_Struct(self, GdaSqlParser, parser);
23
+
24
+ stmt = gda_sql_parser_parse_string(parser, StringValuePtr(sql), &rest, &error);
25
+
26
+ if (!stmt) {
27
+ rb_raise(rb_eRuntimeError, "error parsing sql");
28
+ }
29
+
30
+ return Data_Wrap_Struct(cStatement, NULL, g_object_unref, stmt);
31
+ }
32
+
33
+ static VALUE providers(VALUE klass)
34
+ {
35
+ GdaDataModel * providers;
36
+ gint i, nb;
37
+ VALUE list;
38
+
39
+ list = rb_ary_new();
40
+ providers = gda_config_list_providers();
41
+ nb = gda_data_model_get_n_rows(providers);
42
+
43
+ for (i = 0; i < nb; i++) {
44
+ const gchar *pname;
45
+ const GValue *cvalue;
46
+
47
+ cvalue = gda_data_model_get_value_at(providers, 0, i, NULL);
48
+
49
+ if (!cvalue)
50
+ rb_raise(rb_eRuntimeError, "can't load provider");
51
+
52
+ pname = g_value_get_string(cvalue);
53
+
54
+ rb_ary_push(list, rb_str_new2(pname));
55
+ }
56
+
57
+ g_object_unref(providers);
58
+
59
+ return list;
60
+ }
61
+
62
+ static VALUE sql_identifier_split(VALUE klass, VALUE string)
63
+ {
64
+ gchar ** list;
65
+ int i;
66
+ VALUE ids;
67
+
68
+ ids = rb_ary_new();
69
+ list = gda_sql_identifier_split(StringValuePtr(string));
70
+ for (i = 0; list[i]; i++) {
71
+ rb_ary_push(ids, rb_str_new2(list[i]));
72
+ }
73
+ g_strfreev(list);
74
+
75
+ return ids;
76
+ }
77
+
78
+ void Init_gda()
79
+ {
80
+
81
+ mGDA = rb_define_module("GDA");
82
+ mSQL = rb_define_module_under(mGDA, "SQL");
83
+
84
+ Init_gda_statement();
85
+ Init_gda_nodes();
86
+ Init_gda_provider();
87
+ cParser = rb_define_class_under(mSQL, "Parser", rb_cObject);
88
+
89
+ rb_define_alloc_func(cParser, allocate);
90
+
91
+ rb_define_method(cParser, "parse", parse, 1);
92
+
93
+ rb_define_singleton_method(mSQL, "providers", providers, 0);
94
+ rb_define_singleton_method(mGDA, "sql_identifier_split", sql_identifier_split, 1);
95
+
96
+ gda_init();
97
+ }
98
+
99
+ /* vim: set noet sws=4 sw=4: */
@@ -0,0 +1,18 @@
1
+ #ifndef _RUBY_GDA
2
+ #define _RUBY_GDA
3
+
4
+ #include <ruby.h>
5
+ #include <libgda/libgda.h>
6
+ #include <libgda/sql-parser/gda-sql-parser.h>
7
+ #include <libgda/sql-parser/gda-sql-statement.h>
8
+
9
+ extern VALUE mGDA;
10
+ extern VALUE mSQL;
11
+ extern VALUE cStatement;
12
+ extern VALUE cParser;
13
+
14
+ #include <gda_statement.h>
15
+ #include <gda_nodes.h>
16
+ #include <gda_provider.h>
17
+
18
+ #endif
@@ -0,0 +1,516 @@
1
+ #include <gda.h>
2
+
3
+ VALUE mNodes;
4
+ VALUE cSelect;
5
+ VALUE cFrom;
6
+ VALUE cSelectField;
7
+ VALUE cExpr;
8
+ VALUE cOrder;
9
+ VALUE cNode;
10
+ VALUE cOperation;
11
+ VALUE cTarget;
12
+ VALUE cFunction;
13
+ VALUE cInsert;
14
+ VALUE cDelete;
15
+ VALUE cUpdate;
16
+ VALUE cTable;
17
+ VALUE cUnknown;
18
+ VALUE cJoin;
19
+ VALUE cField;
20
+ VALUE cRollbackSavepoint;
21
+ VALUE cDeleteSavepoint;
22
+ VALUE cSavepoint;
23
+ VALUE cBegin;
24
+ VALUE cRollback;
25
+ VALUE cCommit;
26
+
27
+ #define WrapInteger(klass, type, lname) \
28
+ static VALUE rb_##klass##_##lname(VALUE self) \
29
+ { \
30
+ type *st;\
31
+ Data_Get_Struct(self, type, st); \
32
+ return INT2NUM(st->lname); \
33
+ }
34
+
35
+ #define WrapBoolean(klass, type, lname) \
36
+ static VALUE rb_##klass##_##lname(VALUE self) \
37
+ { \
38
+ type *st;\
39
+ Data_Get_Struct(self, type, st); \
40
+ if (st->lname) \
41
+ return Qtrue; \
42
+ else \
43
+ return Qfalse; \
44
+ }
45
+
46
+ #define WrapString(klass, type, lname) \
47
+ static VALUE rb_##klass##_##lname(VALUE self) \
48
+ { \
49
+ type *st;\
50
+ Data_Get_Struct(self, type, st); \
51
+ if (st->lname) \
52
+ return rb_str_new2(st->lname); \
53
+ else \
54
+ return Qnil; \
55
+ }
56
+
57
+ #define WrapNode(klass, type, lname) \
58
+ static VALUE rb_##klass##_##lname(VALUE self) \
59
+ { \
60
+ type *st;\
61
+ VALUE stmt;\
62
+ Data_Get_Struct(self, type, st); \
63
+ stmt = rb_iv_get(self, "stmt"); \
64
+ return WrapAnyPart(stmt, (GdaSqlAnyPart *)st->lname); \
65
+ }
66
+
67
+ #define WrapList(klass, type, lname) \
68
+ static VALUE rb_##klass##_##lname(VALUE self) \
69
+ { \
70
+ type *ptr; \
71
+ GSList *list; \
72
+ VALUE rb_list; \
73
+ VALUE stmt; \
74
+ Data_Get_Struct(self, type, ptr);\
75
+ stmt = rb_iv_get(self, "stmt"); \
76
+ rb_list = rb_ary_new(); \
77
+ list = ptr->lname; \
78
+ while(list) { \
79
+ rb_ary_push(rb_list, WrapAnyPart(stmt, (GdaSqlAnyPart *)list->data)); \
80
+ list = list->next; \
81
+ } \
82
+ return rb_list; \
83
+ }
84
+
85
+ #define WrapperMethod(klass, lname) \
86
+ rb_define_method(klass, #lname, rb_##klass##_##lname, 0);
87
+
88
+ WrapString(cTable, GdaSqlTable, table_name);
89
+
90
+ WrapString(cField, GdaSqlField, field_name);
91
+
92
+ WrapNode(cSelect, GdaSqlStatementSelect, distinct_expr);
93
+ WrapList(cSelect, GdaSqlStatementSelect, expr_list);
94
+ WrapNode(cSelect, GdaSqlStatementSelect, from);
95
+ WrapNode(cSelect, GdaSqlStatementSelect, where_cond);
96
+ WrapList(cSelect, GdaSqlStatementSelect, group_by);
97
+ WrapNode(cSelect, GdaSqlStatementSelect, having_cond);
98
+ WrapList(cSelect, GdaSqlStatementSelect, order_by);
99
+ WrapNode(cSelect, GdaSqlStatementSelect, limit_count);
100
+ WrapNode(cSelect, GdaSqlStatementSelect, limit_offset);
101
+
102
+ WrapNode(cSelectField, GdaSqlSelectField, expr);
103
+ WrapString(cSelectField, GdaSqlSelectField, field_name);
104
+ WrapString(cSelectField, GdaSqlSelectField, table_name);
105
+ WrapString(cSelectField, GdaSqlSelectField, as);
106
+
107
+ WrapNode(cExpr, GdaSqlExpr, func);
108
+ WrapNode(cExpr, GdaSqlExpr, cond);
109
+ WrapNode(cExpr, GdaSqlExpr, select);
110
+ WrapNode(cExpr, GdaSqlExpr, case_s);
111
+ WrapNode(cExpr, GdaSqlExpr, param_spec);
112
+ WrapString(cExpr, GdaSqlExpr, cast_as);
113
+ WrapBoolean(cExpr, GdaSqlExpr, value_is_ident);
114
+
115
+ WrapList(cFrom, GdaSqlSelectFrom, targets);
116
+ WrapList(cFrom, GdaSqlSelectFrom, joins);
117
+
118
+ WrapList(cOperation, GdaSqlOperation, operands);
119
+
120
+ WrapNode(cTarget, GdaSqlSelectTarget, expr);
121
+ WrapString(cTarget, GdaSqlSelectTarget, table_name);
122
+ WrapString(cTarget, GdaSqlSelectTarget, as);
123
+
124
+ WrapList(cFunction, GdaSqlFunction, args_list);
125
+ WrapString(cFunction, GdaSqlFunction, function_name);
126
+
127
+ WrapNode(cOrder, GdaSqlSelectOrder, expr);
128
+ WrapBoolean(cOrder, GdaSqlSelectOrder, asc);
129
+ WrapString(cOrder, GdaSqlSelectOrder, collation_name);
130
+
131
+ WrapNode(cInsert, GdaSqlStatementInsert, table);
132
+ WrapList(cInsert, GdaSqlStatementInsert, fields_list);
133
+ WrapNode(cInsert, GdaSqlStatementInsert, select);
134
+ WrapString(cInsert, GdaSqlStatementInsert, on_conflict);
135
+
136
+ WrapNode(cUpdate, GdaSqlStatementUpdate, table);
137
+ WrapList(cUpdate, GdaSqlStatementUpdate, fields_list);
138
+ WrapList(cUpdate, GdaSqlStatementUpdate, expr_list);
139
+ WrapNode(cUpdate, GdaSqlStatementUpdate, cond);
140
+ WrapString(cUpdate, GdaSqlStatementUpdate, on_conflict);
141
+
142
+ WrapNode(cDelete, GdaSqlStatementDelete, table);
143
+ WrapNode(cDelete, GdaSqlStatementDelete, cond);
144
+
145
+ WrapNode(cJoin, GdaSqlSelectJoin, expr);
146
+ WrapList(cJoin, GdaSqlSelectJoin, use);
147
+ WrapInteger(cJoin, GdaSqlSelectJoin, position);
148
+
149
+ WrapList(cUnknown, GdaSqlStatementUnknown, expressions);
150
+
151
+ static VALUE distinct_p(VALUE self)
152
+ {
153
+ GdaSqlStatementSelect * st;
154
+
155
+ Data_Get_Struct(self, GdaSqlStatementSelect, st);
156
+
157
+ if (st->distinct)
158
+ return Qtrue;
159
+
160
+ return Qfalse;
161
+ }
162
+
163
+ static VALUE Wrap(VALUE stmt, VALUE klass, GdaSqlAnyPart *part)
164
+ {
165
+ VALUE obj = Data_Wrap_Struct(klass, NULL, NULL, part);
166
+ rb_iv_set(obj, "stmt", stmt);
167
+ return obj;
168
+ }
169
+
170
+ VALUE WrapAnyPart(VALUE stmt, GdaSqlAnyPart *part)
171
+ {
172
+ if (!part)
173
+ return Qnil;
174
+
175
+ switch(part->type) {
176
+ case GDA_SQL_ANY_STMT_SELECT:
177
+ return Wrap(stmt, cSelect, part);
178
+ break;
179
+ case GDA_SQL_ANY_STMT_INSERT:
180
+ return Wrap(stmt, cInsert, part);
181
+ break;
182
+ case GDA_SQL_ANY_STMT_UPDATE:
183
+ return Wrap(stmt, cUpdate, part);
184
+ break;
185
+ case GDA_SQL_ANY_STMT_DELETE:
186
+ return Wrap(stmt, cDelete, part);
187
+ break;
188
+ case GDA_SQL_ANY_STMT_BEGIN:
189
+ return Wrap(stmt, cBegin, part);
190
+ break;
191
+ case GDA_SQL_ANY_STMT_ROLLBACK:
192
+ return Wrap(stmt, cRollback, part);
193
+ break;
194
+ case GDA_SQL_ANY_STMT_COMMIT:
195
+ return Wrap(stmt, cCommit, part);
196
+ break;
197
+ case GDA_SQL_ANY_STMT_SAVEPOINT:
198
+ return Wrap(stmt, cSavepoint, part);
199
+ break;
200
+ case GDA_SQL_ANY_STMT_ROLLBACK_SAVEPOINT:
201
+ return Wrap(stmt, cRollbackSavepoint, part);
202
+ break;
203
+ case GDA_SQL_ANY_STMT_DELETE_SAVEPOINT:
204
+ return Wrap(stmt, cDeleteSavepoint, part);
205
+ break;
206
+ case GDA_SQL_ANY_STMT_UNKNOWN:
207
+ return Wrap(stmt, cUnknown, part);
208
+ break;
209
+ case GDA_SQL_ANY_SQL_SELECT_FROM:
210
+ return Wrap(stmt, cFrom, part);
211
+ break;
212
+ case GDA_SQL_ANY_SQL_SELECT_FIELD:
213
+ return Wrap(stmt, cSelectField, part);
214
+ break;
215
+ case GDA_SQL_ANY_EXPR:
216
+ return Wrap(stmt, cExpr, part);
217
+ break;
218
+ case GDA_SQL_ANY_SQL_FIELD:
219
+ return Wrap(stmt, cField, part);
220
+ break;
221
+ case GDA_SQL_ANY_SQL_SELECT_ORDER:
222
+ return Wrap(stmt, cOrder, part);
223
+ break;
224
+ case GDA_SQL_ANY_SQL_TABLE:
225
+ return Wrap(stmt, cTable, part);
226
+ break;
227
+ case GDA_SQL_ANY_SQL_OPERATION:
228
+ return Wrap(stmt, cOperation, part);
229
+ break;
230
+ case GDA_SQL_ANY_SQL_FUNCTION:
231
+ return Wrap(stmt, cFunction, part);
232
+ break;
233
+ case GDA_SQL_ANY_SQL_SELECT_TARGET:
234
+ return Wrap(stmt, cTarget, part);
235
+ break;
236
+ case GDA_SQL_ANY_SQL_SELECT_JOIN:
237
+ return Wrap(stmt, cJoin, part);
238
+ break;
239
+ default:
240
+ rb_raise(rb_eRuntimeError, "unknown node type: %d\n", part->type);
241
+ return Qnil;
242
+ }
243
+ }
244
+
245
+ static VALUE rb_cInsert_values_list(VALUE self)
246
+ {
247
+ GdaSqlStatementInsert * st;
248
+ GSList * list;
249
+ VALUE array;
250
+ VALUE stmt;
251
+
252
+ Data_Get_Struct(self, GdaSqlStatementInsert, st);
253
+
254
+ stmt = rb_iv_get(self, "stmt");
255
+
256
+ array = rb_ary_new();
257
+ list = st->values_list;
258
+ while(list) {
259
+ VALUE iarray = rb_ary_new();
260
+ GSList * inner = (GSList *)list->data;
261
+
262
+ while(inner) {
263
+ rb_ary_push(iarray, WrapAnyPart(stmt, (GdaSqlAnyPart *)inner->data));
264
+ inner = inner->next;
265
+ }
266
+
267
+ rb_ary_push(array, iarray);
268
+ list = list->next;
269
+ }
270
+
271
+ return array;
272
+ }
273
+
274
+ static VALUE rb_cOperation_operator(VALUE self)
275
+ {
276
+ GdaSqlOperation * st;
277
+
278
+ Data_Get_Struct(self, GdaSqlOperation, st);
279
+
280
+ if (st->operator_type)
281
+ return rb_str_new2(gda_sql_operation_operator_to_string(st->operator_type));
282
+
283
+ return Qnil;
284
+ }
285
+
286
+ static VALUE rb_cJoin_join_type(VALUE self)
287
+ {
288
+ GdaSqlSelectJoin * st;
289
+
290
+ Data_Get_Struct(self, GdaSqlSelectJoin, st);
291
+
292
+ if (st->type)
293
+ return rb_str_new2(gda_sql_select_join_type_to_string(st->type));
294
+
295
+ return Qnil;
296
+ }
297
+
298
+ static VALUE rb_st_type(VALUE self)
299
+ {
300
+ GdaSqlAnyPart * st;
301
+
302
+ Data_Get_Struct(self, GdaSqlAnyPart, st);
303
+
304
+ switch(st->type) {
305
+ case GDA_SQL_ANY_STMT_BEGIN:
306
+ return rb_str_new2("BEGIN");
307
+ break;
308
+ case GDA_SQL_ANY_STMT_ROLLBACK:
309
+ return rb_str_new2("ROLLBACK");
310
+ break;
311
+ case GDA_SQL_ANY_STMT_COMMIT:
312
+ return rb_str_new2("COMMIT");
313
+ break;
314
+ case GDA_SQL_ANY_STMT_SAVEPOINT:
315
+ return rb_str_new2("SAVEPOINT");
316
+ break;
317
+ case GDA_SQL_ANY_STMT_ROLLBACK_SAVEPOINT:
318
+ return rb_str_new2("ROLLBACK SAVEPOINT");
319
+ break;
320
+ case GDA_SQL_ANY_STMT_DELETE_SAVEPOINT:
321
+ return rb_str_new2("DELETE SAVEPOINT");
322
+ break;
323
+ default:
324
+ return Qnil;
325
+ }
326
+ }
327
+
328
+ static VALUE rb_st_isolation_level(VALUE self)
329
+ {
330
+ GdaSqlStatementTransaction * st;
331
+
332
+ Data_Get_Struct(self, GdaSqlStatementTransaction, st);
333
+
334
+ switch(st->isolation_level) {
335
+ default:
336
+ case GDA_TRANSACTION_ISOLATION_UNKNOWN:
337
+ return rb_str_new2("UNKNOWN");
338
+ break;
339
+ case GDA_TRANSACTION_ISOLATION_READ_COMMITTED:
340
+ return rb_str_new2("READ COMMITTED");
341
+ break;
342
+ case GDA_TRANSACTION_ISOLATION_READ_UNCOMMITTED:
343
+ return rb_str_new2("READ UNCOMMITTED");
344
+ break;
345
+ case GDA_TRANSACTION_ISOLATION_REPEATABLE_READ:
346
+ return rb_str_new2("REPEATABLE READ");
347
+ break;
348
+ case GDA_TRANSACTION_ISOLATION_SERIALIZABLE:
349
+ return rb_str_new2("SERIALIZABLE");
350
+ break;
351
+ }
352
+ }
353
+
354
+ static VALUE rb_st_trans_mode(VALUE self)
355
+ {
356
+ GdaSqlStatementTransaction * st;
357
+
358
+ Data_Get_Struct(self, GdaSqlStatementTransaction, st);
359
+
360
+ if (st->trans_mode)
361
+ return rb_str_new2(st->trans_mode);
362
+
363
+ return Qnil;
364
+ }
365
+
366
+ static VALUE rb_st_trans_name(VALUE self)
367
+ {
368
+ GdaSqlStatementTransaction * st;
369
+
370
+ Data_Get_Struct(self, GdaSqlStatementTransaction, st);
371
+
372
+ if (st->trans_name)
373
+ return rb_str_new2(st->trans_name);
374
+
375
+ return Qnil;
376
+ }
377
+
378
+ static VALUE rb_cExpr_value(VALUE self)
379
+ {
380
+ GdaSqlExpr * st;
381
+ GValue * val;
382
+
383
+ Data_Get_Struct(self, GdaSqlExpr, st);
384
+
385
+ val = st->value;
386
+
387
+ return rb_str_new2(gda_value_stringify(val));
388
+ }
389
+
390
+ void Init_gda_nodes()
391
+ {
392
+ mNodes = rb_define_module_under(mGDA, "Nodes");
393
+
394
+ cNode = rb_define_class_under(mNodes, "Node", rb_cObject);
395
+
396
+ cSelect = rb_define_class_under(mNodes, "Select", cNode);
397
+ rb_define_method(cSelect, "distinct?", distinct_p, 0);
398
+
399
+ WrapperMethod(cSelect, from);
400
+ WrapperMethod(cSelect, distinct_expr);
401
+ WrapperMethod(cSelect, expr_list);
402
+ WrapperMethod(cSelect, where_cond);
403
+ WrapperMethod(cSelect, group_by);
404
+ WrapperMethod(cSelect, having_cond);
405
+ WrapperMethod(cSelect, order_by);
406
+ WrapperMethod(cSelect, limit_count);
407
+ WrapperMethod(cSelect, limit_offset);
408
+
409
+ cSelectField = rb_define_class_under(mNodes, "SelectField", cNode);
410
+ WrapperMethod(cSelectField, expr);
411
+ WrapperMethod(cSelectField, field_name);
412
+ WrapperMethod(cSelectField, table_name);
413
+ WrapperMethod(cSelectField, as);
414
+
415
+ cExpr = rb_define_class_under(mNodes, "Expr", cNode);
416
+ WrapperMethod(cExpr, func);
417
+ WrapperMethod(cExpr, cond);
418
+ WrapperMethod(cExpr, select);
419
+ WrapperMethod(cExpr, case_s);
420
+ WrapperMethod(cExpr, param_spec);
421
+ WrapperMethod(cExpr, cast_as);
422
+ WrapperMethod(cExpr, value);
423
+ WrapperMethod(cExpr, value_is_ident);
424
+
425
+ cFrom = rb_define_class_under(mNodes, "From", cNode);
426
+ WrapperMethod(cFrom, targets);
427
+ WrapperMethod(cFrom, joins);
428
+
429
+ cOperation = rb_define_class_under(mNodes, "Operation", cNode);
430
+ WrapperMethod(cOperation, operands);
431
+ WrapperMethod(cOperation, operator);
432
+
433
+ cTarget = rb_define_class_under(mNodes, "Target", cNode);
434
+ WrapperMethod(cTarget, expr);
435
+ WrapperMethod(cTarget, table_name);
436
+ WrapperMethod(cTarget, as);
437
+
438
+ cFunction = rb_define_class_under(mNodes, "Function", cNode);
439
+ WrapperMethod(cFunction, args_list);
440
+ WrapperMethod(cFunction, function_name);
441
+
442
+ cOrder = rb_define_class_under(mNodes, "Order", cNode);
443
+ WrapperMethod(cOrder, expr);
444
+ WrapperMethod(cOrder, asc);
445
+ WrapperMethod(cOrder, collation_name);
446
+
447
+ cInsert = rb_define_class_under(mNodes, "Insert", cNode);
448
+ WrapperMethod(cInsert, table);
449
+ WrapperMethod(cInsert, values_list);
450
+ WrapperMethod(cInsert, fields_list);
451
+ WrapperMethod(cInsert, select);
452
+ WrapperMethod(cInsert, on_conflict);
453
+
454
+ cDelete = rb_define_class_under(mNodes, "Delete", cNode);
455
+ WrapperMethod(cDelete, table);
456
+ WrapperMethod(cDelete, cond);
457
+
458
+ cUpdate = rb_define_class_under(mNodes, "Update", cNode);
459
+ WrapperMethod(cUpdate, table);
460
+ WrapperMethod(cUpdate, fields_list);
461
+ WrapperMethod(cUpdate, expr_list);
462
+ WrapperMethod(cUpdate, cond);
463
+ WrapperMethod(cUpdate, on_conflict);
464
+
465
+ cTable = rb_define_class_under(mNodes, "Table", cNode);
466
+ WrapperMethod(cTable, table_name);
467
+
468
+ cUnknown = rb_define_class_under(mNodes, "Unknown", cNode);
469
+ WrapperMethod(cUnknown, expressions);
470
+
471
+ cJoin = rb_define_class_under(mNodes, "Join", cNode);
472
+ WrapperMethod(cJoin, expr);
473
+ WrapperMethod(cJoin, use);
474
+ WrapperMethod(cJoin, join_type);
475
+ WrapperMethod(cJoin, position);
476
+
477
+ cField = rb_define_class_under(mNodes, "Field", cNode);
478
+ WrapperMethod(cField, field_name);
479
+
480
+ cBegin = rb_define_class_under(mNodes, "Begin", cNode);
481
+ cRollback = rb_define_class_under(mNodes, "Rollback", cNode);
482
+ cCommit = rb_define_class_under(mNodes, "Commit", cNode);
483
+ cSavepoint = rb_define_class_under(mNodes, "Savepoint", cNode);
484
+ cRollbackSavepoint = rb_define_class_under(mNodes, "RollbackSavepoint", cNode);
485
+ cDeleteSavepoint = rb_define_class_under(mNodes, "DeleteSavepoint", cNode);
486
+
487
+ rb_define_method(cRollbackSavepoint, "__type__", rb_st_type, 0);
488
+ rb_define_method(cBegin, "__type__", rb_st_type, 0);
489
+ rb_define_method(cSavepoint, "__type__", rb_st_type, 0);
490
+ rb_define_method(cCommit, "__type__", rb_st_type, 0);
491
+ rb_define_method(cRollback, "__type__", rb_st_type, 0);
492
+ rb_define_method(cDeleteSavepoint, "__type__", rb_st_type, 0);
493
+
494
+ rb_define_method(cRollbackSavepoint, "isolation_level", rb_st_isolation_level, 0);
495
+ rb_define_method(cBegin, "isolation_level", rb_st_isolation_level, 0);
496
+ rb_define_method(cSavepoint, "isolation_level", rb_st_isolation_level, 0);
497
+ rb_define_method(cCommit, "isolation_level", rb_st_isolation_level, 0);
498
+ rb_define_method(cRollback, "isolation_level", rb_st_isolation_level, 0);
499
+ rb_define_method(cDeleteSavepoint, "isolation_level", rb_st_isolation_level, 0);
500
+
501
+ rb_define_method(cRollbackSavepoint, "trans_mode", rb_st_trans_mode, 0);
502
+ rb_define_method(cBegin, "trans_mode", rb_st_trans_mode, 0);
503
+ rb_define_method(cSavepoint, "trans_mode", rb_st_trans_mode, 0);
504
+ rb_define_method(cCommit, "trans_mode", rb_st_trans_mode, 0);
505
+ rb_define_method(cRollback, "trans_mode", rb_st_trans_mode, 0);
506
+ rb_define_method(cDeleteSavepoint, "trans_mode", rb_st_trans_mode, 0);
507
+
508
+ rb_define_method(cRollbackSavepoint, "trans_name", rb_st_trans_name, 0);
509
+ rb_define_method(cBegin, "trans_name", rb_st_trans_name, 0);
510
+ rb_define_method(cSavepoint, "trans_name", rb_st_trans_name, 0);
511
+ rb_define_method(cCommit, "trans_name", rb_st_trans_name, 0);
512
+ rb_define_method(cRollback, "trans_name", rb_st_trans_name, 0);
513
+ rb_define_method(cDeleteSavepoint, "trans_name", rb_st_trans_name, 0);
514
+ }
515
+
516
+ /* vim: set noet sws=4 sw=4: */