tgbyte-activerecord-jdbc-adapter 1.2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +14 -0
  4. data/Gemfile.lock +40 -0
  5. data/History.txt +488 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.rdoc +199 -0
  8. data/Rakefile +60 -0
  9. data/activerecord-jdbc-adapter.gemspec +23 -0
  10. data/bench/bench_attributes.rb +13 -0
  11. data/bench/bench_attributes_new.rb +14 -0
  12. data/bench/bench_create.rb +12 -0
  13. data/bench/bench_find_all.rb +12 -0
  14. data/bench/bench_find_all_mt.rb +25 -0
  15. data/bench/bench_model.rb +85 -0
  16. data/bench/bench_new.rb +12 -0
  17. data/bench/bench_new_valid.rb +12 -0
  18. data/bench/bench_valid.rb +13 -0
  19. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
  20. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
  21. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
  22. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
  23. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
  24. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
  25. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  26. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  27. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
  28. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
  29. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
  30. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
  31. data/lib/activerecord-jdbc-adapter.rb +8 -0
  32. data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
  33. data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
  34. data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
  35. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
  36. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
  37. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
  38. data/lib/arel/visitors/compat.rb +13 -0
  39. data/lib/arel/visitors/db2.rb +17 -0
  40. data/lib/arel/visitors/derby.rb +32 -0
  41. data/lib/arel/visitors/firebird.rb +24 -0
  42. data/lib/arel/visitors/hsqldb.rb +26 -0
  43. data/lib/arel/visitors/sql_server.rb +46 -0
  44. data/lib/arjdbc.rb +24 -0
  45. data/lib/arjdbc/db2.rb +2 -0
  46. data/lib/arjdbc/db2/adapter.rb +510 -0
  47. data/lib/arjdbc/derby.rb +7 -0
  48. data/lib/arjdbc/derby/adapter.rb +358 -0
  49. data/lib/arjdbc/derby/connection_methods.rb +19 -0
  50. data/lib/arjdbc/discover.rb +92 -0
  51. data/lib/arjdbc/firebird.rb +2 -0
  52. data/lib/arjdbc/firebird/adapter.rb +136 -0
  53. data/lib/arjdbc/h2.rb +4 -0
  54. data/lib/arjdbc/h2/adapter.rb +54 -0
  55. data/lib/arjdbc/h2/connection_methods.rb +13 -0
  56. data/lib/arjdbc/hsqldb.rb +4 -0
  57. data/lib/arjdbc/hsqldb/adapter.rb +184 -0
  58. data/lib/arjdbc/hsqldb/connection_methods.rb +15 -0
  59. data/lib/arjdbc/informix.rb +3 -0
  60. data/lib/arjdbc/informix/adapter.rb +138 -0
  61. data/lib/arjdbc/informix/connection_methods.rb +11 -0
  62. data/lib/arjdbc/jdbc.rb +2 -0
  63. data/lib/arjdbc/jdbc/adapter.rb +356 -0
  64. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  65. data/lib/arjdbc/jdbc/base_ext.rb +15 -0
  66. data/lib/arjdbc/jdbc/callbacks.rb +44 -0
  67. data/lib/arjdbc/jdbc/column.rb +47 -0
  68. data/lib/arjdbc/jdbc/compatibility.rb +51 -0
  69. data/lib/arjdbc/jdbc/connection.rb +134 -0
  70. data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
  71. data/lib/arjdbc/jdbc/core_ext.rb +24 -0
  72. data/lib/arjdbc/jdbc/discover.rb +18 -0
  73. data/lib/arjdbc/jdbc/driver.rb +35 -0
  74. data/lib/arjdbc/jdbc/extension.rb +47 -0
  75. data/lib/arjdbc/jdbc/java.rb +14 -0
  76. data/lib/arjdbc/jdbc/jdbc.rake +131 -0
  77. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +88 -0
  78. data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
  79. data/lib/arjdbc/jdbc/railtie.rb +9 -0
  80. data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
  81. data/lib/arjdbc/jdbc/require_driver.rb +16 -0
  82. data/lib/arjdbc/jdbc/type_converter.rb +126 -0
  83. data/lib/arjdbc/mimer.rb +2 -0
  84. data/lib/arjdbc/mimer/adapter.rb +142 -0
  85. data/lib/arjdbc/mssql.rb +4 -0
  86. data/lib/arjdbc/mssql/adapter.rb +477 -0
  87. data/lib/arjdbc/mssql/connection_methods.rb +31 -0
  88. data/lib/arjdbc/mssql/limit_helpers.rb +101 -0
  89. data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
  90. data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
  91. data/lib/arjdbc/mysql.rb +4 -0
  92. data/lib/arjdbc/mysql/adapter.rb +505 -0
  93. data/lib/arjdbc/mysql/connection_methods.rb +28 -0
  94. data/lib/arjdbc/oracle.rb +3 -0
  95. data/lib/arjdbc/oracle/adapter.rb +428 -0
  96. data/lib/arjdbc/oracle/connection_methods.rb +12 -0
  97. data/lib/arjdbc/postgresql.rb +4 -0
  98. data/lib/arjdbc/postgresql/adapter.rb +825 -0
  99. data/lib/arjdbc/postgresql/connection_methods.rb +23 -0
  100. data/lib/arjdbc/sqlite3.rb +4 -0
  101. data/lib/arjdbc/sqlite3/adapter.rb +389 -0
  102. data/lib/arjdbc/sqlite3/connection_methods.rb +35 -0
  103. data/lib/arjdbc/sybase.rb +2 -0
  104. data/lib/arjdbc/sybase/adapter.rb +46 -0
  105. data/lib/arjdbc/version.rb +8 -0
  106. data/lib/generators/jdbc/USAGE +10 -0
  107. data/lib/generators/jdbc/jdbc_generator.rb +9 -0
  108. data/lib/jdbc_adapter.rb +2 -0
  109. data/lib/jdbc_adapter/rake_tasks.rb +3 -0
  110. data/lib/jdbc_adapter/version.rb +3 -0
  111. data/lib/pg.rb +26 -0
  112. data/pom.xml +57 -0
  113. data/rails_generators/jdbc_generator.rb +15 -0
  114. data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
  115. data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
  116. data/rakelib/bundler_ext.rb +11 -0
  117. data/rakelib/compile.rake +23 -0
  118. data/rakelib/db.rake +39 -0
  119. data/rakelib/rails.rake +41 -0
  120. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +62 -0
  121. data/src/java/arjdbc/derby/DerbyModule.java +324 -0
  122. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
  123. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
  124. data/src/java/arjdbc/jdbc/AdapterJavaService.java +68 -0
  125. data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
  126. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1326 -0
  127. data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
  128. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
  129. data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
  130. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +161 -0
  131. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
  132. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +82 -0
  133. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +126 -0
  134. data/test/abstract_db_create.rb +135 -0
  135. data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
  136. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
  137. data/test/activerecord/jall.sh +7 -0
  138. data/test/activerecord/jtest.sh +3 -0
  139. data/test/db/db2.rb +11 -0
  140. data/test/db/derby.rb +12 -0
  141. data/test/db/h2.rb +11 -0
  142. data/test/db/hsqldb.rb +13 -0
  143. data/test/db/informix.rb +11 -0
  144. data/test/db/jdbc.rb +12 -0
  145. data/test/db/jndi_config.rb +40 -0
  146. data/test/db/logger.rb +3 -0
  147. data/test/db/mssql.rb +9 -0
  148. data/test/db/mysql.rb +10 -0
  149. data/test/db/oracle.rb +34 -0
  150. data/test/db/postgres.rb +9 -0
  151. data/test/db/sqlite3.rb +11 -0
  152. data/test/db2_reset_column_information_test.rb +8 -0
  153. data/test/db2_simple_test.rb +66 -0
  154. data/test/derby_migration_test.rb +68 -0
  155. data/test/derby_multibyte_test.rb +12 -0
  156. data/test/derby_reset_column_information_test.rb +8 -0
  157. data/test/derby_row_locking_test.rb +9 -0
  158. data/test/derby_simple_test.rb +139 -0
  159. data/test/generic_jdbc_connection_test.rb +29 -0
  160. data/test/h2_change_column_test.rb +68 -0
  161. data/test/h2_simple_test.rb +41 -0
  162. data/test/has_many_through.rb +79 -0
  163. data/test/helper.rb +87 -0
  164. data/test/hsqldb_simple_test.rb +6 -0
  165. data/test/informix_simple_test.rb +48 -0
  166. data/test/jdbc_common.rb +28 -0
  167. data/test/jndi_callbacks_test.rb +36 -0
  168. data/test/jndi_test.rb +25 -0
  169. data/test/manualTestDatabase.rb +191 -0
  170. data/test/models/add_not_null_column_to_table.rb +9 -0
  171. data/test/models/auto_id.rb +15 -0
  172. data/test/models/data_types.rb +30 -0
  173. data/test/models/entry.rb +40 -0
  174. data/test/models/mixed_case.rb +22 -0
  175. data/test/models/reserved_word.rb +15 -0
  176. data/test/models/string_id.rb +17 -0
  177. data/test/models/thing.rb +16 -0
  178. data/test/models/validates_uniqueness_of_string.rb +19 -0
  179. data/test/mssql_db_create_test.rb +26 -0
  180. data/test/mssql_identity_insert_test.rb +19 -0
  181. data/test/mssql_ignore_system_views_test.rb +27 -0
  182. data/test/mssql_legacy_types_test.rb +58 -0
  183. data/test/mssql_limit_offset_test.rb +136 -0
  184. data/test/mssql_multibyte_test.rb +18 -0
  185. data/test/mssql_null_test.rb +14 -0
  186. data/test/mssql_reset_column_information_test.rb +8 -0
  187. data/test/mssql_row_locking_sql_test.rb +159 -0
  188. data/test/mssql_row_locking_test.rb +9 -0
  189. data/test/mssql_simple_test.rb +55 -0
  190. data/test/mysql_db_create_test.rb +27 -0
  191. data/test/mysql_index_length_test.rb +58 -0
  192. data/test/mysql_info_test.rb +123 -0
  193. data/test/mysql_multibyte_test.rb +10 -0
  194. data/test/mysql_nonstandard_primary_key_test.rb +42 -0
  195. data/test/mysql_reset_column_information_test.rb +8 -0
  196. data/test/mysql_simple_test.rb +125 -0
  197. data/test/oracle_reset_column_information_test.rb +8 -0
  198. data/test/oracle_simple_test.rb +18 -0
  199. data/test/oracle_specific_test.rb +83 -0
  200. data/test/postgres_db_create_test.rb +32 -0
  201. data/test/postgres_drop_db_test.rb +16 -0
  202. data/test/postgres_information_schema_leak_test.rb +29 -0
  203. data/test/postgres_mixed_case_test.rb +29 -0
  204. data/test/postgres_native_type_mapping_test.rb +89 -0
  205. data/test/postgres_nonseq_pkey_test.rb +38 -0
  206. data/test/postgres_reserved_test.rb +22 -0
  207. data/test/postgres_reset_column_information_test.rb +8 -0
  208. data/test/postgres_schema_search_path_test.rb +48 -0
  209. data/test/postgres_simple_test.rb +167 -0
  210. data/test/postgres_table_alias_length_test.rb +15 -0
  211. data/test/postgres_type_conversion_test.rb +34 -0
  212. data/test/row_locking.rb +90 -0
  213. data/test/simple.rb +717 -0
  214. data/test/sqlite3_reset_column_information_test.rb +8 -0
  215. data/test/sqlite3_simple_test.rb +316 -0
  216. data/test/sybase_jtds_simple_test.rb +28 -0
  217. data/test/sybase_reset_column_information_test.rb +8 -0
  218. metadata +275 -0
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ if ARGV.length < 2
4
+ $stderr.puts "syntax: #{__FILE__} [filename] [configuration-name]"
5
+ $stderr.puts " where filename points to a YAML database configuration file"
6
+ $stderr.puts " and the configuration name is in this file"
7
+ exit
8
+ end
9
+
10
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
11
+
12
+ require 'yaml'
13
+ require 'rubygems'
14
+ RAILS_CONNECTION_ADAPTERS = ['mysql', 'jdbc']
15
+ require 'active_record'
16
+
17
+ cfg = (File.open(ARGV[0]) {|f| YAML.load(f) })[ARGV[1]]
18
+
19
+ ActiveRecord::Base.establish_connection(cfg)
20
+
21
+ ActiveRecord::Schema.define do
22
+ drop_table :authors rescue nil
23
+ drop_table :author rescue nil
24
+
25
+ create_table :author, :force => true do |t|
26
+ t.column :name, :string, :null => false
27
+ end
28
+
29
+ # Exercise all types, and add_column
30
+ add_column :author, :description, :text
31
+ add_column :author, :descr, :string, :limit => 50
32
+ add_column :author, :age, :integer, :null => false, :default => 17
33
+ add_column :author, :weight, :float
34
+ add_column :author, :born, :datetime
35
+ add_column :author, :died, :timestamp
36
+ add_column :author, :wakeup_time, :time
37
+ add_column :author, :birth_date, :date
38
+ add_column :author, :private_key, :binary
39
+ add_column :author, :female, :boolean, :default => true
40
+
41
+ change_column :author, :descr, :string, :limit => 100 if /db2|derby/ !~ ARGV[1]
42
+ change_column_default :author, :female, false if /db2|derby|mssql|firebird/ !~ ARGV[1]
43
+ remove_column :author, :died if /db2|derby/ !~ ARGV[1]
44
+ rename_column :author, :wakeup_time, :waking_time if /db2|derby|mimer/ !~ ARGV[1]
45
+
46
+ add_index :author, :name, :unique if /db2/ !~ ARGV[1]
47
+ add_index :author, [:age,:female], :name => :is_age_female if /db2/ !~ ARGV[1]
48
+
49
+ remove_index :author, :name if /db2/ !~ ARGV[1]
50
+ remove_index :author, :name => :is_age_female if /db2/ !~ ARGV[1]
51
+
52
+ rename_table :author, :authors if /db2|firebird|mimer/ !~ ARGV[1]
53
+
54
+
55
+ create_table :products, :force => true do |t|
56
+ t.column :title, :string
57
+ t.column :description, :text
58
+ t.column :image_url, :string
59
+ end
60
+ add_column :products, :price, :float, :default => 0.0
61
+ create_table :orders, :force => true do |t|
62
+ t.column :name, :string
63
+ t.column :address, :text
64
+ t.column :email, :string
65
+ t.column :pay_type, :string, :limit => 10
66
+ end
67
+ create_table :line_items, :force => true do |t|
68
+ t.column :product_id, :integer, :null => false
69
+ t.column :order_id, :integer, :null => false
70
+ t.column :quantity, :integer, :null => false
71
+ t.column :total_price, :float, :null => false
72
+ end
73
+ end
74
+
75
+ class Author < ActiveRecord::Base;
76
+ self.table_name = "author" if /db2|firebird|mimer/ =~ ARGV[1]
77
+ end
78
+
79
+ class Order < ActiveRecord::Base
80
+ has_many :line_items
81
+ end
82
+
83
+ class Product < ActiveRecord::Base
84
+ has_many :orders, :through => :line_items
85
+ has_many :line_items
86
+
87
+ def self.find_products_for_sale
88
+ find(:all, :order => "title")
89
+ end
90
+ end
91
+
92
+ class LineItem < ActiveRecord::Base
93
+ belongs_to :order
94
+ belongs_to :product
95
+ end
96
+
97
+ Product.create(:title => 'Pragmatic Project Automation',
98
+ :description =>
99
+ %{<p>
100
+ <em>Pragmatic Project Automation</em> shows you how to improve the
101
+ consistency and repeatability of your project's procedures using
102
+ automation to reduce risk and errors.
103
+ </p>
104
+ <p>
105
+ Simply put, we're going to put this thing called a computer to work
106
+ for you doing the mundane (but important) project stuff. That means
107
+ you'll have more time and energy to do the really
108
+ exciting---and difficult---stuff, like writing quality code.
109
+ </p>},
110
+ :image_url => '/images/auto.jpg',
111
+ :price => 29.95)
112
+
113
+
114
+ Product.create(:title => 'Pragmatic Version Control',
115
+ :description =>
116
+ %{<p>
117
+ This book is a recipe-based approach to using Subversion that will
118
+ get you up and
119
+ running quickly---and correctly. All projects need version control:
120
+ it's a foundational piece of any project's infrastructure. Yet half
121
+ of all project teams in the U.S. don't use any version control at all.
122
+ Many others don't use it well, and end up experiencing time-consuming problems.
123
+ </p>},
124
+ :image_url => '/images/svn.jpg',
125
+ :price => 28.50)
126
+
127
+ # . . .
128
+
129
+
130
+ Product.create(:title => 'Pragmatic Unit Testing (C#)',
131
+ :description =>
132
+ %{<p>
133
+ Pragmatic programmers use feedback to drive their development and
134
+ personal processes. The most valuable feedback you can get while
135
+ coding comes from unit testing.
136
+ </p>
137
+ <p>
138
+ Without good tests in place, coding can become a frustrating game of
139
+ "whack-a-mole." That's the carnival game where the player strikes at a
140
+ mechanical mole; it retreats and another mole pops up on the opposite side
141
+ of the field. The moles pop up and down so fast that you end up flailing
142
+ your mallet helplessly as the moles continue to pop up where you least
143
+ expect them.
144
+ </p>},
145
+ :image_url => '/images/utc.jpg',
146
+ :price => 27.75)
147
+
148
+
149
+
150
+
151
+ 1.times do
152
+ $stderr.print '.'
153
+ Author.destroy_all
154
+ Author.create(:name => "Arne Svensson", :age => 30)
155
+ if /db2|derby|mimer/ !~ ARGV[1]
156
+ Author.create(:name => "Pelle Gogolsson", :age => 15, :waking_time => Time.now, :private_key => "afbafddsfgsdfg")
157
+ else
158
+ Author.create(:name => "Pelle Gogolsson", :age => 15, :wakeup_time => Time.now, :private_key => "afbafddsfgsdfg")
159
+ end
160
+ Author.find(:first)
161
+ Author.find(:all)
162
+ arne = Author.find(:first)
163
+ arne.destroy
164
+
165
+ pelle = Author.find(:first)
166
+ pelle.name = "Pelle Sweitchon"
167
+ pelle.description = "dfsssdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
168
+ pelle.descr = "adsfasdf"
169
+ pelle.age = 79
170
+ pelle.weight = 57.6
171
+ pelle.born = Time.gm(1982,8,13,10,15,3,0)
172
+ pelle.female = false
173
+ pelle.save
174
+
175
+ prods = Product.find :all
176
+ order = Order.new(:name => "Dalai Lama", :address => "Great Road 32", :email => "abc@dot.com", :pay_type => "cash")
177
+ order.line_items << LineItem.new(:product => prods[0], :quantity => 3, :total_price => (prods[0].price * 3))
178
+ order.line_items << LineItem.new(:product => prods[2], :quantity => 1, :total_price => (prods[2].price))
179
+ order.save
180
+
181
+ puts "order: #{order.line_items.inspect}, with id: #{order.id} and name: #{order.name}"
182
+ end
183
+
184
+ ActiveRecord::Schema.define do
185
+ drop_table :line_items
186
+ drop_table :orders
187
+ drop_table :products
188
+
189
+
190
+ drop_table((/db2|firebird|mimer/=~ARGV[1]? :author : :authors ))
191
+ end
@@ -0,0 +1,9 @@
1
+ class AddNotNullColumnToTable < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :entries, :color, :string, :null => false, :default => "blue"
4
+ end
5
+
6
+ def self.down
7
+ remove_column :entries, :color
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ class CreateAutoIds < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "auto_ids", :force => true do |t|
4
+ t.column :value, :integer
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table "auto_ids"
10
+ end
11
+ end
12
+
13
+ class AutoId < ActiveRecord::Base
14
+ def self.table_name () "auto_ids" end
15
+ end
@@ -0,0 +1,30 @@
1
+ class DbTypeMigration < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "db_types", :force => true do |t|
4
+ t.column :sample_timestamp, :timestamp
5
+ t.column :sample_datetime, :datetime
6
+ t.column :sample_date, :date
7
+ t.column :sample_time, :time
8
+ t.column :sample_decimal, :decimal, :precision => 15, :scale => 0
9
+ t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2
10
+ t.column :sample_default_decimal, :decimal
11
+ t.column :sample_float, :float
12
+ t.column :sample_binary, :binary
13
+ t.column :sample_boolean, :boolean
14
+ t.column :sample_string, :string, :default => ''
15
+ t.column :sample_integer, :integer, :limit => 5
16
+ t.column :sample_integer_with_limit_2, :integer, :limit => 2
17
+ t.column :sample_integer_with_limit_8, :integer, :limit => 8
18
+ t.column :sample_integer_no_limit, :integer
19
+ t.column :sample_integer_neg_default, :integer, :default => -1
20
+ t.column :sample_text, :text
21
+ end
22
+ end
23
+
24
+ def self.down
25
+ drop_table "db_types"
26
+ end
27
+ end
28
+
29
+ class DbType < ActiveRecord::Base
30
+ end
@@ -0,0 +1,40 @@
1
+ class CreateEntries < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "entries", :force => true do |t|
4
+ t.column :title, :string, :limit => 100
5
+ t.column :updated_on, :datetime
6
+ t.column :content, :text
7
+ t.column :rating, :decimal, :precision => 10, :scale => 2
8
+ t.column :user_id, :integer
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table "entries"
14
+ end
15
+ end
16
+
17
+ class Entry < ActiveRecord::Base
18
+ belongs_to :user
19
+
20
+ def to_param
21
+ "#{id}-#{title.gsub(/[^a-zA-Z0-9]/, '-')}"
22
+ end
23
+ end
24
+
25
+ class CreateUsers < ActiveRecord::Migration
26
+ def self.up
27
+ create_table "users", :force => true do |t|
28
+ t.column :login, :string, :limit => 100
29
+ end
30
+ end
31
+
32
+ def self.down
33
+ drop_table "users"
34
+ end
35
+ end
36
+
37
+ class User < ActiveRecord::Base
38
+ has_many :entries
39
+ end
40
+
@@ -0,0 +1,22 @@
1
+ module Migration
2
+ class MixedCase < ActiveRecord::Migration
3
+
4
+ def self.up
5
+ create_table "mixed_cases" do |t|
6
+ t.column :SOME_value, :string
7
+ end
8
+ create_table "tblUsers" do |t|
9
+ t.column :firstName, :string
10
+ t.column :lastName, :string
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table "mixed_cases"
16
+ drop_table "tblUsers"
17
+ end
18
+ end
19
+ end
20
+
21
+ class MixedCase < ActiveRecord::Base
22
+ end
@@ -0,0 +1,15 @@
1
+ class CreateReservedWords < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "reserved_words", :force => true do |t|
4
+ t.column :position, :integer
5
+ t.column :select, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table "reserved_words"
11
+ end
12
+ end
13
+
14
+ class ReservedWord < ActiveRecord::Base
15
+ end
@@ -0,0 +1,17 @@
1
+ class CreateStringIds < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "string_ids", :force => true, :id => false do |t|
4
+ t.string :id
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table "string_ids"
10
+ end
11
+ end
12
+
13
+ class StringId < ActiveRecord::Base
14
+ def self.table_name () "string_ids" end
15
+ # Fake out a table without a primary key
16
+ self.primary_key = "id"
17
+ end
@@ -0,0 +1,16 @@
1
+ class CreateThings < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :things, :id => false do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :things
12
+ end
13
+ end
14
+
15
+ class Thing < ActiveRecord::Base
16
+ end
@@ -0,0 +1,19 @@
1
+ class CreateValidatesUniquenessOf < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "validates_uniqueness_of", :force => true do |t|
4
+ t.column :cs_string, :string
5
+ t.column :ci_string, :string
6
+ t.column :content, :text
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table "validates_uniqueness_of"
12
+ end
13
+ end
14
+
15
+ class ValidatesUniquenessOfString < ActiveRecord::Base
16
+ self.table_name = "validates_uniqueness_of"
17
+ validates_uniqueness_of :cs_string, :case_sensitive => true
18
+ validates_uniqueness_of :ci_string, :case_sensitive => false
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'abstract_db_create'
2
+ require 'db/mssql'
3
+
4
+ class MysqlDbCreateTest < Test::Unit::TestCase
5
+ include AbstractDbCreate
6
+
7
+ def db_config
8
+ MSSQL_CONFIG
9
+ end
10
+
11
+ def test_rake_db_create
12
+ begin
13
+ Rake::Task["db:create"].invoke
14
+ rescue => e
15
+ if e.message =~ /CREATE DATABASE permission denied/
16
+ puts "\nwarning: db:create test skipped; add 'dbcreator' role to user '#{db_config[:username]}' to run"
17
+ return
18
+ end
19
+ end
20
+ ActiveRecord::Base.establish_connection(db_config.merge(:database => "master"))
21
+ select = "SELECT NAME FROM sys.sysdatabases"
22
+ select = "SELECT name FROM master..sysdatabases ORDER BY name" if ActiveRecord::Base.connection.sqlserver_version == "2000"
23
+ databases = ActiveRecord::Base.connection.select_rows(select).flatten
24
+ assert databases.include?(@db_name)
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require 'jdbc_common'
2
+ require 'db/mssql'
3
+
4
+ class MsSQLIdentityInsertTest < Test::Unit::TestCase
5
+
6
+ include MigrationSetup
7
+
8
+ def test_enable_identity_insert_when_necessary
9
+ Entry.connection.execute("INSERT INTO entries([id], [title]) VALUES (333, 'Title')")
10
+ Entry.connection.execute("INSERT INTO entries([title], [id]) VALUES ('Title', 344)")
11
+ Entry.connection.execute("INSERT INTO entries(id, title) VALUES (666, 'Title')")
12
+ Entry.connection.execute("INSERT INTO entries(id, title) (SELECT id+123, title FROM entries)")
13
+ end
14
+
15
+ def test_dont_enable_identity_insert_when_unnecessary
16
+ Entry.connection.execute("INSERT INTO entries([title]) VALUES ('[id]')")
17
+ end
18
+
19
+ end
@@ -0,0 +1,27 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/mssql'
5
+
6
+ class IgnoreSystemViewsTest < Test::Unit::TestCase
7
+
8
+ include MigrationSetup
9
+
10
+ def test_system_views_ignored
11
+ assert_equal true, table_exists?("sys.views"), %{table_exists?("sys.views")}
12
+ assert_equal true, table_exists?("information_schema.views"), %{table_exists?("information_schema.views")}
13
+ assert_equal false, table_exists?("dbo.views"), %{table_exists?("dbo.views")}
14
+ assert_equal false, table_exists?(:views), %{table_exists?(:views)}
15
+ ActiveRecord::Schema.define { suppress_messages { create_table :views } }
16
+ assert_equal true, table_exists?(:views), %{table_exists?(:views)}
17
+ ActiveRecord::Schema.define { suppress_messages { drop_table :views } }
18
+ assert_equal false, table_exists?(:views), %{table_exists?(:views)}
19
+ end
20
+
21
+ private
22
+
23
+ def table_exists?(*args)
24
+ !!ActiveRecord::Base.connection.table_exists?(*args)
25
+ end
26
+ end
27
+