pike.git / lib / modules / Sql.pmod / pgsql.pike

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:283:    fcon=.pgsql_util.PGconn(lcon,this);    return fcon;   }      //! Cancels the currently running query.   //!   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface.   //!   //! @seealso - //! @[reload] + //! @[reload], @[resync]   void cancelquery() {    if(qstate==inquery) {    qstate=cancelpending;    object lcon;    PD("CancelRequest\n");    if(!(lcon=getsocket(1)))    ERROR("Cancel connect failed\n");    lcon.write(({_c.plugint32(16),_c.plugint32(PG_PROTOCOL(1234,5678)),    _c.plugint32(backendpid),cancelsecret}));    lcon.close();
pike.git/lib/modules/Sql.pmod/pgsql.pike:1025:    PD("%O\n",runtimeparameter);    if(force) {    lastmessage+=({sprintf("Reconnected to database %s",host_info())});    runcallback(backendpid,"_reconnect","");    }    return 1;   }      //! @decl void reload()   //! - //! Resets the connection to the database. Can be used for - //! a variety of reasons, for example to detect the status of a connection. + //! For PostgreSQL this function performs the same function as @[resync()].   //!   //! @seealso - //! @[cancelquery] - void reload(void|int special) { + //! @[resync], @[cancelquery] + void reload() { +  resync(); + } +  + //! @decl void resync() + //! + //! Resyncs the database session; typically used to make sure the session is + //! not still in a dangling transaction. + //! + //! If called while queries/portals are still in-flight, this function + //! is a no-op. + //! + //! If called while the connection is in idle state, the function is + //! lightweight and briefly touches base with the database server to + //! make sure client and server are in sync. + //! + //! If issued while inside a transaction, it will rollback the transaction, + //! close all open cursors, drop all temporary tables and reset all + //! session variables to their default values. + //! + //! This function is PostgreSQL-specific, and thus it is not available + //! through the generic SQL-interface. + //! + //! @seealso + //! @[cancelquery], @[reload] + void resync(void|int special) {    mixed err;    int didsync;    if(err = catch {    sendclose(1);    PD("Portalsinflight: %d\n",portalsinflight);    if(!portalsinflight) {    if(!earlyclose) {    PD("Sync\n");    _c.sendcmd(({"S",_c.plugint32(4)}),2);    }    didsync=1;    if(!special) {    _decodemsg(readyforquery); -  +  switch(backendstatus) { +  case 'T':case 'E':    foreach(prepareds;;mapping tp) {    m_delete(tp,"datatypeoid");    m_delete(tp,"datarowdesc");    } -  +  big_query("ROLLBACK"); +  big_query("RESET ALL"); +  big_query("CLOSE ALL"); +  big_query("DISCARD TEMP");    }    } -  +  }    earlyclose=0;    }) {    earlyclose=0;    PD("%O\n",err);    if(!reconnect(1))    ERROR(a2nls(lastmessage));    }    else if(didsync && special==2)    _decodemsg(readyforquery);   #ifndef UNBUFFEREDIO
pike.git/lib/modules/Sql.pmod/pgsql.pike:1722:    tstart=tend-tstart;    if(!tp->tparse || tp->tparse>tstart)    tp->tparse=tstart;    }    tp->trunstart=tend;    }    tprepared=tp;    }    }) {    PD("%O\n",err); -  reload(1); +  resync(1);    backendstatus=UNDEFINED;    throw(err);    }    { object tportal=_c.portal; // Make copy, because it might dislodge    tportal->fetch_row(1); // upon initial fetch_row()    return tportal;    }   }      //! This is an alias for @[big_query()], since @[big_query()] already supports