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.
Files changed (154) hide show
  1. data/.document +4 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +1 -0
  4. data/.yardopts +1 -0
  5. data/COPYING.txt +623 -288
  6. data/{History.txt → ChangeLog.md} +33 -35
  7. data/Gemfile +25 -0
  8. data/README.md +110 -0
  9. data/Rakefile +30 -20
  10. data/bin/ronin-sql +18 -5
  11. data/gemspec.yml +16 -0
  12. data/lib/ronin/formatting/extensions/sql.rb +4 -3
  13. data/lib/ronin/formatting/extensions/sql/string.rb +83 -10
  14. data/lib/ronin/formatting/sql.rb +4 -3
  15. data/lib/ronin/sql.rb +5 -12
  16. data/lib/ronin/{code/sql/create_index.rb → sql/binary_expr.rb} +25 -18
  17. data/lib/ronin/sql/clause.rb +72 -0
  18. data/lib/ronin/sql/clauses.rb +297 -0
  19. data/lib/ronin/sql/emittable.rb +84 -0
  20. data/lib/ronin/sql/emitter.rb +375 -0
  21. data/lib/ronin/sql/field.rb +106 -0
  22. data/lib/ronin/{code/sql/as.rb → sql/fields.rb} +36 -17
  23. data/lib/ronin/{code/sql/binary_expr.rb → sql/function.rb} +27 -27
  24. data/lib/ronin/sql/functions.rb +989 -0
  25. data/lib/ronin/sql/injection.rb +125 -157
  26. data/lib/ronin/{code/sql/default_values_clause.rb → sql/literal.rb} +13 -11
  27. data/lib/ronin/sql/literals.rb +72 -0
  28. data/lib/ronin/sql/operators.rb +332 -0
  29. data/lib/ronin/sql/sql.rb +86 -0
  30. data/lib/ronin/sql/statement.rb +70 -0
  31. data/lib/ronin/sql/statement_list.rb +110 -0
  32. data/lib/ronin/sql/statements.rb +115 -0
  33. data/lib/ronin/{code/sql/desc.rb → sql/unary_expr.rb} +11 -11
  34. data/lib/ronin/sql/version.rb +5 -4
  35. data/ronin-sql.gemspec +61 -0
  36. data/spec/formatting/sql/string_spec.rb +172 -0
  37. data/spec/spec_helper.rb +1 -4
  38. data/spec/sql/binary_expr.rb +5 -0
  39. data/spec/sql/binary_expr_examples.rb +25 -0
  40. data/spec/sql/clause_examples.rb +43 -0
  41. data/spec/sql/clause_spec.rb +31 -0
  42. data/spec/sql/clauses_spec.rb +43 -0
  43. data/spec/sql/emittable_spec.rb +41 -0
  44. data/spec/sql/emitter_spec.rb +472 -0
  45. data/spec/sql/field_spec.rb +103 -0
  46. data/spec/sql/fields_spec.rb +40 -0
  47. data/spec/sql/function_examples.rb +30 -0
  48. data/spec/sql/function_spec.rb +25 -0
  49. data/spec/sql/functions_spec.rb +110 -0
  50. data/spec/sql/injection_spec.rb +233 -0
  51. data/spec/sql/literal_spec.rb +5 -0
  52. data/spec/sql/literals_spec.rb +46 -0
  53. data/spec/sql/operators_spec.rb +44 -0
  54. data/spec/sql/sql_spec.rb +18 -0
  55. data/spec/sql/statement_examples.rb +39 -0
  56. data/spec/sql/statement_list_spec.rb +48 -0
  57. data/spec/sql/statement_sql.rb +38 -0
  58. data/spec/sql/statements_spec.rb +22 -0
  59. data/spec/sql/unary_expr.rb +5 -0
  60. data/spec/sql/unary_expr_examples.rb +20 -0
  61. metadata +116 -217
  62. data.tar.gz.sig +0 -0
  63. data/Manifest.txt +0 -108
  64. data/README.txt +0 -112
  65. data/lib/ronin/code/sql.rb +0 -22
  66. data/lib/ronin/code/sql/add_column_clause.rb +0 -42
  67. data/lib/ronin/code/sql/alter_table.rb +0 -52
  68. data/lib/ronin/code/sql/asc.rb +0 -36
  69. data/lib/ronin/code/sql/between.rb +0 -66
  70. data/lib/ronin/code/sql/clause.rb +0 -35
  71. data/lib/ronin/code/sql/code.rb +0 -35
  72. data/lib/ronin/code/sql/common_dialect.rb +0 -66
  73. data/lib/ronin/code/sql/create.rb +0 -74
  74. data/lib/ronin/code/sql/create_table.rb +0 -44
  75. data/lib/ronin/code/sql/create_view.rb +0 -41
  76. data/lib/ronin/code/sql/delete.rb +0 -52
  77. data/lib/ronin/code/sql/dialect.rb +0 -282
  78. data/lib/ronin/code/sql/drop.rb +0 -55
  79. data/lib/ronin/code/sql/drop_index.rb +0 -41
  80. data/lib/ronin/code/sql/drop_table.rb +0 -41
  81. data/lib/ronin/code/sql/drop_view.rb +0 -41
  82. data/lib/ronin/code/sql/emittable.rb +0 -100
  83. data/lib/ronin/code/sql/exceptions.rb +0 -24
  84. data/lib/ronin/code/sql/exceptions/unknown_clause.rb +0 -29
  85. data/lib/ronin/code/sql/exceptions/unknown_dialect.rb +0 -29
  86. data/lib/ronin/code/sql/exceptions/unknown_statement.rb +0 -29
  87. data/lib/ronin/code/sql/expr.rb +0 -102
  88. data/lib/ronin/code/sql/field.rb +0 -101
  89. data/lib/ronin/code/sql/fields_clause.rb +0 -46
  90. data/lib/ronin/code/sql/from_clause.rb +0 -42
  91. data/lib/ronin/code/sql/function.rb +0 -53
  92. data/lib/ronin/code/sql/group_by_clause.rb +0 -46
  93. data/lib/ronin/code/sql/having_clause.rb +0 -46
  94. data/lib/ronin/code/sql/in.rb +0 -47
  95. data/lib/ronin/code/sql/injected_statement.rb +0 -100
  96. data/lib/ronin/code/sql/injection.rb +0 -203
  97. data/lib/ronin/code/sql/insert.rb +0 -54
  98. data/lib/ronin/code/sql/intersect_clause.rb +0 -42
  99. data/lib/ronin/code/sql/join_clause.rb +0 -123
  100. data/lib/ronin/code/sql/like.rb +0 -73
  101. data/lib/ronin/code/sql/limit_clause.rb +0 -42
  102. data/lib/ronin/code/sql/modifier.rb +0 -48
  103. data/lib/ronin/code/sql/offset_clause.rb +0 -42
  104. data/lib/ronin/code/sql/on_clause.rb +0 -55
  105. data/lib/ronin/code/sql/order_by_clause.rb +0 -42
  106. data/lib/ronin/code/sql/program.rb +0 -225
  107. data/lib/ronin/code/sql/rename_to_clause.rb +0 -42
  108. data/lib/ronin/code/sql/replace.rb +0 -54
  109. data/lib/ronin/code/sql/select.rb +0 -103
  110. data/lib/ronin/code/sql/set_clause.rb +0 -42
  111. data/lib/ronin/code/sql/statement.rb +0 -180
  112. data/lib/ronin/code/sql/token.rb +0 -62
  113. data/lib/ronin/code/sql/unary_expr.rb +0 -47
  114. data/lib/ronin/code/sql/union_all_clause.rb +0 -42
  115. data/lib/ronin/code/sql/union_clause.rb +0 -42
  116. data/lib/ronin/code/sql/update.rb +0 -52
  117. data/lib/ronin/code/sql/values_clause.rb +0 -46
  118. data/lib/ronin/code/sql/where_clause.rb +0 -42
  119. data/lib/ronin/sql/error.rb +0 -26
  120. data/lib/ronin/sql/error/error.rb +0 -62
  121. data/lib/ronin/sql/error/extensions.rb +0 -22
  122. data/lib/ronin/sql/error/extensions/string.rb +0 -77
  123. data/lib/ronin/sql/error/message.rb +0 -62
  124. data/lib/ronin/sql/error/pattern.rb +0 -104
  125. data/lib/ronin/sql/error/patterns.rb +0 -99
  126. data/lib/ronin/sql/extensions.rb +0 -22
  127. data/lib/ronin/sql/extensions/uri.rb +0 -22
  128. data/lib/ronin/sql/extensions/uri/http.rb +0 -107
  129. data/spec/code/sql/common_dialect_spec.rb +0 -205
  130. data/spec/code/sql/create_examples.rb +0 -19
  131. data/spec/code/sql/create_index_spec.rb +0 -25
  132. data/spec/code/sql/create_table_spec.rb +0 -27
  133. data/spec/code/sql/create_view_spec.rb +0 -16
  134. data/spec/code/sql/delete_spec.rb +0 -14
  135. data/spec/code/sql/drop_examples.rb +0 -10
  136. data/spec/code/sql/drop_index_spec.rb +0 -16
  137. data/spec/code/sql/drop_table_spec.rb +0 -16
  138. data/spec/code/sql/drop_view_spec.rb +0 -16
  139. data/spec/code/sql/has_default_values_clause_examples.rb +0 -10
  140. data/spec/code/sql/has_fields_clause_examples.rb +0 -15
  141. data/spec/code/sql/has_from_clause_examples.rb +0 -13
  142. data/spec/code/sql/has_values_clause_examples.rb +0 -15
  143. data/spec/code/sql/has_where_clause_examples.rb +0 -15
  144. data/spec/code/sql/insert_spec.rb +0 -21
  145. data/spec/code/sql/replace_spec.rb +0 -21
  146. data/spec/code/sql/select_spec.rb +0 -105
  147. data/spec/code/sql/update_spec.rb +0 -26
  148. data/spec/helpers/code.rb +0 -14
  149. data/spec/sql/error_spec.rb +0 -24
  150. data/spec/sql/extensions/uri/http_spec.rb +0 -34
  151. data/spec/sql_spec.rb +0 -9
  152. data/tasks/spec.rb +0 -10
  153. data/tasks/yard.rb +0 -13
  154. metadata.gz.sig +0 -0
@@ -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
- module Ronin
23
- module SQL
24
- module Error
25
- class Message
26
-
27
- # The URL which is vulnerable
28
- attr_reader :url
29
-
30
- # The vulnerable query param
31
- attr_accessor :param
32
-
33
- # SQL error type
34
- attr_reader :type
35
-
36
- # SQL Dialect
37
- attr_reader :dialect
38
-
39
- # SQL error message
40
- attr_reader :message
41
-
42
- #
43
- # Creates a new SQL Error object with the specified _type_,
44
- # _dialect_ and _message_.
45
- #
46
- def initialize(type,dialect,message)
47
- @type = type
48
- @dialect = dialect
49
- @message = message
50
- end
51
-
52
- #
53
- # Returns the message in String form.
54
- #
55
- def to_s
56
- @message.to_s
57
- end
58
-
59
- end
60
- end
61
- end
62
- end
@@ -1,104 +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/sql/error/message'
23
-
24
- module Ronin
25
- module SQL
26
- module Error
27
- class Pattern
28
-
29
- # Name of the pattern
30
- attr_reader :name
31
-
32
- # Name of the SQL dialect
33
- attr_accessor :dialect
34
-
35
- # Patterns to use for matching SQL errors
36
- attr_reader :patterns
37
-
38
- #
39
- # Creates a new Pattern object with the specified _name_. If a
40
- # _block_ is given, it will be passed the newly created Pattern
41
- # object.
42
- #
43
- def initialize(name,&block)
44
- @dialect = :common
45
- @name = name.to_sym
46
- @patterns = []
47
-
48
- block.call(self) if block
49
- end
50
-
51
- #
52
- # Add the specified _pattern_ to be used to recognize SQL error
53
- # messages.
54
- #
55
- def recognize(pattern)
56
- @patterns << pattern
57
- return self
58
- end
59
-
60
- #
61
- # Returns the first match between the error pattern and the
62
- # specified _data_. If no matches were found +nil+ will be
63
- # returned.
64
- #
65
- def match(data)
66
- data = data.to_s
67
-
68
- @patterns.each do |pattern|
69
- match = data.match(pattern)
70
-
71
- return Message.new(@name,@dialect,match[0]) if match
72
- end
73
-
74
- return nil
75
- end
76
-
77
- #
78
- # Returns the match index within the specified _data_ where a SQL
79
- # error Pattern occurs. If no SQL error Pattern can be found within
80
- # _data_, +nil+ will be returned.
81
- #
82
- def =~(data)
83
- data = data.to_s
84
-
85
- @patterns.each do |pattern|
86
- if (index = (pattern =~ data))
87
- return index
88
- end
89
- end
90
-
91
- return nil
92
- end
93
-
94
- #
95
- # Returns the name of the error pattern.
96
- #
97
- def to_s
98
- @name.to_s
99
- end
100
-
101
- end
102
- end
103
- end
104
- end
@@ -1,99 +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/sql/error/pattern'
23
-
24
- module Ronin
25
- module SQL
26
- module Error
27
- Error.pattern :ms_sql do |p|
28
- p.dialect = :ms
29
- p.recognize /Microsoft SQL Native Client/
30
- p.recognize /Microsoft OLE DB Provider for SQL Server/
31
- p.recognize /Microsoft OLE DB Provider for ODBC Drivers.*\[Microsoft\]\[ODBC SQL Server Driver\]/
32
- end
33
-
34
- Error.pattern :ms_access do |p|
35
- p.dialect = :ms
36
- p.recognize /Microsoft OLE DB Provider for ODBC Drivers.*\[Microsoft\]\[ODBC Access Driver\]/
37
- p.recognize /\[Microsoft\]\[ODBC Microsoft Access Driver\] Syntax error/
38
- end
39
-
40
- Error.pattern :ms_jetdb do |p|
41
- p.dialect = :ms
42
- p.recognize /Microsoft JET Database Engine/
43
- end
44
-
45
- Error.pattern :ms_adodb do |p|
46
- p.dialect = :ms
47
- p.recognize /ADODB.Command.*error/
48
- end
49
-
50
- Error.pattern :asp_net do |p|
51
- p.dialect = :common
52
- p.recognize /Server Error.*System\.Data\.OleDb\.OleDbException/
53
- end
54
-
55
- Error.pattern :mysql do |p|
56
- p.dialect = :mysql
57
- p.recognize /Warning.*supplied argument is not a valid MySQL result/
58
- p.recognize /Warning.*mysql_.*\(\)/
59
- p.recognize /You have an error in your SQL syntax.*(on|at) line/
60
- end
61
-
62
- Error.pattern :php do |p|
63
- p.dialect = :common
64
- p.recognize /Warning.*failed to open stream/
65
- p.recognize /Fatal Error.*(on|at) line/
66
- end
67
-
68
- Error.pattern :oracle do |p|
69
- p.dialect = :oracle
70
- p.recognize /ORA-[0-9][0-9][0-9][0-9]/
71
- end
72
-
73
- Error.pattern :jdbc do |p|
74
- p.dialect = :common
75
- p.recognize /Invalid SQL statement or JDBC/
76
- end
77
-
78
- Error.pattern :java_servlet do |p|
79
- p.dialect = :common
80
- p.recognize /javax\.servlet\.ServletException/
81
- end
82
-
83
- Error.pattern :apache_tomcat do |p|
84
- p.dialect = :common
85
- p.recognize /org\.apache\.jasper\.JasperException/
86
- end
87
-
88
- Error.pattern :vb_runtime do |p|
89
- p.dialect = :common
90
- p.recognize /Microsoft VBScript runtime/
91
- end
92
-
93
- Error.pattern :vb_asp do |p|
94
- p.dialect = :common
95
- p.recognize /Type mismatch/
96
- end
97
- end
98
- end
99
- end
@@ -1,22 +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/sql/extensions/uri'
@@ -1,22 +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/sql/extensions/uri/http'
@@ -1,107 +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/sql/injection'
23
- require 'ronin/scanners/scanner'
24
- require 'ronin/extensions/uri/http'
25
-
26
- module URI
27
- class HTTP < Generic
28
-
29
- include Ronin::Scanners::Scanner
30
-
31
- #
32
- # Tests the +query_params+ of the HTTP URL with the given _options_ for
33
- # SQL errors.
34
- #
35
- # _options_ may contain the following keys:
36
- # <tt>:sql</tt>:: The SQL injection to use. Defaults to <tt>"'"</tt>.
37
- #
38
- def sql_errors(options={})
39
- errors = {}
40
-
41
- return each_query_param do |param,value|
42
- mesg = Ronin::SQL::Injection.new(self,param).error(options)
43
-
44
- errors[param] = mesg if mesg
45
- end
46
-
47
- return errors
48
- end
49
-
50
- def sql_error(options={})
51
- sql_errors(options).values.first
52
- end
53
-
54
- #
55
- # Returns +true+ if any of the +query_params+ of the HTTP URI return
56
- # SQL errors using the given _options_, returns +false+ otherwise.
57
- #
58
- # _options_ may contain the following keys:
59
- # <tt>:sql</tt>:: The SQL injection to use. Defaults to <tt>"'"</tt>.
60
- #
61
- def has_sql_errors?(options={})
62
- !(sql_errors(options).empty?)
63
- end
64
-
65
- #
66
- # Tests the +query_params+ of the HTTP URL with the given _options_ for
67
- # blind SQL injections.
68
- #
69
- scanner(:sqli) do |url,results,options|
70
- url.each_query_param do |param,value|
71
- integer_tests = [
72
- {:escape => value},
73
- {:escape => value, :close_parenthesis => true}
74
- ]
75
-
76
- string_tests = [
77
- {:escape => value, :close_string => true},
78
- {:escape => value, :close_string => true, :close_parenthesis => true}
79
- ]
80
-
81
- if (value && value =~ /^[0-9]+$/)
82
- # if the param value is numeric, we should try escaping a
83
- # numeric value first.
84
- tests = integer_tests + string_tests
85
- else
86
- # if the param value is a string, we should try escaping a
87
- # string value first.
88
- tests = string_tests + integer_tests
89
- end
90
-
91
- tests.each do |test|
92
- inj = Ronin::SQL::Injection.new(url,param,options.merge(test))
93
-
94
- if inj.vulnerable?(options)
95
- results.call(inj)
96
- break
97
- end
98
- end
99
- end
100
- end
101
-
102
- alias sql_injections sqli_scan
103
- alias sql_injection first_sqli
104
- alias has_sql_injections? has_sqli?
105
-
106
- end
107
- end
@@ -1,205 +0,0 @@
1
- require 'ronin/code/sql/common_dialect'
2
-
3
- require 'spec_helper'
4
-
5
- describe Code::SQL::CommonDialect do
6
- before(:all) do
7
- @dialect = Code::SQL::CommonDialect.new
8
- end
9
-
10
- it "should provide the 'yes' primitive" do
11
- token = @dialect.yes
12
-
13
- token.class.should == Code::SQL::Token
14
- token.to_s.should == 'yes'
15
- end
16
-
17
- it "should provide the 'no' primitive" do
18
- token = @dialect.no
19
-
20
- token.class.should == Code::SQL::Token
21
- token.to_s.should == 'no'
22
- end
23
-
24
- it "should provide the 'on' primitive" do
25
- token = @dialect.on
26
-
27
- token.class.should == Code::SQL::Token
28
- token.to_s.should == 'on'
29
- end
30
-
31
- it "should provide the 'off' primitive" do
32
- token = @dialect.off
33
-
34
- token.class.should == Code::SQL::Token
35
- token.to_s.should == 'off'
36
- end
37
-
38
- it "should provide the 'null' primitive" do
39
- token = @dialect.null
40
-
41
- token.class.should == Code::SQL::Token
42
- token.to_s.should == 'null'
43
- end
44
-
45
- it "should provide the 'int' data-type" do
46
- token = @dialect.int
47
-
48
- token.class.should == Code::SQL::Token
49
- token.to_s.should == 'INT'
50
- end
51
-
52
- it "should provide the 'varchar' data-type" do
53
- token = @dialect.varchar
54
-
55
- token.class.should == Code::SQL::Token
56
- token.to_s.should == 'VARCHAR'
57
- end
58
-
59
- it "should provide the 'varchar' data-type with specific length" do
60
- token = @dialect.varchar(15)
61
-
62
- token.class.should == Code::SQL::Token
63
- token.to_s.should == 'VARCHAR(15)'
64
- end
65
-
66
- it "should provide the 'text' data-type" do
67
- token = @dialect.text
68
-
69
- token.class.should == Code::SQL::Token
70
- token.to_s.should == 'TEXT'
71
- end
72
-
73
- it "should provide the 'record' data-type" do
74
- token = @dialect.record
75
-
76
- token.class.should == Code::SQL::Token
77
- token.to_s.should == 'RECORD'
78
- end
79
-
80
- it "should provide the 'avg' function" do
81
- func = @dialect.avg(:salary)
82
-
83
- func.name.should == :avg
84
- func.fields.should == [:salary]
85
- end
86
-
87
- it "should provide the 'count' function" do
88
- func = @dialect.count(:id)
89
-
90
- func.name.should == :count
91
- func.fields.should == [:id]
92
- end
93
-
94
- it "should provide the 'group_concat' function" do
95
- func = @dialect.group_concat(:id)
96
-
97
- func.name.should == :group_concat
98
- func.fields.should == [:id]
99
- end
100
-
101
- it "should provide the 'min' function" do
102
- func = @dialect.min(:salary)
103
-
104
- func.name.should == :min
105
- func.fields.should == [:salary]
106
- end
107
-
108
- it "should provide the 'max' function" do
109
- func = @dialect.max(:salary)
110
-
111
- func.name.should == :max
112
- func.fields.should == [:salary]
113
- end
114
-
115
- it "should provide the 'sum' function" do
116
- func = @dialect.sum(:salary)
117
-
118
- func.name.should == :sum
119
- func.fields.should == [:salary]
120
- end
121
-
122
- it "should provide the 'total' function" do
123
- func = @dialect.total(:salary)
124
-
125
- func.name.should == :total
126
- func.fields.should == [:salary]
127
- end
128
-
129
- it "should provide the 'create table' statement" do
130
- stmt = @dialect.create_table(:users)
131
-
132
- stmt.class.should == Code::SQL::CreateTable
133
- stmt.table.should == :users
134
- end
135
-
136
- it "should provide the 'create index' statement" do
137
- stmt = @dialect.create_index(:users_index)
138
-
139
- stmt.class.should == Code::SQL::CreateIndex
140
- stmt.index.should == :users_index
141
- end
142
-
143
- it "should provide the 'create view' statement" do
144
- stmt = @dialect.create_view(:users_view)
145
-
146
- stmt.class.should == Code::SQL::CreateView
147
- stmt.view.should == :users_view
148
- end
149
-
150
- it "should provide the 'alter table' statement" do
151
- stmt = @dialect.alter_table(:users)
152
-
153
- stmt.class.should == Code::SQL::AlterTable
154
- stmt.table.should == :users
155
- end
156
-
157
- it "should provide the 'insert' statement" do
158
- stmt = @dialect.insert(:users)
159
-
160
- stmt.class.should == Code::SQL::Insert
161
- stmt.table.should == :users
162
- end
163
-
164
- it "should provide the 'select' statement" do
165
- stmt = @dialect.select(:from => :users)
166
-
167
- stmt.class.should == Code::SQL::Select
168
- stmt.from.table.should == :users
169
- end
170
-
171
- it "should provide the 'update' statement" do
172
- stmt = @dialect.update(:users)
173
-
174
- stmt.class.should == Code::SQL::Update
175
- stmt.table.should == :users
176
- end
177
-
178
- it "should provide the 'delete' statement" do
179
- stmt = @dialect.delete(:users)
180
-
181
- stmt.class.should == Code::SQL::Delete
182
- stmt.table.should == :users
183
- end
184
-
185
- it "should provide the 'drop table' statement" do
186
- stmt = @dialect.drop_table(:users)
187
-
188
- stmt.class.should == Code::SQL::DropTable
189
- stmt.table.should == :users
190
- end
191
-
192
- it "should provide the 'drop index' statement" do
193
- stmt = @dialect.drop_index(:users_index)
194
-
195
- stmt.class.should == Code::SQL::DropIndex
196
- stmt.index.should == :users_index
197
- end
198
-
199
- it "should provide the 'drop view' statement" do
200
- stmt = @dialect.drop_view(:users_view)
201
-
202
- stmt.class.should == Code::SQL::DropView
203
- stmt.view.should == :users_view
204
- end
205
- end