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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:95:    case MACADDROID:    case BPCHAROID:    case VARCHAROID:    case CTIDOID:    case UUIDOID:    return 1; //binary    }    return 0; // text   }    - private sctype mergemode(conxion realbuffer,sctype mode) { + private int mergemode(conxion realbuffer,int mode) {    if(mode>realbuffer->stashflushmode)    realbuffer->stashflushmode=mode;    return realbuffer->stashflushmode;   }      private inline mixed callout(function(mixed ...:void) f,    float|int delay,mixed ... args) {    return local_backend->call_out(f,delay,@args);   }   
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:126:       final bufcon start(void|int waitforreal) {    realbuffer->stashcount++;   #ifdef PG_DEBUG    if(waitforreal)    error("pgsql.bufcon not allowed here\n");   #endif    return this;    }    -  final void sendcmd(void|sctype mode,void|sql_result portal) { +  final void sendcmd(int mode,void|sql_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)) {    realbuffer->started=lock; lock=0; -  realbuffer->sendcmd(sendout); +  realbuffer->sendcmd(SENDOUT);    }    }      }      class conxion {    inherit Stdio.Buffer:i;    inherit Stdio.Buffer:o;       private Thread.Condition fillread;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:239:    final inline int consume(int w) { return i::consume(w); }    final inline int unread(int w) { return i::unread(w); }    final inline string read(int w) { return i::read(w); }    final inline object read_buffer(int w) { return i::read_buffer(w); }    final inline int read_sint(int w) { return i::read_sint(w); }    final inline int read_int8() { return i::read_int8(); }    final inline int read_int16() { return i::read_int16(); }    final inline int read_int32() { return i::read_int32(); }    final inline string read_cstring() { return i::read_cstring(); }    -  final void sendcmd(void|sctype mode,void|sql_result portal) { +  final void sendcmd(void|int mode,void|sql_result portal) {    if(portal)    queueup(portal);   nosync:    do {    switch(mode) {    default:    break nosync; -  case syncsend: +  case SYNCSEND:    PD("%d>Sync %d %d Queue\n",    socket->query_fd(),synctransact,++queueoutidx);    add(PGSYNC); -  mode=sendout; +  mode=SENDOUT;    break; -  case flushlogsend: +  case FLUSHLOGSEND:    PD("%d>%O %d Queue simplequery %d bytes\n",    socket->query_fd(),portal._portalname,++queueoutidx,sizeof(this)); -  mode=flushsend; +  mode=FLUSHSEND;    }    qportals->write(synctransact++);    } while(0);    if(started) {    Thread.MutexKey lock=stashupdate->lock();    if(sizeof(stash)) {    add(stash); stash->clear();    foreach(stashqueue->try_read_array();;sql_result portal)    queueup(portal);    }    mode=mergemode(this,mode); -  stashflushmode=keep; +  stashflushmode=KEEP;    lock=0;    }    catch {   outer:    do {    switch(mode) {    default:    break outer; -  case flushsend: +  case FLUSHSEND:    PD("Flush\n");    add(PGFLUSH); -  case sendout:; +  case SENDOUT:;    }    if(towrite=sizeof(this)) {    PD("%d>Sendcmd %O\n",socket->query_fd(),((string)this)[..towrite-1]);    towrite-=output_to(socket,towrite);    }    } while(0);    started=0;    return;    };    if(pgsqlsess)
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:318:       final void connectloop(int nossl) {    mixed err=catch {    for(;;clear()) {    socket->connect(pgsqlsess._host,pgsqlsess._port);   #if constant(SSL.File)    if(!nossl && !pgsqlsess->nossl    && (pgsqlsess._options.use_ssl || pgsqlsess._options.force_ssl)) {    PD("SSLRequest\n");    start()->add_int32(8)->add_int32(PG_PROTOCOL(1234,5679)) -  ->sendcmd(sendout); +  ->sendcmd(SENDOUT);    switch(read_int8()) {    case 'S':    object fcon=SSL.File(socket,SSL.Context());    if(fcon->connect()) {    socket=fcon;    break;    }    default:PD("%d>Close socket\n",socket->query_fd());    socket->close();    pgsqlsess.nossl=1;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:401:   //!   //! @seealso   //! @[Sql.sql_result], @[Sql.pgsql], @[Sql.Sql], @[Sql.pgsql()->big_query()]   class sql_result {       private object pgsqlsess;    private int numrows;    private int eoffound;    private conxion c;    final mixed _delayederror; -  final portalstate _state; +  final int _state;    final int _fetchlimit;    final int _alltext;    final int _forcetext;       final string _portalname;       final int _bytesreceived;    final int _rowsreceived;    final int _inflight;    final int _portalbuffersize;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:461:    _datarows = Thread.Queue(); numrows = UNDEFINED;    _ddescribe=Thread.Condition();    _ddescribemux=Thread.Mutex();    closemux=Thread.Mutex();    prepbufferready=Thread.Condition();    prepbuffermux=Thread.Mutex();    _portalbuffersize=portalbuffersize;    _alltext = !alltyped;    _params = params;    _forcetext = forcetext; -  _state = portalinit; +  _state = PORTALINIT;    }       //! Returns the command-complete status for this query.    //!    //! @seealso    //! @[affected_rows()]    //!    //! @note    //! This function is PostgreSQL-specific, and thus it is not available    //! through the generic SQL-interface.
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:699:    Thread.Thread(gotdatarowdesc); // Do not use callout, it deadlocks    if(tp)    tp.datarowdesc=datarowdesc;    }       private void gotdatarowdesc() {    if(!prepbuffer) {    Thread.MutexKey lock=prepbuffermux->lock();    prepbufferready->wait(lock);    lock=0; -  if(_state==closed) +  if(_state==CLOSED)    return;    prepbuffermux=0;    }    Stdio.Buffer plugbuffer=prepbuffer;    prepbuffer=0;    plugbuffer->add_int16(sizeof(_datarowdesc));    if(sizeof(_datarowdesc))    foreach(_datarowdesc;;mapping col)    plugbuffer->add_int16(oidformat(col.type));    else if(commitprefix->match(_query)) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:737:    _sendexecute(pgsqlsess->_fetchlimit    && !(cachealways[_query]    || sizeof(_query)>=MINPREPARELENGTH &&    execfetchlimit->match(_query))    && FETCHLIMITLONGRUN,bindbuffer);    }       final void _openportal() {    pgsqlsess->_portalsinflight++;    Thread.MutexKey lock=closemux->lock(); -  _state=bound; +  _state=BOUND;    lock=0;    _statuscmdcomplete=UNDEFINED;    }       final void _purgeportal() {    _unnamedportalkey=_unnamedstatementkey=0;    Thread.MutexKey lock=closemux->lock();    _fetchlimit=0; // disables further Executes    switch(_state) { -  case copyinprogress: -  case bound: +  case COPYINPROGRESS: +  case BOUND:    _datarows->write(1); // Signal EOF    --pgsqlsess->_portalsinflight;    } -  _state=closed; +  _state=CLOSED;    lock=0;    releaseconditions();    }    -  final sctype _closeportal(bufcon plugbuffer) { -  sctype retval=keep; +  final int _closeportal(bufcon plugbuffer) { +  int retval=KEEP;    PD("%O Try Closeportal %d\n",_portalname,_state);    Thread.MutexKey lock=closemux->lock();    _fetchlimit=0; // disables further Executes    int alreadyfilled=sizeof(plugbuffer);    /* alreadyfilled will be non-zero if a parse request has been queued    * before the close was initiated.    * It's a bit of a tricky race, but this check should be sufficient.    */    switch(_state) { -  case portalinit: +  case PORTALINIT:    _unnamedstatementkey=0; -  _state=closed; +  _state=CLOSED;    break; -  case copyinprogress: +  case COPYINPROGRESS:    PD("CopyDone\n");    plugbuffer->add("c\0\0\0\4"); -  case bound: -  _state=closed; +  case BOUND: +  _state=CLOSED;    lock=0;    PD("Close portal %O\n",_portalname);    if(sizeof(_portalname)) {    plugbuffer->add_int8('C')->add_hstring(({'P',_portalname,0}),4,4); -  retval=flushsend; +  retval=FLUSHSEND;    } else    _unnamedportalkey=0;    Thread.MutexKey lockc=pgsqlsess->_commitmux->lock();    if(!--pgsqlsess->_portalsinflight) {    if(pgsqlsess->_waittocommit) {    PD("Signal no portals in flight\n");    pgsqlsess->_readyforcommit->signal();    lockc=0;    } else if(!alreadyfilled) -  pgsqlsess->_readyforquerycount++, retval=syncsend; +  pgsqlsess->_readyforquerycount++, retval=SYNCSEND;    pgsqlsess->_pportalcount=0;    }    lockc=0;    }    lock=0;    return retval;    }       final void _processdataready() {    _rowsreceived++;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:857:    }       final void _sendexecute(int fetchlimit,void|bufcon plugbuffer) {    int flushmode;    PD("Execute portal %O fetchlimit %d\n",_portalname,fetchlimit);    if(!plugbuffer)    plugbuffer=c->start(1);    plugbuffer->add_int8('E')->add_hstring(_portalname,4,8+1)    ->add_int8(0)->add_int32(fetchlimit);    if(!fetchlimit) -  flushmode=_closeportal(plugbuffer)==syncsend?syncsend:flushsend; +  flushmode=_closeportal(plugbuffer)==SYNCSEND?SYNCSEND:FLUSHSEND;    else -  _inflight+=fetchlimit, flushmode=flushsend; +  _inflight+=fetchlimit, flushmode=FLUSHSEND;    plugbuffer->sendcmd(flushmode,this);    }       //! @returns    //! One result row at a time.    //!    //! When using COPY FROM STDOUT, this method returns one row at a time    //! as a single string containing the entire row.    //!    //! @seealso
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:925:    //! The COPY FROM STDIN sequence needs to be completed by either    //! explicitly or implicitly destroying the result object, or by passing no    //! argument to this method.    //!    //! @seealso    //! @[fetch_row()], @[eof()]    void send_row(void|string|array(string) copydata) {    trydelayederror();    if(copydata) {    PD("CopyData\n"); -  c->start()->add_int8('d')->add_hstring(copydata,4,4)->sendcmd(sendout); +  c->start()->add_int8('d')->add_hstring(copydata,4,4)->sendcmd(SENDOUT);    } else    _releasesession();    }       private void run_result_cb(    function(sql_result, array(mixed), mixed ...:void) callback,    array(mixed) args) {    int|array datarow;    while(arrayp(datarow=_datarows->read_array()))    callout(callback, 0, this, datarow, @args);