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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:56:      #pike __REAL_VERSION__   #require constant(Thread.Thread)      #include "pgsql.h"      #define ERROR(X ...) predef::error(X)      int _fetchlimit=FETCHLIMIT;   Thread.Mutex _unnamedportalmux; - protected Thread.Mutex unnamedstatement; + private Thread.Mutex unnamedstatement;   int _portalsinflight;    - protected .pgsql_util.PGassist c; - protected string cancelsecret; - protected int backendpid; - protected int backendstatus; + private .pgsql_util.PGassist c; + private string cancelsecret; + private int backendpid; + private int backendstatus;   mapping(string:mixed) options; - protected array(string) lastmessage=({}); - protected int clearmessage; - protected mapping(string:array(mixed)) notifylist=([]); + private array(string) lastmessage=({}); + private int clearmessage; + private mapping(string:array(mixed)) notifylist=([]);   mapping(string:string) _runtimeparameter;   mapping(string:mapping(string:mixed)) _prepareds=([]); - protected int pstmtcount; - protected int ptstmtcount; // Periodically one would like to reset this + private int pstmtcount; + private int ptstmtcount; // Periodically one would like to reset this    // but checking when this is safe to do    // probably is more costly than the gain   int _pportalcount; - protected int totalhits; - protected int cachedepth=STATEMENTCACHEDEPTH; - protected int timeout=QUERYTIMEOUT; - protected int portalbuffersize=PORTALBUFFERSIZE; - protected int reconnected; // Number of times the connection was reset - protected int reconnectdelay; // Time to next reconnect + private int totalhits; + private int cachedepth=STATEMENTCACHEDEPTH; + private int timeout=QUERYTIMEOUT; + private int portalbuffersize=PORTALBUFFERSIZE; + private int reconnected; // Number of times the connection was reset + private int reconnectdelay; // Time to next reconnect   #ifdef PG_STATS - protected int skippeddescribe; // Number of times we skipped Describe phase - protected int portalsopened; // Number of portals opened - protected int prepstmtused; // Number of times prepared statements were used + private int skippeddescribe; // Number of times we skipped Describe phase + private int portalsopened; // Number of portals opened + private int prepstmtused; // Number of times prepared statements were used   #endif   int _msgsreceived; // Number of protocol messages received   int _bytesreceived; // Number of bytes received - protected int warningsdropcount; // Number of uncollected warnings - protected int warningscollected; - protected int invalidatecache; - protected Thread.Queue qportals; + private int warningsdropcount; // Number of uncollected warnings + private int warningscollected; + private int invalidatecache; + private Thread.Queue qportals;   mixed _delayederror; - protected function (:void) readyforquery_cb; + private function (:void) readyforquery_cb;      string _host; - protected string database, user, pass; + private string database, user, pass;   int _port; - protected Thread.Mutex waitforauth; - protected Thread.Condition waitforauthready; + private Thread.Mutex waitforauth; + private Thread.Condition waitforauthready;   int _readyforquerycount;    - protected string _sprintf(int type, void|mapping flags) { + 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);    break;    }    return res;   }   
pike.git/lib/modules/Sql.pmod/pgsql.pike:295:   //! The server has gone away, and the connection is dead.   //! @endint   //!   //! @seealso   //! @[is_open()]   int ping() {    return is_open() && !catch(c->start()->sendcmd(flushsend))    ? !!reconnected : -1;   }    - protected .pgsql_util.PGassist getsocket(void|int nossl) { + private .pgsql_util.PGassist getsocket(void|int nossl) {    return .pgsql_util.PGassist(this,qportals,(int)nossl);   }      //! Cancels all currently running queries in this session.   //!   //! @seealso   //! @[reload()], @[resync()]   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available
pike.git/lib/modules/Sql.pmod/pgsql.pike:516:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface.   int setfetchlimit(void|int newfetchlimit) {    int oldfetchlimit=_fetchlimit;    if(!undefinedp(newfetchlimit) && newfetchlimit>=0)    _fetchlimit=newfetchlimit;    return oldfetchlimit;   }    - protected string glob2reg(string glob) { + private string glob2reg(string glob) {    if(!glob||!sizeof(glob))    return "%";    return replace(glob,({"*","?","\\","%","_"}),({"%","_","\\\\","\\%","\\_"}));   }    - protected string a2nls(array(string) msg) { + private string a2nls(array(string) msg) {    return msg*"\n"+"\n";   }    - protected string pinpointerror(void|string query,void|string offset) { + private string pinpointerror(void|string query,void|string offset) {    if(!query)    return "";    int k=(int)offset;    if(k<=0)    return MARKSTART+query+MARKEND;    return MARKSTART+(k>1?query[..k-2]:"")+MARKERROR+query[k-1..]+MARKEND;   }    - protected void connect_cb() { + private void connect_cb() {    PD("%O\n",_runtimeparameter);   }    - protected void reconnect_cb() { + private void reconnect_cb() {    lastmessage+=({sprintf("Reconnected to database %s",host_info())});    runcallback(backendpid,"_reconnect","");   }    - protected array(string) showbindings(.pgsql_util.pgsql_result portal) { + private array(string) showbindings(.pgsql_util.pgsql_result portal) {    array(string) msgs=({});    array from;    if(portal && (from = portal._params)) {    array to,paramValues;    [from,to,paramValues] = from;    if(sizeof(paramValues)) {    string val;    int i;    string fmt=sprintf("%%%ds %%3s %%.61s",max(@map(from,sizeof)));    foreach(paramValues;i;val)    msgs+=({sprintf(fmt,from[i],to[i],sprintf("%O",val))});    }    }    return msgs;   }    - protected void preplastmessage(mapping(string:string) msgresponse) { + private void preplastmessage(mapping(string:string) msgresponse) {    lastmessage=({    sprintf("%s %s:%s %s\n (%s:%s:%s)",    msgresponse.S,msgresponse.C,msgresponse.P||"",    msgresponse.M,msgresponse.F||"",msgresponse.R||"",    msgresponse.L||"")});   }    - protected void storetiming(.pgsql_util.pgsql_result portal) { + private void storetiming(.pgsql_util.pgsql_result portal) {    mapping(string:mixed) tp=portal._tprepared;    tp.trun=gethrtime()-tp.trunstart;    m_delete(tp,"trunstart");    portal._tprepared = UNDEFINED;   }    - protected void waitauthready() { + private void waitauthready() {    if(waitforauthready) {    Thread.MutexKey lock=waitforauth->lock();    catch(waitforauthready->wait(lock));    lock=0;    }   }    - protected inline mixed callout(function(mixed ...:void) f, + 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.PGassist ci) {    int terminating=0;    int|.pgsql_util.pgsql_result portal;    mixed err;    {    Stdio.Buffer plugbuffer=Stdio.Buffer()->add_int32(PG_PROTOCOL(3,0));
pike.git/lib/modules/Sql.pmod/pgsql.pike:1251:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface.   void close() {    cancelquery();    if(c)    c->sendterminate();    c=0;   }    - void destroy() { + protected void destroy() {    close();    .pgsql_util.unregister_backend();   }      void _connectfail(void|mixed err) {    PD("Connect failed %O reconnectdelay %d\n",err,reconnectdelay);    if(!err || reconnectdelay) {    int tdelay;    switch(tdelay=reconnectdelay) {    case 0:
pike.git/lib/modules/Sql.pmod/pgsql.pike:1283:    if(!waitforauthready)    waitforauthready=Thread.Condition();    lock=0;    PD("Schedule reconnect in %ds\n",tdelay);    _delayederror=0;    callout(reconnect,tdelay,1);    } else if(err)    _delayederror=err;   }    - protected int reconnect(void|int force) { + private int reconnect(void|int force) {    PD("(Re)connect\n");    if(!force) {    Thread.MutexKey lock=waitforauth->lock();    if(waitforauthready) {    lock=0;    return 0; // Connect still in progress in other thread    }    waitforauthready=Thread.Condition();    lock=0;    }
pike.git/lib/modules/Sql.pmod/pgsql.pike:1342:   //! @decl void reload()   //!   //! For PostgreSQL this function performs the same function as @[resync()].   //!   //! @seealso   //! @[resync()], @[cancelquery()]   void reload() {    resync();   }    - protected void resync_cb() { + private void resync_cb() {    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");    }   }    - protected void sendsync() { + private void sendsync() {    _readyforquerycount++;    c->start()->sendcmd(syncsend);   }      //! @decl void resync()   //!   //! Resyncs the database session; typically used to make sure the session is   //! not still in a dangling transaction.   //!   //! If called while the connection is in idle state, the function is
pike.git/lib/modules/Sql.pmod/pgsql.pike:1463:    if(!old)    old=({notify_cb});    if(selfnotify||args)    old+=({selfnotify});    if(args)    old+=args;    notifylist[condition]=old;    }   }    - protected void runcallback(int pid,string condition,string extrainfo) { + private void runcallback(int pid,string condition,string extrainfo) {    array cb;    if((cb=notifylist[condition]||notifylist[""])    && (pid!=backendpid || sizeof(cb)>1 && cb[1]))    callout(cb[0],0,pid,condition,extrainfo,@cb[2..]);   }      //! @returns   //! The given string, but escapes/quotes all contained magic characters   //! according to the quoting rules of the current session for non-binary   //! arguments in textual SQL-queries.
pike.git/lib/modules/Sql.pmod/pgsql.pike:1712:    mapping m=mkmapping(colnames,row);    delifzero(m,"is_shared");    delifzero(m,"has_index");    delifzero(m,"has_primarykey");    delifzero(m,"default");    ret+=({m});    }    return ret;   }    - protected string trbackendst(int c) { + private string trbackendst(int c) {    switch(c) {    case 'I': return "idle";    case 'T': return "intransaction";    case 'E': return "infailedtransaction";    }    return "";   }      //! @returns   //! The current commitstatus of the connection. Returns either one of:
pike.git/lib/modules/Sql.pmod/pgsql.pike:1736:   //! @value infailedtransaction   //! @endstring   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface.   final string status_commit() {    return trbackendst(backendstatus);   }    - final inline void closestatement( + private inline void closestatement(    .pgsql_util.PGassist|.pgsql_util.PGplugbuffer plugbuffer,string oldprep) {    .pgsql_util.closestatement(plugbuffer,oldprep);   }    - protected inline string int2hex(int i) { + private inline string int2hex(int i) {    return String.int2hex(i);   }    - final inline void throwdelayederror(object parent) { + private inline void throwdelayederror(object parent) {    .pgsql_util.throwdelayederror(parent);   }      //! @decl Sql.pgsql_util.pgsql_result big_query(string query)   //! @decl Sql.pgsql_util.pgsql_result big_query(string query, mapping bindings)   //!   //! This is the only provided interface which allows you to query the   //! database. If you wish to use the simpler @[Sql.Sql()->query()] function,   //! you need to use the @[Sql.Sql] generic SQL-object.   //!