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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:26: Inside #if defined(DEBUG)
     #ifdef DEBUG   #define PD(X ...) werror(X)   #define UNBUFFEREDIO 1 // Make all IO unbuffered   #else   #undef DEBUGMORE   #define PD(X ...)   #endif   //#define NO_LOCKING 1 // This breaks the driver, do not enable,    // only for benchmarking mutex performance - #define USEPGsql 1 // Doesn't use Stdio.FILE, but PG assist + #define USEPGsql 1 // Doesn't use Stdio.FILE, but PGassist      #ifdef USEPGsql   #define UNBUFFEREDIO 1   #endif      #define FETCHLIMIT 1024 // Initial upper limit on the    // number of rows to fetch across the    // network at a time    // 0 for no chunking    // Needs to be >0 for interleaved
pike.git/lib/modules/Sql.pmod/pgsql.pike:313:      inline final private string plugint64(int x) {    return sprintf("%c%c%c%c%c%c%c%c",    x>>56&255,x>>48&255,x>>40&255,x>>32&255,x>>24&255,x>>16&255,x>>8&255,x&255);   }      #ifdef USEPGsql   class PGassist {    inherit Stdio.File:std;    inherit _PGsql.PGsql:pg; -  void create() { +  void create(object pgsqlsess) {    std::create(); -  +  pg::setpgsqlsess(pgsqlsess);    }    int connect(string host,int port) {    int res=std::connect(host,port);    if(res)    pg::create(std::query_fd());    return res;    }   }   #endif      final private object getsocket() {   #ifdef USEPGsql -  object lcon = PGassist(); +  object lcon = PGassist(this);   #else   #ifdef UNBUFFEREDIO    object lcon = Stdio.File();   #else    object lcon = Stdio.FILE();   #endif    flushed=-1;   #endif    return lcon.connect(host,port) && lcon;   }
pike.git/lib/modules/Sql.pmod/pgsql.pike:540:    SSauthdata=GETSTRING(msglen);msglen=0;    break;    default:PD("Unknown Authentication Method %c\n",authtype);    errtype=protocolunsupported;    break;    }    switch(errtype) {    case noerror:    if(mstate==unauthenticated)    SENDCMD(({"p",plugint32(4+sizeof(sendpass)+1), -  sendpass,"\0"})); +  sendpass,"\0"}),1);    break;    default:    case protocolunsupported:    ERROR("Unsupported authenticationmethod %c\n",authtype);    break;    }    break;    }    case 'K':PD("BackendKeyData\n");    msglen-=4+4;backendpid=GETINT32();cancelsecret=GETSTRING(msglen);
pike.git/lib/modules/Sql.pmod/pgsql.pike:862:   //! Resets the connection to the database. Can be used for   //! a variety of reasons, for example to detect the status of a connection.   void reload(void|int special) {    mixed err;    int didsync;    if(err = catch {    sendclose();    PD("Portalsinflight: %d\n",portalsinflight);    if(!portalsinflight) {    PD("Sync\n"); -  SENDCMD(({"S",plugint32(4)}),1); +  SENDCMD(({"S",plugint32(4)}));    didsync=1;    if(!special) {    _decodemsg(readyforquery);    foreach(prepareds;;mapping tprepared) {    m_delete(tprepared,"datatypeoid");    m_delete(tprepared,"datarowdesc");    }    }    }    }) {
pike.git/lib/modules/Sql.pmod/pgsql.pike:1178:    PD("Execute portal %s fetchlimit %d\n",portalname,fetchlimit);    SENDCMD(({"E",plugint32(4+sizeof(portalname)+1+4),portalname,    "\0",plugint32(fetchlimit)}),1);    _portal->_inflight+=fetchlimit;   }      final private void sendclose() {    string portalname;    portalsinflight--;    if(_portal && (portalname=_portal->_portalname)) { +  int inflight=_portal->_inflight;    _portal->_portalname = UNDEFINED;    _portal = UNDEFINED; -  if(!sizeof(portalname)) -  unnamedportalinuse--; +    #ifdef DEBUGMORE    PD("Closetrace %O\n",backtrace());   #endif -  +  if(!sizeof(portalname)) +  unnamedportalinuse--; +  if(/*sizeof(portalname)||inflight*/ 1) {    PD("Close portal %s\n",portalname);    SENDCMD(({"C",plugint32(4+1+sizeof(portalname)+1), -  "P",portalname,"\0"})); +  "P",portalname,"\0"}),1);    _closesent=1;    }    } -  + }      final private string trbackendst(int c) {    switch(c) {    case 'I':return "idle";    case 'T':return "intransaction";    case 'E':return "infailedtransaction";    }    return "unknown";   }   
pike.git/lib/modules/Sql.pmod/pgsql.pike:1300:    string oldprep=tprepared->preparedname;    if(oldprep) {    PD("Close statement %s\n",oldprep);    plugbuf+=({"C",plugint32(4+1+sizeof(oldprep)+1),    "S",oldprep,"\0"});    }    m_delete(prepareds,ind);    }    }    if(sizeof(plugbuf)) -  SENDCMD(plugbuf); // close expireds +  SENDCMD(plugbuf,1); // close expireds    PD("%O\n",plugbuf);    }    prepareds[q]=tprepared=([]);    }    tstart=gethrtime();    } // pgsql_result autoassigns to portal    pgsql_result(this,tprepared,q,_fetchlimit,portalbuffersize);    if(unnamedportalinuse)    portalname=PORTALPREFIX+(string)pportalcount++;    else    unnamedportalinuse++;    _portal->_portalname=portalname;    qstate=inquery;    portalsinflight++;    mixed err;    if(err = catch {    if(!sizeof(preparedname) || !tprepared || !tprepared->preparedname) {    PD("Parse statement %s\n",preparedname);    SENDCMD(({"P",plugint32(4+sizeof(preparedname)+1+sizeof(q)+1+2), -  preparedname,"\0",q,"\0",plugint16(0)})); +  preparedname,"\0",q,"\0",plugint16(0)}),1);    PD("Query: %O\n",q);    } // sends Parameter- and RowDescription for 'S'    conn.set_read_callback(0);    if(!tprepared || !tprepared->datatypeoid) {    PD("Describe statement %s\n",preparedname);    SENDCMD(({"D",plugint32(4+1+sizeof(preparedname)+1),    "S",preparedname,"\0"}),1);    }    else {    _portal->_datatypeoid=tprepared->datatypeoid;
pike.git/lib/modules/Sql.pmod/pgsql.pike:1567:   }      array(mapping(string:mixed)) fetch_fields() {    return _datarowdesc+({});   }      private void releasesession() {    if(_pgsqlsess) {    if(copyinprogress) {    PD("CopyDone\n"); -  _pgsqlsess.SENDCMD("c\0\0\0\4"); +  _pgsqlsess.SENDCMD("c\0\0\0\4",1);    }    _pgsqlsess.reload(2);    }    _qmtxkey=UNDEFINED;    _pgsqlsess=UNDEFINED;   }      void destroy() {    catch { // inside destructors, exceptions don't work    releasesession();
pike.git/lib/modules/Sql.pmod/pgsql.pike:1698:    _pgsqlsess._sendexecute(_fetchlimit);   #endif    return UNDEFINED;    }   #if STREAMEXECUTES    if(_fetchlimit && _inflight<=_fetchlimit-1)    _pgsqlsess._sendexecute(_fetchlimit); // Overlap Executes   #endif    return getdatarow();    case commandcomplete: +  _inflight=0;    releasesession();    switch(buffer) {    case 1:    case 2:    return UNDEFINED;    case 3:    if(sizeof(_datarows))    return getdatarow();    }    break;