ruby-oci8 1.0.7 → 2.0.0
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/ChangeLog +1254 -390
- data/Makefile +10 -13
- data/README +56 -385
- data/VERSION +1 -1
- data/dist-files +26 -27
- data/ext/oci8/.document +1 -0
- data/ext/oci8/MANIFEST +0 -4
- data/ext/oci8/apiwrap.c.tmpl +172 -0
- data/ext/oci8/apiwrap.h.tmpl +61 -0
- data/ext/oci8/apiwrap.rb +91 -0
- data/ext/oci8/apiwrap.yml +1243 -0
- data/ext/oci8/attr.c +124 -384
- data/ext/oci8/bind.c +472 -164
- data/ext/oci8/encoding.c +196 -0
- data/ext/oci8/env.c +84 -253
- data/ext/oci8/error.c +196 -127
- data/ext/oci8/extconf.rb +82 -59
- data/ext/oci8/lob.c +710 -370
- data/ext/oci8/metadata.c +359 -0
- data/ext/oci8/object.c +622 -0
- data/ext/oci8/oci8.c +577 -161
- data/ext/oci8/oci8.h +354 -258
- data/ext/oci8/oci8lib.c +493 -0
- data/ext/oci8/ocidatetime.c +473 -0
- data/ext/oci8/ocinumber.c +1123 -24
- data/ext/oci8/oraconf.rb +72 -106
- data/ext/oci8/oradate.c +511 -321
- data/ext/oci8/stmt.c +752 -572
- data/ext/oci8/win32.c +131 -0
- data/ext/oci8/xmldb.c +383 -0
- data/lib/.document +2 -0
- data/lib/dbd/OCI8.rb +2 -17
- data/lib/oci8.rb.in +41 -1622
- data/lib/oci8/.document +5 -0
- data/lib/oci8/compat.rb +108 -0
- data/lib/oci8/datetime.rb +489 -0
- data/lib/oci8/encoding-init.rb +40 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2077 -0
- data/lib/oci8/object.rb +548 -0
- data/lib/oci8/oci8.rb +773 -0
- data/lib/oci8/oracle_version.rb +144 -0
- data/metaconfig +3 -3
- data/ruby-oci8.gemspec +5 -5
- data/setup.rb +4 -4
- data/test/config.rb +64 -84
- data/test/test_all.rb +14 -21
- data/test/test_array_dml.rb +317 -0
- data/test/test_bind_raw.rb +18 -25
- data/test/test_bind_time.rb +78 -91
- data/test/test_break.rb +37 -35
- data/test/test_clob.rb +33 -89
- data/test/test_connstr.rb +5 -4
- data/test/test_datetime.rb +469 -0
- data/test/test_dbi.rb +99 -60
- data/test/test_dbi_clob.rb +3 -8
- data/test/test_metadata.rb +65 -51
- data/test/test_oci8.rb +151 -55
- data/test/test_oracle_version.rb +70 -0
- data/test/test_oradate.rb +76 -83
- data/test/test_oranumber.rb +405 -71
- data/test/test_rowid.rb +6 -11
- metadata +31 -32
- data/NEWS +0 -420
- data/ext/oci8/const.c +0 -165
- data/ext/oci8/define.c +0 -53
- data/ext/oci8/describe.c +0 -81
- data/ext/oci8/descriptor.c +0 -39
- data/ext/oci8/handle.c +0 -273
- data/ext/oci8/oranumber.c +0 -445
- data/ext/oci8/param.c +0 -37
- data/ext/oci8/server.c +0 -182
- data/ext/oci8/session.c +0 -99
- data/ext/oci8/svcctx.c +0 -238
- data/ruby-oci8.spec +0 -62
- data/support/README +0 -4
- data/support/runit/assert.rb +0 -281
- data/support/runit/cui/testrunner.rb +0 -101
- data/support/runit/error.rb +0 -4
- data/support/runit/method_mappable.rb +0 -20
- data/support/runit/robserver.rb +0 -25
- data/support/runit/setuppable.rb +0 -15
- data/support/runit/teardownable.rb +0 -16
- data/support/runit/testcase.rb +0 -113
- data/support/runit/testfailure.rb +0 -25
- data/support/runit/testresult.rb +0 -121
- data/support/runit/testsuite.rb +0 -43
- data/support/runit/version.rb +0 -3
- data/test/test_describe.rb +0 -137
data/ext/oci8/oraconf.rb
CHANGED
@@ -48,69 +48,48 @@ module MiniRegistry
|
|
48
48
|
# copy the minimum code and reorganize it.
|
49
49
|
ERROR_SUCCESS = 0
|
50
50
|
ERROR_FILE_NOT_FOUND = 2
|
51
|
-
ERROR_NO_MORE_ITEMS = 259
|
52
51
|
|
53
52
|
HKEY_LOCAL_MACHINE = 0x80000002
|
54
|
-
KEY_ENUMERATE_SUB_KEYS = 0x0008
|
55
|
-
KEY_QUERY_VALUE = 0x0001
|
56
53
|
RegOpenKeyExA = Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L')
|
57
|
-
RegEnumKeyExA = Win32API.new('advapi32', 'RegEnumKeyExA', 'LLPPPPPP', 'L')
|
58
54
|
RegQueryValueExA = Win32API.new('advapi32','RegQueryValueExA','LPPPPP','L')
|
59
55
|
RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L')
|
60
56
|
|
61
|
-
def
|
62
|
-
|
63
|
-
code =
|
64
|
-
if code == ERROR_FILE_NOT_FOUND
|
65
|
-
return nil
|
66
|
-
elsif code != ERROR_SUCCESS
|
67
|
-
raise MiniRegistryError.new("Win32::RegQueryValueExA",code)
|
68
|
-
end
|
69
|
-
len = lpcbData.unpack('L')[0]
|
70
|
-
lpType = [0].pack('L')
|
71
|
-
lpData = "\0"*len
|
72
|
-
lpcbData = [len].pack('L')
|
73
|
-
code = RegQueryValueExA.call(hKey, name, nil, lpType, lpData, lpcbData)
|
74
|
-
if code != ERROR_SUCCESS
|
75
|
-
raise MiniRegistryError.new("Win32::RegQueryValueExA",code)
|
76
|
-
end
|
77
|
-
lpData.unpack('Z*')[0]
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.enum_homes
|
81
|
-
phkResult = [0].pack('L')
|
82
|
-
code = RegOpenKeyExA.call(HKEY_LOCAL_MACHINE, 'SOFTWARE\ORACLE', 0, 0x20019, phkResult)
|
57
|
+
def get_reg_value(root, subkey, name)
|
58
|
+
result = [0].pack('L')
|
59
|
+
code = RegOpenKeyExA.call(root, subkey, 0, 0x20019, result)
|
83
60
|
if code != ERROR_SUCCESS
|
84
61
|
raise MiniRegistryError.new("Win32::RegOpenKeyExA", code)
|
85
62
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
code
|
93
|
-
|
94
|
-
if code != ERROR_SUCCESS
|
95
|
-
RegCloseKey.call(hKey)
|
96
|
-
raise MiniRegistryError.new("Win32::RegEnumKeyEx", code)
|
63
|
+
hkey = result.unpack('L')[0]
|
64
|
+
begin
|
65
|
+
lpcbData = [0].pack('L')
|
66
|
+
code = RegQueryValueExA.call(hkey, name, nil, nil, nil, lpcbData)
|
67
|
+
if code == ERROR_FILE_NOT_FOUND
|
68
|
+
return nil
|
69
|
+
elsif code != ERROR_SUCCESS
|
70
|
+
raise MiniRegistryError.new("Win32::RegQueryValueExA",code)
|
97
71
|
end
|
98
|
-
|
72
|
+
len = lpcbData.unpack('L')[0]
|
73
|
+
lpType = "\0\0\0\0"
|
74
|
+
lpData = "\0"*len
|
75
|
+
lpcbData = [len].pack('L')
|
76
|
+
code = RegQueryValueExA.call(hkey, name, nil, lpType, lpData, lpcbData)
|
99
77
|
if code != ERROR_SUCCESS
|
100
|
-
|
101
|
-
raise MiniRegistryError.new("Win32::RegEnumKeyEx", code)
|
78
|
+
raise MiniRegistryError.new("Win32::RegQueryValueExA",code)
|
102
79
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
path = get_str_value(hSubkey, 'ORACLE_HOME')
|
107
|
-
yield name, path
|
108
|
-
RegCloseKey.call(hSubkey)
|
109
|
-
idx += 1
|
80
|
+
lpData.unpack('Z*')[0]
|
81
|
+
ensure
|
82
|
+
RegCloseKey.call(hkey)
|
110
83
|
end
|
111
|
-
RegCloseKey.call(hKey)
|
112
84
|
end
|
113
|
-
|
85
|
+
def get_local_registry(subkey, name)
|
86
|
+
get_reg_value(HKEY_LOCAL_MACHINE, subkey, name)
|
87
|
+
end
|
88
|
+
else
|
89
|
+
# UNIX
|
90
|
+
def get_local_registry(subkey, name)
|
91
|
+
nil
|
92
|
+
end
|
114
93
|
end
|
115
94
|
end # module MiniRegistry
|
116
95
|
|
@@ -314,6 +293,8 @@ class MiniSOReader
|
|
314
293
|
end
|
315
294
|
|
316
295
|
class OraConf
|
296
|
+
include MiniRegistry
|
297
|
+
|
317
298
|
attr_reader :cc_is_gcc
|
318
299
|
attr_reader :version
|
319
300
|
attr_reader :cflags
|
@@ -353,10 +334,8 @@ EOS
|
|
353
334
|
end
|
354
335
|
print <<EOS
|
355
336
|
---------------------------------------------------
|
356
|
-
|
357
|
-
|
358
|
-
Backtrace:
|
359
|
-
#{$!.backtrace.join("\n ")}
|
337
|
+
error messages:
|
338
|
+
#{$!.to_s}
|
360
339
|
---------------------------------------------------
|
361
340
|
See:
|
362
341
|
* http://ruby-oci8.rubyforge.org/#{lang}/HowToInstall.html
|
@@ -385,16 +364,15 @@ EOS
|
|
385
364
|
# get library load path names
|
386
365
|
oci_basename = 'libclntsh'
|
387
366
|
oci_glob_postfix = '.[0-9]*'
|
388
|
-
|
367
|
+
ocidata_basename = ['libociei', 'libociicus']
|
389
368
|
@@ld_envs = %w[LD_LIBRARY_PATH]
|
390
369
|
so_ext = 'so'
|
391
|
-
nls_data_ext = nil
|
392
370
|
check_proc = nil
|
393
371
|
case RUBY_PLATFORM
|
394
372
|
when /mswin32|cygwin|mingw32|bccwin32/
|
395
373
|
oci_basename = 'oci'
|
396
374
|
oci_glob_postfix = ''
|
397
|
-
|
375
|
+
ocidata_basename = ['oraociei11', 'oraociicus11', 'oraociei10', 'oraociicus10']
|
398
376
|
@@ld_envs = %w[PATH]
|
399
377
|
so_ext = 'dll'
|
400
378
|
when /i.86-linux/
|
@@ -437,7 +415,6 @@ EOS
|
|
437
415
|
oci_glob_postfix = ''
|
438
416
|
@@ld_envs = %w[LIBPATH]
|
439
417
|
so_ext = 'a'
|
440
|
-
nls_data_ext = 'so'
|
441
418
|
when /hppa.*-hpux/
|
442
419
|
if [0].pack('l!').length == 4
|
443
420
|
@@ld_envs = %w[SHLIB_PATH]
|
@@ -448,7 +425,7 @@ EOS
|
|
448
425
|
so_ext = 'dylib'
|
449
426
|
check_proc = Proc.new do |file|
|
450
427
|
is_32bit = [0].pack('l!').size == 4
|
451
|
-
is_big_endian = "\x01\x02".unpack('s')
|
428
|
+
is_big_endian = "\x01\x02".unpack('s') == 0x0102
|
452
429
|
if is_32bit
|
453
430
|
if is_big_endian
|
454
431
|
this_cpu = :ppc # 32-bit big-endian
|
@@ -467,12 +444,7 @@ EOS
|
|
467
444
|
if so.cpu.include? this_cpu
|
468
445
|
true
|
469
446
|
else
|
470
|
-
|
471
|
-
arch_types = so.cpu[0..-2].join(', ') + ' and ' + so.cpu[-1].to_s
|
472
|
-
else
|
473
|
-
arch_types = so.cpu[0]
|
474
|
-
end
|
475
|
-
puts " skip: #{file} is for #{arch_types} cpu."
|
447
|
+
puts " skip: #{file} is for #{so.cpu} cpu."
|
476
448
|
false
|
477
449
|
end
|
478
450
|
else
|
@@ -533,9 +505,8 @@ EOS
|
|
533
505
|
end
|
534
506
|
|
535
507
|
if ld_path
|
536
|
-
|
537
|
-
|
538
|
-
if File.exist?(File.join(ld_path, "#{basename}.#{nls_data_ext}"))
|
508
|
+
ocidata_basename.each do |basename|
|
509
|
+
if File.exist?(File.join(ld_path, "#{basename}.#{so_ext}"))
|
539
510
|
puts " #{file} looks like an instant client."
|
540
511
|
return ld_path
|
541
512
|
end
|
@@ -618,7 +589,6 @@ You need /usr/include/sys/types.h to compile ruby-oci8.
|
|
618
589
|
EOS
|
619
590
|
end
|
620
591
|
puts "ok"
|
621
|
-
$stdout.flush
|
622
592
|
end # check_ruby_header
|
623
593
|
|
624
594
|
def try_link_oci
|
@@ -781,10 +751,26 @@ class OraConfFC < OraConf
|
|
781
751
|
if oracle_home.nil?
|
782
752
|
struct = Struct.new("OracleHome", :name, :path)
|
783
753
|
oracle_homes = []
|
784
|
-
|
785
|
-
|
786
|
-
|
754
|
+
begin
|
755
|
+
last_home = get_local_registry("SOFTWARE\\ORACLE\\ALL_HOMES", 'LAST_HOME')
|
756
|
+
0.upto last_home.to_i do |id|
|
757
|
+
oracle_homes << "HOME#{id}"
|
758
|
+
end
|
759
|
+
rescue MiniRegistryError
|
760
|
+
end
|
761
|
+
oracle_homes << "KEY_XE"
|
762
|
+
oracle_homes << "KEY_XEClient"
|
763
|
+
oracle_homes.collect! do |home|
|
764
|
+
begin
|
765
|
+
name = get_local_registry("SOFTWARE\\ORACLE\\#{home}", 'ORACLE_HOME_NAME')
|
766
|
+
path = get_local_registry("SOFTWARE\\ORACLE\\#{home}", 'ORACLE_HOME')
|
767
|
+
path.chomp!("\\")
|
768
|
+
struct.new(name, path) if is_valid_home?(path)
|
769
|
+
rescue MiniRegistryError
|
770
|
+
nil
|
771
|
+
end
|
787
772
|
end
|
773
|
+
oracle_homes.compact!
|
788
774
|
if oracle_homes.empty?
|
789
775
|
raise <<EOS
|
790
776
|
Set the environment variable ORACLE_HOME if Oracle Full Client.
|
@@ -866,33 +852,10 @@ EOS
|
|
866
852
|
def get_home
|
867
853
|
oracle_home = ENV['ORACLE_HOME']
|
868
854
|
if oracle_home.nil?
|
869
|
-
|
855
|
+
raise <<EOS
|
870
856
|
Set the environment variable ORACLE_HOME if Oracle Full Client.
|
871
857
|
Append the path of Oracle client libraries to #{OraConf.ld_envs[0]} if Oracle Instant Client.
|
872
858
|
EOS
|
873
|
-
|
874
|
-
# check sudo environment
|
875
|
-
sudo_command = ENV['SUDO_COMMAND']
|
876
|
-
if /\w*make\b/ =~ sudo_command
|
877
|
-
msg += <<EOS
|
878
|
-
|
879
|
-
The 'sudo' command unset some environment variables for security reasons.
|
880
|
-
Use it only when running 'make install' as follows
|
881
|
-
make
|
882
|
-
sudo make install
|
883
|
-
EOS
|
884
|
-
end
|
885
|
-
if /\w+\/gem\b/ =~ sudo_command
|
886
|
-
msg += <<EOS
|
887
|
-
|
888
|
-
The 'sudo' command unset some environment variables for security reasons.
|
889
|
-
Pass required varialbes as follows
|
890
|
-
sudo env #{OraConf.ld_envs[0]}=$#{OraConf.ld_envs[0]} #{sudo_command}
|
891
|
-
or
|
892
|
-
sudo env ORACLE_HOME=$ORACLE_HOME #{sudo_command}
|
893
|
-
EOS
|
894
|
-
end
|
895
|
-
raise msg
|
896
859
|
end
|
897
860
|
oracle_home
|
898
861
|
end
|
@@ -977,18 +940,21 @@ EOS
|
|
977
940
|
end
|
978
941
|
end
|
979
942
|
|
980
|
-
#
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
943
|
+
# remove object files from libs.
|
944
|
+
objs = []
|
945
|
+
libs.gsub!(/\S+\.o\b/) do |obj|
|
946
|
+
objs << obj
|
947
|
+
""
|
948
|
+
end
|
949
|
+
# change object files to an archive file to work around.
|
950
|
+
if objs.length > 0
|
951
|
+
Logging::open do
|
952
|
+
puts "change object files to an archive file."
|
953
|
+
command = Config::CONFIG["AR"] + " cru oracle_objs.a " + objs.join(" ")
|
954
|
+
puts command
|
955
|
+
system(command)
|
956
|
+
libs = "oracle_objs.a " + libs
|
990
957
|
end
|
991
|
-
|
992
958
|
end
|
993
959
|
libs
|
994
960
|
end # get_libs
|
data/ext/oci8/oradate.c
CHANGED
@@ -1,16 +1,37 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
1
2
|
/*
|
2
|
-
oradate.c
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
*/
|
3
|
+
* oradate.c
|
4
|
+
*
|
5
|
+
* $Author: kubo $
|
6
|
+
* $Date: 2009-01-04 01:58:01 +0900 (Sun, 04 Jan 2009) $
|
7
|
+
*
|
8
|
+
* Copyright (C) 2002-2008 KUBO Takehiro <kubo@jiubao.org>
|
9
|
+
*
|
10
|
+
* date and time between 4712 B.C. and 9999 A.D.
|
11
|
+
*/
|
11
12
|
#include "oci8.h"
|
12
13
|
#include <time.h>
|
13
14
|
|
15
|
+
static VALUE cOraDate;
|
16
|
+
|
17
|
+
/*
|
18
|
+
* Document-class: OraDate
|
19
|
+
*
|
20
|
+
* ruby class compatible with Oracle <tt>DATE</tt> data type.
|
21
|
+
* Date and time between 4712 B.C. and 9999 A.D.
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
struct ora_date {
|
25
|
+
unsigned char century;
|
26
|
+
unsigned char year;
|
27
|
+
unsigned char month;
|
28
|
+
unsigned char day;
|
29
|
+
unsigned char hour;
|
30
|
+
unsigned char minute;
|
31
|
+
unsigned char second;
|
32
|
+
};
|
33
|
+
typedef struct ora_date ora_date_t;
|
34
|
+
|
14
35
|
#define Set_year(od, y) (od)->century = y / 100 + 100, (od)->year = y % 100 + 100
|
15
36
|
#define Set_month(od, m) (od)->month = m
|
16
37
|
#define Set_day(od, d) (od)->day = d
|
@@ -26,401 +47,570 @@ date and time between 4712 B.C. and 9999 A.D.
|
|
26
47
|
#define Get_second(od) ((od)->second - 1)
|
27
48
|
|
28
49
|
#define Check_year(year) \
|
29
|
-
|
30
|
-
|
50
|
+
if (year < -4712 || 9999 < year) \
|
51
|
+
rb_raise(rb_eRangeError, "Out of range for year %d (expect -4712 .. 9999)", year)
|
31
52
|
#define Check_month(month) \
|
32
|
-
|
33
|
-
|
53
|
+
if (month < 1 || 12 < month) \
|
54
|
+
rb_raise(rb_eRangeError, "Out of range for month %d (expect 1 .. 12)", month)
|
34
55
|
#define Check_day(day) \
|
35
|
-
|
36
|
-
|
56
|
+
if (day < 1 || 31 < day) \
|
57
|
+
rb_raise(rb_eRangeError, "Out of range for day %d (expect 1 .. 31)", day)
|
37
58
|
#define Check_hour(hour) \
|
38
|
-
|
39
|
-
|
59
|
+
if (hour < 0 || 23 < hour) \
|
60
|
+
rb_raise(rb_eRangeError, "Out of range for hour %d (expect 0 .. 24)", hour)
|
40
61
|
#define Check_minute(min) \
|
41
|
-
|
42
|
-
|
62
|
+
if (min < 0 || 59 < min) \
|
63
|
+
rb_raise(rb_eRangeError, "Out of range for minute %d (expect 0 .. 59)", min)
|
43
64
|
#define Check_second(sec) \
|
44
|
-
|
45
|
-
|
46
|
-
|
65
|
+
if (sec < 0 || 59 < sec) \
|
66
|
+
rb_raise(rb_eRangeError, "Out of range for second %d (expect 0 .. 59)", sec)
|
47
67
|
|
48
|
-
static
|
68
|
+
static void oci8_set_ora_date(ora_date_t *od, int year, int month, int day, int hour, int minute, int second)
|
49
69
|
{
|
50
|
-
|
51
|
-
|
70
|
+
Set_year(od, year);
|
71
|
+
Set_month(od, month);
|
72
|
+
Set_day(od, day);
|
73
|
+
Set_hour(od, hour);
|
74
|
+
Set_minute(od, minute);
|
75
|
+
Set_second(od, second);
|
52
76
|
}
|
53
77
|
|
54
|
-
|
55
|
-
/* ruby 1.6 */
|
56
|
-
static VALUE ora_date_s_new(int argc, VALUE *argv, VALUE klass)
|
78
|
+
static VALUE ora_date_s_allocate(VALUE klass)
|
57
79
|
{
|
58
|
-
|
59
|
-
|
60
|
-
return obj;
|
80
|
+
ora_date_t *od;
|
81
|
+
return Data_Make_Struct(klass, ora_date_t, NULL, xfree, od);
|
61
82
|
}
|
62
|
-
#endif
|
63
83
|
|
64
84
|
/*
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
85
|
+
* call-seq:
|
86
|
+
* OraDate.new(year = 1, month = 1, day = 1, hour = 0, min = 0, sec = 0) -> oradate
|
87
|
+
*
|
88
|
+
* Returns an <code>OraDate</code> object initialized to the specified date and time.
|
89
|
+
*/
|
69
90
|
static VALUE ora_date_initialize(int argc, VALUE *argv, VALUE self)
|
70
91
|
{
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
return Qnil;
|
92
|
+
VALUE vyear, vmonth, vday, vhour, vmin, vsec;
|
93
|
+
ora_date_t *od = DATA_PTR(self);
|
94
|
+
int year, month, day, hour, min, sec;
|
95
|
+
|
96
|
+
rb_scan_args(argc, argv, "06", &vyear, &vmonth, &vday, &vhour, &vmin, &vsec);
|
97
|
+
/* set year */
|
98
|
+
if (argc > 0) {
|
99
|
+
year = NUM2INT(vyear);
|
100
|
+
Check_year(year);
|
101
|
+
} else {
|
102
|
+
year = 1;
|
103
|
+
}
|
104
|
+
/* set month */
|
105
|
+
if (argc > 1) {
|
106
|
+
month = NUM2INT(vmonth);
|
107
|
+
Check_month(month);
|
108
|
+
} else {
|
109
|
+
month = 1;
|
110
|
+
}
|
111
|
+
/* set day */
|
112
|
+
if (argc > 2) {
|
113
|
+
day = NUM2INT(vday);
|
114
|
+
Check_day(day);
|
115
|
+
} else {
|
116
|
+
day = 1;
|
117
|
+
}
|
118
|
+
/* set hour */
|
119
|
+
if (argc > 3) {
|
120
|
+
hour = NUM2INT(vhour);
|
121
|
+
Check_hour(hour);
|
122
|
+
} else {
|
123
|
+
hour = 0;
|
124
|
+
}
|
125
|
+
/* set minute */
|
126
|
+
if (argc > 4) {
|
127
|
+
min = NUM2INT(vmin);
|
128
|
+
Check_minute(min);
|
129
|
+
} else {
|
130
|
+
min = 0;
|
131
|
+
}
|
132
|
+
/* set second */
|
133
|
+
if (argc > 5) {
|
134
|
+
sec = NUM2INT(vsec);
|
135
|
+
Check_second(sec);
|
136
|
+
} else {
|
137
|
+
sec = 0;
|
138
|
+
}
|
139
|
+
|
140
|
+
oci8_set_ora_date(od, year, month, day, hour, min, sec);
|
141
|
+
return Qnil;
|
122
142
|
}
|
123
143
|
|
144
|
+
/* :nodoc: */
|
124
145
|
static VALUE ora_date_initialize_copy(VALUE lhs, VALUE rhs)
|
125
146
|
{
|
126
|
-
|
147
|
+
ora_date_t *l, *r;
|
127
148
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
Data_Get_Struct(rhs, ora_date_t, r);
|
134
|
-
memcpy(l, r, sizeof(ora_date_t));
|
135
|
-
return lhs;
|
136
|
-
}
|
137
|
-
|
138
|
-
#ifndef HAVE_RB_DEFINE_ALLOC_FUNC
|
139
|
-
/* ruby 1.6 */
|
140
|
-
static VALUE ora_date_clone(VALUE self)
|
141
|
-
{
|
142
|
-
VALUE obj = ora_date_s_allocate(CLASS_OF(self));
|
143
|
-
return ora_date_initialize_copy(obj, self);
|
149
|
+
rb_obj_init_copy(lhs, rhs);
|
150
|
+
Data_Get_Struct(lhs, ora_date_t, l);
|
151
|
+
Data_Get_Struct(rhs, ora_date_t, r);
|
152
|
+
memcpy(l, r, sizeof(ora_date_t));
|
153
|
+
return lhs;
|
144
154
|
}
|
145
|
-
#endif
|
146
155
|
|
147
156
|
/*
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
157
|
+
* call-seq:
|
158
|
+
* OraDate.now() -> oradate
|
159
|
+
*
|
160
|
+
* Returns an <code>OraDate</code> object initialized to the
|
161
|
+
* current local time.
|
162
|
+
*/
|
163
|
+
static VALUE ora_date_s_now(int argc, VALUE *argv, VALUE klass)
|
153
164
|
{
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
165
|
+
VALUE obj = ora_date_s_allocate(klass);
|
166
|
+
ora_date_t *od = DATA_PTR(obj);
|
167
|
+
time_t tm = time(0);
|
168
|
+
int year, month, day, hour, min, sec;
|
169
|
+
#ifdef HAVE_LOCALTIME_R
|
170
|
+
struct tm t;
|
171
|
+
localtime_r(&tm, &t);
|
172
|
+
#define tp (&t)
|
173
|
+
#else
|
174
|
+
struct tm *tp;
|
175
|
+
tp = localtime(&tm);
|
176
|
+
#endif
|
177
|
+
year = tp->tm_year + 1900;
|
178
|
+
month = tp->tm_mon + 1;
|
179
|
+
day = tp->tm_mday;
|
180
|
+
hour = tp->tm_hour;
|
181
|
+
min = tp->tm_min;
|
182
|
+
sec = tp->tm_sec;
|
183
|
+
|
184
|
+
oci8_set_ora_date(od, year, month, day, hour, min, sec);
|
185
|
+
return obj;
|
172
186
|
}
|
173
187
|
|
174
188
|
/*
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
189
|
+
* call-seq:
|
190
|
+
* oradate.to_s -> string
|
191
|
+
*
|
192
|
+
* Returns a string representing <i>oradate</i>.
|
193
|
+
* The string format is 'yyyy/mm/dd hh:mi:ss'.
|
194
|
+
*/
|
179
195
|
static VALUE ora_date_to_s(VALUE self)
|
180
196
|
{
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
197
|
+
ora_date_t *od;
|
198
|
+
char buf[30];
|
199
|
+
|
200
|
+
Data_Get_Struct(self, ora_date_t, od);
|
201
|
+
sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d", Get_year(od), Get_month(od),
|
202
|
+
Get_day(od), Get_hour(od), Get_minute(od), Get_second(od));
|
203
|
+
return rb_usascii_str_new_cstr(buf);
|
188
204
|
}
|
189
205
|
|
190
206
|
/*
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
207
|
+
* call-seq:
|
208
|
+
* oradate.to_a -> array
|
209
|
+
*
|
210
|
+
* Returns a 6-element <i>array</i> of values for <i>oradate</i>:
|
211
|
+
* {<code>[year, month, day, hour, minute, second]</code>}.
|
212
|
+
*/
|
195
213
|
static VALUE ora_date_to_a(VALUE self)
|
196
214
|
{
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
215
|
+
ora_date_t *od;
|
216
|
+
VALUE ary[6];
|
217
|
+
|
218
|
+
Data_Get_Struct(self, ora_date_t, od);
|
219
|
+
ary[0] = INT2FIX(Get_year(od));
|
220
|
+
ary[1] = INT2FIX(Get_month(od));
|
221
|
+
ary[2] = INT2FIX(Get_day(od));
|
222
|
+
ary[3] = INT2FIX(Get_hour(od));
|
223
|
+
ary[4] = INT2FIX(Get_minute(od));
|
224
|
+
ary[5] = INT2FIX(Get_second(od));
|
225
|
+
return rb_ary_new4(6, ary);
|
208
226
|
}
|
209
227
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
228
|
+
/*
|
229
|
+
* call-seq:
|
230
|
+
* oradate.year -> fixnum
|
231
|
+
*
|
232
|
+
* Returns the year (-4712..9999) for <i>oradate</i>.
|
233
|
+
*/
|
234
|
+
static VALUE ora_date_year(VALUE self)
|
235
|
+
{
|
236
|
+
ora_date_t *od;
|
237
|
+
|
238
|
+
Data_Get_Struct(self, ora_date_t, od);
|
239
|
+
return INT2FIX(Get_year(od));
|
217
240
|
}
|
218
241
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
242
|
+
/*
|
243
|
+
* call-seq:
|
244
|
+
* oradate.year = fixnum
|
245
|
+
*
|
246
|
+
* Sets the year (-4712..9999) for <i>oradate</i>.
|
247
|
+
*/
|
248
|
+
static VALUE ora_date_set_year(VALUE self, VALUE val)
|
249
|
+
{
|
250
|
+
ora_date_t *od;
|
251
|
+
int v;
|
252
|
+
|
253
|
+
v = NUM2INT(val);
|
254
|
+
Check_year(v);
|
255
|
+
Data_Get_Struct(self, ora_date_t, od);
|
256
|
+
Set_year(od, v);
|
257
|
+
return self;
|
230
258
|
}
|
231
259
|
|
232
260
|
/*
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
261
|
+
* call-seq:
|
262
|
+
* oradate.month -> fixnum
|
263
|
+
*
|
264
|
+
* Returns the month of the year (1..12) for <i>oradate</i>.
|
265
|
+
*/
|
266
|
+
static VALUE ora_date_month(VALUE self)
|
267
|
+
{
|
268
|
+
ora_date_t *od;
|
269
|
+
|
270
|
+
Data_Get_Struct(self, ora_date_t, od);
|
271
|
+
return INT2FIX(Get_month(od));
|
272
|
+
}
|
239
273
|
|
240
274
|
/*
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
275
|
+
* call-seq:
|
276
|
+
* oradate.month = fixnum
|
277
|
+
*
|
278
|
+
* Sets the month of the year (1..12) for <i>oradate</i>.
|
279
|
+
*/
|
280
|
+
static VALUE ora_date_set_month(VALUE self, VALUE val)
|
281
|
+
{
|
282
|
+
ora_date_t *od;
|
283
|
+
int v;
|
284
|
+
|
285
|
+
v = NUM2INT(val);
|
286
|
+
Check_month(v);
|
287
|
+
Data_Get_Struct(self, ora_date_t, od);
|
288
|
+
Set_month(od, v);
|
289
|
+
return self;
|
290
|
+
}
|
247
291
|
|
248
292
|
/*
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
293
|
+
* call-seq:
|
294
|
+
* oradate.day -> fixnum
|
295
|
+
*
|
296
|
+
* Returns the day of the month (1..31) for <i>oradate</i>.
|
297
|
+
*/
|
298
|
+
static VALUE ora_date_day(VALUE self)
|
299
|
+
{
|
300
|
+
ora_date_t *od;
|
301
|
+
|
302
|
+
Data_Get_Struct(self, ora_date_t, od);
|
303
|
+
return INT2FIX(Get_day(od));
|
304
|
+
}
|
255
305
|
|
256
306
|
/*
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
307
|
+
* call-seq:
|
308
|
+
* oradate.day = fixnum
|
309
|
+
*
|
310
|
+
* Sets the day of the month (1..31) for <i>oradate</i>.
|
311
|
+
*/
|
312
|
+
static VALUE ora_date_set_day(VALUE self, VALUE val)
|
313
|
+
{
|
314
|
+
ora_date_t *od;
|
315
|
+
int v;
|
316
|
+
|
317
|
+
v = NUM2INT(val);
|
318
|
+
Check_day(v);
|
319
|
+
Data_Get_Struct(self, ora_date_t, od);
|
320
|
+
Set_day(od, v);
|
321
|
+
return self;
|
322
|
+
}
|
263
323
|
|
264
324
|
/*
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
325
|
+
* call-seq:
|
326
|
+
* oradate.hour -> fixnum
|
327
|
+
*
|
328
|
+
* Returns the hour of the day (0..23) for <i>oradate</i>.
|
329
|
+
*/
|
330
|
+
static VALUE ora_date_hour(VALUE self)
|
331
|
+
{
|
332
|
+
ora_date_t *od;
|
333
|
+
|
334
|
+
Data_Get_Struct(self, ora_date_t, od);
|
335
|
+
return INT2FIX(Get_hour(od));
|
336
|
+
}
|
271
337
|
|
272
338
|
/*
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
339
|
+
* call-seq:
|
340
|
+
* oradate.hour = fixnum
|
341
|
+
*
|
342
|
+
* Sets the hour of the day (0..23) for <i>oradate</i>.
|
343
|
+
*/
|
344
|
+
static VALUE ora_date_set_hour(VALUE self, VALUE val)
|
345
|
+
{
|
346
|
+
ora_date_t *od;
|
347
|
+
int v;
|
348
|
+
|
349
|
+
v = NUM2INT(val);
|
350
|
+
Check_hour(v);
|
351
|
+
Data_Get_Struct(self, ora_date_t, od);
|
352
|
+
Set_hour(od, v);
|
353
|
+
return self;
|
354
|
+
}
|
279
355
|
|
280
356
|
/*
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
357
|
+
* call-seq:
|
358
|
+
* oradate.minute -> fixnum
|
359
|
+
*
|
360
|
+
* Returns the minute of the hour (0..59) for <i>oradate</i>.
|
361
|
+
*/
|
362
|
+
static VALUE ora_date_minute(VALUE self)
|
286
363
|
{
|
287
|
-
|
364
|
+
ora_date_t *od;
|
288
365
|
|
289
|
-
|
290
|
-
|
291
|
-
od->minute = 1;
|
292
|
-
od->second = 1;
|
293
|
-
return self;
|
366
|
+
Data_Get_Struct(self, ora_date_t, od);
|
367
|
+
return INT2FIX(Get_minute(od));
|
294
368
|
}
|
295
369
|
|
296
|
-
|
370
|
+
/*
|
371
|
+
* call-seq:
|
372
|
+
* oradate.minute = fixnum
|
373
|
+
*
|
374
|
+
* Sets the minute of the hour (0..59) for <i>oradate</i>.
|
375
|
+
*/
|
376
|
+
static VALUE ora_date_set_minute(VALUE self, VALUE val)
|
377
|
+
{
|
378
|
+
ora_date_t *od;
|
379
|
+
int v;
|
380
|
+
|
381
|
+
v = NUM2INT(val);
|
382
|
+
Check_minute(v);
|
383
|
+
Data_Get_Struct(self, ora_date_t, od);
|
384
|
+
Set_minute(od, v);
|
385
|
+
return self;
|
386
|
+
}
|
387
|
+
|
388
|
+
/*
|
389
|
+
* call-seq:
|
390
|
+
* oradate.second -> fixnum
|
391
|
+
*
|
392
|
+
* Returns the second of the minute (0..59) for <i>oradate</i>.
|
393
|
+
*/
|
394
|
+
static VALUE ora_date_second(VALUE self)
|
297
395
|
{
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
396
|
+
ora_date_t *od;
|
397
|
+
|
398
|
+
Data_Get_Struct(self, ora_date_t, od);
|
399
|
+
return INT2FIX(Get_second(od));
|
400
|
+
}
|
401
|
+
|
402
|
+
/*
|
403
|
+
* call-seq:
|
404
|
+
* oradate.second = fixnum
|
405
|
+
*
|
406
|
+
* Sets the second of the minute (0..59) for <i>oradate</i>.
|
407
|
+
*/
|
408
|
+
static VALUE ora_date_set_second(VALUE self, VALUE val)
|
409
|
+
{
|
410
|
+
ora_date_t *od;
|
411
|
+
int v;
|
412
|
+
|
413
|
+
v = NUM2INT(val);
|
414
|
+
Check_second(v);
|
415
|
+
Data_Get_Struct(self, ora_date_t, od);
|
416
|
+
Set_second(od, v);
|
417
|
+
return self;
|
418
|
+
}
|
419
|
+
|
420
|
+
/*
|
421
|
+
* call-seq:
|
422
|
+
* oradate.trunc
|
423
|
+
*
|
424
|
+
* Truncates hour, minute and second to zero for <i>oradate</i>.
|
425
|
+
*
|
426
|
+
* oradate = OraDate.now # 2008/07/17 11:07:30
|
427
|
+
* oradate.trunc # 2008/07/17 00:00:00
|
428
|
+
*/
|
429
|
+
static VALUE ora_date_trunc(VALUE self)
|
430
|
+
{
|
431
|
+
ora_date_t *od;
|
432
|
+
|
433
|
+
Data_Get_Struct(self, ora_date_t, od);
|
434
|
+
od->hour = 1;
|
435
|
+
od->minute = 1;
|
436
|
+
od->second = 1;
|
437
|
+
return self;
|
310
438
|
}
|
311
439
|
|
312
440
|
/*
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
441
|
+
* call-seq:
|
442
|
+
* oradate1 <=> oradate2 -> -1, 0, +1
|
443
|
+
*
|
444
|
+
* Comparison---Compares <i>oradate1</i> with <i>oradate2</i>.
|
445
|
+
* Other comparison operators are available because
|
446
|
+
* <code>Comparable</code> module is included.
|
447
|
+
*/
|
317
448
|
static VALUE ora_date_cmp(VALUE self, VALUE val)
|
318
449
|
{
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
450
|
+
ora_date_t *od1, *od2;
|
451
|
+
Data_Get_Struct(self, ora_date_t, od1);
|
452
|
+
Check_Object(val, cOraDate);
|
453
|
+
Data_Get_Struct(val, ora_date_t, od2);
|
454
|
+
if (od1->century < od2->century) return INT2FIX(-1);
|
455
|
+
if (od1->century > od2->century) return INT2FIX(1);
|
456
|
+
if (od1->year < od2->year) return INT2FIX(-1);
|
457
|
+
if (od1->year > od2->year) return INT2FIX(1);
|
458
|
+
if (od1->month < od2->month) return INT2FIX(-1);
|
459
|
+
if (od1->month > od2->month) return INT2FIX(1);
|
460
|
+
if (od1->day < od2->day) return INT2FIX(-1);
|
461
|
+
if (od1->day > od2->day) return INT2FIX(1);
|
462
|
+
if (od1->hour < od2->hour) return INT2FIX(-1);
|
463
|
+
if (od1->hour > od2->hour) return INT2FIX(1);
|
464
|
+
if (od1->minute < od2->minute) return INT2FIX(-1);
|
465
|
+
if (od1->minute > od2->minute) return INT2FIX(1);
|
466
|
+
if (od1->second < od2->second) return INT2FIX(-1);
|
467
|
+
if (od1->second > od2->second) return INT2FIX(1);
|
468
|
+
return INT2FIX(0);
|
337
469
|
}
|
338
470
|
|
471
|
+
/* :nodoc: */
|
472
|
+
static VALUE ora_date_hash(VALUE self)
|
473
|
+
{
|
474
|
+
ora_date_t *od;
|
475
|
+
unsigned int v;
|
476
|
+
|
477
|
+
Data_Get_Struct(self, ora_date_t, od);
|
478
|
+
v = (od->century << 8)
|
479
|
+
+ (od->year << 15)
|
480
|
+
+ (od->month << 22)
|
481
|
+
+ (od->day << 26)
|
482
|
+
+ (od->hour << 12)
|
483
|
+
+ (od->minute << 6)
|
484
|
+
+ (od->second << 0);
|
485
|
+
return INT2FIX(v);
|
486
|
+
}
|
487
|
+
|
488
|
+
/*
|
489
|
+
* call-seq:
|
490
|
+
* oradate._dump -> string
|
491
|
+
*
|
492
|
+
* Dumps <i>oradate</i> for marshaling.
|
493
|
+
*/
|
339
494
|
static VALUE ora_date_dump(int argc, VALUE *argv, VALUE self)
|
340
495
|
{
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
}
|
496
|
+
ora_date_t *od;
|
497
|
+
Data_Get_Struct(self, ora_date_t, od);
|
498
|
+
return rb_str_new((const char*)od, sizeof(ora_date_t)); /* ASCII-8BIT */
|
499
|
+
}
|
345
500
|
|
501
|
+
/*
|
502
|
+
* call-seq:
|
503
|
+
* OraDate._load(string) -> oradate
|
504
|
+
*
|
505
|
+
* Unmarshals a dumped <code>OraDate</code> object.
|
506
|
+
*/
|
346
507
|
static VALUE ora_date_s_load(VALUE klass, VALUE str)
|
347
508
|
{
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
}
|
509
|
+
ora_date_t *od;
|
510
|
+
VALUE obj;
|
511
|
+
|
512
|
+
Check_Type(str, T_STRING);
|
513
|
+
if (RSTRING_LEN(str) != sizeof(ora_date_t)) {
|
514
|
+
rb_raise(rb_eTypeError, "marshaled OraDate format differ");
|
515
|
+
}
|
516
|
+
obj = Data_Make_Struct(cOraDate, ora_date_t, NULL, xfree, od);
|
517
|
+
memcpy(od, RSTRING_PTR(str), sizeof(ora_date_t));
|
518
|
+
return obj;
|
519
|
+
}
|
359
520
|
|
360
|
-
|
521
|
+
/*
|
522
|
+
* Document-class: OCI8::BindType::OraDate
|
523
|
+
*
|
524
|
+
* This is a helper class to bind OraDate as Oracle's <tt>DATE</tt> datatype.
|
525
|
+
*
|
526
|
+
*/
|
527
|
+
static VALUE bind_oradate_get(oci8_bind_t *obind, void *data, void *null_struct)
|
361
528
|
{
|
362
|
-
|
363
|
-
/* ruby 1.8 */
|
364
|
-
rb_define_alloc_func(cOraDate, RUBY_METHOD_FUNC(ora_date_s_allocate));
|
365
|
-
rb_define_method(cOraDate, "initialize", ora_date_initialize, -1);
|
366
|
-
rb_define_method(cOraDate, "initialize_copy", ora_date_initialize_copy, 1);
|
367
|
-
#else
|
368
|
-
/* ruby 1.6 */
|
369
|
-
rb_define_singleton_method(cOraDate, "new", ora_date_s_new, -1);
|
370
|
-
rb_define_method(cOraDate, "initialize", ora_date_initialize, -1);
|
371
|
-
rb_define_method(cOraDate, "clone", ora_date_clone, 0);
|
372
|
-
rb_define_method(cOraDate, "dup", ora_date_clone, 0);
|
373
|
-
#endif
|
529
|
+
ora_date_t *od;
|
374
530
|
|
375
|
-
|
376
|
-
|
377
|
-
|
531
|
+
VALUE obj = Data_Make_Struct(cOraDate, ora_date_t, NULL, xfree, od);
|
532
|
+
memcpy(od, data, sizeof(ora_date_t));
|
533
|
+
return obj;
|
534
|
+
}
|
378
535
|
|
379
|
-
|
380
|
-
|
536
|
+
static void bind_oradate_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
|
537
|
+
{
|
538
|
+
ora_date_t *od;
|
381
539
|
|
382
|
-
|
383
|
-
|
540
|
+
Check_Object(val, cOraDate);
|
541
|
+
Data_Get_Struct(val, ora_date_t, od);
|
542
|
+
memcpy(data, od, sizeof(ora_date_t));
|
543
|
+
}
|
384
544
|
|
385
|
-
|
386
|
-
|
545
|
+
static void bind_oradate_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
|
546
|
+
{
|
547
|
+
obind->value_sz = sizeof(ora_date_t);
|
548
|
+
obind->alloc_sz = sizeof(ora_date_t);
|
549
|
+
}
|
387
550
|
|
388
|
-
|
389
|
-
|
551
|
+
static void bind_oradate_init_elem(oci8_bind_t *obind, VALUE svc)
|
552
|
+
{
|
553
|
+
static const ora_date_t julian_day_0 = {100-47, 100-12, 1, 1, 1, 1, 1};
|
554
|
+
ub4 idx = 0;
|
555
|
+
do {
|
556
|
+
memcpy((ora_date_t*)obind->valuep + idx, &julian_day_0, sizeof(ora_date_t));
|
557
|
+
} while (++idx < obind->maxar_sz);
|
558
|
+
}
|
390
559
|
|
391
|
-
|
392
|
-
|
560
|
+
static const oci8_bind_class_t bind_oradate_class = {
|
561
|
+
{
|
562
|
+
NULL,
|
563
|
+
oci8_bind_free,
|
564
|
+
sizeof(oci8_bind_t)
|
565
|
+
},
|
566
|
+
bind_oradate_get,
|
567
|
+
bind_oradate_set,
|
568
|
+
bind_oradate_init,
|
569
|
+
bind_oradate_init_elem,
|
570
|
+
NULL,
|
571
|
+
NULL,
|
572
|
+
NULL,
|
573
|
+
SQLT_DAT,
|
574
|
+
};
|
393
575
|
|
394
|
-
|
395
|
-
|
576
|
+
void Init_ora_date(void)
|
577
|
+
{
|
578
|
+
cOraDate = rb_define_class("OraDate", rb_cObject);
|
396
579
|
|
397
|
-
|
580
|
+
rb_define_alloc_func(cOraDate, ora_date_s_allocate);
|
581
|
+
rb_define_method(cOraDate, "initialize", ora_date_initialize, -1);
|
582
|
+
rb_define_method(cOraDate, "initialize_copy", ora_date_initialize_copy, 1);
|
583
|
+
rb_define_singleton_method(cOraDate, "now", ora_date_s_now, 0);
|
584
|
+
rb_define_method(cOraDate, "to_s", ora_date_to_s, 0);
|
585
|
+
rb_define_method(cOraDate, "to_a", ora_date_to_a, 0);
|
398
586
|
|
399
|
-
|
400
|
-
|
587
|
+
rb_define_method(cOraDate, "year", ora_date_year, 0);
|
588
|
+
rb_define_method(cOraDate, "year=", ora_date_set_year, 1);
|
401
589
|
|
402
|
-
|
590
|
+
rb_define_method(cOraDate, "month", ora_date_month, 0);
|
591
|
+
rb_define_method(cOraDate, "month=", ora_date_set_month, 1);
|
403
592
|
|
404
|
-
|
405
|
-
|
406
|
-
}
|
593
|
+
rb_define_method(cOraDate, "day", ora_date_day, 0);
|
594
|
+
rb_define_method(cOraDate, "day=", ora_date_set_day, 1);
|
407
595
|
|
408
|
-
|
409
|
-
|
410
|
-
Set_year(od, year);
|
411
|
-
Set_month(od, month);
|
412
|
-
Set_day(od, day);
|
413
|
-
Set_hour(od, hour);
|
414
|
-
Set_minute(od, minute);
|
415
|
-
Set_second(od, second);
|
416
|
-
}
|
596
|
+
rb_define_method(cOraDate, "hour", ora_date_hour, 0);
|
597
|
+
rb_define_method(cOraDate, "hour=", ora_date_set_hour, 1);
|
417
598
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
599
|
+
rb_define_method(cOraDate, "minute", ora_date_minute, 0);
|
600
|
+
rb_define_method(cOraDate, "minute=", ora_date_set_minute, 1);
|
601
|
+
|
602
|
+
rb_define_method(cOraDate, "second", ora_date_second, 0);
|
603
|
+
rb_define_method(cOraDate, "second=", ora_date_set_second, 1);
|
604
|
+
|
605
|
+
rb_define_method(cOraDate, "trunc", ora_date_trunc, 0);
|
606
|
+
|
607
|
+
rb_define_method(cOraDate, "<=>", ora_date_cmp, 1);
|
608
|
+
rb_include_module(cOraDate, rb_mComparable);
|
609
|
+
|
610
|
+
rb_define_method(cOraDate, "hash", ora_date_hash, 0);
|
611
|
+
|
612
|
+
rb_define_method(cOraDate, "_dump", ora_date_dump, -1);
|
613
|
+
rb_define_singleton_method(cOraDate, "_load", ora_date_s_load, 1);
|
614
|
+
|
615
|
+
oci8_define_bind_class("OraDate", &bind_oradate_class);
|
426
616
|
}
|