db2c 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,13 +9,7 @@ Install
9
9
  $ apt-get install [rlwrap][0]
10
10
  $ gem install db2c
11
11
 
12
- Configuration
13
- -------------
14
-
15
- `DB2C_PROMPT`:
16
- the prompt to display before each line of input. defaults to db2 =>
17
-
18
- ContributingV
12
+ Contributing
19
13
  ------------
20
14
 
21
15
  Once you've made your great commits:
@@ -29,6 +23,7 @@ Once you've made your great commits:
29
23
  Acknowledgement
30
24
  ------------
31
25
 
26
+ Chris Jester-Young ([CKY][4]) found out the problem of using shell metacharacters when executing commands from Ruby.
32
27
  The initial script was inspired by [defunkt's repl][3], for a genenral purpose repl/wrapper, this is your friend.
33
28
 
34
29
  Meta
@@ -48,3 +43,4 @@ Samer Abukhait <samer@on-siteNOSPAM.com>, @s4mer
48
43
  [1]: http://help.github.com/forking/
49
44
  [2]: https://github.com/on-site/db2c/issues
50
45
  [3]: https://github.com/defunkt/repl
46
+ [4]: https://github.com/cky
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  $LOAD_PATH.unshift 'lib'
2
- require "db2c/version"
2
+ require "db2c"
3
3
 
4
4
  def version
5
5
  Db2c::VERSION
data/bin/ac CHANGED
@@ -0,0 +1,540 @@
1
+ absolute
2
+ access
3
+ action
4
+ activate
5
+ ada
6
+ add
7
+ after
8
+ alias
9
+ all
10
+ allocate
11
+ allow
12
+ alter
13
+ alterin
14
+ always
15
+ and
16
+ any
17
+ append
18
+ asc
19
+ ascii
20
+ assertion
21
+ assignment
22
+ associate
23
+ asutime
24
+ atomic
25
+ attributes
26
+ authorization
27
+ authid
28
+ automatic
29
+ avg
30
+ before
31
+ begin
32
+ between
33
+ bigint
34
+ binary
35
+ bind
36
+ bindadd
37
+ bit
38
+ bit_length
39
+ blob
40
+ blocked
41
+ both
42
+ bufferpool
43
+ cache
44
+ call
45
+ called
46
+ caller
47
+ capture
48
+ cardinality
49
+ cascade
50
+ cascaded
51
+ case
52
+ cast
53
+ catalog
54
+ catalog_name
55
+ change
56
+ char
57
+ char_length
58
+ character
59
+ character_length
60
+ check
61
+ checked
62
+ class_origin
63
+ client
64
+ clob
65
+ close
66
+ cluster
67
+ cobol
68
+ cobolle
69
+ collate
70
+ collation
71
+ collect
72
+ collid
73
+ column
74
+ column_name
75
+ command_function
76
+ comment
77
+ commit
78
+ committed
79
+ comparisons
80
+ concat
81
+ condition
82
+ condition_number
83
+ connect
84
+ connection
85
+ connection_name
86
+ conservative
87
+ constraint
88
+ constraint_catalog
89
+ constraint_name
90
+ constraint_schema
91
+ constraints
92
+ contains
93
+ continue
94
+ control
95
+ convert
96
+ copy
97
+ correlation
98
+ corr
99
+ corresponding
100
+ count
101
+ count_big
102
+ create
103
+ cross
104
+ cube
105
+ current
106
+ current_date
107
+ current_path
108
+ current_schema
109
+ current_server
110
+ current_sqlid
111
+ current_time
112
+ current_timestamp
113
+ current_timezone
114
+ current_user
115
+ cursor
116
+ cursors
117
+ cursor_name
118
+ cycle
119
+ date
120
+ data
121
+ database
122
+ datalink
123
+ day
124
+ days
125
+ dbadm
126
+ dbclob
127
+ dbinfo
128
+ db2dari
129
+ db2genrl
130
+ db2general
131
+ db2options
132
+ db2sql
133
+ deadlocks
134
+ deallocate
135
+ dec
136
+ decimal
137
+ declare
138
+ default
139
+ defaults
140
+ define
141
+ definition
142
+ degree
143
+ deferrable
144
+ deferred
145
+ delete
146
+ desc
147
+ describe
148
+ descriptor
149
+ deterministic
150
+ diagnostics
151
+ dimensions
152
+ disable
153
+ disallow
154
+ disconnect
155
+ dispatch
156
+ distinct
157
+ domain
158
+ do
159
+ double
160
+ drop
161
+ dropin
162
+ dynamic
163
+ dynamic_function
164
+ each
165
+ ebcdic
166
+ else
167
+ elseif
168
+ enable
169
+ end
170
+ end-exec
171
+ erase
172
+ escape
173
+ eur
174
+ event
175
+ exact
176
+ except
177
+ exception
178
+ exclude
179
+ excluding
180
+ exclusive
181
+ exec
182
+ execute
183
+ exists
184
+ exit
185
+ explain
186
+ extension
187
+ external
188
+ extract
189
+ false
190
+ federated
191
+ fenced
192
+ fetch
193
+ file
194
+ final
195
+ first
196
+ float
197
+ flush
198
+ following
199
+ for
200
+ force
201
+ foreign
202
+ fortran
203
+ found
204
+ from
205
+ fs
206
+ full
207
+ function
208
+ general
209
+ generated
210
+ get
211
+ global
212
+ goto
213
+ grant
214
+ graphic
215
+ group
216
+ grouping
217
+ handler
218
+ having
219
+ hold
220
+ hour
221
+ hours
222
+ identity
223
+ immediate
224
+ implicit_schema
225
+ include
226
+ including
227
+ increment
228
+ index
229
+ indicator
230
+ inherit
231
+ initially
232
+ initial_insts
233
+ initial_ios
234
+ inner
235
+ inout
236
+ input
237
+ insensitive
238
+ insert
239
+ instead
240
+ insts_per_argbyte
241
+ insts_per_invoc
242
+ int
243
+ integer
244
+ integrity
245
+ intersect
246
+ interval
247
+ into
248
+ ios_per_argbyte
249
+ ios_per_invoc
250
+ iso
251
+ iterate
252
+ isolation
253
+ java
254
+ jis
255
+ join
256
+ key
257
+ language
258
+ large
259
+ last
260
+ leading
261
+ leave
262
+ left
263
+ length
264
+ level
265
+ like
266
+ limit
267
+ link
268
+ linktype
269
+ load
270
+ local
271
+ locator
272
+ locators
273
+ lock
274
+ locks
275
+ locksize
276
+ logged
277
+ long
278
+ longvar
279
+ loop
280
+ lower
281
+ maintained
282
+ mapping
283
+ match
284
+ max
285
+ maxvalue
286
+ message_length
287
+ message_octet_length
288
+ message_text
289
+ method
290
+ microsecond
291
+ microseconds
292
+ minute
293
+ minutes
294
+ minvalue
295
+ mode
296
+ modifies
297
+ module
298
+ monitor
299
+ month
300
+ months
301
+ more
302
+ named
303
+ names
304
+ national
305
+ natural
306
+ nchar
307
+ new
308
+ new_table
309
+ next
310
+ nextval
311
+ nickname
312
+ nocache
313
+ nocycle
314
+ node
315
+ nomaxvalue
316
+ nominvalue
317
+ none
318
+ noorder
319
+ not
320
+ null
321
+ nullable
322
+ nulls
323
+ number
324
+ numeric
325
+ octet_length
326
+ object
327
+ off
328
+ old
329
+ old_table
330
+ ole
331
+ oledb
332
+ once
333
+ online
334
+ only
335
+ open
336
+ optimization
337
+ optimize
338
+ option
339
+ or
340
+ order
341
+ out
342
+ outer
343
+ output
344
+ over
345
+ overlaps
346
+ package
347
+ pad
348
+ partial
349
+ parallel
350
+ parameter
351
+ pascal
352
+ passthru
353
+ password
354
+ path
355
+ partition
356
+ partitioning
357
+ pctfree
358
+ percent_argbytes
359
+ permission
360
+ piecesize
361
+ pipe
362
+ plan
363
+ pli
364
+ position
365
+ preceding
366
+ precision
367
+ prepare
368
+ preserve
369
+ primary
370
+ prior
371
+ priqty
372
+ privileges
373
+ procedure
374
+ program
375
+ public
376
+ query
377
+ queryno
378
+ range
379
+ read
380
+ reads
381
+ real
382
+ recommend
383
+ recovery
384
+ ref
385
+ reference
386
+ references
387
+ referencing
388
+ refresh
389
+ registers
390
+ relative
391
+ release
392
+ rename
393
+ repeatable
394
+ repeat
395
+ rpg
396
+ rpgle
397
+ replace
398
+ replicated
399
+ reset
400
+ resignal
401
+ resolve
402
+ restart
403
+ restore
404
+ restrict
405
+ result
406
+ result_set_locator
407
+ returned_sqlstate
408
+ retain
409
+ return
410
+ returns
411
+ return_status
412
+ revoke
413
+ right
414
+ rollback
415
+ rollup
416
+ routine
417
+ row
418
+ row_count
419
+ rowid
420
+ rows
421
+ run
422
+ savepoint
423
+ sbcs
424
+ scale
425
+ schema
426
+ schema_name
427
+ scope
428
+ scratchpad
429
+ scroll
430
+ search
431
+ second
432
+ seconds
433
+ secqty
434
+ section
435
+ select
436
+ self
437
+ sequence
438
+ serializable
439
+ server
440
+ server_name
441
+ session
442
+ session_user
443
+ set
444
+ sets
445
+ share
446
+ signal
447
+ simple
448
+ size
449
+ smallint
450
+ snapshot
451
+ some
452
+ source
453
+ space
454
+ specific
455
+ sql
456
+ sqlcode
457
+ sqlerror
458
+ sqlexception
459
+ sqlwarning
460
+ sqlid
461
+ sqlstate
462
+ start
463
+ state
464
+ statement
465
+ statistics
466
+ stay
467
+ stogroup
468
+ storage
469
+ style
470
+ subclass_origin
471
+ substring
472
+ summary
473
+ switch
474
+ synonym
475
+ system
476
+ system_user
477
+ table
478
+ tables
479
+ table_name
480
+ tablespace
481
+ tablespaces
482
+ temporary
483
+ then
484
+ threadsafe
485
+ time
486
+ timestamp
487
+ timezone
488
+ timezone_hour
489
+ timezone_minute
490
+ to
491
+ trailing
492
+ transaction
493
+ transform
494
+ translate
495
+ translation
496
+ treat
497
+ trigger
498
+ trim
499
+ true
500
+ type
501
+ unbounded
502
+ uncommitted
503
+ under
504
+ undo
505
+ unicode
506
+ union
507
+ unique
508
+ unknown
509
+ unlink
510
+ until
511
+ update
512
+ upper
513
+ url
514
+ usa
515
+ use
516
+ usage
517
+ user
518
+ using
519
+ value
520
+ values
521
+ varchar
522
+ vargraphic
523
+ variant
524
+ varying
525
+ vcat
526
+ version
527
+ view
528
+ when
529
+ whenever
530
+ where
531
+ while
532
+ with
533
+ without
534
+ work
535
+ wrapper
536
+ write
537
+ year
538
+ years
539
+ yes
540
+ zone
data/bin/db2c CHANGED
@@ -5,7 +5,7 @@ if !system("which db2 > /dev/null 2> /dev/null")
5
5
  exit
6
6
  end
7
7
 
8
- if !system("which rlwrap > /dev/null 2> /dev/null")
8
+ if !ARGV.include?('--no-rlwrap') && !system("which rlwrap > /dev/null 2> /dev/null")
9
9
  puts "This program depends on rlwrap, install rlwrap"
10
10
  exit
11
11
  end
@@ -32,4 +32,24 @@ if ARGV.include? '--man'
32
32
  exec "man #{cdir}/../man/db2c.1"
33
33
  end
34
34
 
35
- exec "rlwrap -A -pblue -f #{cdir}/ac -H ~/.db2c_history db2 #{ARGV.join(' ')}"
35
+ unless ARGV.include? '--no-rlwrap'
36
+ exec "rlwrap -z pipeto -i -r -s 999999 -pBLUE -f #{cdir}/ac -H ~/.db2c_history db2c --no-rlwrap #{ARGV.join(' ')}"
37
+ end
38
+
39
+ $LOAD_PATH.unshift 'lib'
40
+ require "db2c"
41
+
42
+ Db2c::Command.debug = ARGV.any? { |arg| %w( -d --debug -debug debug ).include?(arg) }
43
+
44
+ loop do
45
+ print Db2c::Command.prompt
46
+
47
+ begin
48
+ command = Db2c::Command.new $stdin.gets
49
+ rescue Interrupt
50
+ exit
51
+ end
52
+
53
+ exit if command.quit?
54
+ command.execute
55
+ end
@@ -0,0 +1,52 @@
1
+ module Db2c
2
+ class Command
3
+
4
+ @@cdb = ''
5
+ @@debug = false
6
+
7
+ def initialize input
8
+ if input
9
+ puts "initializing: #{input}" if @@debug
10
+ @input = input.chomp.strip
11
+ @input.gsub! /^db2 /i, ''
12
+ @input.gsub! /;$/, ''
13
+ @input.gsub! /^use /, 'connect to '
14
+ @input.insert 0, "? sql" if @input =~ /^\-\d+$/
15
+ @input.insert 0, "? " if @input =~ /^\d+$/
16
+ @input.insert 0, "values " if @input =~ /^current.+$/i
17
+ end
18
+ end
19
+
20
+ def to_s
21
+ @input
22
+ end
23
+
24
+ def quit?
25
+ @input.nil? || @input =~ /^(exit|quit)$/
26
+ end
27
+
28
+ def valid?
29
+ @input && @input.length > 0
30
+ end
31
+
32
+ def execute
33
+ puts "executing: #{@input}" if @@debug
34
+ system 'db2', @input if valid?
35
+ if @input =~ /^connect to (.*)$/i
36
+ @@cdb = $1.downcase
37
+ end
38
+ end
39
+
40
+ def self.debug=(value)
41
+ @@debug = value
42
+ end
43
+
44
+ def self.prompt
45
+ "db2c".tap do |pr|
46
+ pr << "(#{@@cdb})" if @@cdb.length > 0
47
+ pr << " => "
48
+ end
49
+ end
50
+
51
+ end
52
+ end
data/lib/db2c.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Db2c
2
+ DEFAULT_PROMPT = "db2c => "
3
+ VERSION = "0.0.2"
4
+ end
5
+
6
+ require "db2c/command.rb"
data/man/db2c.1 CHANGED
@@ -18,29 +18,15 @@ DB2 console mode does not support readline and autocomplete, this is a wrapper f
18
18
 
19
19
  $ db2c
20
20
  db2 => connect to testdb
21
+ or: db2 => use testdb
22
+ db2 => current date
23
+ db2 => \-107
21
24
 
22
- Database Connection Information
25
+ Use the arrows for history, you can also use <CTRL>\-r to search the history
23
26
 
24
- Database server = DB2/LINUXX8664 9\.7\.4
25
- SQL authorization ID = SAMER
26
- Local database alias = TESTDB
27
-
28
- >> ? sql\-107
29
-
30
-
31
- SQL0107N The name "<name>" is too long\. The maximum length is
32
- "<length>"\.
33
- \.\. etc \.\.
34
-
35
- >> values current date
36
-
37
- 1
38
- \-\-\-\-\-\-\-\-\-\-
39
- 11/17/2011
40
-
41
- 1 record(s) selected\.
42
-
43
- \.\. etc \.\.
27
+ You can pipe:
28
+ db2 => select * from large\.table | less
29
+ db2 => select * from large\.table | grep something
44
30
  .
45
31
  .fi
46
32
  .
@@ -54,11 +40,6 @@ Displays usage information\.
54
40
  \fB\-\-man\fR
55
41
  Displays this man page\.
56
42
  .
57
- .SH "ENVIRONMENT"
58
- .
59
- .SS "DB2_PROMPT"
60
- the prompt to display before each line of input\. defaults to db2 =>
61
- .
62
43
  .SH "BUGS"
63
44
  \fIhttp://github\.com/on\-site/db2c/issues\fR
64
45
  .
data/man/db2c.1.html CHANGED
@@ -58,7 +58,6 @@
58
58
  <a href="#DESCRIPTION">DESCRIPTION</a>
59
59
  <a href="#EXAMPLES">EXAMPLES</a>
60
60
  <a href="#OPTIONS">OPTIONS</a>
61
- <a href="#ENVIRONMENT">ENVIRONMENT</a>
62
61
  <a href="#BUGS">BUGS</a>
63
62
  <a href="#AUTHOR">AUTHOR</a>
64
63
  <a href="#SEE-ALSO">SEE ALSO</a>
@@ -87,29 +86,15 @@
87
86
 
88
87
  <pre><code>$ db2c
89
88
  db2 =&gt; connect to testdb
89
+ or: db2 =&gt; use testdb
90
+ db2 =&gt; current date
91
+ db2 =&gt; -107
90
92
 
91
- Database Connection Information
93
+ Use the arrows for history, you can also use &lt;CTRL>-r to search the history
92
94
 
93
- Database server = DB2/LINUXX8664 9.7.4
94
- SQL authorization ID = SAMER
95
- Local database alias = TESTDB
96
-
97
- &gt;&gt; ? sql-107
98
-
99
-
100
- SQL0107N The name "&lt;name>" is too long. The maximum length is
101
- "&lt;length>".
102
- .. etc ..
103
-
104
- &gt;&gt; values current date
105
-
106
- 1
107
- ----------
108
- 11/17/2011
109
-
110
- 1 record(s) selected.
111
-
112
- .. etc ..
95
+ You can pipe:
96
+ db2 =&gt; select * from large.table | less
97
+ db2 =&gt; select * from large.table | grep something
113
98
  </code></pre>
114
99
 
115
100
  <h2 id="OPTIONS">OPTIONS</h2>
@@ -120,19 +105,13 @@ SQL0107N The name "&lt;name>" is too long. The maximum length is
120
105
  </dl>
121
106
 
122
107
 
123
- <h2 id="ENVIRONMENT">ENVIRONMENT</h2>
124
-
125
- <h3 id="DB2_PROMPT">DB2_PROMPT</h3>
126
-
127
- <p>the prompt to display before each line of input. defaults to db2 =></p>
128
-
129
108
  <h2 id="BUGS">BUGS</h2>
130
109
 
131
110
  <p><a href="http://github.com/on-site/db2c/issues" data-bare-link="true">http://github.com/on-site/db2c/issues</a></p>
132
111
 
133
112
  <h2 id="AUTHOR">AUTHOR</h2>
134
113
 
135
- <p>Samer Abukhait <a href="&#x6d;&#97;&#105;&#x6c;&#x74;&#111;&#58;&#x73;&#x61;&#109;&#101;&#114;&#x40;&#x6f;&#110;&#x2d;&#x73;&#x69;&#x74;&#101;&#x4e;&#79;&#83;&#x50;&#x41;&#x4d;&#x2e;&#99;&#x6f;&#109;" data-bare-link="true">&#x73;&#97;&#x6d;&#x65;&#x72;&#64;&#111;&#x6e;&#x2d;&#x73;&#105;&#x74;&#101;&#x4e;&#79;&#83;&#80;&#x41;&#x4d;&#x2e;&#99;&#x6f;&#109;</a>, @s4mer</p>
114
+ <p>Samer Abukhait <a href="&#x6d;&#97;&#105;&#108;&#x74;&#x6f;&#58;&#x73;&#97;&#109;&#x65;&#114;&#64;&#111;&#x6e;&#45;&#115;&#x69;&#116;&#101;&#78;&#x4f;&#83;&#80;&#65;&#77;&#x2e;&#99;&#x6f;&#109;" data-bare-link="true">&#x73;&#97;&#109;&#x65;&#x72;&#x40;&#x6f;&#x6e;&#45;&#x73;&#x69;&#x74;&#x65;&#x4e;&#x4f;&#83;&#x50;&#65;&#x4d;&#x2e;&#99;&#111;&#109;</a>, @s4mer</p>
136
115
 
137
116
  <h2 id="SEE-ALSO">SEE ALSO</h2>
138
117
 
data/man/db2c.1.ronn CHANGED
@@ -13,29 +13,15 @@ DB2 console mode does not support readline and autocomplete, this is a wrapper f
13
13
 
14
14
  $ db2c
15
15
  db2 => connect to testdb
16
+ or: db2 => use testdb
17
+ db2 => current date
18
+ db2 => -107
16
19
 
17
- Database Connection Information
20
+ Use the arrows for history, you can also use <CTRL>-r to search the history
18
21
 
19
- Database server = DB2/LINUXX8664 9.7.4
20
- SQL authorization ID = SAMER
21
- Local database alias = TESTDB
22
-
23
- >> ? sql-107
24
-
25
-
26
- SQL0107N The name "<name>" is too long. The maximum length is
27
- "<length>".
28
- .. etc ..
29
-
30
- >> values current date
31
-
32
- 1
33
- ----------
34
- 11/17/2011
35
-
36
- 1 record(s) selected.
37
-
38
- .. etc ..
22
+ You can pipe:
23
+ db2 => select * from large.table | less
24
+ db2 => select * from large.table | grep something
39
25
 
40
26
  ## OPTIONS
41
27
 
@@ -45,12 +31,6 @@ DB2 console mode does not support readline and autocomplete, this is a wrapper f
45
31
  * `--man`:
46
32
  Displays this man page.
47
33
 
48
- ## ENVIRONMENT
49
-
50
- ### DB2_PROMPT
51
-
52
- the prompt to display before each line of input. defaults to db2 =>
53
-
54
34
  ## BUGS
55
35
 
56
36
  <http://github.com/on-site/db2c/issues>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db2c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,23 +9,26 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-17 00:00:00.000000000Z
12
+ date: 2011-11-18 00:00:00.000000000Z
13
13
  dependencies: []
14
- description: a db2 console with with history and autocomplete support
14
+ description: This program wraps db2 command mode with a repl, and wraps that repl
15
+ with rlwrap
15
16
  email: samer@on-siteNOSPAM.com
16
17
  executables:
17
18
  - db2c
18
19
  extensions: []
19
20
  extra_rdoc_files: []
20
21
  files:
21
- - README.md
22
- - Rakefile
23
- - LICENSE
24
22
  - bin/ac
25
23
  - bin/db2c
24
+ - lib/db2c/command.rb
25
+ - lib/db2c.rb
26
26
  - man/db2c.1.html
27
27
  - man/db2c.1
28
28
  - man/db2c.1.ronn
29
+ - LICENSE
30
+ - README.md
31
+ - Rakefile
29
32
  homepage: http://github.com/on-site/db2c
30
33
  licenses: []
31
34
  post_install_message: