Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes

OCIPL::OciLogin Struct Reference

simple OCI login to database More...

#include <ocipl.h>

Inheritance diagram for OCIPL::OciLogin:
Inheritance graph
[legend]
Collaboration diagram for OCIPL::OciLogin:
Collaboration graph
[legend]

List of all members.

Public Types

typedef OciHandle< OCISvcCtx > super
typedef OCISvcCtx HandleType

Public Member Functions

 OciLogin (OciEnv &env)
 OciLogin (OciEnv &env, const LoginPara &login_para)
 OciLogin (OciEnv &env, const tstring &username, const tstring &password, const tstring &tnsname, ub4 mode=OCI_DEFAULT)
void connect (const LoginPara &login_para)
void connect (const tstring &username, const tstring &password, const tstring &tnsname, ub4 mode=OCI_DEFAULT)
 ~OciLogin ()
void disconnect ()
bool connected () const
void commit (ub4 flags=OCI_DEFAULT)
void rollback (ub4 flags=OCI_DEFAULT)
void alloc ()
void destroy ()
void set_attribute (ub4 attrtype, const tstring &str)
void set_attribute (ub4 attrtype, ub4 value)
void set_attribute (ATTR &attr)
void get_attribute (dvoid *attributep, ub4 *sizep, ub4 attrtype)
void set_attribute_handle (ub4 attrtype, void *handle)
 operator HandleType * ()

Static Public Member Functions

static ub4 get_type_id ()
static ub4 get_attr_id ()

Public Attributes

OracleServer _server
tstring _warnings
tstring _tnsname
OciEnv_env

Protected Attributes

OciContext _ctx
OciHandle< OCISession > _session
bool _connected
HandleType_handle

Detailed Description

simple OCI login to database

Definition at line 944 of file ocipl.h.


Member Typedef Documentation

typedef OCISvcCtx OCIPL::OciHandle< OCISvcCtx >::HandleType [inherited]

Definition at line 563 of file ocipl.h.

typedef OciHandle<OCISvcCtx> OCIPL::OciLogin::super

Reimplemented from OCIPL::OciHandle< OCISvcCtx >.

Definition at line 946 of file ocipl.h.


Constructor & Destructor Documentation

OCIPL::OciLogin::OciLogin ( OciEnv env ) [inline]

Definition at line 949 of file ocipl.h.

     :  super(env),
        _server(env),
        _ctx(env, _handle),
        _session(env),
        _connected(false)
    {
    }
OCIPL::OciLogin::OciLogin ( OciEnv env,
const LoginPara login_para 
) [inline]

Definition at line 959 of file ocipl.h.

     :  super(env),
        _server(env),
        _ctx(env, _handle),
        _session(env),
        _connected(false)
    {
        connect(login_para);
    }
OCIPL::OciLogin::OciLogin ( OciEnv env,
const tstring username,
const tstring password,
const tstring tnsname,
ub4  mode = OCI_DEFAULT 
) [inline]

Definition at line 970 of file ocipl.h.

     :  super(env),
        _server(env),
        _ctx(env, _handle),
        _session(env),
        _connected(false)
    {
        connect(username, password, tnsname, mode);
    }
OCIPL::OciLogin::~OciLogin (  ) [inline]

Definition at line 1032 of file ocipl.h.

    {
        disconnect();
    }

Member Function Documentation

void OCIPL::OciHandle< OCISvcCtx >::alloc (  ) [inline, inherited]

Definition at line 596 of file ocipl.h.

    {
        if (_handle)
            destroy();

        sword res = OCIHandleAlloc(_env, (dvoid**)&_handle, super::get_type_id(), 0, 0);
        oci_check_error(_env, res);
    }
void OCIPL::OciLogin::commit ( ub4  flags = OCI_DEFAULT ) [inline]

Definition at line 1061 of file ocipl.h.

    {
        _ctx.commit(flags);
    }
void OCIPL::OciLogin::connect ( const LoginPara login_para ) [inline]

Definition at line 981 of file ocipl.h.

References OCIPL::LoginPara::_mode, OCIPL::LoginPara::_password, OCIPL::LoginPara::_tnsname, and OCIPL::LoginPara::_username.

    {
        connect(login_para._username, login_para._password, login_para._tnsname, login_para._mode);
    }
void OCIPL::OciLogin::connect ( const tstring username,
const tstring password,
const tstring tnsname,
ub4  mode = OCI_DEFAULT 
) [inline]

Definition at line 987 of file ocipl.h.

References OCIPL::oci_check_error(), and TCHAR.

    {
         // set server name
        _server.attach(tnsname);
        _tnsname = tnsname; // store database name for further reference in the application

         // set session parameters
        _session.set_attribute(OCI_ATTR_USERNAME, username);
        _session.set_attribute(OCI_ATTR_PASSWORD, password);

         // login using _server and _session
        set_attribute(_server);

        sword res = OCISessionBegin(_handle, _env._errh, _session, OCI_CRED_RDBMS, mode);

        if (res!=OCI_SUCCESS && res!=OCI_SUCCESS_WITH_INFO) {
            _server.detach();
            oci_check_error(_env, res);
        }

         // look for warning messages ("ORA-28002: the password will expire within ... days")
        if (res == OCI_SUCCESS_WITH_INFO) {
            TOraText buffer[1024];

            sb4 errorcode;
            sword res = OCIErrorGet(_env._errh, 1, NULL, &errorcode, (OraText*)buffer, sizeof(buffer), OCI_HTYPE_ERROR);

            if (res == OCI_SUCCESS)
                _warnings = (const TCHAR*)buffer;
        }

        _connected = true;

        set_attribute(_session);

        /* automatically allocate and initialize server and session handles
        sword res = OCILogon(_env, _env._errh, &_ctx,
                              (TOraText*)username.c_str(), username.length(),
                              (TOraText*)password.c_str(), password.length(),
                              (TOraText*)tnsname.c_str(), tnsname.length());
        oci_check_error(_env, res);
        */
    }

Here is the call graph for this function:

bool OCIPL::OciLogin::connected (  ) const [inline]

Definition at line 1055 of file ocipl.h.

    {
        return _connected;
    }
void OCIPL::OciHandle< OCISvcCtx >::destroy (  ) [inline, inherited]

Definition at line 606 of file ocipl.h.

    {
        sword res = OCIHandleFree(_handle, super::get_type_id());
        _handle = 0;

        oci_check_error(_env, res);
    }
void OCIPL::OciLogin::disconnect (  ) [inline]

Definition at line 1038 of file ocipl.h.

References OCIPL::oci_check_error().

    {
        if (_connected) {
            /* automatically free server and session handles
            sword res = OCILogoff(_svchp, _env._errh);
            _svchp = 0;
            */
            sword res = OCISessionEnd(_handle, _env._errh, _session, OCI_DEFAULT);
            oci_check_error(_env, res);

            _server.detach();

            _connected = false;
        }
    }

Here is the call graph for this function:

static ub4 OCIPL::OciHandleID< OCISvcCtx >::get_attr_id (  ) [static, inherited]
void OCIPL::OciHandle< OCISvcCtx >::get_attribute ( dvoid *  attributep,
ub4 *  sizep,
ub4  attrtype 
) [inline, inherited]

Definition at line 629 of file ocipl.h.

    {
        sword res = OCIAttrGet(_handle, super::get_type_id(), attributep, sizep, attrtype, _env._errh);
        oci_check_error(_env, res);
    }
static ub4 OCIPL::OciHandleID< OCISvcCtx >::get_type_id (  ) [static, inherited]
OCIPL::OciHandle< OCISvcCtx >::operator HandleType * (  ) [inline, inherited]

Definition at line 650 of file ocipl.h.

    {
        return _handle;
    }
void OCIPL::OciLogin::rollback ( ub4  flags = OCI_DEFAULT ) [inline]

Definition at line 1067 of file ocipl.h.

    {
        _ctx.rollback(flags);
    }
void OCIPL::OciHandle< OCISvcCtx >::set_attribute ( ATTR &  attr ) [inline, inherited]

Definition at line 643 of file ocipl.h.

    {
        sword res = OCIAttrSet(_handle, super::get_type_id(), attr, 0, ATTR::get_attr_id(), _env._errh);
        oci_check_error(_env, res);
    }
void OCIPL::OciHandle< OCISvcCtx >::set_attribute ( ub4  attrtype,
ub4  value 
) [inline, inherited]

Definition at line 622 of file ocipl.h.

    {
        sword res = OCIAttrSet(_handle, super::get_type_id(), (OraText*)&value, (ub4)sizeof(value), attrtype, _env._errh);
        oci_check_error(_env, res);
    }
void OCIPL::OciHandle< OCISvcCtx >::set_attribute ( ub4  attrtype,
const tstring str 
) [inline, inherited]

Definition at line 615 of file ocipl.h.

    {
        sword res = OCIAttrSet(_handle, super::get_type_id(), (TOraText*)str.c_str(), (ub4)str.length()*sizeof(TOraText), attrtype, _env._errh);
        oci_check_error(_env, res);
    }
void OCIPL::OciHandle< OCISvcCtx >::set_attribute_handle ( ub4  attrtype,
void *  handle 
) [inline, inherited]

Definition at line 636 of file ocipl.h.

    {
        sword res = OCIAttrSet(_handle, super::get_type_id(), handle, 0, attrtype, _env._errh);
        oci_check_error(_env, res);
    }

Member Data Documentation

bool OCIPL::OciLogin::_connected [protected]

Definition at line 1080 of file ocipl.h.

Definition at line 1077 of file ocipl.h.

OciEnv& OCIPL::OciHandle< OCISvcCtx >::_env [inherited]

Definition at line 659 of file ocipl.h.

HandleType* OCIPL::OciHandle< OCISvcCtx >::_handle [protected, inherited]

Definition at line 656 of file ocipl.h.

Definition at line 1072 of file ocipl.h.

OciHandle<OCISession> OCIPL::OciLogin::_session [protected]

Definition at line 1078 of file ocipl.h.

Definition at line 1074 of file ocipl.h.

Definition at line 1073 of file ocipl.h.


The documentation for this struct was generated from the following file: