activetokyocabinet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,72 @@
1
+ = ActiveTokyoCabinet
2
+
3
+ Copyright (c) 2010 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
4
+
5
+ == Description
6
+
7
+ ActiveTokyoCabinet is a library for using TokyoCabinet under ActiveRecord.
8
+
9
+ ActiveTokyoCabinet depend on TokyoCabinet.
10
+
11
+ see http://1978th.net/tokyocabinet/ .
12
+
13
+ == Project Page
14
+
15
+ http://rubyforge.org/projects/activetokyocabi
16
+
17
+ == Install
18
+
19
+ gem install zipruby
20
+
21
+ == Example
22
+ === database.yml
23
+
24
+ development:
25
+ adapter: tokyocabinet
26
+ database: path_of_database_directory
27
+ # ~~~~~~~~~
28
+
29
+ === Model
30
+
31
+ class Hello < ActiveRecord::Base
32
+ include ActiveTokyoCabinet::TDB
33
+
34
+ # define schema information.
35
+ # (string, int, float)
36
+ string :name
37
+ int :age
38
+ end
39
+
40
+ === Example Controller
41
+
42
+ class HelloController < ApplicationController
43
+ def index
44
+ (20..35).each do |i|
45
+ hello = Hello.new
46
+ hello.name = 'yamada'
47
+ hello.age = 20
48
+ hello.save!
49
+ end
50
+
51
+ p Hello.find(:all,
52
+ :conditions => ["name = ? and age > ?", "yamada", 25],
53
+ :order => 'age desc', :limit => 5, :offset => 3)
54
+
55
+ hello = Hello.find(1)
56
+ hello.name = 'sato'
57
+ hello.save!
58
+
59
+ p Hello.find(:first, :conditions => ["name = ?", "tanaka"])
60
+
61
+ hello = Hello.find(2)
62
+ hello.destroy
63
+
64
+ p Hello.find(:all)
65
+
66
+ Hello.delete_all(["name = ? and age <= ?", "yamada", 30])
67
+
68
+ p Hello.find(:all)
69
+
70
+ render :text => 'hello'
71
+ end
72
+ end
@@ -0,0 +1,235 @@
1
+ require 'active_record/connection_adapters/abstract_adapter'
2
+ require 'tokyocabinet'
3
+ require 'active_tokyocabinet/tdb'
4
+ require 'active_tokyocabinet/sqlparser.tab'
5
+
6
+ module ActiveRecord
7
+ class Base
8
+ def self.tokyocabinet_connection(config)
9
+ unless config[:database]
10
+ raise ArgumentError, "No database file specified. Missing argument: database"
11
+ end
12
+
13
+ if Object.const_defined?(:RAILS_ROOT)
14
+ config[:database] = File.expand_path(config[:database], RAILS_ROOT)
15
+ end
16
+
17
+ ConnectionAdapters::TokyoCabinetAdapter.new(nil, logger, config)
18
+ end
19
+ end
20
+
21
+ module ConnectionAdapters
22
+ class TokyoCabinetAdapter < AbstractAdapter
23
+ def initialize(connection, logger, config)
24
+ super(connection, logger)
25
+ @config = config
26
+ end
27
+
28
+ def table_exists?(table_name)
29
+ path = tdbpath(table_name)
30
+ File.exist?(path)
31
+ end
32
+
33
+ def select(sql, name = nil)
34
+ rows = []
35
+
36
+ log(sql, name) do
37
+ parsed_sql = ActiveTokyoCabinet::SQLParser.new(sql).parse
38
+
39
+ tdbopen(parsed_sql[:table], TokyoCabinet::TDB::OREADER) do |tdb|
40
+ if (qry = tdbqry(tdb, parsed_sql))
41
+ rkeys = qry.search
42
+ else
43
+ rkeys = [parsed_sql[:condition]].flatten
44
+ end
45
+
46
+ select_list = parsed_sql[:select_list]
47
+
48
+ rkeys.each do |rkey|
49
+ rcols = tdb.get(rkey)
50
+ next if rcols.nil?
51
+
52
+ unless select_list.nil? or select_list.empty?
53
+ rcols = select_list.each {|k| r[k] = rcols[k] }
54
+ end
55
+
56
+ rcols['id'] = rkey
57
+ rows << rcols
58
+ end
59
+ end
60
+
61
+ if (count = parsed_sql[:count])
62
+ rows = [{count => rows.length}]
63
+ end
64
+ end
65
+
66
+ return rows
67
+ end
68
+
69
+ def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
70
+ pkey = nil
71
+
72
+ log(sql, name) do
73
+ parsed_sql = ActiveTokyoCabinet::SQLParser.new(sql).parse
74
+
75
+ tdbopen(parsed_sql[:table], TokyoCabinet::TDB::OWRITER) do |tdb|
76
+ pkey = tdb.genuid
77
+ keys = parsed_sql[:column_list]
78
+ vals = parsed_sql[:value_list]
79
+ cols = {}
80
+
81
+ keys.zip(vals).each do |k, v|
82
+ cols[k] = v.to_s
83
+ end
84
+
85
+ unless tdb.put(pkey, cols)
86
+ ecode = tdb.ecode
87
+ raise '%s: %s' % [tdb.errmsg(ecode), sql]
88
+ end
89
+ end
90
+ end
91
+ return pkey
92
+ end
93
+
94
+ def update_sql(sql, name = nil)
95
+ rownum = 0
96
+
97
+ log(sql, name) do
98
+ parsed_sql = ActiveTokyoCabinet::SQLParser.new(sql).parse
99
+
100
+ tdbopen(parsed_sql[:table], TokyoCabinet::TDB::OWRITER) do |tdb|
101
+ set_clause_list = parsed_sql[:set_clause_list]
102
+
103
+ if (qry = tdbqry(tdb, parsed_sql))
104
+ r = qry.proc do |pkey, cols|
105
+ set_clause_list.each do |k, v|
106
+ cols[k] = v.to_s
107
+ end
108
+
109
+ rownum += 1
110
+ TokyoCabinet::TDBQRY::QPPUT
111
+ end
112
+
113
+ unless r
114
+ ecode = tdb.ecode
115
+ raise '%s: %s' % [tdb.errmsg(ecode), sql]
116
+ end
117
+ else
118
+ [parsed_sql[:condition]].flatten.each do |rkey|
119
+ rcols = tdb.get(rkey)
120
+
121
+ set_clause_list.each do |k, v|
122
+ rcols[k] = v.to_s
123
+ end
124
+
125
+ rownum += 1
126
+
127
+ unless tdb.put(rkey, rcols)
128
+ ecode = tdb.ecode
129
+ raise '%s: %s' % [tdb.errmsg(ecode), sql]
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ return rownum
137
+ end
138
+
139
+ def delete_sql(sql, name = nil) #:nodoc:
140
+ rownum = 0
141
+
142
+ log(sql, name) do
143
+ parsed_sql = ActiveTokyoCabinet::SQLParser.new(sql).parse
144
+
145
+ tdbopen(parsed_sql[:table], TokyoCabinet::TDB::OWRITER) do |tdb|
146
+ set_clause_list = parsed_sql[:set_clause_list]
147
+
148
+ if (qry = tdbqry(tdb, parsed_sql))
149
+ r = qry.proc do |pkey, cols|
150
+ rownum += 1
151
+ TokyoCabinet::TDBQRY::QPOUT
152
+ end
153
+
154
+ unless r
155
+ ecode = tdb.ecode
156
+ raise '%s: %s' % [tdb.errmsg(ecode), sql]
157
+ end
158
+ else
159
+ [parsed_sql[:condition]].flatten.each do |rkey|
160
+ rownum += 1
161
+
162
+ unless tdb.out(rkey)
163
+ ecode = tdb.ecode
164
+ raise '%s: %s' % [tdb.errmsg(ecode), sql]
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ return rownum
172
+ end
173
+
174
+ def tdbopen(table_name, omode)
175
+ tdb = TokyoCabinet::TDB::new
176
+ path = tdbpath(table_name)
177
+
178
+ unless File.exist?(path)
179
+ omode = TokyoCabinet::TDB::OWRITER | TokyoCabinet::TDB::OCREAT
180
+ end
181
+
182
+ unless tdb.open(path, omode)
183
+ ecode = tdb.ecode
184
+ raise "%s: %s" % [tdb.errmsg(ecode), path]
185
+ end
186
+
187
+ begin
188
+ yield(tdb)
189
+ ensure
190
+ unless tdb.close
191
+ ecode = tdb.ecode
192
+ raise tdb.errmsg(ecode)
193
+ end
194
+ end
195
+ end
196
+ private :tdbopen
197
+
198
+ def tdbqry(tdb, parsed_sql)
199
+ condition, order, limit, offset = parsed_sql.values_at(:condition, :order, :limit, :offset)
200
+ condition ||= []
201
+
202
+ unless condition.kind_of?(Array) and condition.all? {|i| i.kind_of?(Hash) }
203
+ return nil
204
+ end
205
+
206
+ qry = TokyoCabinet::TDBQRY::new(tdb)
207
+
208
+ condition.each do |cond|
209
+ name, op, expr = cond.values_at(:name, :op, :expr)
210
+ op = TokyoCabinet::TDBQRY.const_get(op)
211
+ expr = expr.kind_of?(Array) ? expr.join(' ') : expr.to_s
212
+ qry.addcond(name, op, expr)
213
+ end
214
+
215
+ if order
216
+ name, type = order.values_at(:name, :type)
217
+ type = TokyoCabinet::TDBQRY.const_get(type)
218
+ qry.setorder(name, type)
219
+ end
220
+
221
+ if limit or offset
222
+ qry.setlimit(limit || 0, offset || 0)
223
+ end
224
+
225
+ return qry
226
+ end
227
+ private :tdbqry
228
+
229
+ def tdbpath(table_name)
230
+ File.join(@config[:database], table_name + ".tct")
231
+ end
232
+ private :tdbpath
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,734 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.6
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require 'strscan'
11
+
12
+ module ActiveTokyoCabinet
13
+
14
+ class SQLParser < Racc::Parser
15
+
16
+ module_eval(<<'...end sqlparser.y/module_eval...', 'sqlparser.y', 198)
17
+
18
+ def initialize(obj)
19
+ src = obj.is_a?(IO) ? obj.read : obj.to_s
20
+ @ss = StringScanner.new(src)
21
+ end
22
+
23
+ def scan
24
+ piece = nil
25
+
26
+ until @ss.eos?
27
+ if (tok = @ss.scan /\s+/)
28
+ # nothing to do
29
+ elsif (tok = @ss.scan /(?:BW|EW|INCALL|INCANY|INC|IN|EQANY|REGEXP|BETWEEN|FTS|FTSALL|FTSANY|FTSEX)\b/i)
30
+ yield tok.upcase.to_sym, tok
31
+ elsif (tok = @ss.scan /(?:>=|<=|>|<|=)/)
32
+ yield tok, tok
33
+ elsif (tok = @ss.scan /(?:INSERT|INTO|VALUES|SELECT|FROM|WHERE|AND|UPDATE|SET|DELETE|COUNT|ORDER|BY|LIMIT|OFFSET|AS)\b/i)
34
+ yield tok.upcase.to_sym, tok
35
+ elsif (tok = @ss.scan /(?:ASC|DESC|STRASC|STRDESC|NUMASC|NUMDESC)\b/i)
36
+ yield :ORDER, tcordertype(tok)
37
+ elsif (tok = @ss.scan /NULL\b/i)
38
+ yield :NULL, nil
39
+ elsif (tok = @ss.scan /'(?:[^']|'')*'/) #'
40
+ yield :STRING, tok.slice(1...-1).gsub(/''/, "'")
41
+ elsif (tok = @ss.scan /-?(?:0|[1-9]\d*)(?:\.\d+)/)
42
+ yield :NUMBER, tok.to_f
43
+ elsif (tok = @ss.scan /-?(?:0|[1-9]\d*)/)
44
+ yield :NUMBER, tok.to_i
45
+ elsif (tok = @ss.scan /[,\(\)\*]/)
46
+ yield tok, tok
47
+ elsif (tok = @ss.scan /(?:[a-z_][\w]+\.)*ID\b/i)
48
+ yield :ID, tok
49
+ elsif (tok = @ss.scan /(?:[a-z_][\w]+\.)*[a-z_][\w]+/i)
50
+ yield :IDENTIFIER, tok
51
+ else
52
+ raise Racc::ParseError, ('parse error on value "%s"' % @ss.rest.inspect)
53
+ end
54
+ end
55
+
56
+ yield false, '$'
57
+ end
58
+ private :scan
59
+
60
+ def parse
61
+ yyparse self, :scan
62
+ end
63
+
64
+ def tccond(op, expr)
65
+ case op.upcase
66
+ when '='
67
+ expr.kind_of?(Numeric) ? :QCNUMEQ : :QCSTREQ
68
+ when 'INC'
69
+ :QCSTRINC
70
+ when 'BW'
71
+ :QCSTRBW
72
+ when 'EW'
73
+ :QCSTREW
74
+ when 'INCALL'
75
+ :QCSTRAND
76
+ when 'INCANY'
77
+ :QCSTROR
78
+ when 'IN', 'EQANY'
79
+ expr.all? {|i| i.kind_of?(Numeric) } ? :QCNUMOREQ : :QCSTROREQ
80
+ when 'REGEXP'
81
+ :QCSTRRX
82
+ when '>'
83
+ :QCNUMGT
84
+ when '>='
85
+ :QCNUMGE
86
+ when '<'
87
+ :QCNUMLT
88
+ when '<='
89
+ :QCNUMLE
90
+ when 'BETWEEN'
91
+ :QCNUMBT
92
+ when 'FTS'
93
+ :QCFTSPH
94
+ when 'FTSALL'
95
+ :QCFTSAND
96
+ when 'FTSANY'
97
+ :QCFTSOR
98
+ when 'FTSEX'
99
+ :QCFTSEX
100
+ else
101
+ raise 'must not happen'
102
+ end
103
+ end
104
+ private :tccond
105
+
106
+ def tcordertype(type)
107
+ case type.upcase
108
+ when 'ASC', 'STRASC'
109
+ :QOSTRASC
110
+ when 'DESC', 'STRASC'
111
+ :QOSTRASC
112
+ when 'NUMASC'
113
+ :QONUMASC
114
+ when 'NUMDESC'
115
+ :QONUMDESC
116
+ else
117
+ raise 'must not happen'
118
+ end
119
+ end
120
+ private :tcordertype
121
+
122
+ ...end sqlparser.y/module_eval...
123
+ ##### State transition tables begin ###
124
+
125
+ racc_action_table = [
126
+ 72, 75, 34, 62, 63, 26, 10, 10, 34, 54,
127
+ 64, 34, 64, 10, 42, 79, 81, 83, 85, 68,
128
+ 69, 71, 73, 74, 76, 77, 78, 80, 82, 84,
129
+ 67, 96, 10, 2, 10, 47, 64, 37, 9, 94,
130
+ 61, 120, 116, 115, 46, 46, 19, 59, 15, 10,
131
+ 86, 34, 10, 1, 57, 58, 4, 10, 10, 26,
132
+ 114, 114, 114, 10, 59, 10, 59, 32, 59, 10,
133
+ 59, 57, 58, 57, 58, 57, 58, 57, 58, 59,
134
+ 86, 59, 88, 89, 88, 91, 57, 58, 57, 58,
135
+ 28, 93, 27, 43, 95, 25, 10, 100, 101, 23,
136
+ 100, 104, 10, 21, 109, 110, 10, 109, 14, 13,
137
+ 12, 117, 119, 10, 10 ]
138
+
139
+ racc_action_check = [
140
+ 49, 49, 29, 46, 46, 18, 32, 26, 35, 38,
141
+ 64, 40, 86, 42, 29, 49, 49, 49, 49, 49,
142
+ 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
143
+ 49, 70, 64, 0, 86, 34, 47, 27, 0, 65,
144
+ 44, 113, 107, 106, 34, 47, 9, 70, 9, 25,
145
+ 65, 24, 27, 0, 70, 70, 0, 34, 47, 44,
146
+ 113, 107, 106, 9, 96, 28, 93, 22, 43, 21,
147
+ 104, 96, 96, 93, 93, 43, 43, 104, 104, 62,
148
+ 50, 114, 53, 54, 55, 61, 62, 62, 114, 114,
149
+ 20, 63, 19, 31, 66, 16, 14, 87, 88, 13,
150
+ 90, 91, 12, 11, 99, 100, 101, 103, 4, 3,
151
+ 2, 109, 111, 1, 89 ]
152
+
153
+ racc_action_pointer = [
154
+ 31, 87, 107, 109, 100, nil, nil, nil, nil, 37,
155
+ nil, 80, 76, 99, 70, nil, 87, nil, -19, 88,
156
+ 82, 43, 63, nil, 39, 23, -19, 26, 39, -10,
157
+ nil, 79, -20, nil, 31, -4, nil, nil, 4, nil,
158
+ -1, nil, -13, 48, 35, nil, -11, 32, nil, -14,
159
+ 64, nil, nil, 65, 73, 67, nil, nil, nil, nil,
160
+ nil, 79, 59, 87, 6, 34, 89, nil, nil, nil,
161
+ 27, nil, nil, nil, nil, nil, nil, nil, nil, nil,
162
+ nil, nil, nil, nil, nil, nil, 8, 78, 80, 88,
163
+ 81, 97, nil, 46, nil, nil, 44, nil, nil, 83,
164
+ 85, 80, nil, 86, 50, nil, 38, 37, nil, 91,
165
+ nil, 95, nil, 36, 61, nil, nil, nil, nil, nil,
166
+ nil, nil ]
167
+
168
+ racc_action_default = [
169
+ -66, -66, -66, -66, -66, -1, -2, -3, -4, -66,
170
+ -40, -66, -66, -66, -66, -12, -66, -41, -13, -66,
171
+ -66, -66, -66, 122, -14, -66, -66, -66, -66, -14,
172
+ -36, -66, -66, -39, -66, -14, -42, -10, -66, -11,
173
+ -14, -35, -66, -66, -66, -23, -66, -66, -15, -66,
174
+ -16, -17, -21, -27, -8, -27, -37, -43, -45, -44,
175
+ -38, -66, -66, -66, -66, -66, -66, -64, -52, -54,
176
+ -66, -55, -65, -56, -57, -53, -58, -59, -60, -48,
177
+ -61, -49, -62, -50, -63, -51, -66, -31, -66, -66,
178
+ -31, -66, -19, -66, -24, -18, -66, -25, -22, -33,
179
+ -66, -66, -9, -33, -66, -46, -66, -66, -7, -66,
180
+ -32, -29, -6, -66, -66, -20, -26, -34, -28, -30,
181
+ -5, -47 ]
182
+
183
+ racc_goto_table = [
184
+ 11, 30, 60, 51, 50, 18, 106, 33, 17, 107,
185
+ 108, 22, 41, 24, 112, 8, 66, 113, 53, 7,
186
+ 31, 92, 56, 55, 35, 36, 39, 40, 44, 97,
187
+ 99, 17, 87, 103, 90, 16, 38, 48, 20, 6,
188
+ 5, 31, 98, 70, 118, 29, 3, nil, nil, nil,
189
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
190
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
191
+ nil, nil, nil, 121, nil, nil, nil, nil, nil, nil,
192
+ nil, nil, nil, nil, nil, nil, nil, nil, 102, nil,
193
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
194
+ 111 ]
195
+
196
+ racc_goto_check = [
197
+ 6, 25, 19, 18, 17, 7, 8, 10, 6, 8,
198
+ 13, 6, 10, 6, 13, 5, 18, 8, 10, 4,
199
+ 6, 19, 25, 10, 6, 6, 6, 6, 7, 19,
200
+ 12, 6, 11, 12, 11, 14, 15, 16, 9, 3,
201
+ 2, 6, 20, 22, 23, 24, 1, nil, nil, nil,
202
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
203
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
204
+ nil, nil, nil, 19, nil, nil, nil, nil, nil, nil,
205
+ nil, nil, nil, nil, nil, nil, nil, nil, 6, nil,
206
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
207
+ 6 ]
208
+
209
+ racc_goto_pointer = [
210
+ nil, 46, 40, 39, 19, 15, -1, -4, -87, 29,
211
+ -17, -21, -57, -89, 26, 9, 3, -30, -31, -41,
212
+ -44, nil, -6, -67, 24, -20 ]
213
+
214
+ racc_goto_default = [
215
+ nil, nil, nil, nil, nil, nil, 49, nil, nil, nil,
216
+ nil, nil, nil, nil, nil, nil, nil, 65, nil, 105,
217
+ 52, 45, nil, nil, nil, nil ]
218
+
219
+ racc_reduce_table = [
220
+ 0, 0, :racc_error,
221
+ 1, 46, :_reduce_none,
222
+ 1, 46, :_reduce_none,
223
+ 1, 46, :_reduce_none,
224
+ 1, 46, :_reduce_none,
225
+ 10, 47, :_reduce_5,
226
+ 8, 48, :_reduce_6,
227
+ 8, 48, :_reduce_7,
228
+ 4, 59, :_reduce_8,
229
+ 6, 59, :_reduce_9,
230
+ 1, 60, :_reduce_none,
231
+ 1, 60, :_reduce_none,
232
+ 1, 54, :_reduce_12,
233
+ 1, 54, :_reduce_none,
234
+ 0, 55, :_reduce_14,
235
+ 2, 55, :_reduce_15,
236
+ 2, 55, :_reduce_16,
237
+ 1, 61, :_reduce_none,
238
+ 3, 61, :_reduce_18,
239
+ 3, 63, :_reduce_19,
240
+ 5, 63, :_reduce_20,
241
+ 1, 62, :_reduce_21,
242
+ 3, 62, :_reduce_22,
243
+ 1, 65, :_reduce_none,
244
+ 3, 65, :_reduce_24,
245
+ 3, 66, :_reduce_25,
246
+ 5, 66, :_reduce_26,
247
+ 0, 56, :_reduce_27,
248
+ 4, 56, :_reduce_28,
249
+ 0, 68, :_reduce_29,
250
+ 1, 68, :_reduce_none,
251
+ 0, 57, :_reduce_31,
252
+ 2, 57, :_reduce_32,
253
+ 0, 58, :_reduce_33,
254
+ 2, 58, :_reduce_34,
255
+ 5, 49, :_reduce_35,
256
+ 1, 69, :_reduce_none,
257
+ 3, 69, :_reduce_37,
258
+ 3, 70, :_reduce_38,
259
+ 4, 50, :_reduce_39,
260
+ 1, 51, :_reduce_none,
261
+ 1, 52, :_reduce_41,
262
+ 3, 52, :_reduce_42,
263
+ 1, 64, :_reduce_none,
264
+ 1, 64, :_reduce_none,
265
+ 1, 64, :_reduce_none,
266
+ 1, 53, :_reduce_46,
267
+ 3, 53, :_reduce_47,
268
+ 1, 67, :_reduce_none,
269
+ 1, 67, :_reduce_none,
270
+ 1, 67, :_reduce_none,
271
+ 1, 67, :_reduce_none,
272
+ 1, 67, :_reduce_none,
273
+ 1, 67, :_reduce_none,
274
+ 1, 67, :_reduce_none,
275
+ 1, 67, :_reduce_none,
276
+ 1, 67, :_reduce_none,
277
+ 1, 67, :_reduce_none,
278
+ 1, 67, :_reduce_none,
279
+ 1, 67, :_reduce_none,
280
+ 1, 67, :_reduce_none,
281
+ 1, 67, :_reduce_none,
282
+ 1, 67, :_reduce_none,
283
+ 1, 67, :_reduce_none,
284
+ 1, 67, :_reduce_none,
285
+ 1, 67, :_reduce_none ]
286
+
287
+ racc_reduce_n = 66
288
+
289
+ racc_shift_n = 122
290
+
291
+ racc_token_table = {
292
+ false => 0,
293
+ :error => 1,
294
+ :INSERT => 2,
295
+ :INTO => 3,
296
+ "(" => 4,
297
+ ")" => 5,
298
+ :VALUES => 6,
299
+ :SELECT => 7,
300
+ :FROM => 8,
301
+ :COUNT => 9,
302
+ :AS => 10,
303
+ "*" => 11,
304
+ :WHERE => 12,
305
+ :ID => 13,
306
+ "=" => 14,
307
+ :IN => 15,
308
+ :AND => 16,
309
+ :ORDER => 17,
310
+ :BY => 18,
311
+ :LIMIT => 19,
312
+ :NUMBER => 20,
313
+ :OFFSET => 21,
314
+ :UPDATE => 22,
315
+ :SET => 23,
316
+ "," => 24,
317
+ :DELETE => 25,
318
+ :IDENTIFIER => 26,
319
+ :STRING => 27,
320
+ :NULL => 28,
321
+ :BW => 29,
322
+ :EW => 30,
323
+ :INCALL => 31,
324
+ :INCANY => 32,
325
+ :INC => 33,
326
+ :EQANY => 34,
327
+ :REGEXP => 35,
328
+ :BETWEEN => 36,
329
+ :FTS => 37,
330
+ :FTSALL => 38,
331
+ :FTSANY => 39,
332
+ :FTSEX => 40,
333
+ ">=" => 41,
334
+ "<=" => 42,
335
+ ">" => 43,
336
+ "<" => 44 }
337
+
338
+ racc_nt_base = 45
339
+
340
+ racc_use_result_var = false
341
+
342
+ Racc_arg = [
343
+ racc_action_table,
344
+ racc_action_check,
345
+ racc_action_default,
346
+ racc_action_pointer,
347
+ racc_goto_table,
348
+ racc_goto_check,
349
+ racc_goto_default,
350
+ racc_goto_pointer,
351
+ racc_nt_base,
352
+ racc_reduce_table,
353
+ racc_token_table,
354
+ racc_shift_n,
355
+ racc_reduce_n,
356
+ racc_use_result_var ]
357
+
358
+ Racc_token_to_s_table = [
359
+ "$end",
360
+ "error",
361
+ "INSERT",
362
+ "INTO",
363
+ "\"(\"",
364
+ "\")\"",
365
+ "VALUES",
366
+ "SELECT",
367
+ "FROM",
368
+ "COUNT",
369
+ "AS",
370
+ "\"*\"",
371
+ "WHERE",
372
+ "ID",
373
+ "\"=\"",
374
+ "IN",
375
+ "AND",
376
+ "ORDER",
377
+ "BY",
378
+ "LIMIT",
379
+ "NUMBER",
380
+ "OFFSET",
381
+ "UPDATE",
382
+ "SET",
383
+ "\",\"",
384
+ "DELETE",
385
+ "IDENTIFIER",
386
+ "STRING",
387
+ "NULL",
388
+ "BW",
389
+ "EW",
390
+ "INCALL",
391
+ "INCANY",
392
+ "INC",
393
+ "EQANY",
394
+ "REGEXP",
395
+ "BETWEEN",
396
+ "FTS",
397
+ "FTSALL",
398
+ "FTSANY",
399
+ "FTSEX",
400
+ "\">=\"",
401
+ "\"<=\"",
402
+ "\">\"",
403
+ "\"<\"",
404
+ "$start",
405
+ "sql",
406
+ "create_statement",
407
+ "read_statemant",
408
+ "update_statemant",
409
+ "delete_statemant",
410
+ "id",
411
+ "id_list",
412
+ "value_list",
413
+ "select_list",
414
+ "where_clause",
415
+ "order_by_clause",
416
+ "limit_clause",
417
+ "offset_clause",
418
+ "count_clause",
419
+ "count_arg",
420
+ "id_search_condition",
421
+ "search_condition",
422
+ "id_predicate",
423
+ "value",
424
+ "boolean_primary",
425
+ "predicate",
426
+ "op",
427
+ "ordering_spec",
428
+ "set_clause_list",
429
+ "set_clause" ]
430
+
431
+ Racc_debug_parser = false
432
+
433
+ ##### State transition tables end #####
434
+
435
+ # reduce 0 omitted
436
+
437
+ # reduce 1 omitted
438
+
439
+ # reduce 2 omitted
440
+
441
+ # reduce 3 omitted
442
+
443
+ # reduce 4 omitted
444
+
445
+ module_eval(<<'.,.,', 'sqlparser.y', 10)
446
+ def _reduce_5(val, _values)
447
+ {:command => :insert, :table => val[2], :column_list => val[4], :value_list => val[8]}
448
+
449
+ end
450
+ .,.,
451
+
452
+ module_eval(<<'.,.,', 'sqlparser.y', 15)
453
+ def _reduce_6(val, _values)
454
+ {:command => :select, :table => val[3], :select_list => val[1], :condition => val[4], :order => val[5], :limit => val[6], :offset => val[7]}
455
+
456
+ end
457
+ .,.,
458
+
459
+ module_eval(<<'.,.,', 'sqlparser.y', 19)
460
+ def _reduce_7(val, _values)
461
+ {:command => :select, :table => val[3], :count => val[1], :condition => val[4]}
462
+
463
+ end
464
+ .,.,
465
+
466
+ module_eval(<<'.,.,', 'sqlparser.y', 24)
467
+ def _reduce_8(val, _values)
468
+ "count_all"
469
+
470
+ end
471
+ .,.,
472
+
473
+ module_eval(<<'.,.,', 'sqlparser.y', 28)
474
+ def _reduce_9(val, _values)
475
+ val[5]
476
+
477
+ end
478
+ .,.,
479
+
480
+ # reduce 10 omitted
481
+
482
+ # reduce 11 omitted
483
+
484
+ module_eval(<<'.,.,', 'sqlparser.y', 36)
485
+ def _reduce_12(val, _values)
486
+ []
487
+
488
+ end
489
+ .,.,
490
+
491
+ # reduce 13 omitted
492
+
493
+ module_eval(<<'.,.,', 'sqlparser.y', 42)
494
+ def _reduce_14(val, _values)
495
+ []
496
+
497
+ end
498
+ .,.,
499
+
500
+ module_eval(<<'.,.,', 'sqlparser.y', 46)
501
+ def _reduce_15(val, _values)
502
+ val[1]
503
+
504
+ end
505
+ .,.,
506
+
507
+ module_eval(<<'.,.,', 'sqlparser.y', 50)
508
+ def _reduce_16(val, _values)
509
+ val[1]
510
+
511
+ end
512
+ .,.,
513
+
514
+ # reduce 17 omitted
515
+
516
+ module_eval(<<'.,.,', 'sqlparser.y', 56)
517
+ def _reduce_18(val, _values)
518
+ val[1]
519
+
520
+ end
521
+ .,.,
522
+
523
+ module_eval(<<'.,.,', 'sqlparser.y', 61)
524
+ def _reduce_19(val, _values)
525
+ val[2]
526
+
527
+ end
528
+ .,.,
529
+
530
+ module_eval(<<'.,.,', 'sqlparser.y', 65)
531
+ def _reduce_20(val, _values)
532
+ val[3]
533
+
534
+ end
535
+ .,.,
536
+
537
+ module_eval(<<'.,.,', 'sqlparser.y', 70)
538
+ def _reduce_21(val, _values)
539
+ [val[0]].flatten
540
+
541
+ end
542
+ .,.,
543
+
544
+ module_eval(<<'.,.,', 'sqlparser.y', 74)
545
+ def _reduce_22(val, _values)
546
+ (val[0] << val[2]).flatten
547
+
548
+ end
549
+ .,.,
550
+
551
+ # reduce 23 omitted
552
+
553
+ module_eval(<<'.,.,', 'sqlparser.y', 80)
554
+ def _reduce_24(val, _values)
555
+ val[1]
556
+
557
+ end
558
+ .,.,
559
+
560
+ module_eval(<<'.,.,', 'sqlparser.y', 85)
561
+ def _reduce_25(val, _values)
562
+ {:name => val[0], :op => tccond(val[1], val[2]), :expr => val[2]}
563
+
564
+ end
565
+ .,.,
566
+
567
+ module_eval(<<'.,.,', 'sqlparser.y', 89)
568
+ def _reduce_26(val, _values)
569
+ {:name => val[0], :op => tccond(val[1], val[3]), :expr => val[3]}
570
+
571
+ end
572
+ .,.,
573
+
574
+ module_eval(<<'.,.,', 'sqlparser.y', 93)
575
+ def _reduce_27(val, _values)
576
+ nil
577
+
578
+ end
579
+ .,.,
580
+
581
+ module_eval(<<'.,.,', 'sqlparser.y', 97)
582
+ def _reduce_28(val, _values)
583
+ {:name => val[2], :type => val[3]}
584
+
585
+ end
586
+ .,.,
587
+
588
+ module_eval(<<'.,.,', 'sqlparser.y', 102)
589
+ def _reduce_29(val, _values)
590
+ :QOSTRASC
591
+
592
+ end
593
+ .,.,
594
+
595
+ # reduce 30 omitted
596
+
597
+ module_eval(<<'.,.,', 'sqlparser.y', 108)
598
+ def _reduce_31(val, _values)
599
+ nil
600
+
601
+ end
602
+ .,.,
603
+
604
+ module_eval(<<'.,.,', 'sqlparser.y', 112)
605
+ def _reduce_32(val, _values)
606
+ val[1]
607
+
608
+ end
609
+ .,.,
610
+
611
+ module_eval(<<'.,.,', 'sqlparser.y', 117)
612
+ def _reduce_33(val, _values)
613
+ nil
614
+
615
+ end
616
+ .,.,
617
+
618
+ module_eval(<<'.,.,', 'sqlparser.y', 121)
619
+ def _reduce_34(val, _values)
620
+ val[1]
621
+
622
+ end
623
+ .,.,
624
+
625
+ module_eval(<<'.,.,', 'sqlparser.y', 126)
626
+ def _reduce_35(val, _values)
627
+ {:command => :update, :table => val[1], :set_clause_list => val[3], :condition => val[4]}
628
+
629
+ end
630
+ .,.,
631
+
632
+ # reduce 36 omitted
633
+
634
+ module_eval(<<'.,.,', 'sqlparser.y', 132)
635
+ def _reduce_37(val, _values)
636
+ val[0].merge val[2]
637
+
638
+ end
639
+ .,.,
640
+
641
+ module_eval(<<'.,.,', 'sqlparser.y', 137)
642
+ def _reduce_38(val, _values)
643
+ {val[0] => val[2]}
644
+
645
+ end
646
+ .,.,
647
+
648
+ module_eval(<<'.,.,', 'sqlparser.y', 142)
649
+ def _reduce_39(val, _values)
650
+ {:command => :delete, :table => val[2], :condition => val[3]}
651
+
652
+ end
653
+ .,.,
654
+
655
+ # reduce 40 omitted
656
+
657
+ module_eval(<<'.,.,', 'sqlparser.y', 149)
658
+ def _reduce_41(val, _values)
659
+ [val[0]]
660
+
661
+ end
662
+ .,.,
663
+
664
+ module_eval(<<'.,.,', 'sqlparser.y', 153)
665
+ def _reduce_42(val, _values)
666
+ val[0] << val[2]
667
+
668
+ end
669
+ .,.,
670
+
671
+ # reduce 43 omitted
672
+
673
+ # reduce 44 omitted
674
+
675
+ # reduce 45 omitted
676
+
677
+ module_eval(<<'.,.,', 'sqlparser.y', 162)
678
+ def _reduce_46(val, _values)
679
+ [val[0]]
680
+
681
+ end
682
+ .,.,
683
+
684
+ module_eval(<<'.,.,', 'sqlparser.y', 166)
685
+ def _reduce_47(val, _values)
686
+ val[0] << val[2]
687
+
688
+ end
689
+ .,.,
690
+
691
+ # reduce 48 omitted
692
+
693
+ # reduce 49 omitted
694
+
695
+ # reduce 50 omitted
696
+
697
+ # reduce 51 omitted
698
+
699
+ # reduce 52 omitted
700
+
701
+ # reduce 53 omitted
702
+
703
+ # reduce 54 omitted
704
+
705
+ # reduce 55 omitted
706
+
707
+ # reduce 56 omitted
708
+
709
+ # reduce 57 omitted
710
+
711
+ # reduce 58 omitted
712
+
713
+ # reduce 59 omitted
714
+
715
+ # reduce 60 omitted
716
+
717
+ # reduce 61 omitted
718
+
719
+ # reduce 62 omitted
720
+
721
+ # reduce 63 omitted
722
+
723
+ # reduce 64 omitted
724
+
725
+ # reduce 65 omitted
726
+
727
+ def _reduce_none(val, _values)
728
+ val[0]
729
+ end
730
+
731
+ end # class SQLParser
732
+
733
+
734
+ end # module ActiveTokyoCabinet