ruby-oci8-master 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +2321 -0
- data/Makefile +88 -0
- data/NEWS +303 -0
- data/README +76 -0
- data/VERSION +1 -0
- data/dist-files +83 -0
- data/doc/api.en.html +527 -0
- data/doc/api.en.rd +554 -0
- data/doc/api.ja.html +525 -0
- data/doc/api.ja.rd +557 -0
- data/doc/manual.css +35 -0
- data/ext/oci8/.document +18 -0
- data/ext/oci8/MANIFEST +18 -0
- data/ext/oci8/apiwrap.c.tmpl +182 -0
- data/ext/oci8/apiwrap.h.tmpl +61 -0
- data/ext/oci8/apiwrap.rb +91 -0
- data/ext/oci8/apiwrap.yml +1455 -0
- data/ext/oci8/attr.c +105 -0
- data/ext/oci8/bind.c +366 -0
- data/ext/oci8/connection_pool.c +199 -0
- data/ext/oci8/encoding.c +289 -0
- data/ext/oci8/env.c +178 -0
- data/ext/oci8/error.c +378 -0
- data/ext/oci8/extconf.rb +179 -0
- data/ext/oci8/lob.c +805 -0
- data/ext/oci8/metadata.c +232 -0
- data/ext/oci8/object.c +727 -0
- data/ext/oci8/oci8.c +1156 -0
- data/ext/oci8/oci8.h +574 -0
- data/ext/oci8/oci8lib.c +527 -0
- data/ext/oci8/ocidatetime.c +484 -0
- data/ext/oci8/ocihandle.c +751 -0
- data/ext/oci8/ocinumber.c +1612 -0
- data/ext/oci8/oraconf.rb +1119 -0
- data/ext/oci8/oradate.c +611 -0
- data/ext/oci8/oranumber_util.c +352 -0
- data/ext/oci8/oranumber_util.h +24 -0
- data/ext/oci8/post-config.rb +5 -0
- data/ext/oci8/stmt.c +673 -0
- data/ext/oci8/thread_util.c +85 -0
- data/ext/oci8/thread_util.h +30 -0
- data/ext/oci8/win32.c +137 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8.rb.in +94 -0
- data/lib/oci8/.document +8 -0
- data/lib/oci8/bindtype.rb +349 -0
- data/lib/oci8/compat.rb +113 -0
- data/lib/oci8/connection_pool.rb +99 -0
- data/lib/oci8/datetime.rb +611 -0
- data/lib/oci8/encoding-init.rb +74 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2132 -0
- data/lib/oci8/object.rb +581 -0
- data/lib/oci8/oci8.rb +721 -0
- data/lib/oci8/ocihandle.rb +425 -0
- data/lib/oci8/oracle_version.rb +144 -0
- data/lib/oci8/properties.rb +73 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +63 -0
- data/setup.rb +1331 -0
- data/test/README +4 -0
- data/test/config.rb +122 -0
- data/test/test_all.rb +51 -0
- data/test/test_appinfo.rb +63 -0
- data/test/test_array_dml.rb +333 -0
- data/test/test_bind_raw.rb +46 -0
- data/test/test_bind_time.rb +178 -0
- data/test/test_break.rb +96 -0
- data/test/test_clob.rb +82 -0
- data/test/test_connstr.rb +81 -0
- data/test/test_datetime.rb +582 -0
- data/test/test_dbi.rb +366 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +100 -0
- data/test/test_error.rb +88 -0
- data/test/test_metadata.rb +1399 -0
- data/test/test_oci8.rb +434 -0
- data/test/test_oracle_version.rb +70 -0
- data/test/test_oradate.rb +256 -0
- data/test/test_oranumber.rb +746 -0
- data/test/test_rowid.rb +33 -0
- metadata +137 -0
@@ -0,0 +1,199 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* connection_pool.c - part of ruby-oci8
|
4
|
+
*
|
5
|
+
* Copyright (C) 2010 KUBO Takehiro <kubo@jiubao.org>
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
#include "oci8.h"
|
9
|
+
|
10
|
+
static VALUE cOCIConnectionPool;
|
11
|
+
|
12
|
+
typedef struct {
|
13
|
+
oci8_base_t base;
|
14
|
+
VALUE pool_name;
|
15
|
+
} oci8_cpool_t;
|
16
|
+
|
17
|
+
static void oci8_cpool_mark(oci8_base_t *base)
|
18
|
+
{
|
19
|
+
oci8_cpool_t *cpool = (oci8_cpool_t *)base;
|
20
|
+
|
21
|
+
rb_gc_mark(cpool->pool_name);
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE cpool_free_thread(void *arg)
|
25
|
+
{
|
26
|
+
OCIConnectionPoolDestroy((OCICPool *)arg, oci8_errhp, OCI_DEFAULT);
|
27
|
+
OCIHandleFree(arg, OCI_HTYPE_CPOOL);
|
28
|
+
return 0;
|
29
|
+
}
|
30
|
+
|
31
|
+
static void oci8_cpool_free(oci8_base_t *base)
|
32
|
+
{
|
33
|
+
oci8_run_native_thread(cpool_free_thread, base->hp.poolhp);
|
34
|
+
base->type = 0;
|
35
|
+
base->hp.ptr = NULL;
|
36
|
+
}
|
37
|
+
|
38
|
+
static void oci8_cpool_init(oci8_base_t *base)
|
39
|
+
{
|
40
|
+
oci8_cpool_t *cpool = (oci8_cpool_t *)base;
|
41
|
+
|
42
|
+
cpool->pool_name = Qnil;
|
43
|
+
}
|
44
|
+
|
45
|
+
static oci8_base_vtable_t oci8_cpool_vtable = {
|
46
|
+
oci8_cpool_mark,
|
47
|
+
oci8_cpool_free,
|
48
|
+
sizeof(oci8_base_t),
|
49
|
+
oci8_cpool_init,
|
50
|
+
};
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* OCI8::ConnectionPool.new(conn_min, conn_max, conn_incr, username = nil, password = nil, dbname = nil) -> connection pool
|
55
|
+
* OCI8::ConnectionPool.new(conn_min, conn_max, conn_incr, connect_string) -> connection pool
|
56
|
+
*
|
57
|
+
* Creates a connection pool.
|
58
|
+
*
|
59
|
+
* <i>conn_min</i> specifies the minimum number of connections in the
|
60
|
+
* connection pool. Valid values are 0 and higher.
|
61
|
+
*
|
62
|
+
* <i>conn_max</i> specifies the maximum number of connections that
|
63
|
+
* can be opened to the database. Once this value is reached, no more
|
64
|
+
* connections are opened. Valid values are 1 and higher.
|
65
|
+
*
|
66
|
+
* <i>conn_incr</i> allows the application to set the next increment
|
67
|
+
* for connections to be opened to the database if the current number
|
68
|
+
* of connections are less than <i>conn_max</i>. Valid values are 0
|
69
|
+
* and higher.
|
70
|
+
*
|
71
|
+
* <i>username</i> and <i>password</i> are required to establish an
|
72
|
+
* implicit primary session. When both are nil, external
|
73
|
+
* authentication is used.
|
74
|
+
*
|
75
|
+
* <i>dbname</i> specifies the database server to connect to.
|
76
|
+
*
|
77
|
+
* If the number of arguments is four, <i>username</i>,
|
78
|
+
* <i>password</i> and <i>dbname</i> are extracted from the fourth
|
79
|
+
* argument <i>connect_string</i>. The syntax is "username/password" or
|
80
|
+
* "username/password@dbname".
|
81
|
+
*/
|
82
|
+
static VALUE oci8_cpool_initialize(int argc, VALUE *argv, VALUE self)
|
83
|
+
{
|
84
|
+
VALUE conn_min;
|
85
|
+
VALUE conn_max;
|
86
|
+
VALUE conn_incr;
|
87
|
+
VALUE username;
|
88
|
+
VALUE password;
|
89
|
+
VALUE dbname;
|
90
|
+
oci8_cpool_t *cpool = DATA_PTR(self);
|
91
|
+
OraText *pool_name;
|
92
|
+
sb4 pool_name_len;
|
93
|
+
sword rv;
|
94
|
+
|
95
|
+
/* check arguments */
|
96
|
+
rb_scan_args(argc, argv, "42", &conn_min, &conn_max, &conn_incr,
|
97
|
+
&username, &password, &dbname);
|
98
|
+
Check_Type(conn_min, T_FIXNUM);
|
99
|
+
Check_Type(conn_max, T_FIXNUM);
|
100
|
+
Check_Type(conn_incr, T_FIXNUM);
|
101
|
+
if (argc == 4) {
|
102
|
+
VALUE mode;
|
103
|
+
VALUE conn_str = username;
|
104
|
+
|
105
|
+
OCI8SafeStringValue(conn_str);
|
106
|
+
oci8_do_parse_connect_string(conn_str, &username, &password, &dbname, &mode);
|
107
|
+
if (!NIL_P(mode)) {
|
108
|
+
rb_raise(rb_eArgError, "invalid connect string \"%s\": Connection pooling doesn't support sysdba and sysoper privileges.", RSTRING_PTR(conn_str));
|
109
|
+
}
|
110
|
+
} else {
|
111
|
+
if (!NIL_P(username)) {
|
112
|
+
OCI8SafeStringValue(username);
|
113
|
+
}
|
114
|
+
if (!NIL_P(password)) {
|
115
|
+
OCI8SafeStringValue(password);
|
116
|
+
}
|
117
|
+
if (!NIL_P(dbname)) {
|
118
|
+
OCI8SafeStringValue(dbname);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
rv = OCIHandleAlloc(oci8_envhp, &cpool->base.hp.ptr, OCI_HTYPE_CPOOL, 0, NULL);
|
123
|
+
if (rv != OCI_SUCCESS)
|
124
|
+
oci8_env_raise(oci8_envhp, rv);
|
125
|
+
cpool->base.type = OCI_HTYPE_CPOOL;
|
126
|
+
|
127
|
+
chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
|
128
|
+
&pool_name, &pool_name_len,
|
129
|
+
NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname),
|
130
|
+
NIL_P(dbname) ? 0 : RSTRING_LEN(dbname),
|
131
|
+
FIX2UINT(conn_min), FIX2UINT(conn_max),
|
132
|
+
FIX2UINT(conn_incr),
|
133
|
+
NIL_P(username) ? NULL : RSTRING_ORATEXT(username),
|
134
|
+
NIL_P(username) ? 0 : RSTRING_LEN(username),
|
135
|
+
NIL_P(password) ? NULL : RSTRING_ORATEXT(password),
|
136
|
+
NIL_P(password) ? 0 : RSTRING_LEN(password),
|
137
|
+
OCI_DEFAULT),
|
138
|
+
&cpool->base);
|
139
|
+
cpool->pool_name = rb_str_new(TO_CHARPTR(pool_name), pool_name_len);
|
140
|
+
rb_str_freeze(cpool->pool_name);
|
141
|
+
return Qnil;
|
142
|
+
}
|
143
|
+
|
144
|
+
/*
|
145
|
+
* call-seq:
|
146
|
+
* reinitialize(min, max, incr)
|
147
|
+
*
|
148
|
+
* Changes the the number of minimum connections, the number of
|
149
|
+
* maximum connections and the connection increment parameter.
|
150
|
+
*/
|
151
|
+
static VALUE oci8_cpool_reinitialize(VALUE self, VALUE conn_min, VALUE conn_max, VALUE conn_incr)
|
152
|
+
{
|
153
|
+
oci8_cpool_t *cpool = DATA_PTR(self);
|
154
|
+
OraText *pool_name;
|
155
|
+
sb4 pool_name_len;
|
156
|
+
|
157
|
+
/* check arguments */
|
158
|
+
Check_Type(conn_min, T_FIXNUM);
|
159
|
+
Check_Type(conn_max, T_FIXNUM);
|
160
|
+
Check_Type(conn_incr, T_FIXNUM);
|
161
|
+
|
162
|
+
chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
|
163
|
+
&pool_name, &pool_name_len, NULL, 0,
|
164
|
+
FIX2UINT(conn_min), FIX2UINT(conn_max),
|
165
|
+
FIX2UINT(conn_incr),
|
166
|
+
NULL, 0, NULL, 0, OCI_CPOOL_REINITIALIZE),
|
167
|
+
&cpool->base);
|
168
|
+
return self;
|
169
|
+
}
|
170
|
+
|
171
|
+
/*
|
172
|
+
* call-seq:
|
173
|
+
* pool_name -> string
|
174
|
+
*
|
175
|
+
* <b>internal use only</b>
|
176
|
+
*
|
177
|
+
* Retruns the pool name.
|
178
|
+
*/
|
179
|
+
static VALUE oci8_cpool_pool_name(VALUE self)
|
180
|
+
{
|
181
|
+
oci8_cpool_t *cpool = DATA_PTR(self);
|
182
|
+
|
183
|
+
return cpool->pool_name;
|
184
|
+
}
|
185
|
+
|
186
|
+
void Init_oci8_connection_pool(VALUE cOCI8)
|
187
|
+
{
|
188
|
+
#if 0
|
189
|
+
cOCIHandle = rb_define_class("OCIHandle", rb_cObject);
|
190
|
+
cOCI8 = rb_define_class("OCI8", cOCIHandle);
|
191
|
+
cOCIConnectionPool = rb_define_class_under(cOCI8, "ConnectionPool", cOCIHandle);
|
192
|
+
#endif
|
193
|
+
|
194
|
+
cOCIConnectionPool = oci8_define_class_under(cOCI8, "ConnectionPool", &oci8_cpool_vtable);
|
195
|
+
|
196
|
+
rb_define_private_method(cOCIConnectionPool, "initialize", oci8_cpool_initialize, -1);
|
197
|
+
rb_define_method(cOCIConnectionPool, "reinitialize", oci8_cpool_reinitialize, 3);
|
198
|
+
rb_define_private_method(cOCIConnectionPool, "pool_name", oci8_cpool_pool_name, 0);
|
199
|
+
}
|
data/ext/oci8/encoding.c
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* encoding.c - part of ruby-oci8
|
4
|
+
*
|
5
|
+
* Copyright (C) 2008-2010 KUBO Takehiro <kubo@jiubao.org>
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
#include "oci8.h"
|
9
|
+
|
10
|
+
#ifndef OCI_NLS_MAXBUFSZ
|
11
|
+
#define OCI_NLS_MAXBUFSZ 100
|
12
|
+
#endif
|
13
|
+
|
14
|
+
/* NLS ratio, maximum number of bytes per one chracter */
|
15
|
+
int oci8_nls_ratio = 1;
|
16
|
+
|
17
|
+
/* Oracle charset id -> Oracle charset name */
|
18
|
+
static VALUE csid2name;
|
19
|
+
|
20
|
+
/* Oracle charset name -> Oracle charset id */
|
21
|
+
static ID id_upcase;
|
22
|
+
static VALUE csname2id;
|
23
|
+
static VALUE oci8_charset_name2id(VALUE svc, VALUE name);
|
24
|
+
#ifdef HAVE_TYPE_RB_ENCODING
|
25
|
+
rb_encoding *oci8_encoding;
|
26
|
+
#endif
|
27
|
+
|
28
|
+
|
29
|
+
/*
|
30
|
+
* call-seq:
|
31
|
+
* charset_id2name(charset_id) -> charset_name
|
32
|
+
*
|
33
|
+
* <b>(new in 2.0.0)</b>
|
34
|
+
*
|
35
|
+
* Returns the Oracle character set name from the specified
|
36
|
+
* character set ID if it is valid. Otherwise, +nil+ is returned.
|
37
|
+
*
|
38
|
+
* === Oracle 9iR2 client or upper
|
39
|
+
*
|
40
|
+
* It is done by using the mapping table stored in the client side.
|
41
|
+
*
|
42
|
+
* === Oracle 9iR1 client or lower
|
43
|
+
*
|
44
|
+
* It executes the following PL/SQL block internally to use
|
45
|
+
* the mapping table stored in the server side.
|
46
|
+
*
|
47
|
+
* BEGIN
|
48
|
+
* :name := nls_charset_name(:csid);
|
49
|
+
* END;
|
50
|
+
*
|
51
|
+
*/
|
52
|
+
VALUE oci8_charset_id2name(VALUE svc, VALUE csid)
|
53
|
+
{
|
54
|
+
VALUE name = rb_hash_aref(csid2name, csid);
|
55
|
+
|
56
|
+
if (!NIL_P(name)) {
|
57
|
+
return name;
|
58
|
+
}
|
59
|
+
Check_Type(csid, T_FIXNUM);
|
60
|
+
if (have_OCINlsCharSetIdToName) {
|
61
|
+
/* Oracle 9iR2 or upper */
|
62
|
+
char buf[OCI_NLS_MAXBUFSZ];
|
63
|
+
sword rv;
|
64
|
+
|
65
|
+
rv = OCINlsCharSetIdToName(oci8_envhp, TO_ORATEXT(buf), sizeof(buf), (ub2)FIX2INT(csid));
|
66
|
+
if (rv != OCI_SUCCESS) {
|
67
|
+
return Qnil;
|
68
|
+
}
|
69
|
+
name = rb_usascii_str_new_cstr(buf);
|
70
|
+
} else {
|
71
|
+
/* Oracle 9iR1 or lower */
|
72
|
+
oci8_exec_sql_var_t bind_vars[2];
|
73
|
+
char buf[OCI_NLS_MAXBUFSZ];
|
74
|
+
ub2 buflen = 0;
|
75
|
+
int ival = FIX2INT(csid);
|
76
|
+
|
77
|
+
/* :name */
|
78
|
+
bind_vars[0].valuep = buf;
|
79
|
+
bind_vars[0].value_sz = OCI_NLS_MAXBUFSZ;
|
80
|
+
bind_vars[0].dty = SQLT_CHR;
|
81
|
+
bind_vars[0].indp = NULL;
|
82
|
+
bind_vars[0].alenp = &buflen;
|
83
|
+
/* :csid */
|
84
|
+
bind_vars[1].valuep = &ival;
|
85
|
+
bind_vars[1].value_sz = sizeof(int);
|
86
|
+
bind_vars[1].dty = SQLT_INT;
|
87
|
+
bind_vars[1].indp = NULL;
|
88
|
+
bind_vars[1].alenp = NULL;
|
89
|
+
|
90
|
+
/* convert chaset id to charset name by querying Oracle server. */
|
91
|
+
oci8_exec_sql(oci8_get_svcctx(svc), "BEGIN :name := nls_charset_name(:csid); END;", 0, NULL, 2, bind_vars, 1);
|
92
|
+
if (buflen == 0) {
|
93
|
+
return Qnil;
|
94
|
+
}
|
95
|
+
name = rb_usascii_str_new(buf, buflen);
|
96
|
+
}
|
97
|
+
OBJ_FREEZE(name);
|
98
|
+
rb_hash_aset(csid2name, csid, name);
|
99
|
+
rb_hash_aset(csname2id, name, csid);
|
100
|
+
return name;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* call-seq:
|
105
|
+
* charset_name2id(charset_name) -> charset_id
|
106
|
+
*
|
107
|
+
* <b>(new in 2.0.0)</b>
|
108
|
+
*
|
109
|
+
* Returns the Oracle character set ID for the specified Oracle
|
110
|
+
* character set name if it is valid. Othewise, +nil+ is returned.
|
111
|
+
*
|
112
|
+
* === Oracle 9iR2 client or upper
|
113
|
+
*
|
114
|
+
* It is done by using the mapping table stored in the client side.
|
115
|
+
*
|
116
|
+
* === Oracle 9iR1 client or lower
|
117
|
+
*
|
118
|
+
* It executes the following PL/SQL block internally to use
|
119
|
+
* the mapping table stored in the server side.
|
120
|
+
*
|
121
|
+
* BEGIN
|
122
|
+
* :csid := nls_charset_id(:name);
|
123
|
+
* END;
|
124
|
+
*
|
125
|
+
*/
|
126
|
+
static VALUE oci8_charset_name2id(VALUE svc, VALUE name)
|
127
|
+
{
|
128
|
+
VALUE csid;
|
129
|
+
|
130
|
+
name = rb_funcall(name, id_upcase, 0);
|
131
|
+
csid = rb_hash_aref(csname2id, StringValue(name));
|
132
|
+
if (!NIL_P(csid)) {
|
133
|
+
return csid;
|
134
|
+
}
|
135
|
+
if (have_OCINlsCharSetNameToId) {
|
136
|
+
/* Oracle 9iR2 or upper */
|
137
|
+
ub2 rv;
|
138
|
+
|
139
|
+
rv = OCINlsCharSetNameToId(oci8_envhp, RSTRING_ORATEXT(name));
|
140
|
+
if (rv == 0) {
|
141
|
+
return Qnil;
|
142
|
+
}
|
143
|
+
csid = INT2FIX(rv);
|
144
|
+
} else {
|
145
|
+
/* Oracle 9iR1 or lower */
|
146
|
+
oci8_exec_sql_var_t bind_vars[2];
|
147
|
+
int ival;
|
148
|
+
sb2 ind = 0; /* null indicator */
|
149
|
+
|
150
|
+
/* :csid */
|
151
|
+
bind_vars[0].valuep = &ival;
|
152
|
+
bind_vars[0].value_sz = sizeof(int);
|
153
|
+
bind_vars[0].dty = SQLT_INT;
|
154
|
+
bind_vars[0].indp = &ind;
|
155
|
+
bind_vars[0].alenp = NULL;
|
156
|
+
/* :name */
|
157
|
+
bind_vars[1].valuep = RSTRING_PTR(name);
|
158
|
+
bind_vars[1].value_sz = RSTRING_LEN(name);
|
159
|
+
bind_vars[1].dty = SQLT_CHR;
|
160
|
+
bind_vars[1].indp = NULL;
|
161
|
+
bind_vars[1].alenp = NULL;
|
162
|
+
|
163
|
+
/* convert chaset name to charset id by querying Oracle server. */
|
164
|
+
oci8_exec_sql(oci8_get_svcctx(svc), "BEGIN :csid := nls_charset_id(:name); END;", 0, NULL, 2, bind_vars, 1);
|
165
|
+
if (ind) {
|
166
|
+
return Qnil;
|
167
|
+
}
|
168
|
+
csid = INT2FIX(ival);
|
169
|
+
}
|
170
|
+
rb_hash_aset(csid2name, csid, name);
|
171
|
+
rb_hash_aset(csname2id, name, csid);
|
172
|
+
return csid;
|
173
|
+
}
|
174
|
+
|
175
|
+
/*
|
176
|
+
* call-seq:
|
177
|
+
* OCI8.nls_ratio -> integer
|
178
|
+
*
|
179
|
+
* <b>(new in 2.1.0)</b>
|
180
|
+
*
|
181
|
+
* Gets NLS ratio, maximum number of bytes per one character of the
|
182
|
+
* current NLS chracter set. It is a factor to calculate the
|
183
|
+
* internal buffer size of a string bind variable whose nls length
|
184
|
+
* semantics is char.
|
185
|
+
*/
|
186
|
+
static VALUE oci8_get_nls_ratio(VALUE klass)
|
187
|
+
{
|
188
|
+
return INT2NUM(oci8_nls_ratio);
|
189
|
+
}
|
190
|
+
|
191
|
+
/*
|
192
|
+
* call-seq:
|
193
|
+
* OCI8.nls_ratio = integer
|
194
|
+
*
|
195
|
+
* <b>(new in 2.1.0)</b>
|
196
|
+
*
|
197
|
+
* Sets NLS ratio, maximum number of bytes per one character of the
|
198
|
+
* current NLS chracter set. It is initialized in 'oci8/encoding-init.rb'
|
199
|
+
* when oci8 is required. You have no need to set it explicitly.
|
200
|
+
*/
|
201
|
+
static VALUE oci8_set_nls_ratio(VALUE klass, VALUE val)
|
202
|
+
{
|
203
|
+
int v = NUM2INT(val);
|
204
|
+
if (v <= 0) {
|
205
|
+
rb_raise(rb_eRangeError, "expected a positive integer but %d", v);
|
206
|
+
}
|
207
|
+
oci8_nls_ratio = v;
|
208
|
+
return val;
|
209
|
+
}
|
210
|
+
|
211
|
+
#ifdef HAVE_TYPE_RB_ENCODING
|
212
|
+
|
213
|
+
/*
|
214
|
+
* call-seq:
|
215
|
+
* OCI8.encoding -> enc
|
216
|
+
*
|
217
|
+
* <b>(new in 2.0.0 and ruby 1.9)</b>
|
218
|
+
*
|
219
|
+
* Returns the Oracle client encoding.
|
220
|
+
*
|
221
|
+
* When string data, such as SQL statements and bind variables,
|
222
|
+
* are passed to Oracle, they are converted to +OCI8.encoding+
|
223
|
+
* in advance.
|
224
|
+
*
|
225
|
+
* # When OCI8.encoding is ISO-8859-1,
|
226
|
+
* conn.exec('insert into country_code values(:1, :2, :3)',
|
227
|
+
* 'AT', 'Austria', "\u00d6sterreichs")
|
228
|
+
* # "\u00d6sterreichs" is 'Österreichs' encoded by UTF-8.
|
229
|
+
* # It is converted to ISO-8859-1 before it is passed to
|
230
|
+
* # the Oracle C API.
|
231
|
+
*
|
232
|
+
*
|
233
|
+
* When string data, such as fetched values and bind variable
|
234
|
+
* for output, are retrieved from Oracle, they are encoded
|
235
|
+
* by +OCI8.encoding+ if +Encoding.default_internal+ is +nil+.
|
236
|
+
* If it isn't +nil+, they are converted from +OCI8.encoding+
|
237
|
+
* to +Encoding.default_internal+.
|
238
|
+
*
|
239
|
+
* If +OCI8.encoding+ is ASCII-8BIT, no encoding conversions
|
240
|
+
* are done.
|
241
|
+
*/
|
242
|
+
static VALUE oci8_get_encoding(VALUE klass)
|
243
|
+
{
|
244
|
+
return rb_enc_from_encoding(oci8_encoding);
|
245
|
+
}
|
246
|
+
|
247
|
+
/*
|
248
|
+
* call-seq:
|
249
|
+
* OCI8.encoding = enc or nil
|
250
|
+
*
|
251
|
+
* <b>(new in 2.0.0 and ruby 1.9)</b>
|
252
|
+
*
|
253
|
+
* Sets Oracle client encoding. You must not use this method.
|
254
|
+
* You should set the environment variable NLS_LANG properly to
|
255
|
+
* change +OCI8.encoding+.
|
256
|
+
*/
|
257
|
+
static VALUE oci8_set_encoding(VALUE klass, VALUE encoding)
|
258
|
+
{
|
259
|
+
if (NIL_P(encoding)) {
|
260
|
+
oci8_encoding = NULL;
|
261
|
+
} else {
|
262
|
+
oci8_encoding = rb_to_encoding(encoding);
|
263
|
+
}
|
264
|
+
return encoding;
|
265
|
+
}
|
266
|
+
#endif
|
267
|
+
|
268
|
+
void Init_oci8_encoding(VALUE cOCI8)
|
269
|
+
{
|
270
|
+
#if 0
|
271
|
+
oci8_cOCIHandle = rb_define_class("OCIHandle", rb_cObject);
|
272
|
+
cOCI8 = rb_define_class("OCI8", oci8_cOCIHandle);
|
273
|
+
#endif
|
274
|
+
csid2name = rb_hash_new();
|
275
|
+
rb_global_variable(&csid2name);
|
276
|
+
|
277
|
+
id_upcase = rb_intern("upcase");
|
278
|
+
csname2id = rb_hash_new();
|
279
|
+
rb_global_variable(&csname2id);
|
280
|
+
|
281
|
+
rb_define_method(cOCI8, "charset_name2id", oci8_charset_name2id, 1);
|
282
|
+
rb_define_method(cOCI8, "charset_id2name", oci8_charset_id2name, 1);
|
283
|
+
rb_define_singleton_method(cOCI8, "nls_ratio", oci8_get_nls_ratio, 0);
|
284
|
+
rb_define_singleton_method(cOCI8, "nls_ratio=", oci8_set_nls_ratio, 1);
|
285
|
+
#ifdef HAVE_TYPE_RB_ENCODING
|
286
|
+
rb_define_singleton_method(cOCI8, "encoding", oci8_get_encoding, 0);
|
287
|
+
rb_define_singleton_method(cOCI8, "encoding=", oci8_set_encoding, 1);
|
288
|
+
#endif
|
289
|
+
}
|