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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:77: Inside #if defined(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;   private int lastping = time(1); + private Thread.Condition resynced; + private Thread.Mutex resyncmux;      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:287:   //! parameters and results can be Pike-native wide strings.   //!   //! @param charset   //! A PostgreSQL charset name.   //!   //! @seealso   //! @[get_charset()], @[create()],   //! @url{https://www.postgresql.org/docs/current/static/multibyte.html@}   /*semi*/final void set_charset(string charset) {    if(charset) -  big_query(sprintf("SET CLIENT_ENCODING TO '%s'", quote(charset))); +  textquery(sprintf("SET CLIENT_ENCODING TO '%s'", quote(charset)));   }      //! @returns   //! The PostgreSQL name for the current connection charset.   //!   //! @seealso   //! @[set_charset()], @[getruntimeparameters()],   //! @url{https://www.postgresql.org/docs/current/static/multibyte.html@}   /*semi*/final string get_charset() {    return getruntimeparameters()[CLIENT_ENCODING];
pike.git/lib/modules/Sql.pmod/pgsql.pike:495:   }      //! For PostgreSQL this function performs the same function as @[resync()].   //!   //! @seealso   //! @[resync()], @[cancelquery()]   /*semi*/final void reload() {    resync();   }    + private void textquery(string q) { + #if 1 +  foreach (q / ";"; ; string sq) +  big_query(sq); + #else // textqueries and portals do not mix well +  big_query(q, (["_text":1])); + #endif + } +  + private void resyncdone() { +  Thread.MutexKey lock = resyncmux->lock(); +  resynced.signal(); // Allow resync() to continue + } +    private void reset_dbsession() {    proxy.statementsinflight->wait_till_drained();    error(1); -  big_query("ROLLBACK"); -  big_query("RESET ALL"); -  big_query("CLOSE ALL"); -  big_query("DISCARD TEMP"); +  textquery("ROLLBACK;RESET ALL;CLOSE ALL;DISCARD TEMP"); +  resyncdone();   }      private void resync_cb() {    switch (proxy.backendstatus) { -  +  default: +  resyncdone(); +  break;    case 'T':case 'E':    foreach (proxy.prepareds; ; mapping tp) {    m_delete(tp, "datatypeoid");    m_delete(tp, "datarowdesc");    m_delete(tp, "datarowtypes");    }    Thread.Thread(reset_dbsession); // Urgently and deadlockfree    }   }   
pike.git/lib/modules/Sql.pmod/pgsql.pike:542:   //!   //! @note   //! This function is PostgreSQL-specific.   /*semi*/final void resync() {    mixed err;    if (is_open()) {    err = catch {    PD("Statementsinflight: %d Portalsinflight: %d\n",    proxy.statementsinflight, proxy.portalsinflight);    if(!proxy.waitforauthready) { +  if (!resynced) { +  resynced = Thread.Condition(); +  resyncmux = Thread.Mutex(); +  }    proxy.readyforquery_cb = resync_cb;    proxy.sendsync(); -  +  if (proxy.readyforquery_cb) { +  Thread.MutexKey lock = resyncmux->lock(); +  resynced.wait(lock); // Wait for the db to finish    } -  +  }    return;    };    PD("%O\n", err);    }    if (sizeof(proxy.lastmessage))    ERROR(proxy.a2nls(proxy.lastmessage));   }      //! Due to restrictions of the Postgres frontend-backend protocol, you always   //! already have to be connected to a database.
pike.git/lib/modules/Sql.pmod/pgsql.pike:661:      //! This function creates a new database (assuming we   //! have sufficient privileges to do this).   //!   //! @param db   //! Name of the new database.   //!   //! @seealso   //! @[drop_db()]   /*semi*/final void create_db(string db) { -  big_query(sprintf("CREATE DATABASE %s", db)); +  textquery(sprintf("CREATE DATABASE %s", db));   }      //! This function destroys a database and all the data it contains (assuming   //! we have sufficient privileges to do so). It is not possible to delete   //! the database you're currently connected to. You can connect to database   //! @expr{"template1"@} to avoid connecting to any live database.   //!   //! @param db   //! Name of the database to be deleted.   //!   //! @seealso   //! @[create_db()]   /*semi*/final void drop_db(string db) { -  big_query(sprintf("DROP DATABASE %s", db)); +  textquery(sprintf("DROP DATABASE %s", db));   }      //! @returns   //! A string describing the server we are   //! talking to. It has the form @expr{"servername/serverversion"@}   //! (like the HTTP protocol description) and is most useful in   //! conjunction with the generic SQL-server module.   //!   //! @seealso   //! @[host_info()]