ibm_db 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,10 @@
1
1
  Change Log
2
2
  ==============
3
+ 2008/04/28 (IBM_DB adapter 0.9.4, driver 0.9.4):
4
+ - Fixed bug [#19679]--> invalid values being returned for blank or null in fetch_assoc
5
+ - Fixed bug [#19223] and [#19224]--> handling of composite and unique indexes incorrect
6
+ - Support for the Rails2.0 type of migrations for columns of type xml [t.xml :xml_col1,:xml_col2]
7
+
3
8
  2008/03/10 (IBM_DB adapter 0.9.3, driver 0.9.3):
4
9
  - Resolved the issue of truncation of output when stored procedure was called
5
10
 
data/ext/ibm_db.c CHANGED
@@ -10,7 +10,7 @@
10
10
  +----------------------------------------------------------------------+
11
11
  */
12
12
 
13
- #define MODULE_RELEASE "0.9.3"
13
+ #define MODULE_RELEASE "0.9.4"
14
14
 
15
15
  #ifdef HAVE_CONFIG_H
16
16
  #include "config.h"
@@ -4703,6 +4703,24 @@ static RETCODE _ruby_ibm_db_get_data2(stmt_handle *stmt_res, SQLUSMALLINT col_nu
4703
4703
 
4704
4704
  return rc;
4705
4705
  }
4706
+
4707
+ /*Function to check if the value of the LOB in the column is null or not*/
4708
+ int isNullLOB(VALUE *return_value,int i,stmt_handle *stmt_res,int op)
4709
+ {
4710
+ if (stmt_res->column_info[i].loc_ind == SQL_NULL_DATA) {
4711
+ if ( op & FETCH_ASSOC ) {
4712
+ rb_hash_aset(*return_value, rb_str_new2((char*)stmt_res->column_info[i].name), Qnil);
4713
+ }
4714
+ if ( op == FETCH_INDEX ) {
4715
+ rb_ary_store(*return_value, i, Qnil);
4716
+ } else if ( op == FETCH_BOTH ) {
4717
+ rb_hash_aset(*return_value, INT2NUM(i), Qnil);
4718
+ }
4719
+ return 1;
4720
+ }
4721
+ return 0;
4722
+ }
4723
+
4706
4724
  /* }}} */
4707
4725
 
4708
4726
  /*
@@ -4829,6 +4847,7 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
4829
4847
  break;
4830
4848
 
4831
4849
  case SQL_CLOB:
4850
+
4832
4851
  rc = _ruby_ibm_db_get_length(stmt_res, col_num+1, &in_length);
4833
4852
  if ( rc == SQL_ERROR ) {
4834
4853
  return Qfalse;
@@ -4855,6 +4874,7 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
4855
4874
  case SQL_LONGVARBINARY:
4856
4875
  #endif /* PASE */
4857
4876
  case SQL_VARBINARY:
4877
+
4858
4878
  rc = _ruby_ibm_db_get_length(stmt_res, col_num+1, &in_length);
4859
4879
  if ( rc == SQL_ERROR ) {
4860
4880
  return Qfalse;
@@ -4891,6 +4911,7 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
4891
4911
  break;
4892
4912
 
4893
4913
  case SQL_XML:
4914
+
4894
4915
  rc = _ruby_ibm_db_get_length(stmt_res, col_num+1, &in_length);
4895
4916
  if ( rc == SQL_ERROR ) {
4896
4917
  return Qfalse;
@@ -5152,6 +5173,13 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(int argc, VALUE *argv, int op)
5152
5173
  break;
5153
5174
 
5154
5175
  case SQL_BLOB:
5176
+
5177
+ /*Check if the data value in the column is null*/
5178
+
5179
+ if(isNullLOB(&return_value,i,stmt_res,op))
5180
+ {
5181
+ break;
5182
+ }
5155
5183
  out_ptr = NULL;
5156
5184
  rc=_ruby_ibm_db_get_length(stmt_res, i+1, &tmp_length);
5157
5185
 
@@ -5208,6 +5236,14 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(int argc, VALUE *argv, int op)
5208
5236
  break;
5209
5237
 
5210
5238
  case SQL_XML:
5239
+
5240
+ /*Check if the data value in the column is null*/
5241
+
5242
+ if(isNullLOB(&return_value,i,stmt_res,op))
5243
+ {
5244
+ break;
5245
+ }
5246
+
5211
5247
  out_ptr = NULL;
5212
5248
  rc = _ruby_ibm_db_get_data(stmt_res, i+1, SQL_C_BINARY, NULL, 0, (SQLINTEGER *)&tmp_length);
5213
5249
  if ( rc == SQL_ERROR ) {
@@ -5250,6 +5286,13 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(int argc, VALUE *argv, int op)
5250
5286
  break;
5251
5287
 
5252
5288
  case SQL_CLOB:
5289
+
5290
+ /*Check if the data value in the column is null*/
5291
+
5292
+ if(isNullLOB(&return_value,i,stmt_res,op))
5293
+ {
5294
+ break;
5295
+ }
5253
5296
  out_ptr = NULL;
5254
5297
  rc = _ruby_ibm_db_get_length(stmt_res, i+1, &tmp_length);
5255
5298
 
@@ -227,8 +227,21 @@ requires credentials: username and password"
227
227
  end #class IBM_DBColumn
228
228
 
229
229
  class TableDefinition
230
+
231
+ #Method to support the new syntax of rails 2.0 migrations for columns of type xml
232
+ def xml(*args )
233
+ options = {}
234
+ if args.last.is_a?(Hash)
235
+ options = args.delete_at(args.length-1)
236
+ end
237
+ args.each do | name |
238
+ column(name,'xml',options)
239
+ end # end args.each
240
+ return self
241
+ end
242
+
230
243
  # Overrides the abstract adapter in order to handle
231
- # the DEFAULT option for the native XML datat type
244
+ # the DEFAULT option for the native XML datatype
232
245
  def column(name, type, options ={})
233
246
  # construct a column definition where @base is adaptor instance
234
247
  column = ColumnDefinition.new(@base, name, type)
@@ -776,38 +789,86 @@ requires credentials: username and password"
776
789
 
777
790
  # Returns an array of non-primary key indexes for a specified table name
778
791
  def indexes(table_name, name = nil)
779
- # to_s required because +table_name+ may be a symbol.
792
+ # to_s required because +table_name+ may be a symbol.
780
793
  table_name = table_name.to_s
781
794
  # Checks if a blank table name has been given.
782
795
  # If so it returns an empty array of columns.
783
796
  return [] if table_name.strip.empty?
784
797
 
785
- # +indexes+ will contain the resulting array
798
+ # +index_array+ will contain the resulting array
786
799
  indexes = []
800
+ index_array = []
801
+ pk_index = nil
802
+ index_schema = []
803
+
804
+ #fetch the primary keys of the table using function primary_keys
805
+ #TABLE_SCHEM:: pk_index[1]
806
+ #TABLE_NAME:: pk_index[2]
807
+ #COLUMN_NAME:: pk_index[3]
808
+ #PK_NAME:: pk_index[5]
809
+ if stmt = IBM_DB::primary_keys( @connection, nil,
810
+ @servertype.set_case(@schema),
811
+ @servertype.set_case(table_name))
812
+ begin
813
+ while ( pk_index_row = IBM_DB::fetch_array(stmt) )
814
+ pk_index_name = pk_index_row[5].downcase
815
+ pk_index_columns = pk_index_row[3].map{|c| c.downcase} # COLUMN_NAME
816
+ if pk_index
817
+ pk_index.columns = "#{pk_index.columns} , #{pk_index_columns}"
818
+ else
819
+ pk_index = IndexDefinition.new(table_name, pk_index_name, true, pk_index_columns)
820
+
821
+ end
822
+ end
823
+ ensure # Free resources associated with the statement
824
+ IBM_DB::free_result(stmt) if stmt
825
+ end
826
+ else # Handle driver execution errors
827
+ error_msg = IBM_DB::conn_errormsg ? IBM_DB::conn_errormsg : IBM_DB::stmt_errormsg
828
+ if error_msg && !error_msg.empty?
829
+ raise "Failed to retrieve primary key metadata due to error: #{error_msg}"
830
+ else
831
+ raise StandardError('Unexpected error during primary key retrieval')
832
+ end
833
+ end
834
+
835
+
787
836
  # Query table statistics for all indexes on the table
788
837
  # "TABLE_NAME: #{index_stats[2]}"
789
838
  # "NON_UNIQUE: #{index_stats[3]}"
790
839
  # "INDEX_NAME: #{index_stats[5]}"
791
840
  # "COLUMN_NAME: #{index_stats[8]}"
792
- if stmt = IBM_DB::statistics( @connection, nil,
841
+ if stmt = IBM_DB::statistics( @connection, nil,
793
842
  @servertype.set_case(@schema),
794
843
  @servertype.set_case(table_name), 1 )
795
- begin
796
- while ( index_stats = IBM_DB::fetch_array(stmt) )
797
- if index_stats[5] # INDEX_NAME
798
- index_name = index_stats[5].downcase
799
- # Non-unique index type (not the primary key)
800
- unless index_stats[3] == 0 # NON_UNIQUE
801
- index_unique = (index_stats[3] == 0)
802
- index_columns = index_stats[8].map{|c| c.downcase} # COLUMN_NAME
803
- # Create an IndexDefinition object and add to the indexes array
804
- indexes << IndexDefinition.new(table_name, index_name, index_unique, index_columns)
805
- end
806
- end
844
+ begin
845
+ while ( index_stats = IBM_DB::fetch_array(stmt) )
846
+ is_composite = false
847
+ if index_stats[5] # INDEX_NAME
848
+ index_name = index_stats[5].downcase
849
+ index_unique = (index_stats[3] == 0)
850
+ index_columns = index_stats[8].map{|c| c.downcase} # COLUMN_NAME
851
+ index_qualifier = index_stats[4] #Index_Qualifier
852
+ # Create an IndexDefinition object and add to the indexes array
853
+ i = 0;
854
+ indexes.each do |index|
855
+ if index.name == index_name && index_schema[i] == index_qualifier
856
+ index.columns = "#{index.columns} , #{index_columns}"
857
+ is_composite = true
858
+ end
859
+ i = i+1
807
860
  end
808
- ensure # Free resources associated with the statement
809
- IBM_DB::free_result(stmt) if stmt
861
+
862
+ unless is_composite
863
+ indexes << IndexDefinition.new(table_name, index_name, index_unique, index_columns)
864
+ index_schema << index_qualifier.downcase
865
+ end
866
+
810
867
  end
868
+ end
869
+ ensure # Free resources associated with the statement
870
+ IBM_DB::free_result(stmt) if stmt
871
+ end
811
872
  else # Handle driver execution errors
812
873
  error_msg = IBM_DB::conn_errormsg ? IBM_DB::conn_errormsg : IBM_DB::stmt_errormsg
813
874
  if error_msg && !error_msg.empty?
@@ -816,10 +877,21 @@ requires credentials: username and password"
816
877
  raise StandardError('Unexpected error during index retrieval')
817
878
  end
818
879
  end
880
+
881
+ # remove the primary key index entry.... shouldnt be dumped by the dumper
882
+
883
+ i = 0
884
+ indexes.each do |index|
885
+ unless index.columns == pk_index.columns
886
+ index.name = "#{index_schema[i]}.#{index.name}"
887
+ index_array << index
888
+ end
889
+ i = i+1
890
+ end
819
891
  # Returns the indexes array
820
- return indexes
892
+ return index_array
821
893
  end
822
-
894
+
823
895
  # Returns an array of Column objects for the table specified by +table_name+
824
896
  def columns(table_name, name = nil)
825
897
  # to_s required because it may be a symbol.
data/test/adapter_test.rb CHANGED
@@ -62,7 +62,7 @@ class AdapterTest < Test::Unit::TestCase
62
62
  end
63
63
 
64
64
  def test_indexes
65
- idx_name = "accounts_idx"
65
+ idx_name = "#{ActiveRecord::Base.connection.schema}.accounts_idx"
66
66
 
67
67
  if @connection.respond_to?(:indexes)
68
68
  indexes = @connection.indexes("accounts")
@@ -152,6 +152,20 @@ if ActiveRecord::Base.connection.supports_migrations?
152
152
  ensure
153
153
  clasz.connection.drop_table(clasz.table_name) rescue nil
154
154
  end
155
+
156
+ def test_new_xml_migrations
157
+ clasz = Class.new(ActiveRecord::Base)
158
+ clasz.table_name = 'test_new_xml_migrations'
159
+ assert_nothing_raised do
160
+ clasz.connection.create_table clasz.table_name do |t|
161
+ t.xml :xml_col,:xml_col1,:xml_col2
162
+ t.string :varchar_col
163
+ t.integer :int_col
164
+ end
165
+ end
166
+ ensure
167
+ clasz.connection.drop_table(clasz.table_name) rescue nil
168
+ end
155
169
  end
156
170
 
157
171
  def test_create_table_with_limits
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: 0.9.3
4
+ version: 0.9.4
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: 2008-03-20 00:00:00 -07:00
12
+ date: 2008-04-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency