intentmedia-activerecord-jdbc-adapter 1.1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/History.txt +404 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.txt +181 -0
  4. data/Rakefile +10 -0
  5. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
  6. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
  7. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
  8. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
  9. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
  10. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
  11. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  12. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  13. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
  14. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
  15. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
  16. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
  17. data/lib/activerecord-jdbc-adapter.rb +8 -0
  18. data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
  19. data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
  20. data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
  21. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
  22. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
  23. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
  24. data/lib/arel/visitors/compat.rb +13 -0
  25. data/lib/arel/visitors/db2.rb +17 -0
  26. data/lib/arel/visitors/derby.rb +21 -0
  27. data/lib/arel/visitors/hsqldb.rb +26 -0
  28. data/lib/arel/visitors/sql_server.rb +46 -0
  29. data/lib/arjdbc.rb +29 -0
  30. data/lib/arjdbc/db2.rb +2 -0
  31. data/lib/arjdbc/db2/adapter.rb +413 -0
  32. data/lib/arjdbc/derby.rb +7 -0
  33. data/lib/arjdbc/derby/adapter.rb +348 -0
  34. data/lib/arjdbc/derby/connection_methods.rb +18 -0
  35. data/lib/arjdbc/discover.rb +92 -0
  36. data/lib/arjdbc/firebird.rb +2 -0
  37. data/lib/arjdbc/firebird/adapter.rb +131 -0
  38. data/lib/arjdbc/h2.rb +4 -0
  39. data/lib/arjdbc/h2/adapter.rb +36 -0
  40. data/lib/arjdbc/h2/connection_methods.rb +12 -0
  41. data/lib/arjdbc/hsqldb.rb +4 -0
  42. data/lib/arjdbc/hsqldb/adapter.rb +184 -0
  43. data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
  44. data/lib/arjdbc/informix.rb +3 -0
  45. data/lib/arjdbc/informix/adapter.rb +138 -0
  46. data/lib/arjdbc/informix/connection_methods.rb +10 -0
  47. data/lib/arjdbc/jdbc.rb +2 -0
  48. data/lib/arjdbc/jdbc/adapter.rb +285 -0
  49. data/lib/arjdbc/jdbc/callbacks.rb +44 -0
  50. data/lib/arjdbc/jdbc/column.rb +38 -0
  51. data/lib/arjdbc/jdbc/compatibility.rb +51 -0
  52. data/lib/arjdbc/jdbc/connection.rb +128 -0
  53. data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
  54. data/lib/arjdbc/jdbc/core_ext.rb +24 -0
  55. data/lib/arjdbc/jdbc/discover.rb +18 -0
  56. data/lib/arjdbc/jdbc/driver.rb +44 -0
  57. data/lib/arjdbc/jdbc/extension.rb +47 -0
  58. data/lib/arjdbc/jdbc/java.rb +14 -0
  59. data/lib/arjdbc/jdbc/jdbc.rake +127 -0
  60. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +87 -0
  61. data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
  62. data/lib/arjdbc/jdbc/railtie.rb +9 -0
  63. data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
  64. data/lib/arjdbc/jdbc/require_driver.rb +16 -0
  65. data/lib/arjdbc/jdbc/type_converter.rb +127 -0
  66. data/lib/arjdbc/mimer.rb +2 -0
  67. data/lib/arjdbc/mimer/adapter.rb +142 -0
  68. data/lib/arjdbc/mssql.rb +4 -0
  69. data/lib/arjdbc/mssql/adapter.rb +472 -0
  70. data/lib/arjdbc/mssql/connection_methods.rb +30 -0
  71. data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
  72. data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
  73. data/lib/arjdbc/mysql.rb +4 -0
  74. data/lib/arjdbc/mysql/adapter.rb +416 -0
  75. data/lib/arjdbc/mysql/connection_methods.rb +27 -0
  76. data/lib/arjdbc/oracle.rb +3 -0
  77. data/lib/arjdbc/oracle/adapter.rb +412 -0
  78. data/lib/arjdbc/oracle/connection_methods.rb +11 -0
  79. data/lib/arjdbc/postgresql.rb +4 -0
  80. data/lib/arjdbc/postgresql/adapter.rb +579 -0
  81. data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
  82. data/lib/arjdbc/sqlite3.rb +4 -0
  83. data/lib/arjdbc/sqlite3/adapter.rb +381 -0
  84. data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
  85. data/lib/arjdbc/sybase.rb +2 -0
  86. data/lib/arjdbc/sybase/adapter.rb +46 -0
  87. data/lib/arjdbc/version.rb +8 -0
  88. data/lib/generators/jdbc/jdbc_generator.rb +9 -0
  89. data/lib/jdbc_adapter.rb +2 -0
  90. data/lib/jdbc_adapter/rake_tasks.rb +3 -0
  91. data/lib/jdbc_adapter/version.rb +3 -0
  92. data/lib/pg.rb +26 -0
  93. data/rails_generators/jdbc_generator.rb +15 -0
  94. data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
  95. data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
  96. data/rakelib/compile.rake +25 -0
  97. data/rakelib/db.rake +19 -0
  98. data/rakelib/package.rake +91 -0
  99. data/rakelib/rails.rake +41 -0
  100. data/rakelib/test.rake +81 -0
  101. data/src/java/arjdbc/derby/DerbyModule.java +322 -0
  102. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
  103. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
  104. data/src/java/arjdbc/jdbc/AdapterJavaService.java +66 -0
  105. data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
  106. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1305 -0
  107. data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
  108. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
  109. data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
  110. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
  111. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
  112. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +57 -0
  113. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
  114. data/test/abstract_db_create.rb +124 -0
  115. data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
  116. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
  117. data/test/db/db2.rb +11 -0
  118. data/test/db/derby.rb +12 -0
  119. data/test/db/h2.rb +11 -0
  120. data/test/db/hsqldb.rb +13 -0
  121. data/test/db/informix.rb +11 -0
  122. data/test/db/jdbc.rb +11 -0
  123. data/test/db/jndi_config.rb +40 -0
  124. data/test/db/logger.rb +3 -0
  125. data/test/db/mssql.rb +9 -0
  126. data/test/db/mysql.rb +10 -0
  127. data/test/db/oracle.rb +34 -0
  128. data/test/db/postgres.rb +9 -0
  129. data/test/db/sqlite3.rb +11 -0
  130. data/test/db2_simple_test.rb +66 -0
  131. data/test/derby_migration_test.rb +68 -0
  132. data/test/derby_multibyte_test.rb +12 -0
  133. data/test/derby_simple_test.rb +99 -0
  134. data/test/generic_jdbc_connection_test.rb +29 -0
  135. data/test/h2_simple_test.rb +41 -0
  136. data/test/has_many_through.rb +79 -0
  137. data/test/helper.rb +5 -0
  138. data/test/hsqldb_simple_test.rb +6 -0
  139. data/test/informix_simple_test.rb +48 -0
  140. data/test/jdbc_common.rb +25 -0
  141. data/test/jndi_callbacks_test.rb +40 -0
  142. data/test/jndi_test.rb +25 -0
  143. data/test/manualTestDatabase.rb +191 -0
  144. data/test/models/add_not_null_column_to_table.rb +12 -0
  145. data/test/models/auto_id.rb +18 -0
  146. data/test/models/data_types.rb +28 -0
  147. data/test/models/entry.rb +43 -0
  148. data/test/models/mixed_case.rb +25 -0
  149. data/test/models/reserved_word.rb +18 -0
  150. data/test/models/string_id.rb +18 -0
  151. data/test/models/validates_uniqueness_of_string.rb +19 -0
  152. data/test/mssql_db_create_test.rb +26 -0
  153. data/test/mssql_identity_insert_test.rb +19 -0
  154. data/test/mssql_legacy_types_test.rb +58 -0
  155. data/test/mssql_limit_offset_test.rb +136 -0
  156. data/test/mssql_multibyte_test.rb +18 -0
  157. data/test/mssql_simple_test.rb +55 -0
  158. data/test/mysql_db_create_test.rb +27 -0
  159. data/test/mysql_info_test.rb +123 -0
  160. data/test/mysql_multibyte_test.rb +10 -0
  161. data/test/mysql_nonstandard_primary_key_test.rb +42 -0
  162. data/test/mysql_simple_test.rb +49 -0
  163. data/test/oracle_simple_test.rb +18 -0
  164. data/test/oracle_specific_test.rb +83 -0
  165. data/test/pick_rails_version.rb +3 -0
  166. data/test/postgres_db_create_test.rb +32 -0
  167. data/test/postgres_drop_db_test.rb +16 -0
  168. data/test/postgres_mixed_case_test.rb +29 -0
  169. data/test/postgres_nonseq_pkey_test.rb +38 -0
  170. data/test/postgres_reserved_test.rb +22 -0
  171. data/test/postgres_schema_search_path_test.rb +44 -0
  172. data/test/postgres_simple_test.rb +65 -0
  173. data/test/postgres_table_alias_length_test.rb +15 -0
  174. data/test/simple.rb +546 -0
  175. data/test/sqlite3_simple_test.rb +233 -0
  176. data/test/sybase_jtds_simple_test.rb +28 -0
  177. metadata +259 -0
data/test/helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Kernel
2
+ def find_executable?(name)
3
+ ENV['PATH'].split(File::PATH_SEPARATOR).detect {|p| File.executable?(File.join(p, name))}
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'jdbc_common'
2
+ require 'db/hsqldb'
3
+
4
+ class HsqldbSimpleTest < Test::Unit::TestCase
5
+ include SimpleTestMethods
6
+ end
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # To run this script, run the following:
4
+ #
5
+ # CREATE DATABASE weblog_development;
6
+ #
7
+ # TODO: Finish the explanation.
8
+
9
+ require 'jdbc_common'
10
+ require 'db/informix'
11
+
12
+ class InformixSimpleTest < Test::Unit::TestCase
13
+ include SimpleTestMethods
14
+
15
+ # Informix does not like "= NULL".
16
+ def test_equals_null
17
+ Entry.create!(:title => "Foo")
18
+ entry = Entry.find(:first, :conditions => ["content = NULL"])
19
+ assert_equal "Foo", entry.title
20
+ end
21
+
22
+ # Informix does not like "!= NULL" or "<> NULL".
23
+ def test_not_equals_null
24
+ Entry.create!(:title => "Foo", :content => "Bar")
25
+ entry = Entry.find_by_title("Foo", :conditions => ["content != NULL"])
26
+ assert_equal "Foo", entry.title
27
+ entry = Entry.find_by_title("Foo", :conditions => ["content <> NULL"])
28
+ assert_equal "Foo", entry.title
29
+ end
30
+ end
31
+
32
+ class InformixMultibyteTest < Test::Unit::TestCase
33
+ include MultibyteTestMethods
34
+
35
+ # Overriding the included test since we can't create text fields via a
36
+ # simple insert in Informix.
37
+ def test_select_multibyte_string
38
+ Entry.create!(:title => 'テスト', :content => '本文')
39
+ entry = Entry.find(:first)
40
+ assert_equal "テスト", entry.title
41
+ assert_equal "本文", entry.content
42
+ assert_equal entry, Entry.find_by_title("テスト")
43
+ end
44
+ end
45
+
46
+ class InformixHasManyThroughTest < Test::Unit::TestCase
47
+ include HasManyThroughMethods
48
+ end
@@ -0,0 +1,25 @@
1
+ # Simple method to reduce the boilerplate
2
+ def jruby?
3
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
4
+ end
5
+
6
+ require 'rubygems'
7
+ require 'pick_rails_version'
8
+ require 'arjdbc' if jruby?
9
+ puts "Using activerecord version #{ActiveRecord::VERSION::STRING}"
10
+ puts "Specify version with AR_VERSION=={version} or RUBYLIB={path}"
11
+ require 'models/auto_id'
12
+ require 'models/entry'
13
+ require 'models/data_types'
14
+ require 'models/add_not_null_column_to_table'
15
+ require 'models/validates_uniqueness_of_string'
16
+ require 'models/string_id'
17
+ require 'simple'
18
+ require 'has_many_through'
19
+ require 'helper'
20
+ require 'test/unit'
21
+
22
+ # Comment/uncomment to enable logging to be loaded for any of the database adapters
23
+ require 'db/logger' if $DEBUG || ENV['DEBUG']
24
+
25
+
@@ -0,0 +1,40 @@
1
+ require 'jdbc_common'
2
+ require 'db/jndi_config'
3
+
4
+ begin
5
+ require 'mocha'
6
+
7
+ class JndiConnectionPoolCallbacksTest < Test::Unit::TestCase
8
+ def setup
9
+ @connection = mock "JdbcConnection"
10
+ @connection.stubs(:jndi_connection?).returns(true)
11
+ @connection.stubs(:adapter=)
12
+ @logger = mock "logger"
13
+ @config = JNDI_CONFIG
14
+ Entry.connection_pool.disconnect!
15
+ assert !Entry.connection_pool.connected?
16
+ class << Entry.connection_pool; public :instance_variable_set; end
17
+ end
18
+
19
+ def teardown
20
+ @connection.stubs(:disconnect!)
21
+ Entry.connection_pool.disconnect!
22
+ end
23
+
24
+ def test_should_call_hooks_on_checkout_and_checkin
25
+ @connection.stubs(:active?).returns(true)
26
+ @connection.expects(:disconnect!)
27
+ @adapter = ActiveRecord::ConnectionAdapters::JdbcAdapter.new @connection, @logger, @config
28
+ Entry.connection_pool.instance_variable_set "@connections", [@adapter]
29
+
30
+ @connection.expects(:reconnect!)
31
+ Entry.connection_pool.checkout
32
+
33
+ @connection.expects(:disconnect!)
34
+ Entry.connection_pool.checkin @adapter
35
+ end
36
+ end
37
+
38
+ rescue LoadError
39
+ warn "mocha not found, disabling mocha-based tests"
40
+ end if ActiveRecord::Base.respond_to?(:connection_pool)
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
+ set_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,12 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ class AddNotNullColumnToTable < ActiveRecord::Migration
5
+ def self.up
6
+ add_column :entries, :color, :string, :null => false, :default => "blue"
7
+ end
8
+
9
+ def self.down
10
+ remove_column :entries, :color
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ class CreateAutoIds < ActiveRecord::Migration
5
+ def self.up
6
+ create_table "auto_ids", :force => true do |t|
7
+ t.column :value, :integer
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table "auto_ids"
13
+ end
14
+ end
15
+
16
+ class AutoId < ActiveRecord::Base
17
+ def self.table_name () "auto_ids" end
18
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ class DbTypeMigration < ActiveRecord::Migration
5
+ def self.up
6
+ create_table "db_types", :force => true do |t|
7
+ t.column :sample_timestamp, :timestamp
8
+ t.column :sample_datetime, :datetime
9
+ t.column :sample_date, :date
10
+ t.column :sample_time, :time
11
+ t.column :sample_decimal, :decimal, :precision => 15, :scale => 0
12
+ t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2
13
+ t.column :sample_float, :float
14
+ t.column :sample_binary, :binary
15
+ t.column :sample_boolean, :boolean
16
+ t.column :sample_string, :string, :default => ''
17
+ t.column :sample_integer, :integer, :limit => 5
18
+ t.column :sample_text, :text
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table "db_types"
24
+ end
25
+ end
26
+
27
+ class DbType < ActiveRecord::Base
28
+ end
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ class CreateEntries < ActiveRecord::Migration
5
+ def self.up
6
+ create_table "entries", :force => true do |t|
7
+ t.column :title, :string, :limit => 100
8
+ t.column :updated_on, :datetime
9
+ t.column :content, :text
10
+ t.column :rating, :decimal, :precision => 10, :scale => 2
11
+ t.column :user_id, :integer
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table "entries"
17
+ end
18
+ end
19
+
20
+ class Entry < ActiveRecord::Base
21
+ belongs_to :user
22
+
23
+ def to_param
24
+ "#{id}-#{title.gsub(/[^a-zA-Z0-9]/, '-')}"
25
+ end
26
+ end
27
+
28
+ class CreateUsers < ActiveRecord::Migration
29
+ def self.up
30
+ create_table "users", :force => true do |t|
31
+ t.column :login, :string, :limit => 100
32
+ end
33
+ end
34
+
35
+ def self.down
36
+ drop_table "users"
37
+ end
38
+ end
39
+
40
+ class User < ActiveRecord::Base
41
+ has_many :entries
42
+ end
43
+