sdbcli 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -76,16 +76,20 @@ https://bitbucket.org/winebarrel/sdbcli
76
76
  queries using the SELECT statement
77
77
  see http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/UsingSelect.html
78
78
 
79
- NEXT
79
+ N[EXT]
80
80
  displays a continuation of a result
81
81
  (NEXT statement is published after SELECT statement)
82
82
 
83
- CUR[RENT]
83
+ C[URRENT]
84
84
  displays a present result
85
85
  (CURRENT statement is published after SELECT statement)
86
86
 
87
- PAGE number
88
- displays a result of the specified page
87
+ P[REV]
88
+ displays a previous result
89
+ (PREV statement is published after SELECT statement)
90
+
91
+ PAGE [number]
92
+ displays a present page number or displays a result of the specified page
89
93
  (PAGE statement is published after SELECT statement)
90
94
 
91
95
  DESC domain_name
data/bin/sdbcli CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
3
 
4
- Version = '1.4.1'
4
+ Version = '1.4.2'
5
5
  HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
6
6
  HISTSIZE = 500
7
7
  SELECT_LIMIT = 2500
@@ -390,16 +390,20 @@ SELECT output_list FROM domain_name [WHERE expression] [sort_instructions] [LIMI
390
390
  queries using the SELECT statement
391
391
  see http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/UsingSelect.html
392
392
 
393
- NEXT
393
+ N[EXT]
394
394
  displays a continuation of a result
395
395
  (NEXT statement is published after SELECT statement)
396
396
 
397
- CUR[RENT]
397
+ C[URRENT]
398
398
  displays a present result
399
399
  (CURRENT statement is published after SELECT statement)
400
400
 
401
- PAGE number
402
- displays a result of the specified page
401
+ P[REV]
402
+ displays a previous result
403
+ (PREV statement is published after SELECT statement)
404
+
405
+ PAGE [number]
406
+ displays a present page number or displays a result of the specified page
403
407
  (PAGE statement is published after SELECT statement)
404
408
 
405
409
  DESC domain_name
@@ -15,6 +15,7 @@ module SimpleDB
15
15
  @select_expr = nil
16
16
  @next_token = nil
17
17
  @current_token = nil
18
+ @current_page = 1
18
19
  end
19
20
 
20
21
  def endpoint
@@ -124,6 +125,7 @@ module SimpleDB
124
125
  @select_expr = expr
125
126
  @current_token = nil
126
127
  @next_token = token
128
+ @current_page = 1
127
129
  end
128
130
 
129
131
  return items
@@ -145,6 +147,7 @@ module SimpleDB
145
147
 
146
148
  @current_token = @next_token
147
149
  @next_token = token
150
+ @current_page += 1
148
151
 
149
152
  return items
150
153
  end
@@ -202,10 +205,52 @@ module SimpleDB
202
205
 
203
206
  @current_token = token
204
207
  @next_token = new_token
208
+ @current_page = page
205
209
 
206
210
  return items
207
211
  end
208
212
 
213
+ def prev_list(consistent = false)
214
+ unless @select_expr and @current_page > 1
215
+ return []
216
+ end
217
+
218
+ ss = StringScanner.new(@select_expr.dup)
219
+ limit = 100
220
+
221
+ until ss.eos?
222
+ if ss.scan(/[^`'"L]+/i) #'
223
+ elsif ss.scan( /`(?:[^`]|``)*`/)
224
+ elsif ss.scan(/'(?:[^']|'')*'/) #'
225
+ elsif ss.scan(/"(?:[^"]|"")*"/) #"
226
+ elsif (tok = ss.scan /LIMIT\s+\d\b/i)
227
+ limit = tok.split(/\s+/).last.to_i
228
+ elsif ss.scan(/./)
229
+ end
230
+ end
231
+
232
+ params = {:SelectExpression => @select_expr, :ConsistentRead => consistent}
233
+ items = []
234
+
235
+ token = (@current_page > 2) ? SimpleDB::TokenGenerator.next_token(limit, @current_page - 1) : :first
236
+
237
+ new_token = iterate(:select, params, token) do |doc|
238
+ doc.css('Item').map do |i|
239
+ items << [i.at_css('Name').content, attrs_to_hash(i)]
240
+ end
241
+ end
242
+
243
+ @current_token = token
244
+ @next_token = new_token
245
+ @current_page -= 1
246
+
247
+ return items
248
+ end
249
+
250
+ def current_page
251
+ @current_page
252
+ end
253
+
209
254
  def delete(domain_name, items = {})
210
255
  until (chunk = items.slice!(0, MAX_NUMBER_SUBMITTED_ITEMS)).empty?
211
256
  params = {}
@@ -13,7 +13,7 @@ module SimpleDB
13
13
 
14
14
  class Parser < Racc::Parser
15
15
 
16
- module_eval(<<'...end sdb-parser.y/module_eval...', 'sdb-parser.y', 274)
16
+ module_eval(<<'...end sdb-parser.y/module_eval...', 'sdb-parser.y', 282)
17
17
 
18
18
  KEYWORDS = %w(
19
19
  ADD
@@ -88,11 +88,13 @@ def scan
88
88
  yield [tok.upcase.to_sym, tok]
89
89
  elsif (tok = @ss.scan /SELECT\b/i)
90
90
  yield [:SELECT, tok + @ss.scan(/.*/)]
91
- elsif (tok = @ss.scan /NEXT\b/i)
91
+ elsif (tok = @ss.scan /N(EXT)?\b/i)
92
92
  yield [:NEXT, @ss.scan(/\s*\|\s*.*/)]
93
- elsif (tok = @ss.scan /CUR(RENT)?\b/i)
93
+ elsif (tok = @ss.scan /C(URRENT)?\b/i)
94
94
  yield [:CURRENT, @ss.scan(/\s*\|\s*.*/)]
95
- elsif (tok = @ss.scan /PAGE\s+\d+/i)
95
+ elsif (tok = @ss.scan /P(REV)?\b/i)
96
+ yield [:PREV, @ss.scan(/\s*\|\s*.*/)]
97
+ elsif (tok = @ss.scan /PAGE(\s+\d+)?/i)
96
98
  yield [:PAGE, tok + @ss.scan(/(\s*\|\s*.*)?/)]
97
99
  elsif (tok = @ss.scan /NULL\b/i)
98
100
  yield [:NULL, nil]
@@ -137,148 +139,150 @@ end
137
139
  ##### State transition tables begin ###
138
140
 
139
141
  racc_action_table = [
140
- 16, 9, 73, 70, 17, 69, 35, 68, 71, 71,
141
- 33, 69, 31, 68, 18, 81, 82, 19, 81, 82,
142
- 20, 21, 22, 23, 24, 56, 25, 26, 27, 42,
143
- 43, 28, 29, 30, 81, 82, 81, 82, 101, 102,
144
- 81, 82, 106, 102, 81, 82, 77, 78, 51, 52,
145
- 81, 82, 81, 82, 63, 64, 57, 58, 61, 61,
146
- 54, 65, 49, 53, 72, 55, 74, 75, 76, 50,
147
- 79, 61, 49, 84, 85, 86, 87, 48, 89, 90,
148
- 91, 47, 93, 46, 45, 44, 41, 100, 40, 103,
149
- 35, 37, 36 ]
142
+ 17, 10, 75, 72, 18, 71, 37, 70, 73, 73,
143
+ 35, 71, 33, 70, 19, 83, 84, 20, 83, 84,
144
+ 21, 22, 23, 24, 25, 26, 58, 27, 28, 29,
145
+ 44, 45, 30, 31, 32, 83, 84, 83, 84, 103,
146
+ 104, 83, 84, 108, 104, 83, 84, 79, 80, 53,
147
+ 54, 83, 84, 83, 84, 65, 66, 59, 60, 63,
148
+ 63, 56, 67, 51, 55, 74, 57, 76, 77, 78,
149
+ 52, 81, 63, 51, 86, 87, 88, 89, 50, 91,
150
+ 92, 93, 49, 95, 48, 47, 46, 43, 102, 42,
151
+ 105, 37, 39, 38 ]
150
152
 
151
153
  racc_action_check = [
152
- 0, 0, 62, 59, 0, 58, 17, 58, 62, 59,
153
- 17, 78, 1, 78, 0, 89, 89, 0, 93, 93,
154
- 0, 0, 0, 0, 0, 48, 0, 0, 0, 27,
155
- 27, 0, 0, 0, 91, 91, 90, 90, 98, 98,
156
- 86, 86, 105, 105, 72, 72, 66, 66, 37, 37,
157
- 102, 102, 103, 103, 53, 53, 49, 50, 51, 52,
158
- 40, 56, 39, 38, 61, 41, 63, 64, 65, 36,
159
- 70, 71, 34, 73, 74, 76, 77, 32, 79, 84,
160
- 85, 31, 87, 30, 29, 28, 26, 94, 24, 100,
161
- 20, 19, 18 ]
154
+ 0, 0, 64, 61, 0, 60, 18, 60, 64, 61,
155
+ 18, 80, 1, 80, 0, 91, 91, 0, 95, 95,
156
+ 0, 0, 0, 0, 0, 0, 50, 0, 0, 0,
157
+ 29, 29, 0, 0, 0, 93, 93, 92, 92, 100,
158
+ 100, 88, 88, 107, 107, 74, 74, 68, 68, 39,
159
+ 39, 104, 104, 105, 105, 55, 55, 51, 52, 53,
160
+ 54, 42, 58, 41, 40, 63, 43, 65, 66, 67,
161
+ 38, 72, 73, 36, 75, 76, 78, 79, 34, 81,
162
+ 86, 87, 33, 89, 32, 31, 30, 28, 96, 26,
163
+ 102, 21, 20, 19 ]
162
164
 
163
165
  racc_action_pointer = [
164
166
  -1, 12, nil, nil, nil, nil, nil, nil, nil, nil,
165
- nil, nil, nil, nil, nil, nil, nil, -1, 76, 84,
166
- 83, nil, nil, nil, 62, nil, 60, -1, 78, 77,
167
- 76, 81, 71, nil, 58, nil, 62, 29, 57, 48,
168
- 53, 58, nil, nil, nil, nil, nil, nil, 18, 49,
169
- 45, 51, 52, 47, nil, nil, 53, nil, -2, -5,
170
- nil, 54, -6, 58, 58, 59, 33, nil, nil, nil,
171
- 61, 64, 41, 64, 65, nil, 65, 59, 4, 68,
172
- nil, nil, nil, nil, 69, 70, 37, 70, nil, 12,
173
- 33, 31, nil, 15, 73, nil, nil, nil, 25, nil,
174
- 77, nil, 47, 49, nil, 29, nil ]
167
+ nil, nil, nil, nil, nil, nil, nil, nil, -1, 77,
168
+ 85, 84, nil, nil, nil, nil, 62, nil, 60, -1,
169
+ 79, 78, 77, 82, 72, nil, 59, nil, 63, 30,
170
+ 58, 49, 54, 59, nil, nil, nil, nil, nil, nil,
171
+ 19, 50, 46, 52, 53, 48, nil, nil, 54, nil,
172
+ -2, -5, nil, 55, -6, 59, 59, 60, 34, nil,
173
+ nil, nil, 62, 65, 42, 65, 66, nil, 66, 60,
174
+ 4, 69, nil, nil, nil, nil, 70, 71, 38, 71,
175
+ nil, 12, 34, 32, nil, 15, 74, nil, nil, nil,
176
+ 26, nil, 78, nil, 48, 50, nil, 30, nil ]
175
177
 
176
178
  racc_action_default = [
177
- -61, -61, -1, -2, -3, -4, -5, -6, -7, -8,
178
- -9, -10, -11, -12, -13, -14, -15, -19, -61, -61,
179
- -44, -46, -47, -48, -61, -50, -61, -61, -61, -61,
180
- -61, -61, -61, -20, -21, -57, -61, -61, -61, -45,
181
- -61, -61, -52, -53, -54, -55, -56, 107, -61, -61,
182
- -61, -61, -61, -61, -49, -51, -61, -58, -61, -30,
183
- -37, -61, -34, -41, -42, -61, -61, -25, -27, -28,
184
- -31, -61, -61, -35, -61, -43, -61, -61, -61, -32,
185
- -38, -16, -17, -39, -36, -61, -61, -61, -26, -61,
186
- -61, -61, -18, -61, -24, -29, -33, -40, -61, -59,
187
- -61, -22, -61, -61, -60, -61, -23 ]
179
+ -63, -63, -1, -2, -3, -4, -5, -6, -7, -8,
180
+ -9, -10, -11, -12, -13, -14, -15, -16, -20, -63,
181
+ -63, -45, -47, -48, -49, -50, -63, -52, -63, -63,
182
+ -63, -63, -63, -63, -63, -21, -22, -59, -63, -63,
183
+ -63, -46, -63, -63, -54, -55, -56, -57, -58, 109,
184
+ -63, -63, -63, -63, -63, -63, -51, -53, -63, -60,
185
+ -63, -31, -38, -63, -35, -42, -43, -63, -63, -26,
186
+ -28, -29, -32, -63, -63, -36, -63, -44, -63, -63,
187
+ -63, -33, -39, -17, -18, -40, -37, -63, -63, -63,
188
+ -27, -63, -63, -63, -19, -63, -25, -30, -34, -41,
189
+ -63, -61, -63, -23, -63, -63, -62, -63, -24 ]
188
190
 
189
191
  racc_goto_table = [
190
- 83, 67, 98, 34, 59, 62, 39, 14, 7, 8,
191
- 10, 11, 105, 12, 92, 13, 6, 95, 96, 97,
192
- 15, 88, 1, 32, 5, 94, 4, 66, 3, 2,
193
- 104, 80, 38 ]
192
+ 85, 69, 100, 36, 61, 64, 41, 14, 7, 8,
193
+ 9, 11, 107, 12, 94, 13, 6, 97, 98, 99,
194
+ 15, 90, 16, 1, 34, 5, 96, 4, 68, 3,
195
+ 106, 2, 82, 40 ]
194
196
 
195
197
  racc_goto_check = [
196
- 15, 21, 19, 17, 22, 22, 17, 13, 7, 8,
197
- 9, 10, 19, 11, 15, 12, 6, 15, 15, 15,
198
- 14, 21, 1, 16, 5, 18, 4, 20, 3, 2,
199
- 15, 23, 24 ]
198
+ 16, 22, 20, 18, 23, 23, 18, 13, 7, 8,
199
+ 9, 10, 20, 11, 16, 12, 6, 16, 16, 16,
200
+ 14, 22, 15, 1, 17, 5, 19, 4, 21, 3,
201
+ 16, 2, 24, 25 ]
200
202
 
201
203
  racc_goto_pointer = [
202
- nil, 22, 29, 28, 26, 24, 16, 8, 9, 10,
203
- 11, 13, 15, 7, 20, -72, 6, -14, -62, -91,
204
- -31, -57, -47, -40, 12 ]
204
+ nil, 23, 31, 29, 27, 25, 16, 8, 9, 10,
205
+ 11, 13, 15, 7, 20, 22, -74, 6, -15, -63,
206
+ -93, -32, -59, -49, -41, 12 ]
205
207
 
206
208
  racc_goto_default = [
207
209
  nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
208
- nil, nil, nil, nil, nil, 99, nil, nil, nil, nil,
209
- nil, nil, nil, 60, nil ]
210
+ nil, nil, nil, nil, nil, nil, 101, nil, nil, nil,
211
+ nil, nil, nil, nil, 62, nil ]
210
212
 
211
213
  racc_reduce_table = [
212
214
  0, 0, :racc_error,
213
- 1, 36, :_reduce_none,
214
- 1, 36, :_reduce_none,
215
- 1, 36, :_reduce_none,
216
- 1, 36, :_reduce_none,
217
- 1, 36, :_reduce_none,
218
- 1, 36, :_reduce_none,
219
- 1, 36, :_reduce_none,
220
- 1, 36, :_reduce_none,
221
- 1, 36, :_reduce_none,
222
- 1, 36, :_reduce_none,
223
- 1, 36, :_reduce_none,
224
- 1, 36, :_reduce_none,
225
- 1, 36, :_reduce_none,
226
- 1, 36, :_reduce_none,
227
- 1, 36, :_reduce_15,
228
- 1, 50, :_reduce_none,
229
- 1, 50, :_reduce_none,
230
- 8, 37, :_reduce_18,
231
- 0, 51, :_reduce_19,
232
- 1, 51, :_reduce_20,
233
- 1, 51, :_reduce_none,
234
- 3, 53, :_reduce_22,
235
- 5, 53, :_reduce_23,
236
- 8, 38, :_reduce_24,
237
- 1, 55, :_reduce_25,
238
- 3, 55, :_reduce_26,
239
- 1, 56, :_reduce_none,
240
- 1, 56, :_reduce_none,
241
- 8, 39, :_reduce_29,
242
- 4, 39, :_reduce_30,
243
- 5, 39, :_reduce_31,
244
- 6, 39, :_reduce_32,
245
- 8, 40, :_reduce_33,
246
- 4, 40, :_reduce_34,
247
- 5, 40, :_reduce_35,
248
- 6, 40, :_reduce_36,
249
- 1, 57, :_reduce_37,
250
- 3, 57, :_reduce_38,
251
- 3, 58, :_reduce_39,
252
- 8, 41, :_reduce_40,
253
- 4, 41, :_reduce_41,
254
- 4, 41, :_reduce_42,
255
- 5, 41, :_reduce_43,
256
- 0, 59, :_reduce_44,
257
- 1, 59, :_reduce_none,
258
- 1, 42, :_reduce_46,
215
+ 1, 37, :_reduce_none,
216
+ 1, 37, :_reduce_none,
217
+ 1, 37, :_reduce_none,
218
+ 1, 37, :_reduce_none,
219
+ 1, 37, :_reduce_none,
220
+ 1, 37, :_reduce_none,
221
+ 1, 37, :_reduce_none,
222
+ 1, 37, :_reduce_none,
223
+ 1, 37, :_reduce_none,
224
+ 1, 37, :_reduce_none,
225
+ 1, 37, :_reduce_none,
226
+ 1, 37, :_reduce_none,
227
+ 1, 37, :_reduce_none,
228
+ 1, 37, :_reduce_none,
229
+ 1, 37, :_reduce_none,
230
+ 1, 37, :_reduce_16,
231
+ 1, 52, :_reduce_none,
232
+ 1, 52, :_reduce_none,
233
+ 8, 38, :_reduce_19,
234
+ 0, 53, :_reduce_20,
235
+ 1, 53, :_reduce_21,
236
+ 1, 53, :_reduce_none,
237
+ 3, 55, :_reduce_23,
238
+ 5, 55, :_reduce_24,
239
+ 8, 39, :_reduce_25,
240
+ 1, 57, :_reduce_26,
241
+ 3, 57, :_reduce_27,
242
+ 1, 58, :_reduce_none,
243
+ 1, 58, :_reduce_none,
244
+ 8, 40, :_reduce_30,
245
+ 4, 40, :_reduce_31,
246
+ 5, 40, :_reduce_32,
247
+ 6, 40, :_reduce_33,
248
+ 8, 41, :_reduce_34,
249
+ 4, 41, :_reduce_35,
250
+ 5, 41, :_reduce_36,
251
+ 6, 41, :_reduce_37,
252
+ 1, 59, :_reduce_38,
253
+ 3, 59, :_reduce_39,
254
+ 3, 60, :_reduce_40,
255
+ 8, 42, :_reduce_41,
256
+ 4, 42, :_reduce_42,
257
+ 4, 42, :_reduce_43,
258
+ 5, 42, :_reduce_44,
259
+ 0, 61, :_reduce_45,
260
+ 1, 61, :_reduce_none,
259
261
  1, 43, :_reduce_47,
260
- 1, 43, :_reduce_48,
261
- 3, 45, :_reduce_49,
262
+ 1, 44, :_reduce_48,
263
+ 1, 45, :_reduce_49,
262
264
  1, 44, :_reduce_50,
263
- 3, 46, :_reduce_51,
264
- 2, 47, :_reduce_52,
265
- 2, 47, :_reduce_53,
266
- 2, 48, :_reduce_54,
265
+ 3, 47, :_reduce_51,
266
+ 1, 46, :_reduce_52,
267
+ 3, 48, :_reduce_53,
268
+ 2, 49, :_reduce_54,
267
269
  2, 49, :_reduce_55,
268
- 2, 49, :_reduce_56,
269
- 1, 52, :_reduce_57,
270
- 3, 52, :_reduce_58,
270
+ 2, 50, :_reduce_56,
271
+ 2, 51, :_reduce_57,
272
+ 2, 51, :_reduce_58,
271
273
  1, 54, :_reduce_59,
272
- 3, 54, :_reduce_60 ]
274
+ 3, 54, :_reduce_60,
275
+ 1, 56, :_reduce_61,
276
+ 3, 56, :_reduce_62 ]
273
277
 
274
- racc_reduce_n = 61
278
+ racc_reduce_n = 63
275
279
 
276
- racc_shift_n = 107
280
+ racc_shift_n = 109
277
281
 
278
282
  racc_token_table = {
279
283
  false => 0,
280
284
  :error => 1,
281
- :current_stmt => 2,
285
+ :prev_stmt => 2,
282
286
  :STRING => 3,
283
287
  :NUMBER => 4,
284
288
  :GET => 5,
@@ -301,18 +305,19 @@ racc_token_table = {
301
305
  :SELECT => 22,
302
306
  :NEXT => 23,
303
307
  :CURRENT => 24,
304
- :CREATE => 25,
305
- :DOMAIN => 26,
306
- :PAGE => 27,
307
- :DROP => 28,
308
- :SHOW => 29,
309
- :DOMAINS => 30,
310
- :REGIONS => 31,
311
- :USE => 32,
312
- :DESC => 33,
313
- :DESCRIBE => 34 }
314
-
315
- racc_nt_base = 35
308
+ :PREV => 25,
309
+ :CREATE => 26,
310
+ :DOMAIN => 27,
311
+ :PAGE => 28,
312
+ :DROP => 29,
313
+ :SHOW => 30,
314
+ :DOMAINS => 31,
315
+ :REGIONS => 32,
316
+ :USE => 33,
317
+ :DESC => 34,
318
+ :DESCRIBE => 35 }
319
+
320
+ racc_nt_base = 36
316
321
 
317
322
  racc_use_result_var = false
318
323
 
@@ -335,7 +340,7 @@ Racc_arg = [
335
340
  Racc_token_to_s_table = [
336
341
  "$end",
337
342
  "error",
338
- "current_stmt",
343
+ "prev_stmt",
339
344
  "STRING",
340
345
  "NUMBER",
341
346
  "GET",
@@ -358,6 +363,7 @@ Racc_token_to_s_table = [
358
363
  "SELECT",
359
364
  "NEXT",
360
365
  "CURRENT",
366
+ "PREV",
361
367
  "CREATE",
362
368
  "DOMAIN",
363
369
  "PAGE",
@@ -377,6 +383,7 @@ Racc_token_to_s_table = [
377
383
  "delete_stmt",
378
384
  "select_stmt",
379
385
  "next_stmt",
386
+ "current_stmt",
380
387
  "page_stmt",
381
388
  "create_stmt",
382
389
  "drop_stmt",
@@ -428,56 +435,58 @@ Racc_debug_parser = false
428
435
 
429
436
  # reduce 14 omitted
430
437
 
431
- module_eval(<<'.,.,', 'sdb-parser.y', 19)
432
- def _reduce_15(val, _values)
438
+ # reduce 15 omitted
439
+
440
+ module_eval(<<'.,.,', 'sdb-parser.y', 20)
441
+ def _reduce_16(val, _values)
433
442
  @stmt_with_expr
434
443
 
435
444
  end
436
445
  .,.,
437
446
 
438
- # reduce 16 omitted
439
-
440
447
  # reduce 17 omitted
441
448
 
442
- module_eval(<<'.,.,', 'sdb-parser.y', 27)
443
- def _reduce_18(val, _values)
449
+ # reduce 18 omitted
450
+
451
+ module_eval(<<'.,.,', 'sdb-parser.y', 28)
452
+ def _reduce_19(val, _values)
444
453
  struct(:GET, :domain => val[3], :item_name => val[7], :attr_names => val[1])
445
454
 
446
455
  end
447
456
  .,.,
448
457
 
449
- module_eval(<<'.,.,', 'sdb-parser.y', 32)
450
- def _reduce_19(val, _values)
458
+ module_eval(<<'.,.,', 'sdb-parser.y', 33)
459
+ def _reduce_20(val, _values)
451
460
  []
452
461
 
453
462
  end
454
463
  .,.,
455
464
 
456
- module_eval(<<'.,.,', 'sdb-parser.y', 36)
457
- def _reduce_20(val, _values)
465
+ module_eval(<<'.,.,', 'sdb-parser.y', 37)
466
+ def _reduce_21(val, _values)
458
467
  []
459
468
 
460
469
  end
461
470
  .,.,
462
471
 
463
- # reduce 21 omitted
472
+ # reduce 22 omitted
464
473
 
465
- module_eval(<<'.,.,', 'sdb-parser.y', 42)
466
- def _reduce_22(val, _values)
474
+ module_eval(<<'.,.,', 'sdb-parser.y', 43)
475
+ def _reduce_23(val, _values)
467
476
  [val[1]]
468
477
 
469
478
  end
470
479
  .,.,
471
480
 
472
- module_eval(<<'.,.,', 'sdb-parser.y', 46)
473
- def _reduce_23(val, _values)
481
+ module_eval(<<'.,.,', 'sdb-parser.y', 47)
482
+ def _reduce_24(val, _values)
474
483
  val[0] + [val[3]]
475
484
 
476
485
  end
477
486
  .,.,
478
487
 
479
- module_eval(<<'.,.,', 'sdb-parser.y', 51)
480
- def _reduce_24(val, _values)
488
+ module_eval(<<'.,.,', 'sdb-parser.y', 52)
489
+ def _reduce_25(val, _values)
481
490
  items = val[7].map do |vals|
482
491
  unless val[4].length == vals.length
483
492
  raise Racc::ParseError, 'The number of an attribute and values differs'
@@ -502,26 +511,26 @@ module_eval(<<'.,.,', 'sdb-parser.y', 51)
502
511
  end
503
512
  .,.,
504
513
 
505
- module_eval(<<'.,.,', 'sdb-parser.y', 75)
506
- def _reduce_25(val, _values)
514
+ module_eval(<<'.,.,', 'sdb-parser.y', 76)
515
+ def _reduce_26(val, _values)
507
516
  [val[0]]
508
517
 
509
518
  end
510
519
  .,.,
511
520
 
512
- module_eval(<<'.,.,', 'sdb-parser.y', 79)
513
- def _reduce_26(val, _values)
521
+ module_eval(<<'.,.,', 'sdb-parser.y', 80)
522
+ def _reduce_27(val, _values)
514
523
  val[0] + [val[2]]
515
524
 
516
525
  end
517
526
  .,.,
518
527
 
519
- # reduce 27 omitted
520
-
521
528
  # reduce 28 omitted
522
529
 
523
- module_eval(<<'.,.,', 'sdb-parser.y', 87)
524
- def _reduce_29(val, _values)
530
+ # reduce 29 omitted
531
+
532
+ module_eval(<<'.,.,', 'sdb-parser.y', 88)
533
+ def _reduce_30(val, _values)
525
534
  attrs = {}
526
535
  val[3].each {|k, v| attrs[k] = v }
527
536
  struct(:UPDATE, :domain => val[1], :items => [[val[7], attrs]])
@@ -529,8 +538,8 @@ module_eval(<<'.,.,', 'sdb-parser.y', 87)
529
538
  end
530
539
  .,.,
531
540
 
532
- module_eval(<<'.,.,', 'sdb-parser.y', 93)
533
- def _reduce_30(val, _values)
541
+ module_eval(<<'.,.,', 'sdb-parser.y', 94)
542
+ def _reduce_31(val, _values)
534
543
  attrs = {}
535
544
  val[3].each {|k, v| attrs[k] = v }
536
545
  @stmt_with_expr = struct(:UPDATE_WITH_EXPR, :domain => val[1], :attrs => attrs, :expr => '')
@@ -538,8 +547,8 @@ module_eval(<<'.,.,', 'sdb-parser.y', 93)
538
547
  end
539
548
  .,.,
540
549
 
541
- module_eval(<<'.,.,', 'sdb-parser.y', 99)
542
- def _reduce_31(val, _values)
550
+ module_eval(<<'.,.,', 'sdb-parser.y', 100)
551
+ def _reduce_32(val, _values)
543
552
  attrs = {}
544
553
  val[3].each {|k, v| attrs[k] = v }
545
554
  @stmt_with_expr = struct(:UPDATE_WITH_EXPR, :domain => val[1], :attrs => attrs, :expr => 'WHERE ')
@@ -547,8 +556,8 @@ module_eval(<<'.,.,', 'sdb-parser.y', 99)
547
556
  end
548
557
  .,.,
549
558
 
550
- module_eval(<<'.,.,', 'sdb-parser.y', 105)
551
- def _reduce_32(val, _values)
559
+ module_eval(<<'.,.,', 'sdb-parser.y', 106)
560
+ def _reduce_33(val, _values)
552
561
  attrs = {}
553
562
  val[3].each {|k, v| attrs[k] = v }
554
563
  @stmt_with_expr = struct(:UPDATE_WITH_EXPR, :domain => val[1], :attrs => attrs, :expr => 'WHERE itemName')
@@ -556,8 +565,8 @@ module_eval(<<'.,.,', 'sdb-parser.y', 105)
556
565
  end
557
566
  .,.,
558
567
 
559
- module_eval(<<'.,.,', 'sdb-parser.y', 112)
560
- def _reduce_33(val, _values)
568
+ module_eval(<<'.,.,', 'sdb-parser.y', 113)
569
+ def _reduce_34(val, _values)
561
570
  attrs = {}
562
571
  val[3].each {|k, v| attrs[k] = v }
563
572
  struct(:MERGE, :domain => val[1], :items => [[val[7], attrs]])
@@ -565,8 +574,8 @@ module_eval(<<'.,.,', 'sdb-parser.y', 112)
565
574
  end
566
575
  .,.,
567
576
 
568
- module_eval(<<'.,.,', 'sdb-parser.y', 118)
569
- def _reduce_34(val, _values)
577
+ module_eval(<<'.,.,', 'sdb-parser.y', 119)
578
+ def _reduce_35(val, _values)
570
579
  attrs = {}
571
580
  val[3].each {|k, v| attrs[k] = v }
572
581
  @stmt_with_expr = struct(:MERGE_WITH_EXPR, :domain => val[1], :attrs => attrs, :expr => '')
@@ -574,8 +583,8 @@ module_eval(<<'.,.,', 'sdb-parser.y', 118)
574
583
  end
575
584
  .,.,
576
585
 
577
- module_eval(<<'.,.,', 'sdb-parser.y', 124)
578
- def _reduce_35(val, _values)
586
+ module_eval(<<'.,.,', 'sdb-parser.y', 125)
587
+ def _reduce_36(val, _values)
579
588
  attrs = {}
580
589
  val[3].each {|k, v| attrs[k] = v }
581
590
  @stmt_with_expr = struct(:MERGE_WITH_EXPR, :domain => val[1], :attrs => attrs, :expr => 'WHERE ')
@@ -583,8 +592,8 @@ module_eval(<<'.,.,', 'sdb-parser.y', 124)
583
592
  end
584
593
  .,.,
585
594
 
586
- module_eval(<<'.,.,', 'sdb-parser.y', 130)
587
- def _reduce_36(val, _values)
595
+ module_eval(<<'.,.,', 'sdb-parser.y', 131)
596
+ def _reduce_37(val, _values)
588
597
  attrs = {}
589
598
  val[3].each {|k, v| attrs[k] = v }
590
599
  @stmt_with_expr = struct(:MERGE_WITH_EXPR, :domain => val[1], :attrs => attrs, :expr => 'WHERE itemName')
@@ -592,66 +601,66 @@ module_eval(<<'.,.,', 'sdb-parser.y', 130)
592
601
  end
593
602
  .,.,
594
603
 
595
- module_eval(<<'.,.,', 'sdb-parser.y', 137)
596
- def _reduce_37(val, _values)
604
+ module_eval(<<'.,.,', 'sdb-parser.y', 138)
605
+ def _reduce_38(val, _values)
597
606
  [val[0]]
598
607
 
599
608
  end
600
609
  .,.,
601
610
 
602
- module_eval(<<'.,.,', 'sdb-parser.y', 141)
603
- def _reduce_38(val, _values)
611
+ module_eval(<<'.,.,', 'sdb-parser.y', 142)
612
+ def _reduce_39(val, _values)
604
613
  val[0] + [val[2]]
605
614
 
606
615
  end
607
616
  .,.,
608
617
 
609
- module_eval(<<'.,.,', 'sdb-parser.y', 146)
610
- def _reduce_39(val, _values)
618
+ module_eval(<<'.,.,', 'sdb-parser.y', 147)
619
+ def _reduce_40(val, _values)
611
620
  [val[0], val[2]]
612
621
 
613
622
  end
614
623
  .,.,
615
624
 
616
- module_eval(<<'.,.,', 'sdb-parser.y', 151)
617
- def _reduce_40(val, _values)
625
+ module_eval(<<'.,.,', 'sdb-parser.y', 152)
626
+ def _reduce_41(val, _values)
618
627
  struct(:DELETE, :domain => val[3], :items => [[val[7], val[1]]])
619
628
 
620
629
  end
621
630
  .,.,
622
631
 
623
- module_eval(<<'.,.,', 'sdb-parser.y', 155)
624
- def _reduce_41(val, _values)
632
+ module_eval(<<'.,.,', 'sdb-parser.y', 156)
633
+ def _reduce_42(val, _values)
625
634
  @stmt_with_expr = struct(:DELETE_WITH_EXPR, :domain => val[3], :attrs => val[1], :expr => '')
626
635
 
627
636
  end
628
637
  .,.,
629
638
 
630
- module_eval(<<'.,.,', 'sdb-parser.y', 159)
631
- def _reduce_42(val, _values)
639
+ module_eval(<<'.,.,', 'sdb-parser.y', 160)
640
+ def _reduce_43(val, _values)
632
641
  @stmt_with_expr = struct(:DELETE_WITH_EXPR, :domain => val[3], :attrs => val[1], :expr => 'WHERE ')
633
642
 
634
643
  end
635
644
  .,.,
636
645
 
637
- module_eval(<<'.,.,', 'sdb-parser.y', 163)
638
- def _reduce_43(val, _values)
646
+ module_eval(<<'.,.,', 'sdb-parser.y', 164)
647
+ def _reduce_44(val, _values)
639
648
  @stmt_with_expr = struct(:DELETE_WITH_EXPR, :domain => val[3], :attrs => val[1], :expr => 'WHERE itemName')
640
649
 
641
650
  end
642
651
  .,.,
643
652
 
644
- module_eval(<<'.,.,', 'sdb-parser.y', 168)
645
- def _reduce_44(val, _values)
653
+ module_eval(<<'.,.,', 'sdb-parser.y', 169)
654
+ def _reduce_45(val, _values)
646
655
  []
647
656
 
648
657
  end
649
658
  .,.,
650
659
 
651
- # reduce 45 omitted
660
+ # reduce 46 omitted
652
661
 
653
- module_eval(<<'.,.,', 'sdb-parser.y', 174)
654
- def _reduce_46(val, _values)
662
+ module_eval(<<'.,.,', 'sdb-parser.y', 175)
663
+ def _reduce_47(val, _values)
655
664
  query = ''
656
665
  ruby = nil
657
666
 
@@ -678,103 +687,112 @@ module_eval(<<'.,.,', 'sdb-parser.y', 174)
678
687
  end
679
688
  .,.,
680
689
 
681
- module_eval(<<'.,.,', 'sdb-parser.y', 200)
682
- def _reduce_47(val, _values)
690
+ module_eval(<<'.,.,', 'sdb-parser.y', 201)
691
+ def _reduce_48(val, _values)
683
692
  ruby = val[0].sub(/\A\s*\|\s*/, '') if val[0]
684
693
  struct(:NEXT, :ruby => ruby)
685
694
 
686
695
  end
687
696
  .,.,
688
697
 
689
- module_eval(<<'.,.,', 'sdb-parser.y', 206)
690
- def _reduce_48(val, _values)
698
+ module_eval(<<'.,.,', 'sdb-parser.y', 207)
699
+ def _reduce_49(val, _values)
700
+ ruby = val[0].sub(/\A\s*\|\s*/, '') if val[0]
701
+ struct(:CURRENT, :ruby => ruby)
702
+
703
+ end
704
+ .,.,
705
+
706
+ module_eval(<<'.,.,', 'sdb-parser.y', 213)
707
+ def _reduce_50(val, _values)
691
708
  ruby = val[0].sub(/\A\s*\|\s*/, '') if val[0]
692
- struct(:CURRENT, :ruby => ruby)
709
+ struct(:PREV, :ruby => ruby)
693
710
 
694
711
  end
695
712
  .,.,
696
713
 
697
- module_eval(<<'.,.,', 'sdb-parser.y', 212)
698
- def _reduce_49(val, _values)
714
+ module_eval(<<'.,.,', 'sdb-parser.y', 219)
715
+ def _reduce_51(val, _values)
699
716
  struct(:CREATE, :domain => val[2])
700
717
 
701
718
  end
702
719
  .,.,
703
720
 
704
- module_eval(<<'.,.,', 'sdb-parser.y', 217)
705
- def _reduce_50(val, _values)
721
+ module_eval(<<'.,.,', 'sdb-parser.y', 224)
722
+ def _reduce_52(val, _values)
706
723
  page, ruby = val[0].split(/\s*\|\s*/, 2)
707
- page = page.split(/\s+/, 2).last.strip.to_i
724
+ page = page.split(/\s+/, 2)[1]
725
+ page = page.strip.to_i if page
708
726
  struct(:PAGE, :page => page, :ruby => ruby)
709
727
 
710
728
  end
711
729
  .,.,
712
730
 
713
- module_eval(<<'.,.,', 'sdb-parser.y', 224)
714
- def _reduce_51(val, _values)
731
+ module_eval(<<'.,.,', 'sdb-parser.y', 232)
732
+ def _reduce_53(val, _values)
715
733
  struct(:DROP, :domain => val[2])
716
734
 
717
735
  end
718
736
  .,.,
719
737
 
720
- module_eval(<<'.,.,', 'sdb-parser.y', 229)
721
- def _reduce_52(val, _values)
738
+ module_eval(<<'.,.,', 'sdb-parser.y', 237)
739
+ def _reduce_54(val, _values)
722
740
  struct(:SHOW, :operand => :domains)
723
741
 
724
742
  end
725
743
  .,.,
726
744
 
727
- module_eval(<<'.,.,', 'sdb-parser.y', 233)
728
- def _reduce_53(val, _values)
745
+ module_eval(<<'.,.,', 'sdb-parser.y', 241)
746
+ def _reduce_55(val, _values)
729
747
  struct(:SHOW, :operand => :regions)
730
748
 
731
749
  end
732
750
  .,.,
733
751
 
734
- module_eval(<<'.,.,', 'sdb-parser.y', 237)
735
- def _reduce_54(val, _values)
752
+ module_eval(<<'.,.,', 'sdb-parser.y', 245)
753
+ def _reduce_56(val, _values)
736
754
  struct(:USE, :endpoint => val[1])
737
755
 
738
756
  end
739
757
  .,.,
740
758
 
741
- module_eval(<<'.,.,', 'sdb-parser.y', 241)
742
- def _reduce_55(val, _values)
759
+ module_eval(<<'.,.,', 'sdb-parser.y', 249)
760
+ def _reduce_57(val, _values)
743
761
  struct(:DESCRIBE, :domain => val[1])
744
762
 
745
763
  end
746
764
  .,.,
747
765
 
748
- module_eval(<<'.,.,', 'sdb-parser.y', 245)
749
- def _reduce_56(val, _values)
766
+ module_eval(<<'.,.,', 'sdb-parser.y', 253)
767
+ def _reduce_58(val, _values)
750
768
  struct(:DESCRIBE, :domain => val[1])
751
769
 
752
770
  end
753
771
  .,.,
754
772
 
755
- module_eval(<<'.,.,', 'sdb-parser.y', 250)
756
- def _reduce_57(val, _values)
773
+ module_eval(<<'.,.,', 'sdb-parser.y', 258)
774
+ def _reduce_59(val, _values)
757
775
  [val[0]]
758
776
 
759
777
  end
760
778
  .,.,
761
779
 
762
- module_eval(<<'.,.,', 'sdb-parser.y', 254)
763
- def _reduce_58(val, _values)
780
+ module_eval(<<'.,.,', 'sdb-parser.y', 262)
781
+ def _reduce_60(val, _values)
764
782
  val[0] + [val[2]]
765
783
 
766
784
  end
767
785
  .,.,
768
786
 
769
- module_eval(<<'.,.,', 'sdb-parser.y', 259)
770
- def _reduce_59(val, _values)
787
+ module_eval(<<'.,.,', 'sdb-parser.y', 267)
788
+ def _reduce_61(val, _values)
771
789
  [val[0]]
772
790
 
773
791
  end
774
792
  .,.,
775
793
 
776
- module_eval(<<'.,.,', 'sdb-parser.y', 263)
777
- def _reduce_60(val, _values)
794
+ module_eval(<<'.,.,', 'sdb-parser.y', 271)
795
+ def _reduce_62(val, _values)
778
796
  [val[0], val[2]].flatten
779
797
 
780
798
  end
@@ -9,6 +9,7 @@ rule
9
9
  | select_stmt
10
10
  | next_stmt
11
11
  | current_stmt
12
+ | prev_stmt
12
13
  | page_stmt
13
14
  | create_stmt
14
15
  | drop_stmt
@@ -202,10 +203,16 @@ rule
202
203
  struct(:NEXT, :ruby => ruby)
203
204
  }
204
205
 
205
- next_stmt : CURRENT
206
+ current_stmt : CURRENT
207
+ {
208
+ ruby = val[0].sub(/\A\s*\|\s*/, '') if val[0]
209
+ struct(:CURRENT, :ruby => ruby)
210
+ }
211
+
212
+ next_stmt : PREV
206
213
  {
207
214
  ruby = val[0].sub(/\A\s*\|\s*/, '') if val[0]
208
- struct(:CURRENT, :ruby => ruby)
215
+ struct(:PREV, :ruby => ruby)
209
216
  }
210
217
 
211
218
  create_stmt : CREATE DOMAIN IDENTIFIER
@@ -216,7 +223,8 @@ rule
216
223
  page_stmt : PAGE
217
224
  {
218
225
  page, ruby = val[0].split(/\s*\|\s*/, 2)
219
- page = page.split(/\s+/, 2).last.strip.to_i
226
+ page = page.split(/\s+/, 2)[1]
227
+ page = page.strip.to_i if page
220
228
  struct(:PAGE, :page => page, :ruby => ruby)
221
229
  }
222
230
 
@@ -345,11 +353,13 @@ def scan
345
353
  yield [tok.upcase.to_sym, tok]
346
354
  elsif (tok = @ss.scan /SELECT\b/i)
347
355
  yield [:SELECT, tok + @ss.scan(/.*/)]
348
- elsif (tok = @ss.scan /NEXT\b/i)
356
+ elsif (tok = @ss.scan /N(EXT)?\b/i)
349
357
  yield [:NEXT, @ss.scan(/\s*\|\s*.*/)]
350
- elsif (tok = @ss.scan /CUR(RENT)?\b/i)
358
+ elsif (tok = @ss.scan /C(URRENT)?\b/i)
351
359
  yield [:CURRENT, @ss.scan(/\s*\|\s*.*/)]
352
- elsif (tok = @ss.scan /PAGE\s+\d+/i)
360
+ elsif (tok = @ss.scan /P(REV)?\b/i)
361
+ yield [:PREV, @ss.scan(/\s*\|\s*.*/)]
362
+ elsif (tok = @ss.scan /PAGE(\s+\d+)?/i)
353
363
  yield [:PAGE, tok + @ss.scan(/(\s*\|\s*.*)?/)]
354
364
  elsif (tok = @ss.scan /NULL\b/i)
355
365
  yield [:NULL, nil]
@@ -132,7 +132,7 @@ module SimpleDB
132
132
  rownum = items.length
133
133
  @driver.delete(parsed.domain, items)
134
134
  Rownum.new(rownum)
135
- when :SELECT, :NEXT, :CURRENT, :PAGE
135
+ when :SELECT, :NEXT, :CURRENT, :PREV, :PAGE
136
136
  items = case command
137
137
  when :SELECT
138
138
  @driver.select(parsed.query, consistent, true)
@@ -140,28 +140,32 @@ module SimpleDB
140
140
  @driver.next_list(consistent)
141
141
  when :CURRENT
142
142
  @driver.current_list(consistent)
143
+ when :PREV
144
+ @driver.prev_list(consistent)
143
145
  when :PAGE
144
- @driver.page_to(parsed.page, consistent)
146
+ parsed.page ? @driver.page_to(parsed.page, consistent) : @driver.current_page
145
147
  else
146
148
  raise 'must not happen'
147
149
  end
148
150
 
149
- def items.method_missing(method_name)
150
- case method_name.to_s
151
- when /itemName/i
152
- self.map {|i| i[0] }
153
- else
154
- self.map {|i| i[1][method_name.to_s] }
155
- end
156
- end
157
-
158
- items.each do |item|
159
- def item.method_missing(method_name)
151
+ unless items.kind_of?(Integer)
152
+ def items.method_missing(method_name)
160
153
  case method_name.to_s
161
154
  when /itemName/i
162
- self[0]
155
+ self.map {|i| i[0] }
163
156
  else
164
- self[1][method_name.to_s]
157
+ self.map {|i| i[1][method_name.to_s] }
158
+ end
159
+ end
160
+
161
+ items.each do |item|
162
+ def item.method_missing(method_name)
163
+ case method_name.to_s
164
+ when /itemName/i
165
+ self[0]
166
+ else
167
+ self[1][method_name.to_s]
168
+ end
165
169
  end
166
170
  end
167
171
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdbcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: