activerecord-jdbc-adapter 0.9.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/History.txt +248 -0
  2. data/LICENSE.txt +21 -0
  3. data/Manifest.txt +125 -0
  4. data/README.txt +218 -0
  5. data/Rakefile +10 -0
  6. data/lib/active_record/connection_adapters/cachedb_adapter.rb +1 -0
  7. data/lib/active_record/connection_adapters/derby_adapter.rb +13 -0
  8. data/lib/active_record/connection_adapters/h2_adapter.rb +13 -0
  9. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +13 -0
  10. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
  11. data/lib/active_record/connection_adapters/jdbc_adapter.rb +640 -0
  12. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +26 -0
  13. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
  14. data/lib/active_record/connection_adapters/mysql_adapter.rb +13 -0
  15. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
  16. data/lib/active_record/connection_adapters/postgresql_adapter.rb +13 -0
  17. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +13 -0
  18. data/lib/generators/jdbc/jdbc_generator.rb +9 -0
  19. data/lib/jdbc_adapter.rb +27 -0
  20. data/lib/jdbc_adapter/jdbc.rake +121 -0
  21. data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
  22. data/lib/jdbc_adapter/jdbc_cachedb.rb +33 -0
  23. data/lib/jdbc_adapter/jdbc_db2.rb +203 -0
  24. data/lib/jdbc_adapter/jdbc_derby.rb +430 -0
  25. data/lib/jdbc_adapter/jdbc_firebird.rb +109 -0
  26. data/lib/jdbc_adapter/jdbc_hsqldb.rb +218 -0
  27. data/lib/jdbc_adapter/jdbc_informix.rb +147 -0
  28. data/lib/jdbc_adapter/jdbc_mimer.rb +141 -0
  29. data/lib/jdbc_adapter/jdbc_mssql.rb +337 -0
  30. data/lib/jdbc_adapter/jdbc_mysql.rb +236 -0
  31. data/lib/jdbc_adapter/jdbc_oracle.rb +377 -0
  32. data/lib/jdbc_adapter/jdbc_postgre.rb +498 -0
  33. data/lib/jdbc_adapter/jdbc_sqlite3.rb +384 -0
  34. data/lib/jdbc_adapter/jdbc_sybase.rb +50 -0
  35. data/lib/jdbc_adapter/missing_functionality_helper.rb +87 -0
  36. data/lib/jdbc_adapter/rake_tasks.rb +10 -0
  37. data/lib/jdbc_adapter/tsql_helper.rb +60 -0
  38. data/lib/jdbc_adapter/version.rb +5 -0
  39. data/lib/pg.rb +4 -0
  40. data/rails_generators/jdbc_generator.rb +15 -0
  41. data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
  42. data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
  43. data/rakelib/compile.rake +23 -0
  44. data/rakelib/package.rake +90 -0
  45. data/rakelib/rails.rake +41 -0
  46. data/rakelib/test.rake +76 -0
  47. data/src/java/jdbc_adapter/JdbcAdapterInternalService.java +53 -0
  48. data/src/java/jdbc_adapter/JdbcConnectionFactory.java +36 -0
  49. data/src/java/jdbc_adapter/JdbcDerbySpec.java +293 -0
  50. data/src/java/jdbc_adapter/JdbcMySQLSpec.java +134 -0
  51. data/src/java/jdbc_adapter/MssqlRubyJdbcConnection.java +71 -0
  52. data/src/java/jdbc_adapter/PostgresRubyJdbcConnection.java +55 -0
  53. data/src/java/jdbc_adapter/RubyJdbcConnection.java +1162 -0
  54. data/src/java/jdbc_adapter/SQLBlock.java +27 -0
  55. data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +41 -0
  56. data/test/abstract_db_create.rb +107 -0
  57. data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
  58. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
  59. data/test/cachedb_simple_test.rb +6 -0
  60. data/test/db/cachedb.rb +9 -0
  61. data/test/db/db2.rb +9 -0
  62. data/test/db/derby.rb +14 -0
  63. data/test/db/h2.rb +11 -0
  64. data/test/db/hsqldb.rb +12 -0
  65. data/test/db/informix.rb +11 -0
  66. data/test/db/jdbc.rb +11 -0
  67. data/test/db/jndi_config.rb +30 -0
  68. data/test/db/logger.rb +3 -0
  69. data/test/db/mssql.rb +9 -0
  70. data/test/db/mysql.rb +10 -0
  71. data/test/db/oracle.rb +34 -0
  72. data/test/db/postgres.rb +9 -0
  73. data/test/db/sqlite3.rb +15 -0
  74. data/test/db2_simple_test.rb +10 -0
  75. data/test/derby_migration_test.rb +21 -0
  76. data/test/derby_multibyte_test.rb +12 -0
  77. data/test/derby_simple_test.rb +21 -0
  78. data/test/generic_jdbc_connection_test.rb +9 -0
  79. data/test/h2_simple_test.rb +6 -0
  80. data/test/has_many_through.rb +79 -0
  81. data/test/helper.rb +5 -0
  82. data/test/hsqldb_simple_test.rb +6 -0
  83. data/test/informix_simple_test.rb +48 -0
  84. data/test/jdbc_adapter/jdbc_db2_test.rb +26 -0
  85. data/test/jdbc_adapter/jdbc_sybase_test.rb +33 -0
  86. data/test/jdbc_common.rb +25 -0
  87. data/test/jndi_callbacks_test.rb +38 -0
  88. data/test/jndi_test.rb +35 -0
  89. data/test/manualTestDatabase.rb +191 -0
  90. data/test/minirunit.rb +109 -0
  91. data/test/minirunit/testConnect.rb +14 -0
  92. data/test/minirunit/testH2.rb +73 -0
  93. data/test/minirunit/testHsqldb.rb +73 -0
  94. data/test/minirunit/testLoadActiveRecord.rb +3 -0
  95. data/test/minirunit/testMysql.rb +83 -0
  96. data/test/minirunit/testRawSelect.rb +24 -0
  97. data/test/models/add_not_null_column_to_table.rb +12 -0
  98. data/test/models/auto_id.rb +18 -0
  99. data/test/models/data_types.rb +28 -0
  100. data/test/models/entry.rb +23 -0
  101. data/test/models/mixed_case.rb +20 -0
  102. data/test/models/reserved_word.rb +18 -0
  103. data/test/models/string_id.rb +18 -0
  104. data/test/models/validates_uniqueness_of_string.rb +19 -0
  105. data/test/mssql_simple_test.rb +6 -0
  106. data/test/mysql_db_create_test.rb +25 -0
  107. data/test/mysql_multibyte_test.rb +10 -0
  108. data/test/mysql_nonstandard_primary_key_test.rb +42 -0
  109. data/test/mysql_simple_test.rb +32 -0
  110. data/test/oracle_simple_test.rb +29 -0
  111. data/test/pick_rails_version.rb +3 -0
  112. data/test/postgres_db_create_test.rb +21 -0
  113. data/test/postgres_mixed_case_test.rb +19 -0
  114. data/test/postgres_nonseq_pkey_test.rb +40 -0
  115. data/test/postgres_reserved_test.rb +22 -0
  116. data/test/postgres_schema_search_path_test.rb +46 -0
  117. data/test/postgres_simple_test.rb +13 -0
  118. data/test/simple.rb +475 -0
  119. data/test/sqlite3_simple_test.rb +233 -0
  120. data/test/sybase_jtds_simple_test.rb +6 -0
  121. metadata +188 -0
@@ -0,0 +1,26 @@
1
+ module JdbcSpec
2
+ module ActiveRecordExtensions
3
+ def self.add_method_to_remove_from_ar_base(meth)
4
+ @methods ||= []
5
+ @methods << meth
6
+ end
7
+
8
+ def self.extended(klass)
9
+ (@methods || []).each {|m| (class << klass; self; end).instance_eval { remove_method(m) rescue nil } }
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'jdbc_adapter/jdbc_mimer'
15
+ require 'jdbc_adapter/jdbc_hsqldb'
16
+ require 'jdbc_adapter/jdbc_oracle'
17
+ require 'jdbc_adapter/jdbc_postgre'
18
+ require 'jdbc_adapter/jdbc_mysql'
19
+ require 'jdbc_adapter/jdbc_derby'
20
+ require 'jdbc_adapter/jdbc_firebird'
21
+ require 'jdbc_adapter/jdbc_db2'
22
+ require 'jdbc_adapter/jdbc_mssql'
23
+ require 'jdbc_adapter/jdbc_cachedb'
24
+ require 'jdbc_adapter/jdbc_sqlite3'
25
+ require 'jdbc_adapter/jdbc_sybase'
26
+ require 'jdbc_adapter/jdbc_informix'
@@ -0,0 +1 @@
1
+ require 'active_record/connection_adapters/jdbc_adapter'
@@ -0,0 +1,13 @@
1
+ tried_gem = false
2
+ begin
3
+ require "jdbc/mysql"
4
+ rescue LoadError
5
+ unless tried_gem
6
+ require 'rubygems'
7
+ gem "jdbc-mysql"
8
+ tried_gem = true
9
+ retry
10
+ end
11
+ # trust that the mysql jar is already present
12
+ end
13
+ require 'active_record/connection_adapters/jdbc_adapter'
@@ -0,0 +1 @@
1
+ require 'active_record/connection_adapters/jdbc_adapter'
@@ -0,0 +1,13 @@
1
+ tried_gem = false
2
+ begin
3
+ require "jdbc/postgres"
4
+ rescue LoadError
5
+ unless tried_gem
6
+ require 'rubygems'
7
+ gem "jdbc-postgres"
8
+ tried_gem = true
9
+ retry
10
+ end
11
+ # trust that the postgres jar is already present
12
+ end
13
+ require 'active_record/connection_adapters/jdbc_adapter'
@@ -0,0 +1,13 @@
1
+ tried_gem = false
2
+ begin
3
+ require "jdbc/sqlite3"
4
+ rescue LoadError
5
+ unless tried_gem
6
+ require 'rubygems'
7
+ gem "jdbc-sqlite3"
8
+ tried_gem = true
9
+ retry
10
+ end
11
+ # trust that the sqlite jar is already present
12
+ end
13
+ require 'active_record/connection_adapters/jdbc_adapter'
@@ -0,0 +1,9 @@
1
+ class JdbcGenerator < Rails::Generators::Base
2
+ def self.source_root
3
+ @source_root ||= File.expand_path('../../../../rails_generators/templates', __FILE__)
4
+ end
5
+
6
+ def create_jdbc_files
7
+ directory '.', '.'
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ if defined?(JRUBY_VERSION)
2
+ begin
3
+ tried_gem ||= false
4
+ require 'active_record/version'
5
+ rescue LoadError
6
+ raise if tried_gem
7
+ require 'rubygems'
8
+ gem 'activerecord'
9
+ tried_gem = true
10
+ retry
11
+ end
12
+ if ActiveRecord::VERSION::MAJOR < 2
13
+ if defined?(RAILS_CONNECTION_ADAPTERS)
14
+ RAILS_CONNECTION_ADAPTERS << %q(jdbc)
15
+ else
16
+ RAILS_CONNECTION_ADAPTERS = %w(jdbc)
17
+ end
18
+ if ActiveRecord::VERSION::MAJOR == 1 && ActiveRecord::VERSION::MINOR == 14
19
+ require 'active_record/connection_adapters/jdbc_adapter'
20
+ end
21
+ else
22
+ require 'active_record'
23
+ require 'active_record/connection_adapters/jdbc_adapter'
24
+ end
25
+ else
26
+ warn "ActiveRecord-JDBC is for use with JRuby only"
27
+ end
@@ -0,0 +1,121 @@
1
+ def redefine_task(*args, &block)
2
+ task_name = Hash === args.first ? args.first.keys[0] : args.first
3
+ existing_task = Rake.application.lookup task_name
4
+ if existing_task
5
+ class << existing_task
6
+ public :instance_variable_set
7
+ attr_reader :actions
8
+ end
9
+ existing_task.instance_variable_set "@prerequisites", FileList[]
10
+ existing_task.actions.shift
11
+ enhancements = existing_task.actions
12
+ existing_task.instance_variable_set "@actions", []
13
+ end
14
+ redefined_task = task(*args, &block)
15
+ enhancements.each {|enhancement| redefined_task.actions << enhancement}
16
+ end
17
+
18
+ def rails_env
19
+ defined?(Rails.env) ? Rails.env : RAILS_ENV
20
+ end
21
+
22
+ namespace :db do
23
+ redefine_task :create => :environment do
24
+ create_database(ActiveRecord::Base.configurations[rails_env])
25
+ end
26
+ task :create => :load_config if Rake.application.lookup(:load_config)
27
+
28
+ redefine_task :drop => :environment do
29
+ config = ActiveRecord::Base.configurations[rails_env]
30
+ begin
31
+ ActiveRecord::Base.establish_connection(config)
32
+ db = ActiveRecord::Base.connection.database_name
33
+ ActiveRecord::Base.connection.drop_database(db)
34
+ rescue
35
+ drop_database(config.merge('adapter' => config['adapter'].sub(/^jdbc/, '')))
36
+ end
37
+ end
38
+ task :drop => :load_config if Rake.application.lookup(:load_config)
39
+
40
+ namespace :create do
41
+ task :all => :environment
42
+ end
43
+
44
+ namespace :drop do
45
+ task :all => :environment
46
+ end
47
+
48
+ class << self
49
+ alias_method :previous_create_database, :create_database
50
+ alias_method :previous_drop_database, :drop_database
51
+ end
52
+
53
+ def create_database(config)
54
+ begin
55
+ ActiveRecord::Base.establish_connection(config)
56
+ ActiveRecord::Base.connection
57
+ rescue
58
+ begin
59
+ if url = config['url'] && url =~ /^(.*(?<!\/)\/)(?=\w)/
60
+ url = $1
61
+ end
62
+
63
+ ActiveRecord::Base.establish_connection(config.merge({'database' => nil, 'url' => url}))
64
+ ActiveRecord::Base.connection.create_database(config['database'])
65
+ ActiveRecord::Base.establish_connection(config)
66
+ rescue
67
+ previous_create_database(config.merge('adapter' => config['adapter'].sub(/^jdbc/, '')))
68
+ end
69
+ end
70
+ end
71
+
72
+ def drop_database(config)
73
+ previous_drop_database(config.merge('adapter' => config['adapter'].sub(/^jdbc/, '')))
74
+ end
75
+
76
+ namespace :structure do
77
+ redefine_task :dump => :environment do
78
+ abcs = ActiveRecord::Base.configurations
79
+ ActiveRecord::Base.establish_connection(abcs[rails_env])
80
+ File.open("db/#{rails_env}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
81
+ if ActiveRecord::Base.connection.supports_migrations?
82
+ File.open("db/#{rails_env}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
83
+ end
84
+ end
85
+ end
86
+
87
+ namespace :test do
88
+ redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
89
+ abcs = ActiveRecord::Base.configurations
90
+ abcs['test']['pg_params'] = '?allowEncodingChanges=true' if abcs['test']['adapter'] =~ /postgresql/i
91
+ ActiveRecord::Base.establish_connection(abcs["test"])
92
+ ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') if abcs["test"]["adapter"] =~ /mysql/i
93
+ IO.readlines("db/#{rails_env}_structure.sql").join.split(";\n\n").each do |ddl|
94
+ begin
95
+ ActiveRecord::Base.connection.execute(ddl.chomp(';'))
96
+ rescue Exception => ex
97
+ puts ex.message
98
+ end
99
+ end
100
+ end
101
+
102
+ redefine_task :purge => :environment do
103
+ abcs = ActiveRecord::Base.configurations
104
+ config = abcs['test'].dup
105
+ if config['adapter'] =~ /postgresql/i
106
+ if config['url']
107
+ db = config['url'][/\/([^\/]*)$/, 1]
108
+ config['url'][/\/([^\/]*)$/, 1] = 'postgres' if db
109
+ else
110
+ db = config['database']
111
+ config['database'] = 'postgres'
112
+ end
113
+ ActiveRecord::Base.establish_connection(config)
114
+ else
115
+ ActiveRecord::Base.establish_connection(config)
116
+ db = ActiveRecord::Base.connection.database_name
117
+ end
118
+ ActiveRecord::Base.connection.recreate_database(db)
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,33 @@
1
+ require 'jdbc_adapter/tsql_helper'
2
+
3
+ module ::JdbcSpec
4
+ module ActiveRecordExtensions
5
+ def cachedb_connection( config )
6
+ config[:port] ||= 1972
7
+ config[:url] ||= "jdbc:Cache://#{config[:host]}:#{config[:port]}/#{ config[:database]}"
8
+ config[:driver] ||= "com.intersys.jdbc.CacheDriver"
9
+ jdbc_connection( config )
10
+ end
11
+ end
12
+
13
+ module CacheDB
14
+ include TSqlMethods
15
+
16
+ def self.adapter_matcher(name, *)
17
+ name =~ /cache/i ? self : false
18
+ end
19
+
20
+ def self.column_selector
21
+ [ /cache/i, lambda { | cfg, col | col.extend( ::JdbcSpec::CacheDB::Column ) } ]
22
+ end
23
+
24
+ module Column
25
+ end
26
+
27
+ def create_table(name, options = { })
28
+ super(name, options)
29
+ primary_key = options[:primary_key] || "id"
30
+ execute "ALTER TABLE #{name} ADD CONSTRAINT #{name}_PK PRIMARY KEY(#{primary_key})" unless options[:id] == false
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,203 @@
1
+ module JdbcSpec
2
+ module DB2
3
+ def self.adapter_matcher(name, config)
4
+ if name =~ /db2/i
5
+ return config[:url] =~ /^jdbc:derby:net:/ ? ::JdbcSpec::Derby : self
6
+ end
7
+ false
8
+ end
9
+
10
+ def self.adapter_selector
11
+ [/db2/i, lambda {|cfg,adapt|
12
+ if cfg[:url] =~ /^jdbc:derby:net:/
13
+ adapt.extend(::JdbcSpec::Derby)
14
+ else
15
+ adapt.extend(::JdbcSpec::DB2)
16
+ end }]
17
+ end
18
+
19
+ module Column
20
+ def type_cast(value)
21
+ return nil if value.nil? || value =~ /^\s*null\s*$/i
22
+ case type
23
+ when :string then value
24
+ when :integer then defined?(value.to_i) ? value.to_i : (value ? 1 : 0)
25
+ when :primary_key then defined?(value.to_i) ? value.to_i : (value ? 1 : 0)
26
+ when :float then value.to_f
27
+ when :datetime then cast_to_date_or_time(value)
28
+ when :timestamp then cast_to_time(value)
29
+ when :time then cast_to_time(value)
30
+ else value
31
+ end
32
+ end
33
+ def cast_to_date_or_time(value)
34
+ return value if value.is_a? Date
35
+ return nil if value.blank?
36
+ guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value))
37
+ end
38
+
39
+ def cast_to_time(value)
40
+ return value if value.is_a? Time
41
+ time_array = ParseDate.parsedate value
42
+ time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
43
+ Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
44
+ end
45
+
46
+ def guess_date_or_time(value)
47
+ (value.hour == 0 and value.min == 0 and value.sec == 0) ?
48
+ Date.new(value.year, value.month, value.day) : value
49
+ end
50
+ end
51
+
52
+ def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
53
+ id = super
54
+ unless id
55
+ table_name = sql.split(/\s/)[2]
56
+ result = select(ActiveRecord::Base.send(:sanitize_sql,
57
+ %[select IDENTITY_VAL_LOCAL() as last_insert_id from #{table_name}],
58
+ nil))
59
+ id = result.last['last_insert_id']
60
+ end
61
+ id
62
+ end
63
+
64
+ def modify_types(tp)
65
+ tp[:primary_key] = 'int not null generated by default as identity (start with 1) primary key'
66
+ tp[:string][:limit] = 255
67
+ tp[:integer][:limit] = nil
68
+ tp[:boolean][:limit] = nil
69
+ tp
70
+ end
71
+
72
+ def add_limit_offset!(sql, options)
73
+ if limit = options[:limit]
74
+ offset = options[:offset] || 0
75
+ sql.gsub!(/SELECT/i, 'SELECT B.* FROM (SELECT A.*, row_number() over () AS internal$rownum FROM (SELECT')
76
+ sql << ") A ) B WHERE B.internal$rownum > #{offset} AND B.internal$rownum <= #{limit + offset}"
77
+ end
78
+ end
79
+
80
+ def quote_column_name(column_name)
81
+ column_name
82
+ end
83
+
84
+ def quote(value, column = nil) # :nodoc:
85
+ if column && column.type == :primary_key
86
+ return value.to_s
87
+ end
88
+ if column && (column.type == :decimal || column.type == :integer) && value
89
+ return value.to_s
90
+ end
91
+ case value
92
+ when String
93
+ if column && column.type == :binary
94
+ "BLOB('#{quote_string(value)}')"
95
+ else
96
+ "'#{quote_string(value)}'"
97
+ end
98
+ else super
99
+ end
100
+ end
101
+
102
+ def quote_string(string)
103
+ string.gsub(/'/, "''") # ' (for ruby-mode)
104
+ end
105
+
106
+ def quoted_true
107
+ '1'
108
+ end
109
+
110
+ def quoted_false
111
+ '0'
112
+ end
113
+
114
+ def recreate_database(name)
115
+ do_not_drop = ["stmg_dbsize_info","hmon_atm_info","hmon_collection","policy"]
116
+ tables.each do |table|
117
+ unless do_not_drop.include?(table)
118
+ drop_table(table)
119
+ end
120
+ end
121
+ end
122
+
123
+ def remove_index(table_name, options = { })
124
+ execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}"
125
+ end
126
+
127
+ # This method makes tests pass without understanding why.
128
+ # Don't use this in production.
129
+ def columns(table_name, name = nil)
130
+ super.select do |col|
131
+ # strip out "magic" columns from DB2 (?)
132
+ !/rolename|roleid|create_time|auditpolicyname|auditpolicyid|remarks/.match(col.name)
133
+ end
134
+ end
135
+
136
+ def add_quotes(name)
137
+ return name unless name
138
+ %Q{"#{name}"}
139
+ end
140
+
141
+ def strip_quotes(str)
142
+ return str unless str
143
+ return str unless /^(["']).*\1$/ =~ str
144
+ str[1..-2]
145
+ end
146
+
147
+ def expand_double_quotes(name)
148
+ return name unless name && name['"']
149
+ name.gsub(/"/,'""')
150
+ end
151
+
152
+
153
+ def structure_dump #:nodoc:
154
+ definition=""
155
+ rs = @connection.connection.meta_data.getTables(nil,nil,nil,["TABLE"].to_java(:string))
156
+ while rs.next
157
+ tname = rs.getString(3)
158
+ definition << "CREATE TABLE #{tname} (\n"
159
+ rs2 = @connection.connection.meta_data.getColumns(nil,nil,tname,nil)
160
+ first_col = true
161
+ while rs2.next
162
+ col_name = add_quotes(rs2.getString(4));
163
+ default = ""
164
+ d1 = rs2.getString(13)
165
+ default = d1 ? " DEFAULT #{d1}" : ""
166
+
167
+ type = rs2.getString(6)
168
+ col_size = rs2.getString(7)
169
+ nulling = (rs2.getString(18) == 'NO' ? " NOT NULL" : "")
170
+ create_col_string = add_quotes(expand_double_quotes(strip_quotes(col_name))) +
171
+ " " +
172
+ type +
173
+ "" +
174
+ nulling +
175
+ default
176
+ if !first_col
177
+ create_col_string = ",\n #{create_col_string}"
178
+ else
179
+ create_col_string = " #{create_col_string}"
180
+ end
181
+
182
+ definition << create_col_string
183
+
184
+ first_col = false
185
+ end
186
+ definition << ");\n\n"
187
+ end
188
+ definition
189
+ end
190
+
191
+ def dump_schema_information
192
+ begin
193
+ if (current_schema = ActiveRecord::Migrator.current_version) > 0
194
+ #TODO: Find a way to get the DB2 instace name to properly form the statement
195
+ return "INSERT INTO DB2INST2.SCHEMA_INFO (version) VALUES (#{current_schema})"
196
+ end
197
+ rescue ActiveRecord::StatementInvalid
198
+ # No Schema Info
199
+ end
200
+ end
201
+
202
+ end
203
+ end