public
Fork of nicksieger/activerecord-jdbc-adapter
Description: ActiveRecord adapter for JDBC and JRuby
Homepage: http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter
Clone URL: git://github.com/abedra/activerecord-jdbc-adapter.git
Search Repo:
db2 driver spike
abedra (author)
Mon May 12 07:24:59 -0700 2008
commit  ebd4c32571883dc13fdd26323bce4ddbdf66e03e
tree    0e93e5127b0f96d15809ad933a1c2796676a39b5
parent  cae98b50850fb82b73579686812653481427ac77
...
100
101
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
104
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
0
@@ -100,5 +100,81 @@ module JdbcSpec
0
     def quoted_false
0
       '0'
0
     end
0
+
0
+ def recreate_database(name)
0
+ do_not_drop = ["stmg_dbsize_info","hmon_atm_info","hmon_collection","policy"]
0
+ tables.each do |table|
0
+ unless do_not_drop.include?(table)
0
+ drop_table(table)
0
+ end
0
+ end
0
+ end
0
+
0
+ def add_quotes(name)
0
+ return name unless name
0
+ %Q{"#{name}"}
0
+ end
0
+
0
+ def strip_quotes(str)
0
+ return str unless str
0
+ return str unless /^(["']).*\1$/ =~ str
0
+ str[1..-2]
0
+ end
0
+
0
+ def expand_double_quotes(name)
0
+ return name unless name && name['"']
0
+ name.gsub(/"/,'""')
0
+ end
0
+
0
+
0
+ def structure_dump #:nodoc:
0
+ definition=""
0
+ rs = @connection.connection.meta_data.getTables(nil,nil,nil,["TABLE"].to_java(:string))
0
+ while rs.next
0
+ tname = rs.getString(3)
0
+ definition << "CREATE TABLE #{tname} (\n"
0
+ rs2 = @connection.connection.meta_data.getColumns(nil,nil,tname,nil)
0
+ first_col = true
0
+ while rs2.next
0
+ col_name = add_quotes(rs2.getString(4));
0
+ default = ""
0
+ d1 = rs2.getString(13)
0
+ default = d1 ? " DEFAULT #{d1}" : ""
0
+
0
+ type = rs2.getString(6)
0
+ col_size = rs2.getString(7)
0
+ nulling = (rs2.getString(18) == 'NO' ? " NOT NULL" : "")
0
+ create_col_string = add_quotes(expand_double_quotes(strip_quotes(col_name))) +
0
+ " " +
0
+ type +
0
+ "" +
0
+ nulling +
0
+ default
0
+ if !first_col
0
+ create_col_string = ",\n #{create_col_string}"
0
+ else
0
+ create_col_string = " #{create_col_string}"
0
+ end
0
+
0
+ definition << create_col_string
0
+
0
+ first_col = false
0
+ end
0
+ definition << ");\n\n"
0
+ end
0
+ definition
0
+ end
0
+
0
+ def dump_schema_information
0
+ begin
0
+ if (current_schema = ActiveRecord::Migrator.current_version) > 0
0
+ #TODO: Find a way to get the DB2 instace name to properly form the statement
0
+ return "INSERT INTO DB2INST2.SCHEMA_INFO (version) VALUES (#{current_schema})"
0
+ end
0
+ rescue ActiveRecord::StatementInvalid
0
+ # No Schema Info
0
+ end
0
+ end
0
+
0
   end
0
 end

Comments

    No one has commented yet.