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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:71:    // but checking when this is safe to do    // probably is more costly than the gain   #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 we used prepared statements   #endif   private int cachedepth = STATEMENTCACHEDEPTH;   private int portalbuffersize = PORTALBUFFERSIZE;   private int timeout = QUERYTIMEOUT; + private array connparmcache; + private int reconnected;      protected string _sprintf(int type) {    string res;    switch(type) {    case 'O':    res = sprintf(DRIVERNAME"(%s@%s:%d/%s,%d,%d)",    proxy.user, proxy.host, proxy.port, proxy.database,    proxy.c?->socket && proxy.c->socket->query_fd(), proxy.backendpid);    break;    }
pike.git/lib/modules/Sql.pmod/pgsql.pike:107:   //!   //! @param database   //! Specifies the database to connect to. Not specifying this is   //! only supported if the PostgreSQL backend has a default database   //! configured. If you do not want to connect to any live database,   //! you can use @expr{"template1"@}.   //!   //! @param options   //! Currently supports at least the following:   //! @mapping + //! @member int "reconnect" + //! Set it to zero to disable automatic reconnects upon losing + //! the connection to the database. Not setting it, or setting + //! it to one, will cause one timed reconnect to take place. + //! Setting it to -1 will cause the system to try and reconnect + //! indefinitely.   //! @member int "use_ssl"   //! If the database supports and allows SSL connections, the session   //! will be SSL encrypted, if not, the connection will fallback   //! to plain unencrypted.   //! @member int "force_ssl"   //! If the database supports and allows SSL connections, the session   //! will be SSL encrypted, if not, the connection will abort.   //! @member int "text_query"   //! Send queries to and retrieve results from the database using text   //! instead of the, generally more efficient, default native binary method.
pike.git/lib/modules/Sql.pmod/pgsql.pike:169:   //! @[Postgres.postgres], @[Sql.Sql], @[select_db()],   //! @url{https://www.postgresql.org/docs/current/static/runtime-config-client.html@}   protected void create(void|string host, void|string database,    void|string user, void|string pass,    void|mapping(string:mixed) options) {    string spass = pass && pass != "" ? Standards.IDNA.to_ascii(pass) : pass;    if(pass) {    String.secure(pass);    pass = "CENSORED";    } -  proxy = .pgsql_util.proxy(host, database, +  connparmcache = ({ host, database,    user && user != "" ? Standards.IDNA.to_ascii(user, 1) : user, -  spass, options || ([])); +  spass, options || ([])}); +  proxy = .pgsql_util.proxy(@connparmcache);   }      //! @returns   //! The textual description of the last   //! server-related error. Returns @expr{0@} if no error has occurred   //! yet. It is not cleared upon reading (can be invoked multiple   //! times, will return the same result until a new error occurs).   //!   //! During the execution of a statement, this function accumulates all   //! non-error messages (notices, warnings, etc.). If a statement does not
pike.git/lib/modules/Sql.pmod/pgsql.pike:238:   //! @value 0   //! Everything ok.   //! @value -1   //! The server has gone away, and the connection is dead.   //! @endint   //!   //! @seealso   //! @[is_open()]   /*semi*/final int ping() {    waitauthready(); -  return is_open() && !catch(proxy.c->start()->sendcmd(FLUSHSEND)) ? 0 : -1; +  return is_open() +  && !catch(proxy.c->start()->sendcmd(FLUSHSEND)) ? !!reconnected : -1;   }      //! Cancels all currently running queries in this session.   //!   //! @seealso   //! @[reload()], @[resync()]   //!   //! @note   //! This function is PostgreSQL-specific.   /*semi*/final void cancelquery() {
pike.git/lib/modules/Sql.pmod/pgsql.pike:874:    return String.int2hex(i);   }      private inline void throwdelayederror(object parent) {    .pgsql_util.throwdelayederror(parent);   }      private void startquery(int forcetext, .pgsql_util.sql_result portal, string q,    mapping(string:mixed) tp, string preparedname) {    .pgsql_util.conxion c = proxy.c; +  if (!c && (proxy.options["reconnect"] +  || zero_type(proxy.options["reconnect"]))) { +  sleep(BACKOFFDELAY); // Force a backoff delay +  if (!proxy.c) { +  reconnected++; +  proxy = .pgsql_util.proxy(@connparmcache); +  } +  c = proxy.c; +  }    if (forcetext) { // FIXME What happens if portals are still open?    portal._unnamedportalkey = proxy.unnamedportalmux->lock(1);    portal._portalname = "";    portal->_parseportal(); portal->_bindportal();    proxy.readyforquerycount++;    {    Thread.MutexKey lock = proxy.unnamedstatement->lock(1);    .pgsql_util.conxsess cs = c->start(1);    CHAIN(cs)->add_int8('Q')->add_hstring(({q, 0}), 4, 4);    cs->sendcmd(FLUSHLOGSEND, portal);