ibm_db 1.0.1 → 1.0.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/CHANGES +6 -0
- data/LICENSE +1 -1
- data/README +1 -1
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +109 -90
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +48 -0
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
Change Log
|
2
2
|
==============
|
3
|
+
2009/03/06 (IBM_DB adapter 1.0.2, driver 1.0.1) :
|
4
|
+
- Support for specifying connection timeout in adapter
|
5
|
+
- Fixed Bug [23317] --> Fixed assumption of id as the primary key while updation/insertion of lob fields
|
6
|
+
- Fixed Bug [23389] --> Provided proper exception handling.
|
7
|
+
- Fixed the insertion of incorrect value for lob objects in case of has_and_belongs_to_many associations.
|
8
|
+
|
3
9
|
2008/12/18 (IBM_DB adapter 1.0.1, driver 1.0.1) :
|
4
10
|
- Support for datatype decfloat
|
5
11
|
- Changes in installation process. Now user should set IBM_DB_INCLUDE env variable instead of IBM_DB_DIR
|
data/LICENSE
CHANGED
data/README
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
=====================================================================
|
2
|
-
README for the IBM_DB Adapter (1.0.
|
2
|
+
README for the IBM_DB Adapter (1.0.2) and Driver (1.0.1) (2009/03/06)
|
3
3
|
For ActiveRecord Version >= 1.15.5 (and Rails >= 1.2.5)
|
4
4
|
=====================================================================
|
5
5
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# +----------------------------------------------------------------------+
|
2
2
|
# | Licensed Materials - Property of IBM |
|
3
3
|
# | |
|
4
|
-
# | (C) Copyright IBM Corporation 2006, 2007, 2008
|
4
|
+
# | (C) Copyright IBM Corporation 2006, 2007, 2008, 2009 |
|
5
5
|
# +----------------------------------------------------------------------+
|
6
6
|
# | Authors: Antonio Cangiano <cangiano@ca.ibm.com> |
|
7
7
|
# | : Mario Ds Briggs <mario.briggs@in.ibm.com> |
|
@@ -20,68 +20,73 @@ module ActiveRecord
|
|
20
20
|
def handle_lobs()
|
21
21
|
if connection.kind_of?(ConnectionAdapters::IBM_DBAdapter)
|
22
22
|
# Checks that the insert or update had at least a BLOB, CLOB or XML field
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
23
|
+
connection.sql.each do |clob_sql|
|
24
|
+
if clob_sql =~ /BLOB\('(.*)'\)/i ||
|
25
|
+
clob_sql =~ /@@@IBMTEXT@@@/i ||
|
26
|
+
clob_sql =~ /@@@IBMXML@@@/i ||
|
27
|
+
clob_sql =~ /@@@IBMBINARY@@@/i
|
28
|
+
update_query = "UPDATE #{self.class.table_name} SET ("
|
29
|
+
counter = 0
|
30
|
+
values = []
|
31
|
+
params = []
|
32
|
+
# Selects only binary, text and xml columns
|
33
|
+
self.class.columns.select{|col| col.type == :binary ||
|
34
|
+
col.type == :text ||
|
35
|
+
col.type == :xml}.each do |col|
|
36
|
+
# Adds the selected columns to the query
|
37
|
+
if counter == 0
|
38
|
+
update_query << "#{col.name}"
|
39
|
+
else
|
40
|
+
update_query << ",#{col.name}"
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
# Add a '?' for the parameter or a NULL if the value is nil or empty
|
44
|
+
# (except for a CLOB field where '' can be a value)
|
45
|
+
if self[col.name].nil? ||
|
46
|
+
self[col.name] == {} ||
|
47
|
+
(self[col.name] == '' && col.type != :text)
|
48
|
+
params << 'NULL'
|
49
|
+
else
|
50
|
+
values << self[col.name]
|
51
|
+
params << '?'
|
52
|
+
end
|
53
|
+
counter += 1
|
54
|
+
end
|
55
|
+
# no subsequent update is required if no relevant columns are found
|
56
|
+
next if counter == 0
|
57
|
+
|
58
|
+
update_query << ") = "
|
59
|
+
# IBM_DB accepts 'SET (column) = NULL' but not (NULL),
|
60
|
+
# therefore the sql needs to be changed for a single NULL field.
|
61
|
+
if params.size==1 && params[0] == 'NULL'
|
62
|
+
update_query << "NULL"
|
48
63
|
else
|
49
|
-
|
50
|
-
params << '?'
|
64
|
+
update_query << "(" + params.join(',') + ")"
|
51
65
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
update_query << " WHERE #{self.class.primary_key} = #{id}"
|
66
|
+
|
67
|
+
update_query << " WHERE #{self.class.primary_key} = '#{self[self.class.primary_key.downcase]}'"
|
68
|
+
|
69
|
+
unless stmt = IBM_DB.prepare(connection.connection, update_query)
|
70
|
+
error_msg = IBM_DB.conn_errormsg
|
71
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
72
|
+
if error_msg && !error_msg.empty?
|
73
|
+
raise "Statement prepare for updating LOB/XML column failed : #{error_msg}"
|
74
|
+
else
|
75
|
+
raise StandardError.new('An unexpected error occurred during update of LOB/XML column')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
connection.log_query(update_query,'update of LOB/XML field(s)in handle_lobs')
|
66
79
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
raise "Failed to
|
80
|
+
# rollback any failed LOB/XML field updates (and remove associated marker)
|
81
|
+
unless IBM_DB.execute(stmt, values)
|
82
|
+
connection.execute("ROLLBACK")
|
83
|
+
raise "Failed to insert/update LOB/XML field(s) due to: #{IBM_DB.stmt_errormsg(stmt)}"
|
71
84
|
else
|
72
|
-
|
85
|
+
IBM_DB.free_result stmt
|
73
86
|
end
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
# rollback any failed LOB/XML field updates (and remove associated marker)
|
78
|
-
unless IBM_DB.execute(stmt, values)
|
79
|
-
connection.execute("ROLLBACK")
|
80
|
-
raise "Failed to insert/update LOB/XML field(s) due to: #{IBM_DB.stmt_errormsg(stmt)}"
|
81
|
-
else
|
82
|
-
IBM_DB.free_result stmt
|
83
|
-
end
|
84
|
-
end # if connection.sql
|
87
|
+
end # if clob_sql
|
88
|
+
end #connection.sql.each
|
89
|
+
connection.sql = []
|
85
90
|
end # if connection.kind_of?
|
86
91
|
end # handle_lobs
|
87
92
|
private :handle_lobs
|
@@ -112,8 +117,7 @@ module ActiveRecord
|
|
112
117
|
# Retrieves database user credentials from the +config+ hash
|
113
118
|
# or raises ArgumentError in case of failure.
|
114
119
|
if !config.has_key?(:username) || !config.has_key?(:password)
|
115
|
-
raise ArgumentError, "Missing argument(s):
|
116
|
-
requires credentials: username and password"
|
120
|
+
raise ArgumentError, "Missing argument(s): Username/Password for #{config[:database]} is not specified"
|
117
121
|
else
|
118
122
|
username = config[:username].to_s
|
119
123
|
password = config[:password].to_s
|
@@ -149,7 +153,7 @@ requires credentials: username and password"
|
|
149
153
|
host = config[:host]
|
150
154
|
# A net address connection requires a port. If no port has been specified, 50000 is used by default
|
151
155
|
port = config[:port] || 50000
|
152
|
-
# Connects to the database using the
|
156
|
+
# Connects to the database specified using the hostname, port, authentication type, username and password info
|
153
157
|
# Starting with DB2 9.1FP5 secure connections using SSL are supported.
|
154
158
|
# On the client side using CLI this is supported from CLI version V95FP2 and onwards.
|
155
159
|
# This feature is set by specifying SECURITY=SSL in the connection string.
|
@@ -163,6 +167,8 @@ requires credentials: username and password"
|
|
163
167
|
PWD=#{password};"
|
164
168
|
conn_string << "SECURITY=#{config[:security]};" if config.has_key?(:security)
|
165
169
|
conn_string << "AUTHENTICATION=#{config[:authentication]};" if config.has_key?(:authentication)
|
170
|
+
conn_string << "CONNECTTIMEOUT=#{config[:timeout]};" if config.has_key?(:timeout)
|
171
|
+
|
166
172
|
connection = IBM_DB.connect conn_string, '', '', conn_options
|
167
173
|
else
|
168
174
|
# No host implies a local catalog-based connection: +database+ represents catalog alias
|
@@ -176,7 +182,7 @@ requires credentials: username and password"
|
|
176
182
|
ConnectionAdapters::IBM_DBAdapter.new(connection, logger, config, conn_options)
|
177
183
|
else
|
178
184
|
# If the connection failed, it raises a Runtime error
|
179
|
-
raise "Failed to connect to
|
185
|
+
raise "Failed to connect to [#{database}] due to: #{IBM_DB.conn_errormsg}"
|
180
186
|
end
|
181
187
|
end # method self.ibm_db_connection
|
182
188
|
end # class Base
|
@@ -387,6 +393,8 @@ requires credentials: username and password"
|
|
387
393
|
# // - Available only from CLI version V95fp2 and above
|
388
394
|
# authentication: 'SERVER' // AUTHENTICATION type which the client uses -
|
389
395
|
# // - to connect to the database server. By default value is SERVER
|
396
|
+
# timeout: 10 // Specifies the time in seconds (0 - 32767) to wait for a reply from server -
|
397
|
+
# //- when trying to establish a connection before generating a timeout
|
390
398
|
#
|
391
399
|
# When schema is not specified, the username value is used instead.
|
392
400
|
#
|
@@ -414,12 +422,15 @@ requires credentials: username and password"
|
|
414
422
|
@schema = config[:schema]
|
415
423
|
@security = config[:security] || nil
|
416
424
|
@authentication = config[:authentication] || nil
|
425
|
+
@timeout = config[:timeout] || 0 # default timeout value is 0
|
417
426
|
|
418
427
|
# Caching database connection options (auditing and billing support)
|
419
428
|
@app_user = conn_options[:app_user] if conn_options.has_key?(:app_user)
|
420
429
|
@account = conn_options[:account] if conn_options.has_key?(:account)
|
421
430
|
@application = conn_options[:application] if conn_options.has_key?(:application)
|
422
431
|
@workstation = conn_options[:workstation] if conn_options.has_key?(:workstation)
|
432
|
+
|
433
|
+
@sql = []
|
423
434
|
|
424
435
|
# Calls the parent class +ConnectionAdapters+' initializer
|
425
436
|
# which sets @connection, @logger, @runtime and @last_verification
|
@@ -544,6 +555,7 @@ requires credentials: username and password"
|
|
544
555
|
PWD=#{@password};"
|
545
556
|
@conn_string << "SECURITY=#{@security};" if @security
|
546
557
|
@conn_string << "AUTHENTICATION=#{@authentication};" if @authentication
|
558
|
+
@conn_string << "CONNECTTIMEOUT=#{@timeout};"
|
547
559
|
# Connects and assigns the resulting IBM_DB.Connection to the +@connection+ instance variable
|
548
560
|
@connection = IBM_DB.connect(@conn_string, '', '', @conn_options)
|
549
561
|
else
|
@@ -688,11 +700,12 @@ requires credentials: username and password"
|
|
688
700
|
|
689
701
|
insert_query << " VALUES ("+ params.join(',') + ")"
|
690
702
|
unless stmt = IBM_DB.prepare(@connection, insert_query)
|
691
|
-
error_msg = IBM_DB.conn_errormsg
|
703
|
+
error_msg = IBM_DB.conn_errormsg
|
704
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
692
705
|
if error_msg && !error_msg.empty?
|
693
706
|
raise "Failed to prepare statement due to : #{error_msg}"
|
694
707
|
else
|
695
|
-
raise StandardError('
|
708
|
+
raise StandardError.new('An unexpected error occurred during insert')
|
696
709
|
end
|
697
710
|
end
|
698
711
|
|
@@ -712,7 +725,7 @@ requires credentials: username and password"
|
|
712
725
|
def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
713
726
|
if stmt = execute(sql, name)
|
714
727
|
begin
|
715
|
-
@sql
|
728
|
+
@sql << sql
|
716
729
|
return id_value || @servertype.last_generated_id(stmt)
|
717
730
|
# Ensures to free the resources associated with the statement
|
718
731
|
ensure
|
@@ -743,7 +756,7 @@ requires credentials: username and password"
|
|
743
756
|
# Logs and execute the given sql query.
|
744
757
|
if stmt = execute(sql, name)
|
745
758
|
begin
|
746
|
-
@sql
|
759
|
+
@sql << sql
|
747
760
|
# Retrieves the number of affected rows
|
748
761
|
IBM_DB.num_rows(stmt)
|
749
762
|
# Ensures to free the resources associated with the statement
|
@@ -985,11 +998,12 @@ requires credentials: username and password"
|
|
985
998
|
IBM_DB.free_result(stmt) # Free resources associated with the statement
|
986
999
|
end
|
987
1000
|
else # Handle driver execution errors
|
988
|
-
error_msg = IBM_DB.conn_errormsg
|
1001
|
+
error_msg = IBM_DB.conn_errormsg
|
1002
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
989
1003
|
if error_msg && !error_msg.empty?
|
990
1004
|
raise "Failed to retrieve tables metadata due to error: #{error_msg}"
|
991
1005
|
else
|
992
|
-
raise StandardError('
|
1006
|
+
raise StandardError.new('An unexpected error occurred during retrieval of table metadata')
|
993
1007
|
end
|
994
1008
|
end
|
995
1009
|
# Returns the tables array
|
@@ -1032,11 +1046,12 @@ requires credentials: username and password"
|
|
1032
1046
|
IBM_DB.free_result(stmt) if stmt
|
1033
1047
|
end
|
1034
1048
|
else # Handle driver execution errors
|
1035
|
-
error_msg = IBM_DB.conn_errormsg
|
1049
|
+
error_msg = IBM_DB.conn_errormsg
|
1050
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
1036
1051
|
if error_msg && !error_msg.empty?
|
1037
1052
|
raise "Failed to retrieve primary key metadata due to error: #{error_msg}"
|
1038
1053
|
else
|
1039
|
-
raise StandardError('
|
1054
|
+
raise StandardError.new('An unexpected error occurred during primary key retrieval')
|
1040
1055
|
end
|
1041
1056
|
end
|
1042
1057
|
|
@@ -1077,12 +1092,13 @@ requires credentials: username and password"
|
|
1077
1092
|
IBM_DB.free_result(stmt) if stmt
|
1078
1093
|
end
|
1079
1094
|
else # Handle driver execution errors
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1095
|
+
error_msg = IBM_DB.conn_errormsg
|
1096
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
1097
|
+
if error_msg && !error_msg.empty?
|
1098
|
+
raise "Failed to retrieve index metadata due to error: #{error_msg}"
|
1099
|
+
else
|
1100
|
+
raise StandardError.new('An unexpected error occurred during index retrieval')
|
1101
|
+
end
|
1086
1102
|
end
|
1087
1103
|
|
1088
1104
|
# remove the primary key index entry.... should not be dumped by the dumper
|
@@ -1153,21 +1169,23 @@ requires credentials: username and password"
|
|
1153
1169
|
end
|
1154
1170
|
end
|
1155
1171
|
rescue StandardError # Handle driver fetch errors
|
1156
|
-
error_msg = IBM_DB.conn_errormsg
|
1172
|
+
error_msg = IBM_DB.conn_errormsg
|
1173
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
1157
1174
|
if error_msg && !error_msg.empty?
|
1158
1175
|
raise "Failed to retrieve column metadata during fetch: #{error_msg}"
|
1159
1176
|
else
|
1160
|
-
raise
|
1177
|
+
raise "An unexpected error occurred during retrieval of metadata"
|
1161
1178
|
end
|
1162
1179
|
ensure # Free resources associated with the statement
|
1163
1180
|
IBM_DB.free_result(stmt)
|
1164
1181
|
end
|
1165
1182
|
else # Handle driver execution errors
|
1166
|
-
error_msg = IBM_DB.conn_errormsg
|
1183
|
+
error_msg = IBM_DB.conn_errormsg
|
1184
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
1167
1185
|
if error_msg && !error_msg.empty?
|
1168
1186
|
raise "Failed to retrieve column metadata due to error: #{error_msg}"
|
1169
1187
|
else
|
1170
|
-
raise StandardError('
|
1188
|
+
raise StandardError.new('An unexpected error occurred during retrieval of columns metadata')
|
1171
1189
|
end
|
1172
1190
|
end
|
1173
1191
|
# Returns the columns array
|
@@ -1303,7 +1321,7 @@ requires credentials: username and password"
|
|
1303
1321
|
"A column that is part of a table containing an XML column cannot be dropped. \
|
1304
1322
|
To remove the column, the table must be dropped and recreated without the #{column_name} column: #{exec_err}"
|
1305
1323
|
else
|
1306
|
-
raise
|
1324
|
+
raise "#{exec_err}"
|
1307
1325
|
end
|
1308
1326
|
end
|
1309
1327
|
end
|
@@ -1336,10 +1354,10 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
1336
1354
|
raise StatementInvalid, IBM_DB.stmt_errormsg
|
1337
1355
|
end
|
1338
1356
|
rescue StandardError
|
1339
|
-
error_msg = IBM_DB.conn_errormsg
|
1357
|
+
error_msg = IBM_DB.conn_errormsg
|
1340
1358
|
if error_msg && !error_msg.empty?
|
1341
|
-
raise "Failed to execute statement due to error: #{error_msg}"
|
1342
|
-
else
|
1359
|
+
raise "Failed to execute statement due to communication error: #{error_msg}"
|
1360
|
+
else
|
1343
1361
|
raise
|
1344
1362
|
end
|
1345
1363
|
end
|
@@ -1405,11 +1423,12 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
1405
1423
|
IBM_DB.free_result stmt
|
1406
1424
|
end
|
1407
1425
|
else
|
1408
|
-
error_msg = IBM_DB.conn_errormsg
|
1426
|
+
error_msg = IBM_DB.conn_errormsg
|
1427
|
+
error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
|
1409
1428
|
if error_msg && !error_msg.empty?
|
1410
1429
|
raise "Failed to retrieve last generated id due to error: #{error_msg}"
|
1411
1430
|
else
|
1412
|
-
raise StandardError('
|
1431
|
+
raise StandardError.new('An unexpected error occurred during retrieval of last generated id')
|
1413
1432
|
end
|
1414
1433
|
end
|
1415
1434
|
end
|
@@ -1424,7 +1443,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
1424
1443
|
"Please consult documentation for compatible data types while changing column datatype. \
|
1425
1444
|
The column datatype change to [#{data_type}] is not supported by this data server: #{exec_err}"
|
1426
1445
|
else
|
1427
|
-
raise
|
1446
|
+
raise "#{exec_err}"
|
1428
1447
|
end
|
1429
1448
|
end
|
1430
1449
|
reorg_table(table_name)
|
@@ -1613,9 +1632,9 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1613
1632
|
raise StatementInvalid, IBM_DB.stmt_errormsg
|
1614
1633
|
end
|
1615
1634
|
rescue StandardError
|
1616
|
-
error_msg = IBM_DB.conn_errormsg
|
1635
|
+
error_msg = IBM_DB.conn_errormsg
|
1617
1636
|
if error_msg && !error_msg.empty?
|
1618
|
-
raise "Failed to execute statement due to error: #{error_msg}"
|
1637
|
+
raise "Failed to execute statement due to communication error: #{error_msg}"
|
1619
1638
|
else
|
1620
1639
|
raise
|
1621
1640
|
end
|
@@ -1628,9 +1647,9 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1628
1647
|
raise StatementInvalid, IBM_DB.stmt_errormsg
|
1629
1648
|
end
|
1630
1649
|
rescue StandardError
|
1631
|
-
error_msg = IBM_DB.conn_errormsg
|
1650
|
+
error_msg = IBM_DB.conn_errormsg
|
1632
1651
|
if error_msg && !error_msg.empty?
|
1633
|
-
raise "Failed to execute statement due to error: #{error_msg}"
|
1652
|
+
raise "Failed to execute statement due to communication error: #{error_msg}"
|
1634
1653
|
else
|
1635
1654
|
raise
|
1636
1655
|
end
|
@@ -78,6 +78,21 @@ class DeveloperWithCounterSQL < ActiveRecord::Base
|
|
78
78
|
:counter_sql => 'SELECT COUNT(*) AS count_all FROM projects INNER JOIN developers_projects ON projects.id = developers_projects.project_id WHERE developers_projects.developer_id =#{id}'
|
79
79
|
end
|
80
80
|
|
81
|
+
if current_adapter?(:IBM_DBAdapter)
|
82
|
+
class Novel < ActiveRecord::Base
|
83
|
+
has_and_belongs_to_many :writers
|
84
|
+
end
|
85
|
+
|
86
|
+
class Writer < ActiveRecord::Base
|
87
|
+
has_and_belongs_to_many :novels
|
88
|
+
end
|
89
|
+
|
90
|
+
class NovelsWriter < ActiveRecord::Base
|
91
|
+
belongs_to :writers
|
92
|
+
belongs_to :novels
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
81
96
|
class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
|
82
97
|
fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects,
|
83
98
|
:parrots, :pirates, :treasures, :price_estimates, :tags, :taggings
|
@@ -269,6 +284,39 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
|
|
269
284
|
assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated
|
270
285
|
end
|
271
286
|
|
287
|
+
if current_adapter?(:IBM_DBAdapter)
|
288
|
+
def test_lob_handling
|
289
|
+
assert_nothing_raised do
|
290
|
+
Novel.connection.create_table 'novels' do |t|
|
291
|
+
t.text :story
|
292
|
+
t.string :title
|
293
|
+
end
|
294
|
+
Writer.connection.create_table 'writers' do |t|
|
295
|
+
t.string :name
|
296
|
+
end
|
297
|
+
NovelsWriter.connection.create_table 'novels_writers' do |t|
|
298
|
+
t.belongs_to :novels
|
299
|
+
t.belongs_to :writers
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
w = Writer.new :name => 'Praveen'
|
304
|
+
w.save!
|
305
|
+
|
306
|
+
novel_story = "This is a short and sweet story"
|
307
|
+
|
308
|
+
novel = Novel.new :story => novel_story,:title => "Cool isn't it"
|
309
|
+
novel.writers << w
|
310
|
+
novel.save!
|
311
|
+
|
312
|
+
assert_equal novel_story,Novel.find(novel.id).story
|
313
|
+
ensure
|
314
|
+
Novel.connection.drop_table 'novels' rescue nil
|
315
|
+
Writer.connection.drop_table 'writers' rescue nil
|
316
|
+
NovelsWriter.connection.drop_table 'novels_writers' rescue nil
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
272
320
|
def test_create_by_new_record
|
273
321
|
devel = Developer.new(:name => "Marcel", :salary => 75000)
|
274
322
|
proj1 = devel.projects.build(:name => "Make bed")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IBM
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-03-06 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|