ronin-sql 0.2.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +623 -288
- data/{History.txt → ChangeLog.md} +33 -35
- data/Gemfile +25 -0
- data/README.md +110 -0
- data/Rakefile +30 -20
- data/bin/ronin-sql +18 -5
- data/gemspec.yml +16 -0
- data/lib/ronin/formatting/extensions/sql.rb +4 -3
- data/lib/ronin/formatting/extensions/sql/string.rb +83 -10
- data/lib/ronin/formatting/sql.rb +4 -3
- data/lib/ronin/sql.rb +5 -12
- data/lib/ronin/{code/sql/create_index.rb → sql/binary_expr.rb} +25 -18
- data/lib/ronin/sql/clause.rb +72 -0
- data/lib/ronin/sql/clauses.rb +297 -0
- data/lib/ronin/sql/emittable.rb +84 -0
- data/lib/ronin/sql/emitter.rb +375 -0
- data/lib/ronin/sql/field.rb +106 -0
- data/lib/ronin/{code/sql/as.rb → sql/fields.rb} +36 -17
- data/lib/ronin/{code/sql/binary_expr.rb → sql/function.rb} +27 -27
- data/lib/ronin/sql/functions.rb +989 -0
- data/lib/ronin/sql/injection.rb +125 -157
- data/lib/ronin/{code/sql/default_values_clause.rb → sql/literal.rb} +13 -11
- data/lib/ronin/sql/literals.rb +72 -0
- data/lib/ronin/sql/operators.rb +332 -0
- data/lib/ronin/sql/sql.rb +86 -0
- data/lib/ronin/sql/statement.rb +70 -0
- data/lib/ronin/sql/statement_list.rb +110 -0
- data/lib/ronin/sql/statements.rb +115 -0
- data/lib/ronin/{code/sql/desc.rb → sql/unary_expr.rb} +11 -11
- data/lib/ronin/sql/version.rb +5 -4
- data/ronin-sql.gemspec +61 -0
- data/spec/formatting/sql/string_spec.rb +172 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/sql/binary_expr.rb +5 -0
- data/spec/sql/binary_expr_examples.rb +25 -0
- data/spec/sql/clause_examples.rb +43 -0
- data/spec/sql/clause_spec.rb +31 -0
- data/spec/sql/clauses_spec.rb +43 -0
- data/spec/sql/emittable_spec.rb +41 -0
- data/spec/sql/emitter_spec.rb +472 -0
- data/spec/sql/field_spec.rb +103 -0
- data/spec/sql/fields_spec.rb +40 -0
- data/spec/sql/function_examples.rb +30 -0
- data/spec/sql/function_spec.rb +25 -0
- data/spec/sql/functions_spec.rb +110 -0
- data/spec/sql/injection_spec.rb +233 -0
- data/spec/sql/literal_spec.rb +5 -0
- data/spec/sql/literals_spec.rb +46 -0
- data/spec/sql/operators_spec.rb +44 -0
- data/spec/sql/sql_spec.rb +18 -0
- data/spec/sql/statement_examples.rb +39 -0
- data/spec/sql/statement_list_spec.rb +48 -0
- data/spec/sql/statement_sql.rb +38 -0
- data/spec/sql/statements_spec.rb +22 -0
- data/spec/sql/unary_expr.rb +5 -0
- data/spec/sql/unary_expr_examples.rb +20 -0
- metadata +116 -217
- data.tar.gz.sig +0 -0
- data/Manifest.txt +0 -108
- data/README.txt +0 -112
- data/lib/ronin/code/sql.rb +0 -22
- data/lib/ronin/code/sql/add_column_clause.rb +0 -42
- data/lib/ronin/code/sql/alter_table.rb +0 -52
- data/lib/ronin/code/sql/asc.rb +0 -36
- data/lib/ronin/code/sql/between.rb +0 -66
- data/lib/ronin/code/sql/clause.rb +0 -35
- data/lib/ronin/code/sql/code.rb +0 -35
- data/lib/ronin/code/sql/common_dialect.rb +0 -66
- data/lib/ronin/code/sql/create.rb +0 -74
- data/lib/ronin/code/sql/create_table.rb +0 -44
- data/lib/ronin/code/sql/create_view.rb +0 -41
- data/lib/ronin/code/sql/delete.rb +0 -52
- data/lib/ronin/code/sql/dialect.rb +0 -282
- data/lib/ronin/code/sql/drop.rb +0 -55
- data/lib/ronin/code/sql/drop_index.rb +0 -41
- data/lib/ronin/code/sql/drop_table.rb +0 -41
- data/lib/ronin/code/sql/drop_view.rb +0 -41
- data/lib/ronin/code/sql/emittable.rb +0 -100
- data/lib/ronin/code/sql/exceptions.rb +0 -24
- data/lib/ronin/code/sql/exceptions/unknown_clause.rb +0 -29
- data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +0 -29
- data/lib/ronin/code/sql/exceptions/unknown_statement.rb +0 -29
- data/lib/ronin/code/sql/expr.rb +0 -102
- data/lib/ronin/code/sql/field.rb +0 -101
- data/lib/ronin/code/sql/fields_clause.rb +0 -46
- data/lib/ronin/code/sql/from_clause.rb +0 -42
- data/lib/ronin/code/sql/function.rb +0 -53
- data/lib/ronin/code/sql/group_by_clause.rb +0 -46
- data/lib/ronin/code/sql/having_clause.rb +0 -46
- data/lib/ronin/code/sql/in.rb +0 -47
- data/lib/ronin/code/sql/injected_statement.rb +0 -100
- data/lib/ronin/code/sql/injection.rb +0 -203
- data/lib/ronin/code/sql/insert.rb +0 -54
- data/lib/ronin/code/sql/intersect_clause.rb +0 -42
- data/lib/ronin/code/sql/join_clause.rb +0 -123
- data/lib/ronin/code/sql/like.rb +0 -73
- data/lib/ronin/code/sql/limit_clause.rb +0 -42
- data/lib/ronin/code/sql/modifier.rb +0 -48
- data/lib/ronin/code/sql/offset_clause.rb +0 -42
- data/lib/ronin/code/sql/on_clause.rb +0 -55
- data/lib/ronin/code/sql/order_by_clause.rb +0 -42
- data/lib/ronin/code/sql/program.rb +0 -225
- data/lib/ronin/code/sql/rename_to_clause.rb +0 -42
- data/lib/ronin/code/sql/replace.rb +0 -54
- data/lib/ronin/code/sql/select.rb +0 -103
- data/lib/ronin/code/sql/set_clause.rb +0 -42
- data/lib/ronin/code/sql/statement.rb +0 -180
- data/lib/ronin/code/sql/token.rb +0 -62
- data/lib/ronin/code/sql/unary_expr.rb +0 -47
- data/lib/ronin/code/sql/union_all_clause.rb +0 -42
- data/lib/ronin/code/sql/union_clause.rb +0 -42
- data/lib/ronin/code/sql/update.rb +0 -52
- data/lib/ronin/code/sql/values_clause.rb +0 -46
- data/lib/ronin/code/sql/where_clause.rb +0 -42
- data/lib/ronin/sql/error.rb +0 -26
- data/lib/ronin/sql/error/error.rb +0 -62
- data/lib/ronin/sql/error/extensions.rb +0 -22
- data/lib/ronin/sql/error/extensions/string.rb +0 -77
- data/lib/ronin/sql/error/message.rb +0 -62
- data/lib/ronin/sql/error/pattern.rb +0 -104
- data/lib/ronin/sql/error/patterns.rb +0 -99
- data/lib/ronin/sql/extensions.rb +0 -22
- data/lib/ronin/sql/extensions/uri.rb +0 -22
- data/lib/ronin/sql/extensions/uri/http.rb +0 -107
- data/spec/code/sql/common_dialect_spec.rb +0 -205
- data/spec/code/sql/create_examples.rb +0 -19
- data/spec/code/sql/create_index_spec.rb +0 -25
- data/spec/code/sql/create_table_spec.rb +0 -27
- data/spec/code/sql/create_view_spec.rb +0 -16
- data/spec/code/sql/delete_spec.rb +0 -14
- data/spec/code/sql/drop_examples.rb +0 -10
- data/spec/code/sql/drop_index_spec.rb +0 -16
- data/spec/code/sql/drop_table_spec.rb +0 -16
- data/spec/code/sql/drop_view_spec.rb +0 -16
- data/spec/code/sql/has_default_values_clause_examples.rb +0 -10
- data/spec/code/sql/has_fields_clause_examples.rb +0 -15
- data/spec/code/sql/has_from_clause_examples.rb +0 -13
- data/spec/code/sql/has_values_clause_examples.rb +0 -15
- data/spec/code/sql/has_where_clause_examples.rb +0 -15
- data/spec/code/sql/insert_spec.rb +0 -21
- data/spec/code/sql/replace_spec.rb +0 -21
- data/spec/code/sql/select_spec.rb +0 -105
- data/spec/code/sql/update_spec.rb +0 -26
- data/spec/helpers/code.rb +0 -14
- data/spec/sql/error_spec.rb +0 -24
- data/spec/sql/extensions/uri/http_spec.rb +0 -34
- data/spec/sql_spec.rb +0 -9
- data/tasks/spec.rb +0 -10
- data/tasks/yard.rb +0 -13
- metadata.gz.sig +0 -0
@@ -1,42 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
|
-
# tasks.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This program is free software; you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation; either version 2 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program; if not, write to the Free Software
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
-
#
|
21
|
-
|
22
|
-
require 'ronin/code/sql/clause'
|
23
|
-
|
24
|
-
module Ronin
|
25
|
-
module Code
|
26
|
-
module SQL
|
27
|
-
class RenameToClause < Clause
|
28
|
-
|
29
|
-
attr_accessor :table
|
30
|
-
|
31
|
-
def initialize(table)
|
32
|
-
@table = table
|
33
|
-
end
|
34
|
-
|
35
|
-
def emit
|
36
|
-
emit_token('RENAME TO') + emit_value(@table)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
|
-
# tasks.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This program is free software; you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation; either version 2 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program; if not, write to the Free Software
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
-
#
|
21
|
-
|
22
|
-
require 'ronin/code/sql/statement'
|
23
|
-
require 'ronin/code/sql/fields_clause'
|
24
|
-
require 'ronin/code/sql/values_clause'
|
25
|
-
require 'ronin/code/sql/default_values_clause'
|
26
|
-
|
27
|
-
module Ronin
|
28
|
-
module Code
|
29
|
-
module SQL
|
30
|
-
class Replace < Statement
|
31
|
-
|
32
|
-
clause :fields, FieldsClause
|
33
|
-
clause :default_values, DefaultValuesClause
|
34
|
-
clause :values, ValuesClause
|
35
|
-
|
36
|
-
def initialize(dialect,options={},&block)
|
37
|
-
@table = options[:table]
|
38
|
-
|
39
|
-
super(dialect,options,&block)
|
40
|
-
end
|
41
|
-
|
42
|
-
def table(name)
|
43
|
-
@table = name
|
44
|
-
return value
|
45
|
-
end
|
46
|
-
|
47
|
-
def emit
|
48
|
-
emit_token('REPLACE INTO') + emit_value(@table) + super
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
|
-
# tasks.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This program is free software; you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation; either version 2 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program; if not, write to the Free Software
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
-
#
|
21
|
-
|
22
|
-
require 'ronin/code/sql/statement'
|
23
|
-
require 'ronin/code/sql/fields_clause'
|
24
|
-
require 'ronin/code/sql/from_clause'
|
25
|
-
require 'ronin/code/sql/join_clause'
|
26
|
-
require 'ronin/code/sql/where_clause'
|
27
|
-
require 'ronin/code/sql/group_by_clause'
|
28
|
-
require 'ronin/code/sql/having_clause'
|
29
|
-
require 'ronin/code/sql/order_by_clause'
|
30
|
-
require 'ronin/code/sql/limit_clause'
|
31
|
-
require 'ronin/code/sql/offset_clause'
|
32
|
-
require 'ronin/code/sql/union_clause'
|
33
|
-
require 'ronin/code/sql/union_all_clause'
|
34
|
-
|
35
|
-
module Ronin
|
36
|
-
module Code
|
37
|
-
module SQL
|
38
|
-
class Select < Statement
|
39
|
-
|
40
|
-
clause :fields, FieldsClause
|
41
|
-
clause :from, FromClause
|
42
|
-
clause :join, JoinClause
|
43
|
-
clause :where, WhereClause
|
44
|
-
clause :group_by, GroupByClause
|
45
|
-
clause :having, HavingClause
|
46
|
-
clause :order_by, OrderByClause
|
47
|
-
clause :limit, LimitClause
|
48
|
-
clause :offset, OffsetClause
|
49
|
-
clause :union, UnionClause
|
50
|
-
clause :union_all, UnionAllClause
|
51
|
-
|
52
|
-
def initialize(dialect,options={},&block)
|
53
|
-
super(dialect,options)
|
54
|
-
|
55
|
-
if options[:distinct_rows]
|
56
|
-
self.distinct_rows!
|
57
|
-
end
|
58
|
-
|
59
|
-
if options[:all_rows]
|
60
|
-
self.all_rows!
|
61
|
-
end
|
62
|
-
|
63
|
-
unless options[:fields]
|
64
|
-
fields(all)
|
65
|
-
end
|
66
|
-
|
67
|
-
instance_eval(&block) if block
|
68
|
-
end
|
69
|
-
|
70
|
-
def all_rows!
|
71
|
-
@all_rows = true
|
72
|
-
return self
|
73
|
-
end
|
74
|
-
|
75
|
-
def all_rows?
|
76
|
-
@all_rows == true
|
77
|
-
end
|
78
|
-
|
79
|
-
def distinct_rows!
|
80
|
-
@distinct_rows = true
|
81
|
-
return self
|
82
|
-
end
|
83
|
-
|
84
|
-
def distinct_rows?
|
85
|
-
@distinct_rows == true
|
86
|
-
end
|
87
|
-
|
88
|
-
def emit
|
89
|
-
tokens = emit_token('SELECT')
|
90
|
-
|
91
|
-
if @distinct_rows
|
92
|
-
tokens += emit_token('DISTINCT')
|
93
|
-
elsif @all_rows
|
94
|
-
tokens += emit_token('ALL')
|
95
|
-
end
|
96
|
-
|
97
|
-
return tokens + super
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
|
-
# tasks.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This program is free software; you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation; either version 2 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program; if not, write to the Free Software
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
-
#
|
21
|
-
|
22
|
-
require 'ronin/code/sql/clause'
|
23
|
-
|
24
|
-
module Ronin
|
25
|
-
module Code
|
26
|
-
module SQL
|
27
|
-
class SetClause < Clause
|
28
|
-
|
29
|
-
attr_accessor :values
|
30
|
-
|
31
|
-
def initialize(*values)
|
32
|
-
@values = values
|
33
|
-
end
|
34
|
-
|
35
|
-
def emit
|
36
|
-
emit_token('WHERE') + emit_row(@values)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
|
-
# tasks.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This program is free software; you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation; either version 2 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program; if not, write to the Free Software
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
-
#
|
21
|
-
|
22
|
-
require 'ronin/code/sql/expr'
|
23
|
-
require 'ronin/code/sql/token'
|
24
|
-
require 'ronin/code/sql/field'
|
25
|
-
require 'ronin/code/sql/binary_expr'
|
26
|
-
require 'ronin/code/sql/unary_expr'
|
27
|
-
require 'ronin/code/sql/like'
|
28
|
-
require 'ronin/code/sql/in'
|
29
|
-
require 'ronin/extensions/meta'
|
30
|
-
|
31
|
-
module Ronin
|
32
|
-
module Code
|
33
|
-
module SQL
|
34
|
-
class Statement < Expr
|
35
|
-
|
36
|
-
attr_reader :clauses
|
37
|
-
|
38
|
-
#
|
39
|
-
# Creates a new Statement object connected to the specified
|
40
|
-
# _dialect_. If a _block_ is given, it will be evaluated within
|
41
|
-
# the newly created Statement object.
|
42
|
-
#
|
43
|
-
def initialize(dialect,options={},&block)
|
44
|
-
super()
|
45
|
-
|
46
|
-
@dialect = dialect
|
47
|
-
@clauses = []
|
48
|
-
|
49
|
-
options.each do |name,args|
|
50
|
-
if self.class.has_clause?(name)
|
51
|
-
clause(name,*args)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
instance_eval(&block) if block
|
56
|
-
end
|
57
|
-
|
58
|
-
#
|
59
|
-
# Returns the Array denoting the precedence of clauses provided by
|
60
|
-
# the statement.
|
61
|
-
#
|
62
|
-
def self.clause_order
|
63
|
-
@@clause_order ||= []
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# Returns the Hash of the clause names and the Clause classes
|
68
|
-
# provided by the statement.
|
69
|
-
#
|
70
|
-
def self.clauses
|
71
|
-
@@clauses ||= {}
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# Returns +true+ if the statement provides a clause with the
|
76
|
-
# specified _name_, returns +false+ otherwise.
|
77
|
-
#
|
78
|
-
def self.has_clause?(name)
|
79
|
-
self.clauses.has_key?(name.to_sym)
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# Returns +true+ if the statement has a clause with the specified
|
84
|
-
# _name_, returns +false+ otherwise.
|
85
|
-
#
|
86
|
-
def has_clause?(name)
|
87
|
-
index = self.class.clause_order.index(name.to_sym)
|
88
|
-
|
89
|
-
return !(@clauses[index].nil?)
|
90
|
-
end
|
91
|
-
|
92
|
-
#
|
93
|
-
# Returns the clause with the specified _name_.
|
94
|
-
#
|
95
|
-
def get_clause(name)
|
96
|
-
index = self.class.clause_order.index(name.to_sym)
|
97
|
-
|
98
|
-
return @clauses[index]
|
99
|
-
end
|
100
|
-
|
101
|
-
#
|
102
|
-
# Returns an Array of unformatted tokens that represent the
|
103
|
-
# statement.
|
104
|
-
#
|
105
|
-
def emit
|
106
|
-
tokens = []
|
107
|
-
|
108
|
-
@clauses.each do |clause|
|
109
|
-
if clause
|
110
|
-
tokens += clause.emit
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
return tokens
|
115
|
-
end
|
116
|
-
|
117
|
-
protected
|
118
|
-
|
119
|
-
#
|
120
|
-
# Adds a clause with the specified _name_, _clause_type_ and given
|
121
|
-
# _options_ to the statement.
|
122
|
-
#
|
123
|
-
# _options_ may contain the following:
|
124
|
-
# <tt>:before</tt>:: The name of the clause to take precedence
|
125
|
-
# over.
|
126
|
-
# <tt>:after</tt>:: The name of the clause which will take
|
127
|
-
# precedence over the newly added clause.
|
128
|
-
#
|
129
|
-
def self.clause(name,clause_type,options={})
|
130
|
-
name = name.to_sym
|
131
|
-
index = self.clause_order.length
|
132
|
-
|
133
|
-
if options[:before]
|
134
|
-
index = self.clause_order.index(options[:before])
|
135
|
-
elsif options[:after]
|
136
|
-
index = self.clause_order.index(options[:after]) + 1
|
137
|
-
end
|
138
|
-
|
139
|
-
self.clause_order.insert(index,name)
|
140
|
-
self.clauses[name] = clause_type
|
141
|
-
|
142
|
-
if clause_type.kind_of?(Class)
|
143
|
-
class_def(name) { |*args| clause(name,*args) }
|
144
|
-
else
|
145
|
-
class_def(name) { clause(name) }
|
146
|
-
end
|
147
|
-
|
148
|
-
return clause_type
|
149
|
-
end
|
150
|
-
|
151
|
-
def clause(name,*arguments)
|
152
|
-
clause_index = self.class.clause_order.index(name)
|
153
|
-
|
154
|
-
unless (@clauses[clause_index] && arguments.empty?)
|
155
|
-
clause_type = self.class.clauses[name]
|
156
|
-
|
157
|
-
@clauses[clause_index] = clause_type.new(*arguments)
|
158
|
-
end
|
159
|
-
|
160
|
-
return @clauses[clause_index]
|
161
|
-
end
|
162
|
-
|
163
|
-
def select(options={},&block)
|
164
|
-
@dialect.statement(:select,options,&block)
|
165
|
-
end
|
166
|
-
|
167
|
-
def method_missing(name,*arguments,&block)
|
168
|
-
if @dialect.has_statement?(name)
|
169
|
-
return @dialect.statement(name,*arguments,&block)
|
170
|
-
elsif @dialect.class.public_method_defined?(name)
|
171
|
-
return @dialect.send(name,*arguments,&block)
|
172
|
-
elsif (arguments.empty? && block.nil?)
|
173
|
-
return @dialect.field(name)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
data/lib/ronin/code/sql/token.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin SQL - A Ronin library providing support for SQL related security
|
3
|
-
# tasks.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This program is free software; you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation; either version 2 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program; if not, write to the Free Software
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
-
#
|
21
|
-
|
22
|
-
require 'ronin/code/sql/emittable'
|
23
|
-
require 'ronin/code/token'
|
24
|
-
|
25
|
-
module Ronin
|
26
|
-
module Code
|
27
|
-
module SQL
|
28
|
-
class Token < Code::Token
|
29
|
-
|
30
|
-
include Emittable
|
31
|
-
|
32
|
-
#
|
33
|
-
# Creates a new Token object with the specified _value_.
|
34
|
-
#
|
35
|
-
def initialize(value)
|
36
|
-
@value = value
|
37
|
-
end
|
38
|
-
|
39
|
-
def Token.quote
|
40
|
-
Token.new("'")
|
41
|
-
end
|
42
|
-
|
43
|
-
def Token.separator
|
44
|
-
Token.new(';')
|
45
|
-
end
|
46
|
-
|
47
|
-
def Token.open_paren
|
48
|
-
Token.new('(')
|
49
|
-
end
|
50
|
-
|
51
|
-
def Token.close_paren
|
52
|
-
Token.new(')')
|
53
|
-
end
|
54
|
-
|
55
|
-
def Token.comma
|
56
|
-
Token.new(',')
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|