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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:54:   //! @seealso   //! @[Sql.Sql], @[Sql.postgres], @url{http://www.postgresql.org/docs/@}      #pike __REAL_VERSION__   #require constant(Thread.Thread)      #include "pgsql.h"      #define ERROR(X ...) predef::error(X)    - int _fetchlimit=FETCHLIMIT; - Thread.Mutex _unnamedportalmux; + final int _fetchlimit=FETCHLIMIT; + final Thread.Mutex _unnamedportalmux;   private Thread.Mutex unnamedstatement; - int _portalsinflight; + final int _portalsinflight;      private .pgsql_util.PGassist c;   private string cancelsecret; - private int backendpid; - private int backendstatus; - mapping(string:mixed) options; + private int backendpid, backendstatus; + final mapping(string:mixed) _options;   private array(string) lastmessage=({});   private int clearmessage;   private mapping(string:array(mixed)) notifylist=([]); - mapping(string:string) _runtimeparameter; - mapping(string:mapping(string:mixed)) _prepareds=([]); + final mapping(string:string) _runtimeparameter; + final mapping(string:mapping(string:mixed)) _prepareds=([]);   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; + final int _pportalcount;   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 reconnected; // Number of times the connection was reset   private int reconnectdelay; // Time to next reconnect   #ifdef PG_STATS - 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 + private int skippeddescribe; // Number of times we skipped Describe phase + private int portalsopened; // Number of portals opened + private int prepstmtused; // Number of times we used prepared statements   #endif - int _msgsreceived; // Number of protocol messages received - int _bytesreceived; // Number of bytes received - private int warningsdropcount; // Number of uncollected warnings + final int _msgsreceived; // Number of protocol messages received + final int _bytesreceived; // Number of bytes received + private int warningsdropcount; // Number of uncollected warnings   private int warningscollected;   private int invalidatecache;   private Thread.Queue qportals; - mixed _delayederror; + final mixed _delayederror;   private function (:void) readyforquery_cb;    - string _host; + final string _host; + final int _port;   private string database, user, pass; - int _port; +    private Thread.Mutex waitforauth;   private Thread.Condition waitforauthready; - int _readyforquerycount; + 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);    break;    }    return res;
pike.git/lib/modules/Sql.pmod/pgsql.pike:202:   protected void create(void|string host, void|string database,    void|string user, void|string pass,    void|mapping(string:mixed) options) {    this::pass = pass;    if(pass) {    String.secure(pass);    pass = "CENSORED";    }    this::user = user;    this::database = database; -  this::options = options || ([]); +  _options = options || ([]);       if(!host) host = PGSQL_DEFAULT_HOST;    if(has_value(host,":") && sscanf(host,"%s:%d",host,_port)!=2)    ERROR("Error in parsing the hostname argument\n");    this::_host = host;       if(!_port)    _port = PGSQL_DEFAULT_PORT;    .pgsql_util.register_backend();    waitforauth=Thread.Mutex();
pike.git/lib/modules/Sql.pmod/pgsql.pike:599:   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));    if(user)    plugbuffer->add("user\0")->add(user)->add_int8(0);    if(database)    plugbuffer->add("database\0")->add(database)->add_int8(0); -  options->reconnect=undefinedp(options->reconnect) || options->reconnect; -  foreach(options +  _options.reconnect=undefinedp(_options.reconnect) || _options.reconnect; +  foreach(_options    -(<"use_ssl","force_ssl","cache_autoprepared_statements","reconnect",    "text_query","is_superuser","server_encoding","server_version",    "integer_datetimes","session_authorization">);    string name;mixed value)    plugbuffer->add(name)->add_int8(0)->add((string)value)->add_int8(0);    plugbuffer->add_int8(0);    PD("%O\n",(string)plugbuffer);    ci->start()->add_hstring(plugbuffer,4,4)->sendcmd(sendout);    } // Do not flush at this point, PostgreSQL 9.4 disapproves    cancelsecret=0;
pike.git/lib/modules/Sql.pmod/pgsql.pike:1232:    if(!or._delayederror)    or._delayederror=err;    if(objectp(portal))    portal->_releasesession();    portal=0;    continue;    }    break;    }    _delayederror=err; -  if(!ci->close() && !terminating && options.reconnect) +  if(!ci->close() && !terminating && _options.reconnect)    _connectfail();    if(err)    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
pike.git/lib/modules/Sql.pmod/pgsql.pike:1271:    }    if(!err || reconnectdelay) {    int tdelay;    switch(tdelay=reconnectdelay) {    case 0:    reconnectdelay=RECONNECTDELAY;    break;    default:    if(err)    _delayederror=err; -  if(options.reconnect!=-1) +  if(_options.reconnect!=-1)    return;    reconnectdelay=RECONNECTBACKOFF;    break;    }    Thread.MutexKey lock=waitforauth->lock();    if(!waitforauthready)    waitforauthready=Thread.Condition();    lock=0;    PD("Schedule reconnect in %ds\n",tdelay);    _delayederror=0;
pike.git/lib/modules/Sql.pmod/pgsql.pike:1312:    prepstmtused=0;   #endif    if(!force)    c->sendterminate();    else    c->close();    c=0;    PD("Flushing old cache\n");    foreach(_prepareds;;mapping tp)    m_delete(tp,"preparedname"); -  if(!options.reconnect) +  if(!_options.reconnect)    return 0;    }    PD("Actually start to connect\n");    qportals=Thread.Queue(); -  +  _commitmux=Thread.Mutex(); +  _readyforcommit=Thread.Condition();    _readyforquerycount=1; -  +  _waittocommit=0;    qportals->write(1);    if(!(c=getsocket())) {    string msg=sprintf("Couldn't connect to database on %s:%d",_host,_port);    if(force) {    if(!sizeof(lastmessage) || lastmessage[sizeof(lastmessage)-1]!=msg)    lastmessage+=({msg});    return 0;    } else    ERROR(msg+"\n");    }
pike.git/lib/modules/Sql.pmod/pgsql.pike:1815:   //! @ref{:_text@} option.   //!   //! @seealso   //! @[big_typed_query()], @[Sql.Sql], @[Sql.sql_result],   //! @[Sql.Sql()->query()], @[Sql.pgsql_util.pgsql_result]   .pgsql_util.pgsql_result big_query(string q,    void|mapping(string|int:mixed) bindings,    void|int _alltyped) {    throwdelayederror(this);    string preparedname=""; -  int forcecache=-1, forcetext=options.text_query; -  int syncparse=zero_type(options.sync_parse)?-1:options.sync_parse; +  int forcecache=-1, forcetext=_options.text_query; +  int syncparse=zero_type(_options.sync_parse)?-1:_options.sync_parse;    if(waitforauthready)    waitauthready();    string cenc=_runtimeparameter[CLIENT_ENCODING];    switch(cenc) {    case UTF8CHARSET:    q=string_to_utf8(q);    break;    default:    if(String.width(q)>8)    ERROR("Don't know how to convert %O to %s encoding\n",q,cenc);
pike.git/lib/modules/Sql.pmod/pgsql.pike:1894:    && (sizeof(q)>=MINPREPARELENGTH || .pgsql_util.cachealways[q])) {    object plugbuffer=c->start();    if(tp=_prepareds[q]) {    if(tp.preparedname) {   #ifdef PG_STATS    prepstmtused++;   #endif    preparedname=tp.preparedname;    } else if((tstart=tp.trun)    && tp.tparse*FACTORPLAN>=tstart -  && (undefinedp(options.cache_autoprepared_statements) -  || options.cache_autoprepared_statements)) +  && (undefinedp(_options.cache_autoprepared_statements) +  || _options.cache_autoprepared_statements))    preparedname=PREPSTMTPREFIX+int2hex(pstmtcount++);    } else {    if(totalhits>=cachedepth)    foreach(_prepareds;string ind;tp) {    int oldhits=tp.hits;    totalhits-=oldhits-(tp.hits=oldhits>>1);    if(oldhits<=1) {    closestatement(plugbuffer,tp.preparedname);    m_delete(_prepareds,ind);    }