ruby-oci8 2.1.2-x86-mingw32 → 2.1.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ class OCI8
7
7
 
8
8
  # Returns the type descriptor object which correspond to the given class.
9
9
  #
10
- # @param [class of an OCI8::Object::Base's subclass]
10
+ # @param [class of an OCI8::Object::Base's subclass] klass
11
11
  # @return [OCI8::TDO]
12
12
  #
13
13
  # @private
@@ -29,7 +29,7 @@ class OCI8
29
29
 
30
30
  # Returns the type descriptor object which correspond to the given metadata.
31
31
  #
32
- # @param [OCI8::Metadata::Base's subclass]
32
+ # @param [OCI8::Metadata::Base's subclass] metadata
33
33
  # @return [OCI8::TDO]
34
34
  #
35
35
  # @private
@@ -466,7 +466,7 @@ EOS
466
466
  when :date
467
467
  [ATTR_OCIDATE, nil, SIZE_OF_OCIDATE, 2, ALIGNMENT_OF_OCIDATE,
468
468
  Proc.new do |val| datetime_to_array(val, :date) end, # set_proc
469
- Proc.new do |val| array_to_datetime(val, :local) end, # get_proc
469
+ Proc.new do |val| array_to_time(val, :local) end, # get_proc
470
470
  ]
471
471
  when :binary_double
472
472
  [ATTR_BINARY_DOUBLE, nil, SIZE_OF_DOUBLE, 2, ALIGNMENT_OF_DOUBLE]
@@ -1,4 +1,4 @@
1
- # oci8.rb -- implements OCI8 and OCI8::Cursor
1
+ # oci8.rb -- OCI8
2
2
  #
3
3
  # Copyright (C) 2002-2012 KUBO Takehiro <kubo@jiubao.org>
4
4
  #
@@ -154,8 +154,8 @@ class OCI8
154
154
  end
155
155
 
156
156
  allocate_handles()
157
- session_handle.send(:attr_set_string, OCI_ATTR_USERNAME, username) if username
158
- session_handle.send(:attr_set_string, OCI_ATTR_PASSWORD, password) if password
157
+ @session_handle.send(:attr_set_string, OCI_ATTR_USERNAME, username) if username
158
+ @session_handle.send(:attr_set_string, OCI_ATTR_PASSWORD, password) if password
159
159
  server_attach(dbname, attach_mode)
160
160
  session_begin(cred ? cred : OCI_CRED_RDBMS, mode ? mode : OCI_DEFAULT)
161
161
 
@@ -169,16 +169,18 @@ class OCI8
169
169
  @username = nil
170
170
  end
171
171
 
172
- # call-seq:
173
- # parse(sql_text) -> an OCI8::Cursor
174
- #
175
172
  # Returns a prepared SQL handle.
173
+ #
174
+ # @param [String] sql SQL statement
175
+ # @return [OCI8::Cursor]
176
176
  def parse(sql)
177
177
  @last_error = nil
178
178
  parse_internal(sql)
179
179
  end
180
180
 
181
181
  # same with OCI8#parse except that this doesn't reset OCI8#last_error.
182
+ #
183
+ # @private
182
184
  def parse_internal(sql)
183
185
  cursor = OCI8::Cursor.new(self, sql)
184
186
  cursor.prefetch_rows = @prefetch_rows if @prefetch_rows
@@ -276,6 +278,8 @@ class OCI8
276
278
  end
277
279
 
278
280
  # same with OCI8#exec except that this doesn't reset OCI8#last_error.
281
+ #
282
+ # @private
279
283
  def exec_internal(sql, *bindvars)
280
284
  begin
281
285
  cursor = parse(sql)
@@ -308,9 +312,11 @@ class OCI8
308
312
  end
309
313
  end # exec
310
314
 
311
- # :call-seq:
312
- # select_one(sql, *bindvars) -> first_one_row
315
+ # Executes a SQL statement and fetches the first one row.
313
316
  #
317
+ # @param [String] sql SQL statement
318
+ # @param [Object] bindvars bind variables
319
+ # @return [Array] an array of first row.
314
320
  def select_one(sql, *bindvars)
315
321
  cursor = self.parse(sql)
316
322
  begin
@@ -335,12 +341,11 @@ class OCI8
335
341
  "#<OCI8:#{username}>"
336
342
  end
337
343
 
338
- # :call-seq:
339
- # oracle_server_version -> oraver
340
- #
341
344
  # Returns an OCI8::OracleVersion of the Oracle server version.
342
345
  #
343
346
  # See also: OCI8.oracle_client_version
347
+ #
348
+ # @return [OCI8::OracleVersion]
344
349
  def oracle_server_version
345
350
  unless defined? @oracle_server_version
346
351
  if vernum = oracle_server_vernum
@@ -360,335 +365,22 @@ class OCI8
360
365
  @oracle_server_version
361
366
  end
362
367
 
363
- # :call-seq:
364
- # database_charset_name -> string
365
- #
366
- # (new in 2.1.0)
368
+ # Returns the Oracle database character set name.
367
369
  #
368
- # Returns the database character set name.
370
+ # @since 2.1.0
371
+ # @return [String] Oracle database character set name
369
372
  def database_charset_name
370
- charset_id2name(server_handle.send(:attr_get_ub2, OCI_ATTR_CHARSET_ID))
373
+ charset_id2name(@server_handle.send(:attr_get_ub2, OCI_ATTR_CHARSET_ID))
371
374
  end
372
375
 
373
- # :call-seq:
374
- # OCI8.client_charset_name -> string
376
+ # Returns the client-side Oracle character set name.
375
377
  #
376
- # (new in 2.1.0)
377
- #
378
- # Returns the client character set name.
378
+ # @since 2.1.0
379
+ # @return [String] client-side character set name
379
380
  def self.client_charset_name
380
381
  @@client_charset_name
381
382
  end
382
-
383
- # The instance of this class corresponds to cursor in the term of
384
- # Oracle, which corresponds to java.sql.Statement of JDBC and statement
385
- # handle $sth of Perl/DBI.
386
- #
387
- # Don't create the instance by calling 'new' method. Please create it by
388
- # calling OCI8#exec or OCI8#parse.
389
- class Cursor
390
-
391
- # explicitly indicate the date type of fetched value. run this
392
- # method within parse and exec. pos starts from 1. lentgh is used
393
- # when type is String.
394
- #
395
- # example:
396
- # cursor = conn.parse("SELECT ename, hiredate FROM emp")
397
- # cursor.define(1, String, 20) # fetch the first column as String.
398
- # cursor.define(2, Time) # fetch the second column as Time.
399
- # cursor.exec()
400
- def define(pos, type, length = nil)
401
- __define(pos, make_bind_object(:type => type, :length => length))
402
- self
403
- end # define
404
-
405
- # Binds variables explicitly.
406
- #
407
- # When key is number, it binds by position, which starts from 1.
408
- # When key is string, it binds by the name of placeholder.
409
- #
410
- # example:
411
- # cursor = conn.parse("SELECT * FROM emp WHERE ename = :ename")
412
- # cursor.bind_param(1, 'SMITH') # bind by position
413
- # ...or...
414
- # cursor.bind_param(':ename', 'SMITH') # bind by name
415
- #
416
- # To bind as number, Fixnum and Float are available, but Bignum is
417
- # not supported. If its initial value is NULL, please set nil to
418
- # +type+ and Fixnum or Float to +val+.
419
- #
420
- # example:
421
- # cursor.bind_param(1, 1234) # bind as Fixnum, Initial value is 1234.
422
- # cursor.bind_param(1, 1234.0) # bind as Float, Initial value is 1234.0.
423
- # cursor.bind_param(1, nil, Fixnum) # bind as Fixnum, Initial value is NULL.
424
- # cursor.bind_param(1, nil, Float) # bind as Float, Initial value is NULL.
425
- #
426
- # In case of binding a string, set the string itself to
427
- # +val+. When the bind variable is used as output, set the
428
- # string whose length is enough to store or set the length.
429
- #
430
- # example:
431
- # cursor = conn.parse("BEGIN :out := :in || '_OUT'; END;")
432
- # cursor.bind_param(':in', 'DATA') # bind as String with width 4.
433
- # cursor.bind_param(':out', nil, String, 7) # bind as String with width 7.
434
- # cursor.exec()
435
- # p cursor[':out'] # => 'DATA_OU'
436
- # # Though the length of :out is 8 bytes in PL/SQL block, it is
437
- # # bound as 7 bytes. So result is cut off at 7 byte.
438
- #
439
- # In case of binding a string as RAW, set OCI::RAW to +type+.
440
- #
441
- # example:
442
- # cursor = conn.parse("INSERT INTO raw_table(raw_column) VALUE (:1)")
443
- # cursor.bind_param(1, 'RAW_STRING', OCI8::RAW)
444
- # cursor.exec()
445
- # cursor.close()
446
- def bind_param(key, param, type = nil, length = nil)
447
- case param
448
- when Hash
449
- when Class
450
- param = {:value => nil, :type => param, :length => length}
451
- else
452
- param = {:value => param, :type => type, :length => length}
453
- end
454
- __bind(key, make_bind_object(param))
455
- self
456
- end # bind_param
457
-
458
- # Executes the SQL statement assigned the cursor. The type of
459
- # return value depends on the type of sql statement: select;
460
- # insert, update and delete; create, alter, drop and PL/SQL.
461
- #
462
- # In case of select statement, it returns the number of the
463
- # select-list.
464
- #
465
- # In case of insert, update or delete statement, it returns the
466
- # number of processed rows.
467
- #
468
- # In case of create, alter, drop and PL/SQL statement, it returns
469
- # true. In contrast with OCI8#exec, it returns true even
470
- # though PL/SQL. Use OCI8::Cursor#[] explicitly to get bind
471
- # variables.
472
- def exec(*bindvars)
473
- bind_params(*bindvars)
474
- __execute(nil) # Pass a nil to specify the statement isn't an Array DML
475
- case type
476
- when :select_stmt
477
- define_columns()
478
- else
479
- row_count
480
- end
481
- end # exec
482
-
483
- # Set the maximum array size for bind_param_array
484
- #
485
- # All the binds will be clean from cursor if instance variable max_array_size is set before
486
- #
487
- # Instance variable actual_array_size holds the size of the arrays users actually binds through bind_param_array
488
- # all the binding arrays are required to be the same size
489
- def max_array_size=(size)
490
- raise "expect positive number for max_array_size." if size.nil? && size <=0
491
- __clearBinds if !@max_array_size.nil?
492
- @max_array_size = size
493
- @actual_array_size = nil
494
- end # max_array_size=
495
-
496
- # Bind array explicitly
497
- #
498
- # When key is number, it binds by position, which starts from 1.
499
- # When key is string, it binds by the name of placeholder.
500
- #
501
- # The max_array_size should be set before calling bind_param_array
502
- #
503
- # example:
504
- # cursor = conn.parse("INSERT INTO test_table VALUES (:str)")
505
- # cursor.max_array_size = 3
506
- # cursor.bind_param_array(1, ['happy', 'new', 'year'], String, 30)
507
- # cursor.exec_array
508
- def bind_param_array(key, var_array, type = nil, max_item_length = nil)
509
- raise "please call max_array_size= first." if @max_array_size.nil?
510
- raise "expect array as input param for bind_param_array." if !var_array.nil? && !(var_array.is_a? Array)
511
- raise "the size of var_array should not be greater than max_array_size." if !var_array.nil? && var_array.size > @max_array_size
512
-
513
- if var_array.nil?
514
- raise "all binding arrays should be the same size." unless @actual_array_size.nil? || @actual_array_size == 0
515
- @actual_array_size = 0
516
- else
517
- raise "all binding arrays should be the same size." unless @actual_array_size.nil? || var_array.size == @actual_array_size
518
- @actual_array_size = var_array.size if @actual_array_size.nil?
519
- end
520
-
521
- param = {:value => var_array, :type => type, :length => max_item_length, :max_array_size => @max_array_size}
522
- first_non_nil_elem = var_array.nil? ? nil : var_array.find{|x| x!= nil}
523
-
524
- if type.nil?
525
- if first_non_nil_elem.nil?
526
- raise "bind type is not given."
527
- else
528
- type = first_non_nil_elem.class
529
- end
530
- end
531
-
532
- bindclass = OCI8::BindType::Mapping[type]
533
- if bindclass.nil? and type.is_a? Class
534
- bindclass = OCI8::BindType::Mapping[type.to_s]
535
- OCI8::BindType::Mapping[type] = bindclass if bindclass
536
- end
537
- raise "unsupported dataType: #{type}" if bindclass.nil?
538
- bindobj = bindclass.create(@con, var_array, param, @max_array_size)
539
- __bind(key, bindobj)
540
- self
541
- end # bind_param_array
542
-
543
- # Executes the SQL statement assigned the cursor with array binding
544
- def exec_array
545
- raise "please call max_array_size= first." if @max_array_size.nil?
546
-
547
- if !@actual_array_size.nil? && @actual_array_size > 0
548
- __execute(@actual_array_size)
549
- else
550
- raise "please set non-nil values to array binding parameters"
551
- end
552
-
553
- case type
554
- when :update_stmt, :delete_stmt, :insert_stmt
555
- row_count
556
- else
557
- true
558
- end
559
- end # exec_array
560
-
561
- # Gets the names of select-list as array. Please use this
562
- # method after exec.
563
- def get_col_names
564
- @names ||= @column_metadata.collect { |md| md.name }
565
- end # get_col_names
566
-
567
- # call-seq:
568
- # column_metadata -> column information
569
- #
570
- # (new in 1.0.0 and 2.0)
571
- #
572
- # Gets an array of OCI8::Metadata::Column of a select statement.
573
- #
574
- # example:
575
- # cursor = conn.exec('select * from tab')
576
- # puts ' Name Type'
577
- # puts ' ----------------------------------------- ----------------------------'
578
- # cursor.column_metadata.each do |colinfo|
579
- # puts format(' %-41s %s',
580
- # colinfo.name,
581
- # colinfo.type_string)
582
- # end
583
- def column_metadata
584
- @column_metadata
585
- end
586
-
587
- # call-seq:
588
- # fetch_hash
589
- #
590
- # get fetched data as a Hash. The hash keys are column names.
591
- # If a block is given, acts as an iterator.
592
- def fetch_hash
593
- if iterator?
594
- while ret = fetch_a_hash_row()
595
- yield(ret)
596
- end
597
- else
598
- fetch_a_hash_row
599
- end
600
- end # fetch_hash
601
-
602
- # close the cursor.
603
- def close
604
- free()
605
- @names = nil
606
- @column_metadata = nil
607
- end # close
608
-
609
- private
610
-
611
- def make_bind_object(param)
612
- case param
613
- when Hash
614
- key = param[:type]
615
- val = param[:value]
616
- max_array_size = param[:max_array_size]
617
-
618
- if key.nil?
619
- if val.nil?
620
- raise "bind type is not given."
621
- elsif val.is_a? OCI8::Object::Base
622
- key = :named_type
623
- param = @con.get_tdo_by_class(val.class)
624
- else
625
- key = val.class
626
- end
627
- elsif key.class == Class && key < OCI8::Object::Base
628
- param = @con.get_tdo_by_class(key)
629
- key = :named_type
630
- end
631
- when OCI8::Metadata::Base
632
- key = param.data_type
633
- case key
634
- when :named_type
635
- if param.type_name == 'XMLTYPE'
636
- key = :xmltype
637
- else
638
- param = @con.get_tdo_by_metadata(param.type_metadata)
639
- end
640
- end
641
- else
642
- raise "unknown param #{param.intern}"
643
- end
644
-
645
- bindclass = OCI8::BindType::Mapping[key]
646
- if bindclass.nil? and key.is_a? Class
647
- bindclass = OCI8::BindType::Mapping[key.to_s]
648
- OCI8::BindType::Mapping[key] = bindclass if bindclass
649
- end
650
- raise "unsupported datatype: #{key}" if bindclass.nil?
651
- bindclass.create(@con, val, param, max_array_size)
652
- end
653
-
654
- def define_columns
655
- num_cols = __param_count
656
- 1.upto(num_cols) do |i|
657
- parm = __paramGet(i)
658
- define_one_column(i, parm) unless __defined?(i)
659
- @column_metadata[i - 1] = parm
660
- end
661
- num_cols
662
- end # define_columns
663
-
664
- def define_one_column(pos, param)
665
- __define(pos, make_bind_object(param))
666
- end # define_one_column
667
-
668
- def bind_params(*bindvars)
669
- bindvars.each_with_index do |val, i|
670
- if val.is_a? Array
671
- bind_param(i + 1, val[0], val[1], val[2])
672
- else
673
- bind_param(i + 1, val)
674
- end
675
- end
676
- end # bind_params
677
-
678
- def fetch_a_hash_row
679
- if rs = fetch()
680
- ret = {}
681
- get_col_names.each do |name|
682
- ret[name] = rs.shift
683
- end
684
- ret
685
- else
686
- nil
687
- end
688
- end # fetch_a_hash_row
689
-
690
- end # OCI8::Cursor
691
- end # OCI8
383
+ end
692
384
 
693
385
  class OraDate
694
386
 
@@ -779,6 +471,8 @@ end
779
471
 
780
472
  class Numeric
781
473
  # Converts +self+ to {OraNumber}.
474
+ #
475
+ # @return [OraNumber]
782
476
  def to_onum
783
477
  OraNumber.new(self)
784
478
  end
@@ -787,7 +481,7 @@ end
787
481
  class String # :nodoc:
788
482
 
789
483
  # Converts +self+ to {OraNumber}.
790
- # Optional <i>fmt</i> and <i>nlsparam</i> is used as
484
+ # Optional <i>format</i> and <i>nls_params</i> is used as
791
485
  # {http://docs.oracle.com/cd/E11882_01/server.112/e17118/functions211.htm Oracle SQL function TO_NUMBER}
792
486
  # does.
793
487
  #
@@ -796,8 +490,8 @@ class String # :nodoc:
796
490
  # '123,456.789'.to_onum('999,999,999.999') # => #<OraNumber:123456.789>
797
491
  # '123.456,789'.to_onum('999G999G999D999', "NLS_NUMERIC_CHARACTERS = ',.'") # => #<OraNumber:123456.789>
798
492
  #
799
- # @param [String] fmt
800
- # @param [String] nlsparam
493
+ # @param [String] format
494
+ # @param [String] nls_params
801
495
  # @return [OraNumber]
802
496
  def to_onum(format = nil, nls_params = nil)
803
497
  OraNumber.new(self, format, nls_params)