/* * call-seq: * OCI8::ConnectionPool.new(conn_min, conn_max, conn_incr, username = nil, password = nil, dbname = nil) -> connection pool * OCI8::ConnectionPool.new(conn_min, conn_max, conn_incr, connect_string) -> connection pool * * Creates a connection pool. * * <i>conn_min</i> specifies the minimum number of connections in the * connection pool. Valid values are 0 and higher. * * <i>conn_max</i> specifies the maximum number of connections that * can be opened to the database. Once this value is reached, no more * connections are opened. Valid values are 1 and higher. * * <i>conn_incr</i> allows the application to set the next increment * for connections to be opened to the database if the current number * of connections are less than <i>conn_max</i>. Valid values are 0 * and higher. * * <i>username</i> and <i>password</i> are required to establish an * implicit primary session. When both are nil, external * authentication is used. * * <i>dbname</i> specifies the database server to connect to. * * If the number of arguments is four, <i>username</i>, * <i>password</i> and <i>dbname</i> are extracted from the fourth * argument <i>connect_string</i>. The syntax is "username/password" or * "username/password@dbname". */ static VALUE oci8_cpool_initialize(int argc, VALUE *argv, VALUE self) { VALUE conn_min; VALUE conn_max; VALUE conn_incr; VALUE username; VALUE password; VALUE dbname; oci8_cpool_t *cpool = DATA_PTR(self); OraText *pool_name; sb4 pool_name_len; sword rv; /* check arguments */ rb_scan_args(argc, argv, "42", &conn_min, &conn_max, &conn_incr, &username, &password, &dbname); Check_Type(conn_min, T_FIXNUM); Check_Type(conn_max, T_FIXNUM); Check_Type(conn_incr, T_FIXNUM); if (argc == 4) { VALUE mode; VALUE conn_str = username; OCI8SafeStringValue(conn_str); oci8_do_parse_connect_string(conn_str, &username, &password, &dbname, &mode); if (!NIL_P(mode)) { rb_raise(rb_eArgError, "invalid connect string \"%s\": Connection pooling doesn't support sysdba and sysoper privileges.", RSTRING_PTR(conn_str)); } } else { if (!NIL_P(username)) { OCI8SafeStringValue(username); } if (!NIL_P(password)) { OCI8SafeStringValue(password); } if (!NIL_P(dbname)) { OCI8SafeStringValue(dbname); } } rv = OCIHandleAlloc(oci8_envhp, &cpool->base.hp.ptr, OCI_HTYPE_CPOOL, 0, NULL); if (rv != OCI_SUCCESS) oci8_env_raise(oci8_envhp, rv); cpool->base.type = OCI_HTYPE_CPOOL; oci_lc(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp, &pool_name, &pool_name_len, NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname), NIL_P(dbname) ? 0 : RSTRING_LEN(dbname), FIX2UINT(conn_min), FIX2UINT(conn_max), FIX2UINT(conn_incr), NIL_P(username) ? NULL : RSTRING_ORATEXT(username), NIL_P(username) ? 0 : RSTRING_LEN(username), NIL_P(password) ? NULL : RSTRING_ORATEXT(password), NIL_P(password) ? 0 : RSTRING_LEN(password), OCI_DEFAULT)); cpool->pool_name = rb_str_new(TO_CHARPTR(pool_name), pool_name_len); rb_str_freeze(cpool->pool_name); return Qnil; }
VALUE oci8_get_error_message(ub4 msgno, const char *default_msg) { char head[32]; size_t headsz; const char *errmsg = NULL; char msgbuf[64]; if (have_OCIMessageGet) { if (msghp == NULL) { chkerr(OCIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_CONST_ORATEXT("rdbms"), TO_CONST_ORATEXT("ora"), OCI_DURATION_PROCESS)); } errmsg = TO_CHARPTR(OCIMessageGet(msghp, msgno, NULL, 0)); } if (errmsg == NULL) { if (default_msg != NULL) { errmsg = default_msg; } else { /* last resort */ snprintf(msgbuf, sizeof(msgbuf), "Message %u not found; product=rdbms; facility=ora", msgno); errmsg = msgbuf; } } headsz = snprintf(head, sizeof(head), "ORA-%05u: ", msgno); return rb_str_append(rb_usascii_str_new(head, headsz), rb_external_str_new_with_enc(errmsg, strlen(errmsg), oci8_encoding)); }
/* =begin --- OraNumber#to_i() =end */ static VALUE ora_number_to_i(VALUE self) { ora_vnumber_t *ovn = get_ora_number(self); unsigned char buf[ORA_NUMBER_BUF_SIZE]; ora_number_to_str(buf, NULL, &(ovn->num), ovn->size); return rb_cstr2inum(TO_CHARPTR(buf), 10); }
/* =begin --- OraNumber#to_f() =end */ static VALUE ora_number_to_f(VALUE self) { ora_vnumber_t *ovn = get_ora_number(self); unsigned char buf[ORA_NUMBER_BUF_SIZE]; ora_number_to_str(buf, NULL, &(ovn->num), ovn->size); return rb_float_new(rb_cstr_to_dbl(TO_CHARPTR(buf), Qfalse)); }
/* =begin --- OraNumber#to_s() =end */ static VALUE ora_number_to_s(VALUE self) { ora_vnumber_t *ovn = get_ora_number(self); unsigned char buf[ORA_NUMBER_BUF_SIZE]; size_t len; ora_number_to_str(buf, &len, &(ovn->num), ovn->size); return rb_str_new(TO_CHARPTR(buf), len); }
VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype) { text *val; ub4 size; sword rv; rv = OCIAttrGet(base->hp.ptr, base->type, &val, &size, attrtype, oci8_errhp); if (rv != OCI_SUCCESS) oci8_raise(oci8_errhp, rv, NULL); return rb_external_str_new_with_enc(TO_CHARPTR(val), size, oci8_encoding); }
/* =begin --- OCIServer#version() get server version. :return value string of server version. For example Oracle8 Release 8.0.5.0.0 - Production PL/SQL Release 8.0.5.0.0 - Production correspond native OCI function: ((|OCIServerVersion|)) =end */ VALUE oci8_server_version(VALUE self) { oci8_handle_t *h; OraText buf[1024]; sword rv; Get_Handle(self, h); /* 0 */ rv = OCIServerVersion(h->hp, h->errhp, buf, sizeof(buf), h->type); if (rv != OCI_SUCCESS) oci8_raise(h->errhp, rv, NULL); return rb_str_new2(TO_CHARPTR(buf)); }
static VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line) { VALUE exc; char errmsg[128]; sb4 errcode = -1; VALUE msg; VALUE parse_error_offset = Qnil; VALUE sql = Qnil; int rv; int numarg = 1; switch (status) { case OCI_ERROR: exc = eOCIError; msg = get_error_msg(errhp, type, "Error", &errcode); numarg = 4; break; case OCI_SUCCESS_WITH_INFO: exc = eOCISuccessWithInfo; msg = get_error_msg(errhp, type, "Error", &errcode); numarg = 4; break; case OCI_NO_DATA: exc = eOCINoData; msg = get_error_msg(errhp, type, "No Data", &errcode); numarg = 4; break; case OCI_INVALID_HANDLE: exc = eOCIInvalidHandle; msg = rb_usascii_str_new_cstr("Invalid Handle"); break; case OCI_NEED_DATA: exc = eOCINeedData; msg = rb_usascii_str_new_cstr("Need Data"); break; case OCI_STILL_EXECUTING: exc = eOCIStillExecuting; msg = rb_usascii_str_new_cstr("Still Executing"); break; case OCI_CONTINUE: exc = eOCIContinue; msg = rb_usascii_str_new_cstr("Continue"); break; default: sprintf(errmsg, "Unknown error (%d)", status); exc = eOCIException; msg = rb_usascii_str_new_cstr(errmsg); } if (stmthp != NULL) { ub2 offset; text *text; ub4 size; rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &offset, 0, OCI_ATTR_PARSE_ERROR_OFFSET, errhp); if (rv == OCI_SUCCESS) { parse_error_offset = INT2FIX(offset); } rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &text, &size, OCI_ATTR_STATEMENT, errhp); if (rv == OCI_SUCCESS) { sql = rb_external_str_new_with_enc(TO_CHARPTR(text), size, oci8_encoding); } } exc = rb_funcall(exc, oci8_id_new, numarg, msg, INT2FIX(errcode), sql, parse_error_offset); return set_backtrace(exc, file, line); }