Hi everybody,
        I'm a CGI developer (among others), and I've made a perl cgi which queries a
database and sends formatted results. Queries made by that script are sometimes
very, very heavy, and I want to setup a timeout, so query is cancelled after a
predefined time. Reading pod documentation I discovered 'cancel' is not
implemented in DBD::Pg, but I knew asynchronous cancel was supported by
PostgreSQL.
        
        I tried to create the missing 'cancel' implementation, looking the same code at
Oracle and Sybase driver, and how it is used inside 'psql' program, and my
little effort to implement it was the next:

/* This was added to Pg.xs, after finish definition */

void
cancel(sth)
    SV *        sth
    CODE:
    D_imp_sth(sth);
    D_imp_dbh_from_sth;
    if (!DBIc_ACTIVE(imp_dbh)) {
        /* Either an explicit disconnect() or global destruction        */
        /* has disconnected us from the database. Finish is meaningless */
        /* XXX warn */
        XSRETURN_YES;
    }
    if (!DBIc_ACTIVE(imp_sth)) {
        /* No active statement to finish        */
        XSRETURN_YES;
    }
    ST(0) = dbd_st_cancel(sth, imp_sth) ? &sv_yes : &sv_no;



/* This was added to dbdimp.c, after dbd_st_finish definition */

int                                                                             
dbd_st_cancel(sth, imp_sth)
    SV *sth;
    imp_sth_t *imp_sth;
{
        D_imp_dbh_from_sth;
        if (dbis->debug >= 1) { fprintf(DBILOGFP, "dbd_st_cancel\n"); }
        
        return PQrequestCancel(imp_dbh->conn);
}

        The function compiles and always returns true for a valid connection, but
backend from Postgres doesn't stop (at least until it finishes). Tests were made
with PostgreSQL 7.1.3 and DBD::Pg 1.0.1 in Linux.

        What did I forget to do? Has someone the knowledge to implement it properly?
It's very useful in other scenarios, like Ctrl+C handling or a cgi which is
stopped by user request.

        Thanks in advance,
                Jos� Mar�a
-- 
Jos� Mar�a Fern�ndez Gonz�lez           e-mail: [EMAIL PROTECTED]
Tlfn:   (+34) 91 585 49 21              Fax:    (+34) 91 585 45 06
Grupo de Dise�o de Proteinas            Protein Design Group
Centro Nacional de Biotecnolog�a        National Center of Biotechnology
C.P.: 28049                             Zip Code: 28049
Campus Universidad Aut�noma. Cantoblanco, Madrid, Spain.

Reply via email to