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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:10:   //!   //! The pgsql backend, shared between all connection instances.   //! It even runs in non-callback mode.   //!      protected Thread.Mutex backendmux = Thread.Mutex();   final Pike.Backend local_backend = Pike.SmallBackend();   protected int clientsregistered;      multiset cachealways=(<"BEGIN","begin","END","end","COMMIT","commit">); - object createprefix + Regexp createprefix    =Regexp("^[ \t\f\r\n]*[Cc][Rr][Ee][Aa][Tt][Ee][ \t\f\r\n]"); - protected object dontcacheprefix + protected Regexp dontcacheprefix    =Regexp("^[ \t\f\r\n]*([Ff][Ee][Tt][Cc][Hh]|[Cc][Oo][Pp][Yy])[ \t\f\r\n]"); - protected object execfetchlimit + protected Regexp execfetchlimit    =Regexp("^[ \t\f\r\n]*(([Uu][Pp][Dd][Aa]|[Dd][Ee][Ll][Ee])[Tt][Ee]|\   [Ii][Nn][Ss][Ee][Rr][Tt])[ \t\f\r\n]|\   [ \t\f\r\n][Ll][Ii][Mm][Ii][Tt][ \t\f\r\n]+[12][; \t\f\r\n]*$");    - final void closestatement(object plugbuffer,string oldprep) { + final void closestatement(PGplugbuffer|PGassist plugbuffer,string oldprep) {    if(oldprep) {    PD("Close statement %s\n",oldprep);    plugbuffer->add_int8('C')->add_hstring(({'S',oldprep,0}),4,4);    }   }      protected void run_local_backend() {    Thread.MutexKey lock;    int looponce;    do {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:108:    final PGplugbuffer start(void|int waitforreal) {    realbuffer->stashcount++;   #ifdef PG_DEBUG    if(waitforreal)    error("pgsql.PGplugbuffer not allowed here\n");   #endif    return this;    }       final -  void sendcmd(void|sctype mode,void|object portal) { +  void sendcmd(void|sctype mode,void|pgsql_result portal) {    Thread.MutexKey lock=realbuffer->stashupdate->lock();    if(portal)    realbuffer->stashqueue->write(portal);    realbuffer->stash->add(this);    mode=mergemode(realbuffer,mode);    if(!--realbuffer->stashcount)    realbuffer->stashavail.signal();    lock=0;    this->clear();    if(lock=realbuffer->nostash->trylock(1)) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:376:    final Thread.Condition _ddescribe;    final Thread.Mutex _ddescribemux;    final Thread.MutexKey _unnamedportalkey,_unnamedstatementkey;    protected Thread.Mutex closemux;    final array _params;    final string _statuscmdcomplete;    final string _query;    final Thread.Queue _datarows;    final array(mapping(string:mixed)) _datarowdesc;    final int _oldpbpos; -  protected object prepbuffer; +  protected Stdio.Buffer prepbuffer;    protected Thread.Condition prepbufferready;    protected Thread.Mutex prepbuffermux;    final string _preparedname;    final mapping(string:mixed) _tprepared;       protected string _sprintf(int type, void|mapping flags) {    string res=UNDEFINED;    switch(type) {    case 'O':    res=sprintf("pgsql_result numrows: %d eof: %d inflight: %d\n"
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:507:    }       final void _preparebind(array dtoid) {    array(string|int) paramValues=_params?_params[2]:({});    if(sizeof(dtoid)!=sizeof(paramValues))    SUSERERROR("Invalid number of bindings, expected %d, got %d\n",    sizeof(dtoid),sizeof(paramValues));   #ifdef PG_DEBUGMORE    PD("ParamValues to bind: %O\n",paramValues);   #endif -  object plugbuffer=Stdio.Buffer(); +  Stdio.Buffer plugbuffer=Stdio.Buffer();    plugbuffer->add(_portalname=    (_unnamedportalkey=pgsqlsess._unnamedportalmux->trylock(1))    ? "" : PORTALPREFIX+int2hex(pgsqlsess._pportalcount++) )->add_int8(0)    ->add(_preparedname)->add_int8(0)->add_int16(sizeof(paramValues));    foreach(dtoid;;int textbin)    plugbuffer->add_int16(oidformat(textbin));    plugbuffer->add_int16(sizeof(paramValues));    string cenc=pgsqlsess._runtimeparameter[CLIENT_ENCODING];    foreach(paramValues;int i;mixed value) {    if(undefinedp(value) || objectp(value)&&value->is_val_null)
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:657:    if(tp)    tp.datarowdesc=datarowdesc;    }       protected void gotdatarowdesc() {    if(!prepbuffer) {    Thread.MutexKey lock=prepbuffermux->lock();    prepbufferready->wait(lock);    lock=0;    } -  object plugbuffer=prepbuffer; +  Stdio.Buffer plugbuffer=prepbuffer;    prepbuffer=0;    plugbuffer->add_int16(sizeof(_datarowdesc));    foreach(_datarowdesc;;mapping col)    plugbuffer->add_int16(oidformat(col.type));    PD("Bind portal %O statement %O\n",_portalname,_preparedname);    _fetchlimit=pgsqlsess->_fetchlimit;    _openportal(); -  object bindbuffer=c->start(1); +  PGassist bindbuffer=c->start(1);    _unnamedstatementkey=0;    bindbuffer->add_int8('B')->add_hstring(plugbuffer,4,4);    if(!_tprepared)    closestatement(bindbuffer,_preparedname);    _sendexecute(pgsqlsess->_fetchlimit    && !(cachealways[_query]    || sizeof(_query)>=MINPREPARELENGTH &&    execfetchlimit->match(_query))    && FETCHLIMITLONGRUN,bindbuffer);    }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:752:    else if(!_fetchlimit)    PD("<%O _fetchlimit %d, _inflight %d, skip execute\n",    _portalname,_fetchlimit,_inflight);    lock=0;    }    }       final void _releasesession() {    _inflight=0;    _datarows->write(1); // Signal EOF -  object plugbuffer=c->start(1); +  PGassist plugbuffer=c->start(1);    plugbuffer->sendcmd(_closeportal(plugbuffer));    pgsqlsess=UNDEFINED;    }       protected void destroy() {    catch { // inside destructors, exceptions don't work    _releasesession();    };    }