The Python Oracle

What is the return value of Connection.ping() in cx_oracle?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles

--

Chapters
00:00 What Is The Return Value Of Connection.Ping() In Cx_oracle?
00:48 Accepted Answer Score 6
02:09 Answer 2 Score 9
02:23 Thank you

--

Full question
https://stackoverflow.com/questions/4266...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #oracle #cxoracle

#avk47



ANSWER 1

Score 9


Thanks to Ben's answer, given a connectionObject from the cx_Oracle library, this should at least incapsulate what you might want.

def isOpen(connectionObject):
    try:
        return connectionObject.ping() is None
    except:
        return False



ACCEPTED ANSWER

Score 6


The cx_Oracle documentation states that this is:

This method is an extension to the DB API definition and is only available in Oracle 10g R2 and higher.

However, this method isn't documented in PEP 249 - the current Python Database API specification in either the connection methods or optional extensions (or anywhere else for that matter).

The MySQL implementation of PEP 249 also has this method; the documentation states that:

When the connection is not available, an InterfaceError is raised. Use the is_connected() method to check the connection without raising an error.

Raises InterfaceError on errors.

As this is identical to the cx_Oracle behaviour I would assume that this is the answer to your question and what you've determined the behaviour to be is correct:

  • There is no return if the connection is active
  • An InterfaceError is raised if the connection is not active

If we look at the code for .ping(), it confirms that this is the manner in which the method has been implemented:

static PyObject *Connection_Ping(
    udt_Connection *self,               // connection
    PyObject* args)                     // arguments
{
    sword status;

    if (Connection_IsConnected(self) < 0)
        return NULL;
    status = OCIPing(self->handle, self->environment->errorHandle,
            OCI_DEFAULT);
    if (Environment_CheckForError(self->environment, status,
            "Connection_Ping()") < 0)
        return NULL;
    Py_INCREF(Py_None);
    return Py_None;
}