コード例 #1
0
ファイル: oci8.c プロジェクト: jcasts/ruby-oci8
/*
 * call-seq:
 *   oracle_server_vernum -> an integer
 *
 * <b>(new in 2.0.1)</b>
 *
 * Returns a numerical format of the Oracle server version.
 *
 * See also: #oracle_server_version
 */
static VALUE oci8_oracle_server_vernum(VALUE self)
{
    oci8_svcctx_t *svcctx = DATA_PTR(self);
    char buf[100];
    ub4 version;
    char *p;

    if (have_OCIServerRelease) {
        /* Oracle 9i or later */
        oci_lc(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version));
        return UINT2NUM(version);
    } else {
        /* Oracle 8.x */
        oci_lc(OCIServerVersion(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type));
        if ((p = strchr(buf, '.')) != NULL) {
            unsigned int major, minor, update, patch, port_update;
            while (p >= buf && *p != ' ') {
                p--;
            }
            if (sscanf(p + 1, "%u.%u.%u.%u.%u", &major, &minor, &update, &patch, &port_update) == 5) {
                return INT2FIX(ORAVERNUM(major, minor, update, patch, port_update));
            }
        }
        return Qnil;
    }
}
コード例 #2
0
ファイル: server.c プロジェクト: kevincolyar/ruby_oracle_libs
/*
=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));
}
コード例 #3
0
ファイル: ora_con.c プロジェクト: GreenfieldTech/kamailio
/*
 * Reconnect to server (after error)
 */
sword db_oracle_reconnect(ora_con_t* con)
{
	sword status;

	if (con->connected)
		db_oracle_disconnect(con);

	/* timelimited operation, but OCI tcp-network does not support it :( */
	status = OCIServerAttach(con->srvhp, con->errhp, (OraText*)con->uri,
		con->uri_len, 0);
	if (status == OCI_SUCCESS) {
		++con->connected;
		/*
		 * timelimited operation, but OCI has BUG in asynch
		 * implementation of OCISessionBegin :(.
		 *
		 * Next code is 'empiric hack' that work (tested) in v10/v11.
		 */
		status = begin_timelimit(con, 1);
		if (status != OCI_SUCCESS) goto done;
		status = OCISessionBegin(con->svchp, con->errhp, con->authp,
			OCI_CRED_RDBMS, OCI_DEFAULT);
		while (wait_timelimit(con, status)) {
			sword code;

			status = OCIServerVersion(con->svchp, con->errhp, NULL,
				0, OCI_HTYPE_SVCCTX);

			if (   status != OCI_ERROR
			    || OCIErrorGet(con->errhp, 1, NULL, &code, NULL, 0,
				     OCI_HTYPE_ERROR) != OCI_SUCCESS) break;
			switch (code) {
			case 24909:	/* other call in progress */
				status = OCI_STILL_EXECUTING;
				continue;

			case 3127:	/* no new operation until active ends */
				status = OCISessionBegin(con->svchp, con->errhp,
					con->authp, OCI_CRED_RDBMS, OCI_DEFAULT);
			default:
				break;
			}
			break;
		}
		if (done_timelimit(con, status)) goto done;

		if (status == OCI_SUCCESS)
			++con->connected;
	}
done:
	return status;
}
コード例 #4
0
ファイル: dbpool_oracle.c プロジェクト: dimimpou/gwlib
static void* oracle_open_conn(const DBConf *db_conf)
{
    OracleConf *cfg = db_conf->oracle;
    sword errorcode = 0;
    text version[512];
    struct ora_conn *conn = gw_malloc(sizeof(struct ora_conn));

    gw_assert(conn != NULL);
    memset(conn, 0, sizeof(struct ora_conn));

    debug("dbpool.oracle",0,"oracle_open_conn called");

    /* init OCI environment */
    errorcode = OCIEnvCreate(&conn->envp,
                             OCI_THREADED|OCI_ENV_NO_MUTEX,
                             NULL,
                             oracle_malloc,
                             oracle_realloc,
                             oracle_free,
                             0,0);
    if (errorcode != OCI_SUCCESS) {
         oracle_checkerr(NULL, errorcode);
         error(0, "Got error while OCIEnvCreate %d", errorcode);
         gw_free(conn);
         return NULL;
    }

    debug("dbpool.oracle",0,"oci environment created");

    /* allocate error handle */
    errorcode = OCIHandleAlloc(conn->envp, (dvoid**) &conn->errhp, 
                               OCI_HTYPE_ERROR, 0, 0);
    if (errorcode != OCI_SUCCESS) {
        oracle_checkerr(NULL, errorcode);
        OCIHandleFree(conn->envp, OCI_HTYPE_ENV);
        gw_free(conn);
        return NULL;
    }

    debug("dbpool.oracle",0,"oci error handle allocated");

    /* open oracle user session */
    errorcode = OCILogon(conn->envp, conn->errhp, &conn->svchp,
                         (unsigned char*)octstr_get_cstr(cfg->username), octstr_len(cfg->username),
                         (unsigned char*)octstr_get_cstr(cfg->password), octstr_len(cfg->password),
                         (unsigned char*)octstr_get_cstr(cfg->tnsname), octstr_len(cfg->tnsname));

    if (errorcode != OCI_SUCCESS) {
        oracle_checkerr(conn->errhp, errorcode);
        OCIHandleFree(conn->errhp, OCI_HTYPE_ERROR);
        OCIHandleFree(conn->envp, OCI_HTYPE_ENV);
        gw_free(conn);
        return NULL;
    }

    debug("dbpool.oracle",0,"connected to database");

    errorcode = OCIServerVersion(conn->svchp, conn->errhp, version, 
                                 sizeof(version), OCI_HTYPE_SVCCTX);
    if (errorcode != OCI_SUCCESS) {
        oracle_checkerr(conn->errhp, errorcode);
    } else {
        info(0, "Connected to: %s", version);
    }

    return conn;
}
コード例 #5
0
ファイル: oracle.c プロジェクト: eaglexmw/gsql
gboolean
oracle_session_open (GSQLEOracleSession *oracle_session,
                     gchar *username,
                     gchar *password,
                     gchar *database,
                     gchar *buffer)
{
    GSQL_TRACE_FUNC;

    unsigned char buf[64];
    gint ret;


    /* initialize the mode to be the threaded and object environment */
    if ( OCIEnvNlsCreate(&(oracle_session->envhp), OCI_THREADED|OCI_OBJECT, (dvoid *)0,
                         0, 0, 0, (size_t) 0, (dvoid **)0, 0, 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIEnvNlsCreate... failed");
        return FALSE;
    };

    /* allocate a server handle */
    if ( OCIHandleAlloc ((dvoid *)(oracle_session->envhp),
                         (dvoid **)&(oracle_session->srvhp),
                         OCI_HTYPE_SERVER, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a server handle)... failed");
        return FALSE;
    };

    /* allocate an error handle */
    if ( OCIHandleAlloc ((dvoid *)(oracle_session->envhp),
                         (dvoid **)&(oracle_session->errhp),
                         OCI_HTYPE_ERROR, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate an error handle)... failed");
        return FALSE;
    };

    /* create a server context */

    if ( OCIServerAttach (oracle_session->srvhp,
                          oracle_session->errhp,
                          (text *) database,
                          g_utf8_strlen (database, 64),
                          OCI_DEFAULT)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "%s",
                    oracle_get_error_string(oracle_session->errhp)
                   );
        return FALSE;
    };

    /* allocate a service handle */
    if ( OCIHandleAlloc ((dvoid *) (oracle_session->envhp),
                         (dvoid **)&(oracle_session->svchp),
                         OCI_HTYPE_SVCCTX, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a service handle)... failed");
        return FALSE;
    };

    /* set the server attribute in the service context handle*/
    if ( OCIAttrSet ((dvoid *) oracle_session->svchp,
                     OCI_HTYPE_SVCCTX,
                     (dvoid *) oracle_session->srvhp,
                     (ub4) 0,
                     OCI_ATTR_SERVER,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIAttrSet... failed");
        return FALSE;
    };

    /* allocate a user session handle */
    if ( OCIHandleAlloc ((dvoid *) (oracle_session->envhp),
                         (dvoid **)&(oracle_session->usrhp),
                         OCI_HTYPE_SESSION, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a user session handle)... failed");
        return FALSE;
    };

    /* set user name attribute in user session handle */

    if ( OCIAttrSet ((dvoid *) oracle_session->usrhp,
                     OCI_HTYPE_SESSION,
                     (dvoid *) username,
                     (ub4) g_utf8_strlen(username, 64),
                     OCI_ATTR_USERNAME,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIAttrSet (OCI_ATTR_USERNAME)... failed");
        return FALSE;
    };

    /* set password attribute in user session handle */

    if ( OCIAttrSet ((dvoid *)(oracle_session->usrhp),
                     OCI_HTYPE_SESSION,
                     (dvoid *)password,
                     (ub4) g_utf8_strlen(password, 64),
                     OCI_ATTR_PASSWORD,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIAttrSet(OCI_ATTR_PASSWORD)... failed");
        return FALSE;
    };


    /* make the connection*/
    if (  OCISessionBegin ((dvoid *) oracle_session->svchp,
                           oracle_session->errhp,
                           oracle_session->usrhp,
                           OCI_CRED_RDBMS,
                           oracle_session->mode)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "%s",
                    oracle_get_error_string(oracle_session->errhp)
                   );
        return FALSE;
    };

    oracle_client_info(oracle_session->client_version);

    if ( OCIAttrSet ((dvoid *)(oracle_session->usrhp),
                     OCI_HTYPE_SESSION,
                     (dvoid *) oracle_session->client_version,
                     (ub4) g_utf8_strlen(oracle_session->client_version, 64),
                     OCI_ATTR_CLIENT_INFO,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "OCIAttrSet(OCI_ATTR_CLIENT_INFO)... failed");
        return FALSE;
    };


    /* set the user session attribute in the service context handle*/
    if ( OCIAttrSet ((dvoid *)oracle_session->svchp,
                     OCI_HTYPE_SVCCTX,
                     (dvoid *) oracle_session->usrhp,
                     (ub4) 0,
                     OCI_ATTR_SESSION, oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "OCIAttrSet (OCI_ATTR_SESSION)... failed");
        return FALSE;
    };

    OCIServerVersion ((dvoid *) oracle_session->svchp,
                      oracle_session->errhp,
                      oracle_session->server_version,
                      1024, OCI_HTYPE_SVCCTX);
    GSQL_DEBUG ("oracle_session->server_version=[%s]", oracle_session->server_version);

    oracle_session->dbms_output = FALSE;
    oracle_session->debug_mode = FALSE;

    return TRUE;
};
コード例 #6
0
ファイル: ora_con.c プロジェクト: GreenfieldTech/kamailio
/*
 * Create a new connection structure,
 * open the Oracle connection and set reference count to 1
 */
ora_con_t* db_oracle_new_connection(const struct db_id* id)
{
	ora_con_t* con;
	char buf[512];
	size_t uri_len;
	sword status;

	if (!id || !id->username || !*id->username || !id->password ||
		!*id->password || !id->database || !*id->database)
	{
bad_param:
		LM_ERR("invalid parameter value\n");
		return NULL;
	}


	if (!id->host || !*id->host) {
		if (id->port) goto bad_param;
		uri_len = snprintf(buf, sizeof(buf), "%s", id->database);
	} else if (id->port) {
		uri_len = snprintf(buf, sizeof(buf), "%s:%u/%s",
				id->host, id->port, id->database);
	} else {
		uri_len = snprintf(buf, sizeof(buf), "%s/%s",
				id->host, id->database);
	}
	if (uri_len >= sizeof(buf)) goto bad_param;
	LM_DBG("opening connection: oracle://xxxx:xxxx@%s\n", buf);

	con = (ora_con_t*)pkg_malloc(sizeof(*con) + uri_len+1);
	if (!con) {
		LM_ERR("no private memory left\n");
		return NULL;
	}

	memset(con, 0, sizeof(*con));
	con->hdr.ref = 1;
	con->hdr.id = (struct db_id*)id;	/* set here - freed on error */
	con->uri_len = uri_len;
	memcpy(con->uri, buf, uri_len+1);

	if (   OCIEnvCreate(&con->envhp,
			OCI_DEFAULT | OCI_NEW_LENGTH_SEMANTICS,
            		NULL, NULL, NULL, NULL, 0, NULL) != OCI_SUCCESS
	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->errhp,
		    OCI_HTYPE_ERROR, 0, NULL) != OCI_SUCCESS
	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->srvhp,
		    OCI_HTYPE_SERVER, 0, NULL) != OCI_SUCCESS
	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->svchp,
		    OCI_HTYPE_SVCCTX, 0, NULL) != OCI_SUCCESS
	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->authp,
        	    OCI_HTYPE_SESSION, 0, NULL) != OCI_SUCCESS)
	{

		LM_ERR("no oracle memory left\n");
		db_oracle_free_connection(con);
		return NULL;
	}

	status = OCIAttrSet(con->svchp, OCI_HTYPE_SVCCTX, con->srvhp, 0,
			OCI_ATTR_SERVER, con->errhp);
	if (status != OCI_SUCCESS) goto connect_err;
	status = OCIAttrSet(con->authp, OCI_HTYPE_SESSION,
                 id->username, (ub4)strlen(id->username),
                 OCI_ATTR_USERNAME, con->errhp);
	if (status != OCI_SUCCESS) goto connect_err;
	status = OCIAttrSet(con->authp, OCI_HTYPE_SESSION,
                 id->password, (ub4)strlen(id->password),
                 OCI_ATTR_PASSWORD, con->errhp);
	if (status != OCI_SUCCESS) goto connect_err;
	status = OCIAttrSet(con->svchp, OCI_HTYPE_SVCCTX, con->authp, 0,
                   OCI_ATTR_SESSION, con->errhp);
	if (status != OCI_SUCCESS) goto connect_err;
	status = db_oracle_reconnect(con);
	if (status != OCI_SUCCESS) {
connect_err:
		if (   (status != OCI_ERROR && status != OCI_SUCCESS_WITH_INFO)
		    || OCIErrorGet(con->errhp, 1, NULL, &status, (OraText*)buf,
			    sizeof(buf), OCI_HTYPE_ERROR) != OCI_SUCCESS)
		{
			LM_ERR("internal driver error\n");
		} else {
			LM_ERR("driver: %s\n", buf);
		}
drop_connection:
		db_oracle_free_connection(con);
		return NULL;
	}

	// timelimited operation
	status = begin_timelimit(con, 0);
	if (status != OCI_SUCCESS) goto connect_err;
	do status = OCIServerVersion(con->svchp, con->errhp, (OraText*)buf,
		(ub4)sizeof(buf), OCI_HTYPE_SVCCTX);
	while (wait_timelimit(con, status));
	if (done_timelimit(con, status)) goto drop_connection;
	if (status != OCI_SUCCESS) goto connect_err;
	LM_INFO("server version is %s\n", buf);
	return con;
}
コード例 #7
0
ファイル: oci_wrapper.cpp プロジェクト: AsherBond/MondocosmOS
OWConnection::OWConnection( const char* pszUserIn,
                            const char* pszPasswordIn,
                            const char* pszServerIn )
{
    pszUser         = CPLStrdup( pszUserIn );
    pszPassword     = CPLStrdup( pszPasswordIn );
    pszServer       = CPLStrdup( pszServerIn );
    hEnv            = NULL;
    hError          = NULL;
    hSvcCtx         = NULL;
    hDescribe       = NULL;
    hNumArrayTDO    = NULL;
    hGeometryTDO    = NULL;
    hGeoRasterTDO   = NULL;
    hElemArrayTDO   = NULL;
    hOrdnArrayTDO   = NULL;
    bSuceeeded      = false;
    nCharSize       = 1;

    // ------------------------------------------------------
    //  Operational Systems's authentication option
    // ------------------------------------------------------

    const char* pszUserId = "/";

    ub4 eCred = OCI_CRED_RDBMS;

    if( EQUAL(pszServer, "") &&
        EQUAL(pszPassword, "") &&
        EQUAL(pszUser, "") )
    {
        eCred = OCI_CRED_EXT;
    }
    else
    {
        pszUserId = pszUser;
    }

    // ------------------------------------------------------
    //  Initialize Environment handler
    // ------------------------------------------------------

    if( OCIEnvCreate( &hEnv,
        (ub4) ( OCI_DEFAULT | OCI_OBJECT | OCI_THREADED ),
        (dvoid *) 0, (dvoid * (*)(dvoid *, size_t)) 0,
        (dvoid * (*)(dvoid *, dvoid *, size_t)) 0,
        (void (*)(dvoid *, dvoid *)) 0, (size_t) 0,
        (dvoid **) 0), NULL )
    {
        return;
    }

    // ------------------------------------------------------
    //  Initialize Error handler
    // ------------------------------------------------------

    if( CheckError( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hError,
        OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0), NULL ) )
    {
        return;
    }

    // ------------------------------------------------------
    //  Initialize Server Context
    // ------------------------------------------------------

    if( CheckError( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hSvcCtx,
        OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0), hError ) )
    {
        return;
    }

    // ------------------------------------------------------
    //  Allocate Server and Authentication (Session) handler
    // ------------------------------------------------------

    if( CheckError( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hServer,
        (ub4) OCI_HTYPE_SERVER, (size_t) 0, (dvoid **) 0), hError ) )
    {
        return;
    }

    if( CheckError( OCIHandleAlloc((dvoid *) hEnv, (dvoid **)&hSession,
        (ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0), hError ) )
    {
        return;
    }

    // ------------------------------------------------------
    //  Attach to the server
    // ------------------------------------------------------

    if( CheckError( OCIServerAttach( hServer, hError, (text*) pszServer,
        strlen((char*) pszServer), 0), hError ) )
    {
        return;
    }

    if( CheckError( OCIAttrSet((dvoid *) hSession, (ub4) OCI_HTYPE_SESSION,
        (dvoid *) pszUserId, (ub4) strlen( pszUserId),
        (ub4) OCI_ATTR_USERNAME, hError), hError ) )
    {
        return;
    }

    if( CheckError( OCIAttrSet((dvoid *) hSession, (ub4) OCI_HTYPE_SESSION,
        (dvoid *) pszPassword, (ub4) strlen((char *) pszPassword),
        (ub4) OCI_ATTR_PASSWORD, hError), hError ) )
    {
        return;
    }

    if( CheckError( OCIAttrSet( (dvoid *) hSvcCtx, OCI_HTYPE_SVCCTX, (dvoid *)hServer,
        (ub4) 0, OCI_ATTR_SERVER, (OCIError *) hError), hError ) )
    {
        return;
    }

    // ------------------------------------------------------
    //  Initialize Session
    // ------------------------------------------------------

    if( CheckError( OCISessionBegin(hSvcCtx, hError, hSession, eCred,
        (ub4) OCI_DEFAULT), hError ) )
    {
        return;
    }

    // ------------------------------------------------------
    //  Initialize Service
    // ------------------------------------------------------

    if( CheckError( OCIAttrSet((dvoid *) hSvcCtx, (ub4) OCI_HTYPE_SVCCTX,
        (dvoid *) hSession, (ub4) 0,
        (ub4) OCI_ATTR_SESSION, hError), hError ) )
    {
        return;
    }

    bSuceeeded = true;

    // ------------------------------------------------------
    //  Get Character Size based on current Locale
    // ------------------------------------------------------

    OCINlsNumericInfoGet( hEnv, hError,
        &nCharSize, OCI_NLS_CHARSET_MAXBYTESZ );

    // ------------------------------------------------------
    //  Get Server Version
    // ------------------------------------------------------

    char szVersionTxt[OWTEXT];

    OCIServerVersion (
        hSvcCtx,
        hError,
        (text*) szVersionTxt,
        (ub4) OWTEXT,
        (ub1) OCI_HTYPE_SVCCTX );

    nVersion = OWParseServerVersion( szVersionTxt );

    // ------------------------------------------------------
    //  Initialize/Describe types
    // ------------------------------------------------------

    CheckError( OCIHandleAlloc(
        (dvoid*) hEnv,
        (dvoid**) (dvoid*) &hDescribe,
        (ub4) OCI_HTYPE_DESCRIBE,
        (size_t) 0,
        (dvoid**) NULL ), hError );

    hNumArrayTDO    = DescribeType( SDO_NUMBER_ARRAY );
    hGeometryTDO    = DescribeType( SDO_GEOMETRY );
    hGeoRasterTDO   = DescribeType( SDO_GEORASTER );
    hElemArrayTDO   = DescribeType( SDO_ELEM_INFO_ARRAY);
    hOrdnArrayTDO   = DescribeType( SDO_ORDINATE_ARRAY);

    if( nVersion > 10 )
    {
        hPCTDO      = DescribeType( SDO_PC );
    }
}
コード例 #8
0
ファイル: ogrocisession.cpp プロジェクト: Mavrx-inc/gdal
int OGROCISession::EstablishSession( const char *pszUseridIn,
                                     const char *pszPasswordIn,
                                     const char *pszDatabaseIn )

{
/* -------------------------------------------------------------------- */
/*      Operational Systems's authentication option                     */
/* -------------------------------------------------------------------- */

    ub4 eCred = OCI_CRED_RDBMS;

    if( EQUAL(pszDatabaseIn, "") &&
        EQUAL(pszPasswordIn, "") &&
        EQUAL(pszUseridIn, "/") )
    {
        eCred = OCI_CRED_EXT;
    }

/* -------------------------------------------------------------------- */
/*      Initialize Environment handler                                  */
/* -------------------------------------------------------------------- */

    if( Failed( OCIInitialize((ub4) (OCI_DEFAULT | OCI_OBJECT), (dvoid *)0,
                (dvoid * (*)(dvoid *, size_t)) 0,
                (dvoid * (*)(dvoid *, dvoid *, size_t))0,
                (void (*)(dvoid *, dvoid *)) 0 ) ) )
    {
        return FALSE;
    }

    if( Failed( OCIEnvInit( (OCIEnv **) &hEnv, OCI_DEFAULT, (size_t) 0,
                (dvoid **) 0 ) ) )
    {
        return FALSE;
    }

    if( Failed( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hError,
                OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0) ) )
    {
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Initialize Server Context                                       */
/* -------------------------------------------------------------------- */

    if( Failed( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hServer,
                OCI_HTYPE_SERVER, (size_t) 0, (dvoid **) 0) ) )
    {
        return FALSE;
    }

    if( Failed( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hSvcCtx,
                OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0) ) )
    {
        return FALSE;
    }

    if( Failed( OCIServerAttach( hServer, hError, (text*) pszDatabaseIn,
                static_cast<int>(strlen((char*) pszDatabaseIn)), 0) ) )
    {
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Initialize Service Context                                      */
/* -------------------------------------------------------------------- */

    if( Failed( OCIAttrSet( (dvoid *) hSvcCtx, OCI_HTYPE_SVCCTX, (dvoid *)hServer,
                (ub4) 0, OCI_ATTR_SERVER, (OCIError *) hError) ) )
    {
        return FALSE;
    }

    if( Failed( OCIHandleAlloc((dvoid *) hEnv, (dvoid **)&hSession,
                (ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0) ) )
    {
        return FALSE;
    }

    if( Failed( OCIAttrSet((dvoid *) hSession, (ub4) OCI_HTYPE_SESSION,
                (dvoid *) pszUseridIn, (ub4) strlen((char *) pszUseridIn),
                (ub4) OCI_ATTR_USERNAME, hError) ) )
    {
        return FALSE;
    }

    if( Failed( OCIAttrSet((dvoid *) hSession, (ub4) OCI_HTYPE_SESSION,
                (dvoid *) pszPasswordIn, (ub4) strlen((char *) pszPasswordIn),
                (ub4) OCI_ATTR_PASSWORD, hError) ) )
    {
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Initialize Session                                              */
/* -------------------------------------------------------------------- */

    if( Failed( OCISessionBegin(hSvcCtx, hError, hSession, eCred,
                (ub4) OCI_DEFAULT) ) )
    {
        CPLDebug("OCI", "OCISessionBegin() failed to initialize session");
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Initialize Service                                              */
/* -------------------------------------------------------------------- */

    if( Failed( OCIAttrSet((dvoid *) hSvcCtx, (ub4) OCI_HTYPE_SVCCTX,
                (dvoid *) hSession, (ub4) 0,
                (ub4) OCI_ATTR_SESSION, hError) ) )
    {
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Create a describe handle.                                       */
/* -------------------------------------------------------------------- */

    if( Failed(
        OCIHandleAlloc( hEnv, (dvoid **) &hDescribe, (ub4)OCI_HTYPE_DESCRIBE,
                        (size_t)0, (dvoid **)0 ),
        "OCIHandleAlloc(Describe)" ) )
        return FALSE;

/* -------------------------------------------------------------------- */
/*      Try to get the MDSYS.SDO_GEOMETRY type object.                  */
/* -------------------------------------------------------------------- */
    /* If we have no MDSYS.SDO_GEOMETRY then we consider we are
        working along with the VRT driver and access non spatial tables.
        See #2202 for more details (Tamas Szekeres)*/
    if (OCIDescribeAny(hSvcCtx, hError,
                       (text *) SDO_GEOMETRY, (ub4) strlen(SDO_GEOMETRY),
                       OCI_OTYPE_NAME, (ub1) OCI_DEFAULT, (ub1)OCI_PTYPE_TYPE,
                       hDescribe ) != OCI_ERROR)
    {
        hGeometryTDO = PinTDO( SDO_GEOMETRY );
        if( hGeometryTDO == NULL )
            return FALSE;

/* -------------------------------------------------------------------- */
/*      Try to get the MDSYS.SDO_ORDINATE_ARRAY type object.            */
/* -------------------------------------------------------------------- */
        hOrdinatesTDO = PinTDO( "MDSYS.SDO_ORDINATE_ARRAY" );
        if( hOrdinatesTDO == NULL )
            return FALSE;

/* -------------------------------------------------------------------- */
/*      Try to get the MDSYS.SDO_ELEM_INFO_ARRAY type object.           */
/* -------------------------------------------------------------------- */
        hElemInfoTDO = PinTDO( "MDSYS.SDO_ELEM_INFO_ARRAY" );
        if( hElemInfoTDO == NULL )
            return FALSE;
    }
/* -------------------------------------------------------------------- */
/*      Record information about the session.                           */
/* -------------------------------------------------------------------- */
    pszUserid = CPLStrdup(pszUseridIn);
    pszPassword = CPLStrdup(pszPasswordIn);
    pszDatabase = CPLStrdup(pszDatabaseIn);

/* -------------------------------------------------------------------- */
/*      Get server version information                                  */
/* -------------------------------------------------------------------- */

    char szVersionTxt[256];

    OCIServerVersion( hSvcCtx, hError, (text*) szVersionTxt, 
                    (ub4) sizeof(szVersionTxt), (ub1) OCI_HTYPE_SVCCTX );

    char** papszNameValue = CSLTokenizeString2( szVersionTxt, " .", 
                                                CSLT_STRIPLEADSPACES );

    int count = CSLCount( papszNameValue);

    for( int i = 0; i < count; i++)
    {
        if( EQUAL(papszNameValue[i], "Release") )
        {
            if( i + 1 < count )
            {
                nServerVersion = atoi(papszNameValue[i + 1]);
            }
            if( i + 2 < count )
            {
                nServerRelease = atoi(papszNameValue[i + 2]);
            }
            break;
        }
    }

    CPLDebug("OCI", "From '%s' :", szVersionTxt);
    CPLDebug("OCI", "Version:%d", nServerVersion);
    CPLDebug("OCI", "Release:%d", nServerRelease);

/* -------------------------------------------------------------------- */
/*      Set maximun name length (before 12.2 ? 30 : 128)                */
/* -------------------------------------------------------------------- */

    if( nServerVersion >= 12 && nServerRelease >= 2 )
    {
        nMaxNameLength = 128;
    }

    CPLFree( papszNameValue );

/* -------------------------------------------------------------------- */
/*      Setting up the OGR compatible time formatting rules.            */
/* -------------------------------------------------------------------- */
    OGROCIStatement oSetNLSTimeFormat( this );
    if( oSetNLSTimeFormat.Execute( "ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD' \
        NLS_TIME_FORMAT='HH24:MI:SS' NLS_TIME_TZ_FORMAT='HH24:MI:SS TZHTZM' \
        NLS_TIMESTAMP_FORMAT='YYYY/MM/DD HH24:MI:SS' \
        NLS_TIMESTAMP_TZ_FORMAT='YYYY/MM/DD HH24:MI:SS TZHTZM' \
        NLS_NUMERIC_CHARACTERS = '. '" ) != CE_None )
        return OGRERR_FAILURE;

    return TRUE;
}