Class: OCIEnv
Class Method Summary collapse
- .create(*args) ⇒ Object
- .init(*args) ⇒ Object
- .initialise(*args) ⇒ Object
- .terminate(*args) ⇒ Object
Instance Method Summary collapse
- #alloc(klass) ⇒ Object
-
#logon(username, password, dbname) ⇒ Object
begin — OCIEnv#logon(username, password, dbname) Logon to the Oracle server.
Methods inherited from OCIHandle
#attrGet, #attrSet, #free, new
Class Method Details
.create(*args) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'ext/oci8/env.c', line 112
static VALUE oci8_env_s_create(int argc, VALUE *argv, VALUE klass)
{
VALUE vmode;
ub4 mode;
OCIEnv *envhp = NULL;
OCIError *errhp;
oci8_handle_t *h;
sword rv;
rb_scan_args(argc, argv, "01", &vmode);
Get_Int_With_Default(argc, 1, vmode, mode, OCI_DEFAULT); /* 1 */
rv = OCIEnvCreate(&envhp, mode, NULL, NULL, NULL, NULL, 0, NULL);
if (envhp == NULL) {
oci8_raise_init_error();
}
if (rv != OCI_SUCCESS)
oci8_env_raise(envhp, rv);
rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL);
if (rv != OCI_SUCCESS)
oci8_env_raise(envhp, rv);
h = oci8_make_handle(OCI_HTYPE_ENV, envhp, errhp, NULL, 0);
return h->self;
}
|
.init(*args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/oci8/env.c', line 63
static VALUE oci8_env_s_init(int argc, VALUE *argv, VALUE klass)
{
VALUE vmode;
ub4 mode;
OCIEnv *envhp = NULL;
OCIError *errhp;
oci8_handle_t *h;
sword rv;
rb_scan_args(argc, argv, "01", &vmode);
Get_Int_With_Default(argc, 1, vmode, mode, OCI_DEFAULT); /* 1 */
rv = OCIEnvInit(&envhp, OCI_DEFAULT, 0, NULL);
if (envhp == NULL) {
oci8_raise_init_error();
}
if (rv != OCI_SUCCESS)
oci8_env_raise(envhp, rv);
rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL);
if (rv != OCI_SUCCESS)
oci8_env_raise(envhp, rv);
h = oci8_make_handle(OCI_HTYPE_ENV, envhp, errhp, NULL, 0);
return h->self;
}
|
.initialise(*args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'ext/oci8/env.c', line 30
static VALUE oci8_env_s_initialize(int argc, VALUE *argv, VALUE klass)
{
VALUE vmode;
ub4 mode;
sword rv;
#ifndef WIN32
/* workaround code.
*
* Some instant clients set the environment variables
* ORA_NLS_PROFILE33, ORA_NLS10 and ORACLE_HOME if they aren't
* set. It causes problems on some platforms.
*/
if (RTEST(rb_eval_string("RUBY_VERSION == \"1.8.4\""))) {
if (getenv("ORA_NLS_PROFILE33") == NULL) {
ruby_setenv("ORA_NLS_PROFILE33", "");
}
if (getenv("ORA_NLS10") == NULL) {
ruby_setenv("ORA_NLS10", "");
}
if (getenv("ORACLE_HOME") == NULL) {
ruby_setenv("ORACLE_HOME", ".");
}
}
#endif /* WIN32 */
rb_scan_args(argc, argv, "01", &vmode);
Get_Int_With_Default(argc, 1, vmode, mode, OCI_DEFAULT); /* 1 */
rv = OCIInitialize(mode, NULL, NULL, NULL, NULL);
return INT2FIX(rv);
}
|
.terminate(*args) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'ext/oci8/env.c', line 148
static VALUE oci8_env_s_terminate(int argc, VALUE *argv, VALUE klass)
{
VALUE vmode;
ub4 mode;
if (rb_scan_args(argc, argv, "01", &vmode) == 1) {
Check_Type(vmode, T_FIXNUM);
mode = FIX2INT(vmode);
} else {
mode = OCI_DEFAULT;
}
OCITerminate(mode);
return Qnil;
}
|
Instance Method Details
#alloc(klass) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'ext/oci8/env.c', line 179
static VALUE oci8_handle_alloc(VALUE self, VALUE klass)
{
sword rv;
dvoid *hp;
oci8_handle_t *envh;
oci8_handle_t *h;
int i;
struct {
VALUE *klass;
ub4 type;
alloc_func_t alloc_func;
} alloc_map[] = {
{&cOCISvcCtx, OCI_HTYPE_SVCCTX, (alloc_func_t)OCIHandleAlloc},
{&cOCIStmt, OCI_HTYPE_STMT, (alloc_func_t)OCIHandleAlloc},
{&cOCIServer, OCI_HTYPE_SERVER, (alloc_func_t)OCIHandleAlloc},
{&cOCISession, OCI_HTYPE_SESSION, (alloc_func_t)OCIHandleAlloc},
{&cOCIDescribe, OCI_HTYPE_DESCRIBE, (alloc_func_t)OCIHandleAlloc},
{&cOCILobLocator, OCI_DTYPE_LOB, (alloc_func_t)OCIDescriptorAlloc},
{&cOCIFileLocator, OCI_DTYPE_FILE, (alloc_func_t)OCIDescriptorAlloc},
};
#define ALLOC_MAP_SIZE (sizeof(alloc_map) / sizeof(alloc_map[0]))
Get_Handle(self, envh);
for (i = 0;i < ALLOC_MAP_SIZE;i++) {
if (alloc_map[i].klass[0] == klass)
break;
}
if (i == ALLOC_MAP_SIZE) {
rb_raise(rb_eTypeError, "not valid handle type %s", rb_class2name(CLASS_OF(klass)));
}
rv = alloc_map[i].alloc_func(envh->hp, &hp, alloc_map[i].type, 0, NULL);
if (rv != OCI_SUCCESS)
oci8_env_raise(envh->hp, rv);
h = oci8_make_handle(alloc_map[i].type, hp, envh->errhp, envh, 0);
return h->self;
}
|
#logon(username, password, dbname) ⇒ Object
begin
— OCIEnv#logon(username, password, dbname)
Logon to the Oracle server.
See ((<Simplified Logon>)) and ((<Explicit Attach and Begin Session>))
:username
the username.
:password
the user's password.
:dbname
the name of the database, or nil.
:return value
A instance of ((<OCISvcCtx>))
For example:
env = OCIEnv.create()
svc = env.logon("SCOTT", "TIGER", nil)
or
svc = env.logon("SCOTT", "TIGER", "ORCL.WORLD")
correspond native OCI function: ((|OCILogon|))
end
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'ext/oci8/env.c', line 241
static VALUE oci8_logon(VALUE self, VALUE username, VALUE password, VALUE dbname)
{
oci8_handle_t *envh;
oci8_handle_t *svch;
OCISvcCtx *svchp;
oci8_string_t u, p, d;
VALUE obj;
sword rv;
Get_Handle(self, envh);
Get_String(username, u);
Get_String(password, p);
Get_String(dbname, d);
rv = OCILogon(envh->hp, envh->errhp, &svchp,
u.ptr, u.len, p.ptr, p.len, d.ptr, d.len);
if (rv != OCI_SUCCESS) {
oci8_raise(envh->errhp, rv, NULL);
}
svch = oci8_make_handle(OCI_HTYPE_SVCCTX, svchp, envh->errhp, envh, 0);
obj = svch->self;
return obj;
}
|