ronin-sql 0.1.1 → 0.2.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.
Files changed (101) hide show
  1. data/History.txt +43 -0
  2. data/Manifest.txt +76 -23
  3. data/README.txt +31 -6
  4. data/Rakefile +2 -2
  5. data/lib/ronin/code/sql/{keyword.rb → add_column_clause.rb} +9 -13
  6. data/lib/ronin/code/sql/as.rb +47 -0
  7. data/lib/ronin/code/sql/asc.rb +38 -0
  8. data/lib/ronin/code/sql/between.rb +18 -12
  9. data/lib/ronin/code/sql/binary_expr.rb +12 -5
  10. data/lib/ronin/code/sql/clause.rb +37 -0
  11. data/lib/ronin/code/sql/code.rb +1 -1
  12. data/lib/ronin/code/sql/common_dialect.rb +16 -10
  13. data/lib/ronin/code/sql/create.rb +68 -0
  14. data/lib/ronin/code/sql/create_index.rb +9 -39
  15. data/lib/ronin/code/sql/create_table.rb +9 -56
  16. data/lib/ronin/code/sql/create_view.rb +7 -29
  17. data/lib/ronin/code/sql/default_values_clause.rb +38 -0
  18. data/lib/ronin/code/sql/delete.rb +10 -25
  19. data/lib/ronin/code/sql/desc.rb +38 -0
  20. data/lib/ronin/code/sql/dialect.rb +172 -52
  21. data/lib/ronin/code/sql/{builder.rb → drop.rb} +16 -20
  22. data/lib/ronin/code/sql/drop_index.rb +43 -0
  23. data/lib/ronin/code/sql/drop_table.rb +8 -16
  24. data/lib/ronin/code/sql/drop_view.rb +43 -0
  25. data/lib/ronin/code/sql/emittable.rb +102 -0
  26. data/lib/ronin/code/sql/exceptions/unknown_clause.rb +31 -0
  27. data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +2 -2
  28. data/lib/ronin/code/sql/exceptions/unknown_statement.rb +31 -0
  29. data/lib/ronin/code/sql/exceptions.rb +3 -1
  30. data/lib/ronin/code/sql/expr.rb +7 -96
  31. data/lib/ronin/code/sql/field.rb +40 -23
  32. data/lib/ronin/code/sql/fields_clause.rb +48 -0
  33. data/lib/ronin/code/sql/from_clause.rb +44 -0
  34. data/lib/ronin/code/sql/function.rb +15 -12
  35. data/lib/ronin/code/sql/group_by_clause.rb +48 -0
  36. data/lib/ronin/code/sql/having_clause.rb +48 -0
  37. data/lib/ronin/code/sql/in.rb +9 -9
  38. data/lib/ronin/code/sql/injected_statement.rb +102 -0
  39. data/lib/ronin/code/sql/injection.rb +171 -5
  40. data/lib/ronin/code/sql/insert.rb +15 -45
  41. data/lib/ronin/code/sql/intersect_clause.rb +44 -0
  42. data/lib/ronin/code/sql/join_clause.rb +125 -0
  43. data/lib/ronin/code/sql/{like_expr.rb → like.rb} +19 -31
  44. data/lib/ronin/code/sql/limit_clause.rb +44 -0
  45. data/lib/ronin/code/sql/modifier.rb +50 -0
  46. data/lib/ronin/code/sql/offset_clause.rb +44 -0
  47. data/lib/ronin/code/sql/on_clause.rb +57 -0
  48. data/lib/ronin/code/sql/order_by_clause.rb +44 -0
  49. data/lib/ronin/code/sql/program.rb +170 -23
  50. data/lib/ronin/code/sql/rename_to_clause.rb +44 -0
  51. data/lib/ronin/code/sql/replace.rb +15 -17
  52. data/lib/ronin/code/sql/select.rb +46 -141
  53. data/lib/ronin/code/sql/set_clause.rb +44 -0
  54. data/lib/ronin/code/sql/statement.rb +117 -47
  55. data/lib/ronin/code/sql/token.rb +64 -0
  56. data/lib/ronin/code/sql/unary_expr.rb +9 -5
  57. data/lib/ronin/code/sql/union_all_clause.rb +44 -0
  58. data/lib/ronin/code/sql/union_clause.rb +44 -0
  59. data/lib/ronin/code/sql/update.rb +10 -31
  60. data/lib/ronin/code/sql/values_clause.rb +48 -0
  61. data/lib/ronin/code/sql/where_clause.rb +44 -0
  62. data/lib/ronin/code/sql.rb +1 -1
  63. data/lib/ronin/sql/error/error.rb +64 -0
  64. data/lib/ronin/sql/error/message.rb +64 -0
  65. data/lib/ronin/sql/error/pattern.rb +106 -0
  66. data/lib/ronin/sql/error/patterns.rb +100 -0
  67. data/lib/ronin/sql/error.rb +5 -30
  68. data/lib/ronin/sql/extensions/uri/http.rb +76 -21
  69. data/lib/ronin/sql/extensions/uri.rb +1 -1
  70. data/lib/ronin/sql/extensions.rb +2 -1
  71. data/lib/ronin/sql/injection.rb +213 -0
  72. data/lib/ronin/sql/version.rb +2 -2
  73. data/lib/ronin/sql.rb +7 -2
  74. data/spec/code/sql/create_examples.rb +19 -0
  75. data/spec/code/sql/create_index_spec.rb +25 -0
  76. data/spec/code/sql/create_table_spec.rb +27 -0
  77. data/spec/code/sql/create_view_spec.rb +16 -0
  78. data/spec/code/sql/delete_spec.rb +14 -0
  79. data/spec/code/sql/drop_examples.rb +10 -0
  80. data/spec/code/sql/drop_index_spec.rb +16 -0
  81. data/spec/code/sql/drop_table_spec.rb +16 -0
  82. data/spec/code/sql/drop_view_spec.rb +16 -0
  83. data/spec/code/sql/has_default_values_clause_examples.rb +10 -0
  84. data/spec/code/sql/has_fields_clause_examples.rb +15 -0
  85. data/spec/code/sql/has_from_clause_examples.rb +13 -0
  86. data/spec/code/sql/has_values_clause_examples.rb +15 -0
  87. data/spec/code/sql/has_where_clause_examples.rb +15 -0
  88. data/spec/code/sql/insert_spec.rb +21 -0
  89. data/spec/code/sql/replace_spec.rb +21 -0
  90. data/spec/code/sql/select_spec.rb +105 -0
  91. data/spec/code/sql/update_spec.rb +26 -0
  92. data/spec/helpers/code.rb +14 -0
  93. data/spec/sql/error_spec.rb +24 -0
  94. data/spec/sql/extensions/string_spec.rb +28 -0
  95. data/spec/sql_spec.rb +9 -0
  96. data/tasks/spec.rb +2 -0
  97. metadata +82 -29
  98. data/lib/ronin/code/sql/injection_builder.rb +0 -137
  99. data/lib/ronin/code/sql/injection_style.rb +0 -79
  100. data/lib/ronin/code/sql/style.rb +0 -170
  101. data/lib/ronin/sql/sql.rb +0 -83
@@ -3,7 +3,7 @@
3
3
  # Ronin SQL - A Ronin library providing support for SQL related security
4
4
  # tasks.
5
5
  #
6
- # Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -22,37 +22,33 @@
22
22
  #
23
23
 
24
24
  require 'ronin/code/sql/statement'
25
- require 'ronin/code/sql/dialect'
26
- require 'ronin/code/sql/common_dialect'
27
- require 'ronin/code/sql/style'
28
25
 
29
26
  module Ronin
30
27
  module Code
31
28
  module SQL
32
- class Builder < Statement
29
+ class Drop < Statement
33
30
 
34
- def initialize(style,options={},&block)
35
- @commands = []
31
+ def initialize(dialect,type,name=nil,options={},&block)
32
+ @type = type
33
+ @name = name
34
+ @if_exists = options[:if_exists]
36
35
 
37
- super(style,&block)
36
+ super(dialect,&block)
38
37
  end
39
38
 
40
- def compile
41
- @style.compile_statements(@commands)
42
- end
43
-
44
- protected
45
-
46
- def command(cmd)
47
- @commands << cmd
39
+ def if_exists
40
+ @if_exists = true
48
41
  return self
49
42
  end
50
43
 
51
- def method_missing(sym,*args,&block)
52
- result = super(sym,*args,&block)
44
+ def emit
45
+ tokens = emit_token('DROP')
46
+ tokens += emit_token(@type)
47
+
48
+ tokens += emit_token('IF EXISTS') if @if_exists
49
+ tokens += emit_value(@name)
53
50
 
54
- @commands << result if result.kind_of?(Statement)
55
- return result
51
+ return tokens
56
52
  end
57
53
 
58
54
  end
@@ -0,0 +1,43 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/drop'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class DropIndex < Drop
30
+
31
+ def initialize(dialect,index=nil,options={},&block)
32
+ super(dialect,'INDEX',index,options,&block)
33
+ end
34
+
35
+ def index(name)
36
+ @name = name
37
+ return self
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -3,7 +3,7 @@
3
3
  # Ronin SQL - A Ronin library providing support for SQL related security
4
4
  # tasks.
5
5
  #
6
- # Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -21,30 +21,22 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/code/sql/statement'
24
+ require 'ronin/code/sql/drop'
25
25
 
26
26
  module Ronin
27
27
  module Code
28
28
  module SQL
29
- class DropTable < Statement
29
+ class DropTable < Drop
30
30
 
31
- option :if_exists, "IF EXISTS"
32
-
33
- def initialize(style,table=nil,&block)
34
- @table = table
35
- @exists = false
36
-
37
- super(style,&block)
31
+ def initialize(dialect,table=nil,options={},&block)
32
+ super(dialect,'TABLE',table,options,&block)
38
33
  end
39
34
 
40
- def compile
41
- compile_expr(keyword_drop,if_exists?,@table)
35
+ def table(name)
36
+ @name = name
37
+ return self
42
38
  end
43
39
 
44
- protected
45
-
46
- keyword :drop, 'DROP TABLE'
47
-
48
40
  end
49
41
  end
50
42
  end
@@ -0,0 +1,43 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/sql/drop'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class DropView < Drop
30
+
31
+ def initialize(dialect,view=nil,options={},&block)
32
+ super(dialect,'VIEW',view,options,&block)
33
+ end
34
+
35
+ def view(name)
36
+ @name = name
37
+ return self
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,102 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/code/emittable'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ module Emittable
30
+ include Code::Emittable
31
+
32
+ protected
33
+
34
+ def emit_token(value)
35
+ value.to_s.split(/\s/).map { |word| Token.new(word) }
36
+ end
37
+
38
+ def emit_value(value)
39
+ if value.kind_of?(Statement)
40
+ tokens = []
41
+
42
+ tokens << Token.open_paren
43
+ tokens += value.emit
44
+ tokens << Token.close_paren
45
+
46
+ return tokens
47
+ else
48
+ return super(value)
49
+ end
50
+ end
51
+
52
+ def emit_values(values)
53
+ tokens = []
54
+
55
+ values.each { |value| tokens += emit_value(value) }
56
+
57
+ return tokens
58
+ end
59
+
60
+ #
61
+ # Emits the comma separated list of the specified _values_.
62
+ #
63
+ def emit_list(values)
64
+ tokens = []
65
+
66
+ (values.length - 1).times do |index|
67
+ tokens << emit_value(values[index])
68
+ tokens << Token.new(',')
69
+ end
70
+
71
+ tokens << emit_value(values.last)
72
+ return tokens
73
+ end
74
+
75
+ #
76
+ # Emits the specified SQL _row_.
77
+ #
78
+ def emit_row(row)
79
+ case row.length
80
+ when 0
81
+ return []
82
+ when 1
83
+ return emit_list(row)
84
+ else
85
+ return [Token.new('(')] + emit_list(row) + [Token.new(')')]
86
+ end
87
+ end
88
+
89
+ #
90
+ # Emits the specified _statement_.
91
+ #
92
+ def emit_statement(statement)
93
+ if statement.kind_of?(Statement)
94
+ return statement.emit
95
+ else
96
+ return statement
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ module Ronin
25
+ module Code
26
+ module SQL
27
+ class UnknownClause < RuntimeError
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,7 +3,7 @@
3
3
  # Ronin SQL - A Ronin library providing support for SQL related security
4
4
  # tasks.
5
5
  #
6
- # Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
24
24
  module Ronin
25
25
  module Code
26
26
  module SQL
27
- class DialectNotFound < RuntimeError
27
+ class UnknownDialect < RuntimeError
28
28
  end
29
29
  end
30
30
  end
@@ -0,0 +1,31 @@
1
+ #
2
+ #--
3
+ # Ronin SQL - A Ronin library providing support for SQL related security
4
+ # tasks.
5
+ #
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ module Ronin
25
+ module Code
26
+ module SQL
27
+ class UnknownStatement < RuntimeError
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,7 +3,7 @@
3
3
  # Ronin SQL - A Ronin library providing support for SQL related security
4
4
  # tasks.
5
5
  #
6
- # Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -22,3 +22,5 @@
22
22
  #
23
23
 
24
24
  require 'ronin/code/sql/exceptions/unknown_dialect'
25
+ require 'ronin/code/sql/exceptions/unknown_statement'
26
+ require 'ronin/code/sql/exceptions/unknown_clause'
@@ -3,7 +3,7 @@
3
3
  # Ronin SQL - A Ronin library providing support for SQL related security
4
4
  # tasks.
5
5
  #
6
- # Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/code/sql/keyword'
24
+ require 'ronin/code/sql/emittable'
25
25
  require 'ronin/extensions/meta'
26
26
 
27
27
  module Ronin
@@ -29,15 +29,10 @@ module Ronin
29
29
  module SQL
30
30
  class Expr
31
31
 
32
- # The style to use
33
- attr_reader :style
34
-
35
- def initialize(style)
36
- @style = style
37
- end
32
+ include Emittable
38
33
 
39
34
  def in?(*range)
40
- In.new(@style,self,*range)
35
+ In.new(self,*range)
41
36
  end
42
37
 
43
38
  def ===(*range)
@@ -48,38 +43,12 @@ module Ronin
48
43
  in?(*range).not!
49
44
  end
50
45
 
51
- def compile
52
- # place holder
53
- end
54
-
55
- def to_s
56
- compile
57
- end
58
-
59
46
  protected
60
47
 
61
- def keyword(value)
62
- keyword_cache[value.to_sym]
63
- end
64
-
65
- def keywords(*values)
66
- values.map { |value| keyword(value) }
67
- end
68
-
69
- def self.keyword(name,value=name.to_s.upcase)
70
- name = name.to_s.downcase
71
-
72
- class_def("keyword_#{name}") do
73
- keyword(value)
74
- end
75
-
76
- return self
77
- end
78
-
79
48
  def self.binary_op(op,*names)
80
49
  names.each do |name|
81
50
  class_def(name) do |expr|
82
- BinaryExpr.new(@style,op,self,expr)
51
+ BinaryExpr.new(op,self,expr)
83
52
  end
84
53
  end
85
54
 
@@ -104,7 +73,7 @@ module Ronin
104
73
  def self.like_op(op,*names)
105
74
  names.each do |name|
106
75
  class_def(name) do |expr,escape|
107
- LikeExpr.new(@style,op,self,expr,escape)
76
+ Like.new(op,self,expr,escape)
108
77
  end
109
78
  end
110
79
 
@@ -119,7 +88,7 @@ module Ronin
119
88
  def self.unary_op(op,*names)
120
89
  names.each do |name|
121
90
  class_def(name) do
122
- UnaryExpr.new(@style,op,self)
91
+ UnaryExpr.new(op,self)
123
92
  end
124
93
  end
125
94
 
@@ -129,64 +98,6 @@ module Ronin
129
98
  unary_op 'NOT', :not!
130
99
  unary_op 'EXISTS', :exists?
131
100
 
132
- def compile_space
133
- @style.compile_space
134
- end
135
-
136
- def preappend_space(str)
137
- @style.preappend_space(str)
138
- end
139
-
140
- def append_space(str)
141
- @style.append_space(str)
142
- end
143
-
144
- def space(*str)
145
- @style.space(*str)
146
- end
147
-
148
- def compile_newline
149
- @style.compile_newline
150
- end
151
-
152
- def quote_string(data)
153
- @style.quote_string(data)
154
- end
155
-
156
- def compile_keyword(name)
157
- @style.compile_keyword(name)
158
- end
159
-
160
- def compile_list(*expr)
161
- @style.compile_list(*expr)
162
- end
163
-
164
- def compile_datalist(*expr)
165
- @style.compile_list(*expr)
166
- end
167
-
168
- def compile_row(*expr)
169
- @style.compile_row(*expr)
170
- end
171
-
172
- def compile_data(data)
173
- @style.compile_data(data)
174
- end
175
-
176
- def compile_expr(*expr)
177
- @style.compile_expr(*expr)
178
- end
179
-
180
- def compile_statements(*statements)
181
- @style.compile_statements(*statements)
182
- end
183
-
184
- private
185
-
186
- def keyword_cache
187
- @keyword_cache ||= Hash.new { |hash,key| hash[key] = Keyword.new(@style,key) }
188
- end
189
-
190
101
  end
191
102
  end
192
103
  end
@@ -3,7 +3,7 @@
3
3
  # Ronin SQL - A Ronin library providing support for SQL related security
4
4
  # tasks.
5
5
  #
6
- # Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -22,26 +22,41 @@
22
22
  #
23
23
 
24
24
  require 'ronin/code/sql/expr'
25
+ require 'ronin/code/sql/as'
25
26
  require 'ronin/code/sql/between'
27
+ require 'ronin/code/sql/asc'
28
+ require 'ronin/code/sql/desc'
26
29
 
27
30
  module Ronin
28
31
  module Code
29
32
  module SQL
30
33
  class Field < Expr
31
34
 
32
- def initialize(style,name,prefix=nil)
33
- super(style)
34
-
35
+ def initialize(symbols,name,prefix=nil)
36
+ @symbols = symbols
35
37
  @prefix = prefix
36
38
  @name = name
37
39
  end
38
40
 
39
- def *
40
- field_cache[:"*"]
41
+ def field(name)
42
+ sym = @symbols.symbol("#{path}.#{name}")
43
+ sym.value ||= Field.new(@symbols,name,self)
44
+
45
+ return sym
41
46
  end
42
47
 
48
+ def all
49
+ field('*')
50
+ end
51
+
52
+ alias * all
53
+
43
54
  def id
44
- field_cache[:id]
55
+ field('id')
56
+ end
57
+
58
+ def as(name)
59
+ As.new(self,name)
45
60
  end
46
61
 
47
62
  def between(start,stop)
@@ -52,32 +67,34 @@ module Ronin
52
67
  between(range.begin,range.end)
53
68
  end
54
69
 
55
- def compile
56
- if @prefix
57
- return "#{@prefix}.#{@name}"
58
- else
59
- return @name.to_s
60
- end
70
+ def asc
71
+ Asc.new(self)
61
72
  end
62
73
 
63
- def to_sym
64
- compile.to_sym
74
+ def desc
75
+ Desc.new(self)
76
+ end
77
+
78
+ def emit
79
+ [path.to_sym]
65
80
  end
66
81
 
67
82
  protected
68
83
 
69
- def method_missing(sym,*args)
70
- if (args.length==0 && @prefix.nil?)
71
- return field_cache[sym]
84
+ def path
85
+ if @prefix
86
+ return "#{@prefix}.#{@name}"
87
+ else
88
+ return "#{@name}"
72
89
  end
73
-
74
- raise(NoMethodError,sym.id2name)
75
90
  end
76
91
 
77
- private
92
+ def method_missing(name,*arguments,&block)
93
+ if (arguments.empty? && @prefix.nil? && block.nil?)
94
+ return field(name)
95
+ end
78
96
 
79
- def field_cache
80
- @field_cache ||= Hash.new { |hash,key| hash[key] = Field.new(@style,key,self) }
97
+ raise(NoMethodError,sym.id2name)
81
98
  end
82
99
 
83
100
  end