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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:106:   private Thread.Mutex waitforauth;   private Thread.Condition waitforauthready;   final Thread.Mutex _commitmux;   final Thread.Condition _readyforcommit;   final int _waittocommit, _readyforquerycount;      private string _sprintf(int type, void|mapping flags) {    string res=UNDEFINED;    switch(type) {    case 'O': -  res=sprintf(DRIVERNAME"(%s@%s:%d/%s,%d)", -  user,_host,_port,database,backendpid); +  res=sprintf(DRIVERNAME"(%s@%s:%d/%s,%d,%d)", +  user,_host,_port,database,c?->socket?->query_fd(),backendpid);    break;    }    return res;   }      //! @decl void create()   //! @decl void create(string host, void|string database, void|string user,@   //! void|string password, void|mapping(string:mixed) options)   //!   //! With no arguments, this function initialises (reinitialises if a
pike.git/lib/modules/Sql.pmod/pgsql.pike:336:   //! Changes the connection charset. When set to @expr{"UTF8"@}, the query,   //! parameters and results can be Pike-native wide strings.   //!   //! @param charset   //! A PostgreSQL charset name.   //!   //! @seealso   //! @[get_charset()], @[create()],   //! @url{http://www.postgresql.org/search/?u=%2Fdocs%2Fcurrent%2F&q=character+sets@}   void set_charset(string charset) { +  if(charset)    big_query(sprintf("SET CLIENT_ENCODING TO '%s'",quote(charset)));   }      //! @returns   //! The PostgreSQL name for the current connection charset.   //!   //! @seealso   //! @[set_charset()], @[getruntimeparameters()],   //! @url{http://www.postgresql.org/search/?u=%2Fdocs%2Fcurrent%2F&q=character+sets@}   string get_charset() {
pike.git/lib/modules/Sql.pmod/pgsql.pike:581:      private void storetiming(.pgsql_util.sql_result portal) {    mapping(string:mixed) tp=portal._tprepared;    tp.trun=gethrtime()-tp.trunstart;    m_delete(tp,"trunstart");    portal._tprepared = UNDEFINED;   }      private void waitauthready() {    if(waitforauthready) { -  PD("Wait for auth ready %O\n",backtrace()[-2]); +  PD("%d Wait for auth ready %O\n",c?->socket?->query_fd(),backtrace()[-2]);    Thread.MutexKey lock=waitforauth->lock();    catch(waitforauthready->wait(lock));    lock=0; -  PD("Wait for auth ready released.\n"); +  PD("%d Wait for auth ready released.\n",c?->socket?->query_fd());    }   }      private inline mixed callout(function(mixed ...:void) f,    float|int delay,mixed ... args) {    return .pgsql_util.local_backend->call_out(f,delay,@args);   }      final void _processloop(.pgsql_util.conxion ci) {    int terminating=0;
pike.git/lib/modules/Sql.pmod/pgsql.pike:623:    ci->start()->add_hstring(plugbuffer,4,4)->sendcmd(sendout);    } // Do not flush at this point, PostgreSQL 9.4 disapproves    cancelsecret=0;   #ifdef PG_DEBUG    PD("Processloop\n");    string datarowdebug;    int datarowdebugcount;       void showportal(int msgtype) {    if(objectp(portal)) -  PD("<%O %d %c switch portal\n", -  portal._portalname,++ci->queueinidx,msgtype); +  PD("%d<%O %d %c switch portal\n", +  ci->socket->query_fd(),portal._portalname,++ci->queueinidx,msgtype);    else if(portal>0) -  PD("<Sync %d %d %c portal\n",++ci->queueinidx,portal,msgtype); +  PD("%d<Sync %d %d %c portal\n", +  ci->socket->query_fd(),++ci->queueinidx,portal,msgtype);    };   #endif    for(;;) {    err=catch {   #ifdef PG_DEBUG    if(!portal && datarowdebug) {    PD("%s rows %d\n",datarowdebug,datarowdebugcount);    datarowdebug=0; datarowdebugcount=0;    }   #endif
pike.git/lib/modules/Sql.pmod/pgsql.pike:653:    }    int msglen=ci->read_int32();    _msgsreceived++;    _bytesreceived+=1+msglen;    enum errortype {    noerror=0,    protocolerror,    protocolunsupported    };    errortype errtype=noerror; +  PD("%d",ci->socket->query_fd());    switch(msgtype) {    array(mapping) getcols() {    int bintext=ci->read_int8();    int cols=ci->read_int16();   #ifdef PG_DEBUG    array a;    msglen-=4+1+2+2*cols;    foreach(a=allocate(cols,([]));;mapping m)    m.type=ci->read_int16();   #else
pike.git/lib/modules/Sql.pmod/pgsql.pike:1112:    msgresponse=getresponse();    warningsdropcount+=warningscollected;    warningscollected=0;    switch(msgresponse.C) {    case "P0001":    lastmessage=({sprintf("%s: %s",msgresponse.S,msgresponse.M)});    USERERROR(a2nls(lastmessage    +({pinpointerror(portal._query,msgresponse.P)})    +showbindings(portal)));    case "53000":case "53100":case "53200":case "53300":case "53400": -  case "57P01":case "57P02":case "57P03": +  case "57P01":case "57P02":case "57P03":case "57P04":case "3D000":    preplastmessage(msgresponse);    PD(a2nls(lastmessage));throw(0);    case "08P01":case "42P05":    errtype=protocolerror;    case "XX000":case "42883":case "42P01":    invalidatecache=1;    default:    preplastmessage(msgresponse);    if(msgresponse.D)    lastmessage+=({msgresponse.D});
pike.git/lib/modules/Sql.pmod/pgsql.pike:1262:    throw(err);   }      //! Closes the connection to the database, any running queries are   //! terminated instantly.   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface.   void close() { -  cancelquery(); -  if(c) -  c->sendterminate(); +  catch(cancelquery()); +  catch(c->sendterminate());    c=0; -  +  if(waitforauthready) +  destruct(waitforauthready);   }      protected void destroy() { -  close(); +  catch(close());    .pgsql_util.unregister_backend();   }      void _connectfail(void|mixed err) {    PD("Connect failed %O reconnectdelay %d\n",err,reconnectdelay); -  +  catch {    if(waitforauthready)    destruct(waitforauthready); -  +  };    if(!err || reconnectdelay) {    int tdelay;    switch(tdelay=reconnectdelay) {    case 0:    reconnectdelay=RECONNECTDELAY;    break;    default:    if(err)    _delayederror=err;    if(_options.reconnect!=-1)
pike.git/lib/modules/Sql.pmod/pgsql.pike:1412:   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface.   void resync() {    mixed err;    if(!is_open()&&!reconnect())    ERROR(a2nls(lastmessage));    err = catch {    PD("Portalsinflight: %d\n",_portalsinflight); +  if(!waitforauthready) {    readyforquery_cb=resync_cb;    sendsync(); -  +  }    return;    };    PD("%O\n",err);    if(!reconnect())    ERROR(a2nls(lastmessage));   }      //! This function allows you to connect to a database. Due to   //! restrictions of the Postgres frontend-backend protocol, you always   //! have to be connected to a database, so in fact this function just