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,10 +22,11 @@
22
22
  #
23
23
 
24
24
  require 'ronin/code/sql/expr'
25
+ require 'ronin/code/sql/token'
25
26
  require 'ronin/code/sql/field'
26
27
  require 'ronin/code/sql/binary_expr'
27
28
  require 'ronin/code/sql/unary_expr'
28
- require 'ronin/code/sql/like_expr'
29
+ require 'ronin/code/sql/like'
29
30
  require 'ronin/code/sql/in'
30
31
  require 'ronin/extensions/meta'
31
32
 
@@ -34,76 +35,145 @@ module Ronin
34
35
  module SQL
35
36
  class Statement < Expr
36
37
 
37
- def initialize(style,&block)
38
- super(style)
38
+ attr_reader :clauses
39
+
40
+ #
41
+ # Creates a new Statement object connected to the specified
42
+ # _dialect_. If a _block_ is given, it will be evaluated within
43
+ # the newly created Statement object.
44
+ #
45
+ def initialize(dialect,options={},&block)
46
+ super()
47
+
48
+ @dialect = dialect
49
+ @clauses = []
50
+
51
+ options.each do |name,args|
52
+ if self.class.has_clause?(name)
53
+ clause(name,*args)
54
+ end
55
+ end
39
56
 
40
57
  instance_eval(&block) if block
41
58
  end
42
59
 
43
- protected
60
+ #
61
+ # Returns the Array denoting the precedence of clauses provided by
62
+ # the statement.
63
+ #
64
+ def self.clause_order
65
+ @@clause_order ||= []
66
+ end
44
67
 
45
- def self.option(name,value=nil)
46
- class_eval %{
47
- def #{name}(&block)
48
- instance_variable_set("@#{name}",true)
68
+ #
69
+ # Returns the Hash of the clause names and the Clause classes
70
+ # provided by the statement.
71
+ #
72
+ def self.clauses
73
+ @@clauses ||= {}
74
+ end
49
75
 
50
- instance_eval(&block) if block
51
- return self
52
- end
53
- }
76
+ #
77
+ # Returns +true+ if the statement provides a clause with the
78
+ # specified _name_, returns +false+ otherwise.
79
+ #
80
+ def self.has_clause?(name)
81
+ self.clauses.has_key?(name.to_sym)
82
+ end
83
+
84
+ #
85
+ # Returns +true+ if the statement has a clause with the specified
86
+ # _name_, returns +false+ otherwise.
87
+ #
88
+ def has_clause?(name)
89
+ index = self.class.clause_order.index(name.to_sym)
90
+
91
+ return !(@clauses[index].nil?)
92
+ end
54
93
 
55
- class_def("#{name}?") do
56
- if value
57
- keyword(value.to_s) if instance_variable_get("@#{name}")
58
- else
59
- instance_variable_get("@#{name}")
94
+ #
95
+ # Returns the clause with the specified _name_.
96
+ #
97
+ def get_clause(name)
98
+ index = self.class.clause_order.index(name.to_sym)
99
+
100
+ return @clauses[index]
101
+ end
102
+
103
+ #
104
+ # Returns an Array of unformatted tokens that represent the
105
+ # statement.
106
+ #
107
+ def emit
108
+ tokens = []
109
+
110
+ @clauses.each do |clause|
111
+ if clause
112
+ tokens += clause.emit
60
113
  end
61
114
  end
115
+
116
+ return tokens
62
117
  end
63
118
 
64
- def self.option_list(name,values=[])
65
- values.each do |opt|
66
- class_eval %{
67
- def #{opt}_#{name}(&block)
68
- instance_variable_set("@#{name}",'#{opt.to_s.upcase}')
119
+ protected
69
120
 
70
- instance_eval(&block) if block
71
- return self
72
- end
73
- }
121
+ #
122
+ # Adds a clause with the specified _name_, _clause_type_ and given
123
+ # _options_ to the statement.
124
+ #
125
+ # _options_ may contain the following:
126
+ # <tt>:before</tt>:: The name of the clause to take precedence
127
+ # over.
128
+ # <tt>:after</tt>:: The name of the clause which will take
129
+ # precedence over the newly added clause.
130
+ #
131
+ def self.clause(name,clause_type,options={})
132
+ name = name.to_sym
133
+ index = self.clause_order.length
134
+
135
+ if options[:before]
136
+ index = self.clause_order.index(options[:before])
137
+ elsif options[:after]
138
+ index = self.clause_order.index(options[:after]) + 1
74
139
  end
75
140
 
76
- class_def("#{name}?") do
77
- opt = instance_variable_get("@#{name}")
141
+ self.clause_order.insert(index,name)
142
+ self.clauses[name] = clause_type
78
143
 
79
- return keyword(opt) if opt
80
- return nil
144
+ if clause_type.kind_of?(Class)
145
+ class_def(name) { |*args| clause(name,*args) }
146
+ else
147
+ class_def(name) { clause(name) }
81
148
  end
82
- end
83
149
 
84
- def all
85
- field_cache[:'*']
150
+ return clause_type
86
151
  end
87
152
 
88
- def id
89
- field_cache[:id]
90
- end
153
+ def clause(name,*arguments)
154
+ clause_index = self.class.clause_order.index(name)
91
155
 
92
- def method_missing(sym,*args,&block)
93
- if @style.dialect.expresses?(sym)
94
- return @style.dialect.express(sym,*args,&block)
95
- end
156
+ unless (@clauses[clause_index] && arguments.empty?)
157
+ clause_type = self.class.clauses[name]
96
158
 
97
- # return a field
98
- return @style.dialect.field(sym) if args.empty?
159
+ @clauses[clause_index] = clause_type.new(*arguments)
160
+ end
99
161
 
100
- return super(sym,*args,&block)
162
+ return @clauses[clause_index]
101
163
  end
102
164
 
103
- private
165
+ def select(options={},&block)
166
+ @dialect.statement(:select,options,&block)
167
+ end
104
168
 
105
- def field_cache
106
- @field_cache ||= Hash.new { |hash,key| hash[key] = Field.new(@style,key) }
169
+ def method_missing(name,*arguments,&block)
170
+ if @dialect.has_statement?(name)
171
+ return @dialect.statement(name,*arguments,&block)
172
+ elsif @dialect.class.public_method_defined?(name)
173
+ return @dialect.send(name,*arguments,&block)
174
+ elsif (arguments.empty? && block.nil?)
175
+ return @dialect.field(name)
176
+ end
107
177
  end
108
178
 
109
179
  end
@@ -0,0 +1,64 @@
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/emittable'
25
+ require 'ronin/code/token'
26
+
27
+ module Ronin
28
+ module Code
29
+ module SQL
30
+ class Token < Code::Token
31
+
32
+ include Emittable
33
+
34
+ #
35
+ # Creates a new Token object with the specified _value_.
36
+ #
37
+ def initialize(value)
38
+ @value = value
39
+ end
40
+
41
+ def Token.quote
42
+ Token.new("'")
43
+ end
44
+
45
+ def Token.separator
46
+ Token.new(';')
47
+ end
48
+
49
+ def Token.open_paren
50
+ Token.new('(')
51
+ end
52
+
53
+ def Token.close_paren
54
+ Token.new(')')
55
+ end
56
+
57
+ def Token.comma
58
+ Token.new(',')
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ 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
@@ -28,15 +28,19 @@ module Ronin
28
28
  module SQL
29
29
  class UnaryExpr < Expr
30
30
 
31
- def initialize(style,op,expr)
32
- super(style)
31
+ # Operator
32
+ attr_reader :op
33
33
 
34
+ # Expression
35
+ attr_reader :expr
36
+
37
+ def initialize(op,expr)
34
38
  @op = op
35
39
  @expr = expr
36
40
  end
37
41
 
38
- def compile
39
- compile_expr(compile_keyword(@op),@expr)
42
+ def emit
43
+ emit_token(@op) + emit_value(@expr)
40
44
  end
41
45
 
42
46
  end
@@ -0,0 +1,44 @@
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/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class UnionAllClause < Clause
30
+
31
+ attr_accessor :select
32
+
33
+ def initialize(select)
34
+ @select = select
35
+ end
36
+
37
+ def emit
38
+ emit_token('UNION ALL') + emit_statement(@select)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
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/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class UnionClause < Clause
30
+
31
+ attr_accessor :select
32
+
33
+ def initialize(select)
34
+ @select = select
35
+ end
36
+
37
+ def emit
38
+ emit_token('UNION') + emit_statement(@select)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ 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,18 +22,21 @@
22
22
  #
23
23
 
24
24
  require 'ronin/code/sql/statement'
25
+ require 'ronin/code/sql/set_clause'
26
+ require 'ronin/code/sql/where_clause'
25
27
 
26
28
  module Ronin
27
29
  module Code
28
30
  module SQL
29
31
  class Update < Statement
30
32
 
31
- def initialize(style,table=nil,set_data={},where_expr=nil,&block)
33
+ clause :set, SetClause
34
+ clause :where, WhereClause
35
+
36
+ def initialize(dialect,table=nil,options={},&block)
32
37
  @table = table
33
- @set_data = set_data
34
- @where_expr = where_expr
35
38
 
36
- super(style,&block)
39
+ super(dialect,options,&block)
37
40
  end
38
41
 
39
42
  def table(value)
@@ -41,32 +44,8 @@ module Ronin
41
44
  return self
42
45
  end
43
46
 
44
- def set(data)
45
- @set_data = data
46
- return self
47
- end
48
-
49
- def where(expr)
50
- @where_expr = expr
51
- return self
52
- end
53
-
54
- def compile
55
- set_values = "#{keyword_set} "+@set_data.map { |name,value|
56
- "#{name} = #{quote_string(value)}"
57
- }.join(', ')
58
-
59
- return compile_expr(keyword_update,@table,set_values,where?)
60
- end
61
-
62
- protected
63
-
64
- keyword :update
65
- keyword :where
66
- keyword :set
67
-
68
- def where?
69
- compile_expr(keyword_where,@where_expr) if @where_expr
47
+ def emit
48
+ emit_token('UPDATE') + emit_value(@table) + super
70
49
  end
71
50
 
72
51
  end
@@ -0,0 +1,48 @@
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/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class ValuesClause < Clause
30
+
31
+ # Values of the clause
32
+ attr_accessor :values
33
+
34
+ #
35
+ # Creates a new ValuesClause object with the specified _values_.
36
+ #
37
+ def initialize(*values)
38
+ @values = values
39
+ end
40
+
41
+ def emit
42
+ emit_token('VALUES') + emit_row(@values)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
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/clause'
25
+
26
+ module Ronin
27
+ module Code
28
+ module SQL
29
+ class WhereClause < Clause
30
+
31
+ attr_accessor :expr
32
+
33
+ def initialize(expr)
34
+ @expr = expr
35
+ end
36
+
37
+ def emit
38
+ emit_token('WHERE') + emit_value(@expr)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ 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
@@ -0,0 +1,64 @@
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/sql/error/pattern'
25
+
26
+ module Ronin
27
+ module SQL
28
+ module Error
29
+ #
30
+ # Returns all defined SQL Pattern objects.
31
+ #
32
+ def Error.patterns
33
+ @@ronin_sql_error_patterns ||= {}
34
+ end
35
+
36
+ #
37
+ # Defines a new SQL Pattern object with the given _options_.
38
+ #
39
+ def Error.pattern(name,&block)
40
+ pattern = (Error.patterns[name] ||= Pattern.new(name))
41
+
42
+ block.call(pattern) if block
43
+ return pattern
44
+ end
45
+
46
+ #
47
+ # Returns the SQL Pattern objects with the specified _names_.
48
+ #
49
+ def Error.patterns_for(*names)
50
+ names.map { |name| Error.patterns[name] }.compact
51
+ end
52
+
53
+ #
54
+ # Returns the SQL Pattern objects for the dialect with the
55
+ # specified _name_.
56
+ #
57
+ def Error.patterns_for_dialect(name)
58
+ Error.patterns.values.select do |pattern|
59
+ pattern.dialect == name
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end