activerecord-jdbc-adapter-onsite 1.2.2
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.
- data/.gitignore +22 -0
- data/.travis.yml +14 -0
- data/Appraisals +16 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/History.txt +488 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +214 -0
- data/Rakefile +62 -0
- data/activerecord-jdbc-adapter.gemspec +23 -0
- data/bench/bench_attributes.rb +13 -0
- data/bench/bench_attributes_new.rb +14 -0
- data/bench/bench_create.rb +12 -0
- data/bench/bench_find_all.rb +12 -0
- data/bench/bench_find_all_mt.rb +25 -0
- data/bench/bench_model.rb +85 -0
- data/bench/bench_new.rb +12 -0
- data/bench/bench_new_valid.rb +12 -0
- data/bench/bench_valid.rb +13 -0
- data/gemfiles/rails23.gemfile +10 -0
- data/gemfiles/rails23.gemfile.lock +38 -0
- data/gemfiles/rails30.gemfile +9 -0
- data/gemfiles/rails30.gemfile.lock +33 -0
- data/gemfiles/rails31.gemfile +9 -0
- data/gemfiles/rails31.gemfile.lock +35 -0
- data/gemfiles/rails32.gemfile +9 -0
- data/gemfiles/rails32.gemfile.lock +35 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +32 -0
- data/lib/arel/visitors/firebird.rb +24 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +46 -0
- data/lib/arjdbc.rb +24 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +541 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/derby/adapter.rb +358 -0
- data/lib/arjdbc/derby/connection_methods.rb +19 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/firebird/adapter.rb +140 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +54 -0
- data/lib/arjdbc/h2/connection_methods.rb +13 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/arjdbc/hsqldb/adapter.rb +184 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +15 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +142 -0
- data/lib/arjdbc/informix/connection_methods.rb +11 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +356 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +47 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +134 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +35 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/arjdbc/jdbc/jdbc.rake +131 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +88 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +477 -0
- data/lib/arjdbc/mssql/connection_methods.rb +31 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +101 -0
- data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
- data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +505 -0
- data/lib/arjdbc/mysql/connection_methods.rb +28 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/arjdbc/oracle/adapter.rb +432 -0
- data/lib/arjdbc/oracle/connection_methods.rb +12 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +861 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +23 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +389 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +35 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +10 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/pom.xml +57 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/db.rake +39 -0
- data/rakelib/rails.rake +41 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +69 -0
- data/src/java/arjdbc/derby/DerbyModule.java +324 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +68 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1346 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +161 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +82 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +126 -0
- data/test/abstract_db_create.rb +135 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/activerecord/jall.sh +7 -0
- data/test/activerecord/jtest.sh +3 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +12 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +18 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_reset_column_information_test.rb +8 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_reset_column_information_test.rb +8 -0
- data/test/derby_row_locking_test.rb +9 -0
- data/test/derby_simple_test.rb +139 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_change_column_test.rb +68 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +108 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +28 -0
- data/test/jndi_callbacks_test.rb +36 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +9 -0
- data/test/models/auto_id.rb +15 -0
- data/test/models/custom_pk_name.rb +14 -0
- data/test/models/data_types.rb +30 -0
- data/test/models/entry.rb +40 -0
- data/test/models/mixed_case.rb +22 -0
- data/test/models/reserved_word.rb +15 -0
- data/test/models/string_id.rb +17 -0
- data/test/models/thing.rb +16 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_ignore_system_views_test.rb +27 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_null_test.rb +14 -0
- data/test/mssql_reset_column_information_test.rb +8 -0
- data/test/mssql_row_locking_sql_test.rb +159 -0
- data/test/mssql_row_locking_test.rb +9 -0
- data/test/mssql_simple_test.rb +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_index_length_test.rb +58 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_reset_column_information_test.rb +8 -0
- data/test/mysql_simple_test.rb +125 -0
- data/test/oracle_reset_column_information_test.rb +8 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_information_schema_leak_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_native_type_mapping_test.rb +93 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_reset_column_information_test.rb +8 -0
- data/test/postgres_schema_search_path_test.rb +48 -0
- data/test/postgres_simple_test.rb +168 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/postgres_type_conversion_test.rb +34 -0
- data/test/row_locking.rb +90 -0
- data/test/simple.rb +731 -0
- data/test/sqlite3_reset_column_information_test.rb +8 -0
- data/test/sqlite3_simple_test.rb +316 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- data/test/sybase_reset_column_information_test.rb +8 -0
- metadata +288 -0
data/test/jndi_test.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# In order to run these tests, you need to have a few things on your
|
|
2
|
+
# classpath. First, you're going to need the Sun File system
|
|
3
|
+
# context. You can get that here:
|
|
4
|
+
#
|
|
5
|
+
# http://java.sun.com/products/jndi/serviceproviders.html.
|
|
6
|
+
#
|
|
7
|
+
# Make sure that you put both the fscontext.jar and the
|
|
8
|
+
# providerutil.jar on your classpath.
|
|
9
|
+
#
|
|
10
|
+
# To support the connection pooling in the test, you'll need
|
|
11
|
+
# commons-dbcp, commons-pool, and commons-collections.
|
|
12
|
+
#
|
|
13
|
+
# Finally, you'll need the jdbc driver, which is derby, for this test.
|
|
14
|
+
|
|
15
|
+
require 'jdbc_common'
|
|
16
|
+
require 'db/jndi_config'
|
|
17
|
+
|
|
18
|
+
class DerbyJndiTest < Test::Unit::TestCase
|
|
19
|
+
include SimpleTestMethods
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
at_exit {
|
|
23
|
+
require 'fileutils'
|
|
24
|
+
FileUtils.rm_rf 'derby-testdb'
|
|
25
|
+
}
|
|
@@ -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,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,14 @@
|
|
|
1
|
+
class CreateCustomPkName < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :custom_pk_names, :force => true, :id => false do |t|
|
|
4
|
+
t.primary_key :custom_id
|
|
5
|
+
t.string :name
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
def self.down
|
|
9
|
+
drop_table :custom_pk_names
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
class CustomPkName < ActiveRecord::Base
|
|
13
|
+
self.primary_key = "custom_id"
|
|
14
|
+
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
|