Added support for starting up and shutting down the database using the new

methods available in Oracle 10g Release 2 and higher.
This commit is contained in:
Anthony Tuininga 2007-10-01 19:47:24 +00:00
parent 8c93273f5e
commit 2ecf97230d
3 changed files with 174 additions and 1 deletions

View File

@ -67,6 +67,8 @@ static int Connection_SetOCIAttr(udt_Connection*, PyObject*, ub4*);
#endif
#ifdef ORACLE_10GR2
static PyObject *Connection_Ping(udt_Connection*, PyObject*);
static PyObject *Connection_Shutdown(udt_Connection*, PyObject*, PyObject*);
static PyObject *Connection_Startup(udt_Connection*, PyObject*, PyObject*);
#endif
@ -87,6 +89,10 @@ static PyMethodDef g_ConnectionMethods[] = {
{ "__exit__", (PyCFunction) Connection_ContextManagerExit, METH_VARARGS },
#ifdef ORACLE_10GR2
{ "ping", (PyCFunction) Connection_Ping, METH_NOARGS },
{ "shutdown", (PyCFunction) Connection_Shutdown,
METH_VARARGS | METH_KEYWORDS},
{ "startup", (PyCFunction) Connection_Startup,
METH_VARARGS | METH_KEYWORDS},
#endif
{ NULL }
};
@ -1253,10 +1259,96 @@ static PyObject *Connection_Ping(
status = OCIPing(self->handle, self->environment->errorHandle,
OCI_DEFAULT);
if (Environment_CheckForError(self->environment, status,
"Connection_UnregisterCallback(): clear") < 0)
"Connection_Ping()") < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
//-----------------------------------------------------------------------------
// Connection_Shutdown()
// Shuts down the database. Note that this must be done in two phases except
// in the situation where the instance is aborted.
//-----------------------------------------------------------------------------
static PyObject *Connection_Shutdown(
udt_Connection *self, // connection
PyObject* args, // arguments
PyObject* keywordArgs) // keyword arguments
{
static char *keywordList[] = { "mode", NULL };
sword status;
ub4 mode;
// parse arguments
mode = OCI_DEFAULT;
if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|i", keywordList,
&mode))
return NULL;
// perform the work
if (Connection_IsConnected(self) < 0)
return NULL;
status = OCIDBShutdown(self->handle, self->environment->errorHandle, NULL,
mode);
if (Environment_CheckForError(self->environment, status,
"Connection_Shutdown()") < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
//-----------------------------------------------------------------------------
// Connection_Startup()
// Starts up the database, equivalent to "startup nomount" in SQL*Plus.
//-----------------------------------------------------------------------------
static PyObject *Connection_Startup(
udt_Connection *self, // connection
PyObject* args, // arguments
PyObject* keywordArgs) // keyword arguments
{
static char *keywordList[] = { "force", "restrict", NULL };
PyObject *forceObj, *restrictObj;
int flagTemp;
sword status;
ub4 flags;
// parse arguments
forceObj = restrictObj = NULL;
if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|OO", keywordList,
&forceObj, &restrictObj))
return NULL;
// set the flags to use during startup
flags = 0;
if (forceObj) {
flagTemp = PyObject_IsTrue(forceObj);
if (flagTemp < 0)
return NULL;
if (flagTemp)
flags |= OCI_DBSTARTUPFLAG_FORCE;
}
if (restrictObj) {
flagTemp = PyObject_IsTrue(restrictObj);
if (flagTemp < 0)
return NULL;
if (flagTemp)
flags |= OCI_DBSTARTUPFLAG_RESTRICT;
}
// perform the work
if (Connection_IsConnected(self) < 0)
return NULL;
status = OCIDBStartup(self->handle, self->environment->errorHandle, NULL,
OCI_DEFAULT, flags);
if (Environment_CheckForError(self->environment, status,
"Connection_Startup()") < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
#endif

View File

@ -500,5 +500,13 @@ void initcx_Oracle(void)
ADD_OCI_CONSTANT(SPOOL_ATTRVAL_NOWAIT)
ADD_OCI_CONSTANT(SPOOL_ATTRVAL_FORCEGET)
#endif
#ifdef ORACLE_10GR2
ADD_OCI_CONSTANT(PRELIM_AUTH)
ADD_OCI_CONSTANT(DBSHUTDOWN_ABORT)
ADD_OCI_CONSTANT(DBSHUTDOWN_FINAL)
ADD_OCI_CONSTANT(DBSHUTDOWN_IMMEDIATE)
ADD_OCI_CONSTANT(DBSHUTDOWN_TRANSACTIONAL)
ADD_OCI_CONSTANT(DBSHUTDOWN_TRANSACTIONAL_LOCAL)
#endif
}

View File

@ -195,6 +195,48 @@ information on the Python database API specification.
This type object is used to describe columns in a database that are dates.
\end{datadesc}
\begin{datadesc}{DBSHUTDOWN_ABORT}
This constant is used in database shutdown to indicate that the program
should not wait for current calls to complete or for users to disconnect from
the database. Use only in unusual circumstances since database recovery may
be necessary upon next startup.
\strong{NOTE:} This attribute is an extension to the DB API definition.
\end{datadesc}
\begin{datadesc}{DBSHUTDOWN_FINAL}
This constant is used in database shutdown to indicate that the instance can
be truly halted. This should only be done after the database has been shut
down in one of the other modes (except abort) and the database has been
closed and dismounted using the appropriate SQL commands.
\strong{NOTE:} This attribute is an extension to the DB API definition.
\end{datadesc}
\begin{datadesc}{DBSHUTDOWN_IMMEDIATE}
This constant is used in database shutdown to indicate that all uncommitted
transactions should be rolled back and any connected users should be
disconnected.
\strong{NOTE:} This attribute is an extension to the DB API definition.
\end{datadesc}
\begin{datadesc}{DBSHUTDOWN_TRANSACTIONAL}
This constant is used in database shutdown to indicate that further
connections should be prohibited and no new transactions should be allowed.
It then waits for active transactions to complete.
\strong{NOTE:} This attribute is an extension to the DB API definition.
\end{datadesc}
\begin{datadesc}{DBSHUTDOWN_TRANSACTIONAL_LOCAL}
This constant is used in database shutdown to indicate that further
connections should be prohibited and no new transactions should be allowed.
It then waits for only local active transactions to complete.
\strong{NOTE:} This attribute is an extension to the DB API definition.
\end{datadesc}
\begin{datadesc}{FIXED_CHAR}
This type object is used to describe columns in a database that are fixed
length strings (in Oracle this is CHAR columns); these behave differently
@ -299,6 +341,13 @@ information on the Python database API specification.
This type object is used to describe the pseudo column "rowid".
\end{datadesc}
\begin{datadesc}{PRELIM_AUTH}
This constant is used to define the preliminary authentication mode required
for performing database startup and shutdown.
\strong{NOTE:} This attribute is an extension to the DB API definition.
\end{datadesc}
\begin{datadesc}{SPOOL_ATTRVAL_FORCEGET}
This constant is used to define the "get" mode on session pools and indicates
that a new connection will be returned if there are no free sessions
@ -578,6 +627,30 @@ object is destroyed or closed.
Rollback any pending transactions.
\end{funcdesc}
\begin{funcdesc}{shutdown}{\optional{\var{mode}}}
Shutdown the database. In order to do this the connection must connected as
SYSDBA or SYSOPER. First shutdown using one of the DBSHUTDOWN constants
defined in the constants (\ref{constants}) section. Next issue the SQL
statements required to close the database ("alter database close normal")
and dismount the database ("alter database dismount") followed by a second
call to this method with the DBSHUTDOWN_FINAL mode.
\strong{NOTE:} This method is an extension to the DB API definition and is
only available in Oracle 10g R2 and higher.
\end{funcdesc}
\begin{funcdesc}{startup}{\var{force=False}, \var{restrict=False}}
Startup the database. This is equivalent to the SQL*Plus command
"startup nomount". The connection must be connected as SYSDBA or SYSOPER with
the PRELIM_AUTH option specified for this to work. Once this method has
completed, connect again without the PRELIM_AUTH option and issue the
statements required to mount ("alter database mount") and open ("alter
database open") the database.
\strong{NOTE:} This method is an extension to the DB API definition and is
only available in Oracle 10g R2 and higher.
\end{funcdesc}
\begin{datadesc}{stmtcachesize}
This read-write attribute specifies the size of the statement cache. This
value can make a significant difference in performance (up to 100x) if you