sqlparser 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7aa0a464c04ab5dae6d04b0b8ee0720080149e97
4
+ data.tar.gz: 3adf0fc5c537d7b45332b1e38eeeec56908dfa65
5
+ SHA512:
6
+ metadata.gz: 7008403d781d72ecd30c0124ef380830d638f8d6a542a307ebdf5be1ab9e1c0d5ed40dec4fc35cecfb80d7b4d0b246539b3b264151626d31f3da213e1dfdbe9f
7
+ data.tar.gz: 89055caecc4669e27c4e4b596774a58ad652909462155479d46a9058a233b3ad87077d2f1e4c1755a0213b549a3b16740f01702e899e32746457f5d035d33424
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/sqlparser.rb ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: sqlparser.rb
4
+
5
+ require 'lineparser'
6
+
7
+ class SqlParser
8
+
9
+ attr_reader :to_a
10
+
11
+ def initialize(raw_lines)
12
+
13
+ patterns = [
14
+ [:root, 'SELECT *', :select_all],
15
+ [:root, 'SELECT :cols', :select],
16
+ [:root, 'FROM :tables', :from],
17
+ [:root, 'WHERE :condition', :where],
18
+ [:where, 'AND :and', :where_and ],
19
+ [:where, 'OR :or', :where_or ],
20
+ [:root, 'INSERT INTO *', :insert_into],
21
+ [:root, 'VALUES :cols', :insert_values],
22
+ [:all, /--/, :comment]
23
+ ]
24
+
25
+ lp = LineParser.new patterns
26
+
27
+ lines = raw_lines\
28
+ .sub(/\bselect\s+/,'SELECT ')\
29
+ .sub(/\s+from\s+/,"\nFROM ")\
30
+ .sub(/\s+where\s+/,"\nWHERE ")\
31
+ .sub(/\s+and\s+/,"\n AND ").sub(/\s+or\s+/,"\n OR ")
32
+
33
+ @to_a = lp.parse lines
34
+ end
35
+
36
+ end
37
+
38
+ if __FILE__ == $0 then
39
+
40
+ SqlParser.new(ARGV[0]).to_a
41
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqlparser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE0MDkwNTE3MDUyNVoXDTE1MDkwNTE3MDUyNVowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBANATfqZZGeZ3WqbGNS0m2nZlcxHs+YaZPf/6wc5YSH6sXEpiTBC2LdlkXfRi
19
+ a5PGW1WdNeUSdI5tDJ8fzz5YSYiW0oztq57+0oHR2WxeXrygdPlJ+BkZ5UhVQ7op
20
+ +WzVcQ0wf0KZMA3bfphVbL2wsejP67WX2KJjeg7YyyQsL2nt4eOJl/W9cPQ2iPys
21
+ 5UWnv5LFGZG9yLYLKukWkWKdB758a7x7/uGwllqHExlrJXhsvtX1fXVVGBg5mTa5
22
+ ah065biE5aZbHzgu8X03fiYokCUKMshouJqZadcB9XiKzLOXDBTu+NJR9IkJ67Kx
23
+ Z3eot2bfAc8gZCZreMCZvsuiHmUCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUi7/pNOSRU4gKv2z/ROj8vkQesxIwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEABk/QIAVk
27
+ 5tiQB8X6kPufPcPS0iNc2egh59INw1SkwieJlDMvYm51jks4MS38HwDQ4br6evFJ
28
+ uOqQQ3F4J1m9nC1GLtjosXWcZElHw1C5TbEms0J1zxeD4zfZZSd5OyNyh5JPCK6Y
29
+ 4SYssK/BnJH+DMOydOB+ca7B1y7HWu9fuYY7XnOm0KLXV0a/gKb8m391eX4QoYg7
30
+ KCpSiMYC5Plm4H0SN0C7TtjDVtr17ZgaQbCeaY2hlLB8tZIFkd+RsDCEmbU/02dR
31
+ SCd9fqRfntwh9h2Aqx8TsR/lY1HdOSFrPaqsJP8X+ujA+aT1JnW113CxF0vUlNwS
32
+ 2MuS+Uj0ZrOVyg==
33
+ -----END CERTIFICATE-----
34
+ date: 2014-09-05 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: lineparser
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.1'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.13
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.1'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.1.13
56
+ description:
57
+ email: james@r0bertson.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/sqlparser.rb
63
+ homepage: https://github.com/jrobertson/sqlparser
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Parses basic SQL statements.
87
+ test_files: []
metadata.gz.sig ADDED
Binary file