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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:59:      #include "pgsql.h"      #define ERROR(X ...) predef::error(X)      final int _fetchlimit=FETCHLIMIT;   final Thread.Mutex _unnamedportalmux;   private Thread.Mutex unnamedstatement;   final int _portalsinflight;    - private .pgsql_util.PGassist c; + private .pgsql_util.conxion c;   private string cancelsecret;   private int backendpid, backendstatus;   final mapping(string:mixed) _options;   private array(string) lastmessage=({});   private int clearmessage;   private mapping(string:array(mixed)) notifylist=([]);   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
pike.git/lib/modules/Sql.pmod/pgsql.pike:296:   //! 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;   }    - private .pgsql_util.PGassist getsocket(void|int nossl) { -  return .pgsql_util.PGassist(this,qportals,(int)nossl); + private .pgsql_util.conxion getsocket(void|int nossl) { +  return .pgsql_util.conxion(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   //! through the generic SQL-interface.   void cancelquery() {    PD("CancelRequest\n"); -  .pgsql_util.PGassist lcon=getsocket(1); +  .pgsql_util.conxion lcon=getsocket(1);    lcon->add_int32(16)->add_int32(PG_PROTOCOL(1234,5678))    ->add_int32(backendpid)->add(cancelsecret)->sendcmd(flushsend);    lcon->close();   #ifdef PG_DEBUGMORE    PD("Closetrace %O\n",backtrace());   #endif    if(c) { -  .pgsql_util.PGassist plugbuffer=c->start(1); -  foreach(qportals->peek_array();;int|.pgsql_util.pgsql_result portal) +  .pgsql_util.conxion plugbuffer=c->start(1); +  foreach(qportals->peek_array();;int|.pgsql_util.sql_result portal)    if(objectp(portal))    portal->_closeportal(plugbuffer);    plugbuffer->sendcmd(sendout);    }   }      //! Changes the connection charset. When set to @expr{"UTF8"@}, the query,   //! parameters and results can be Pike-native wide strings.   //!   //! @param charset
pike.git/lib/modules/Sql.pmod/pgsql.pike:547:      private void connect_cb() {    PD("%O\n",_runtimeparameter);   }      private void reconnect_cb() {    lastmessage+=({sprintf("Reconnected to database %s",host_info())});    runcallback(backendpid,"_reconnect","");   }    - private array(string) showbindings(.pgsql_util.pgsql_result portal) { + private array(string) showbindings(.pgsql_util.sql_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)
pike.git/lib/modules/Sql.pmod/pgsql.pike:572:   }      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||"")});   }    - private void storetiming(.pgsql_util.pgsql_result portal) { + 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]);    Thread.MutexKey lock=waitforauth->lock();
pike.git/lib/modules/Sql.pmod/pgsql.pike:594:    lock=0;    PD("Wait for auth ready released.\n");    }   }      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) { + final void _processloop(.pgsql_util.conxion ci) {    int terminating=0; -  int|.pgsql_util.pgsql_result portal; +  int|.pgsql_util.sql_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    -(<"use_ssl","force_ssl","cache_autoprepared_statements","reconnect",
pike.git/lib/modules/Sql.pmod/pgsql.pike:808: Inside #if defined(PG_DEBUG)
  #ifdef PG_DEBUG    msglen-=4+1;    PD("<ReadyForQuery %c\n",backendstatus);   #endif    for(;objectp(portal);portal=qportals->read()) {   #ifdef PG_DEBUG    showportal(msgtype);   #endif    portal->_purgeportal();    } -  foreach(qportals->peek_array();;.pgsql_util.pgsql_result qp) { +  foreach(qportals->peek_array();;.pgsql_util.sql_result qp) {    if(objectp(qp) && qp._synctransact && qp._synctransact<=portal) {    PD("Checking portal %O %d<=%d\n",    qp._portalname,qp._synctransact,portal);    qp->_purgeportal();    }    }    portal=0;    _readyforquerycount--;    if(readyforquery_cb)    readyforquery_cb(),readyforquery_cb=0;
pike.git/lib/modules/Sql.pmod/pgsql.pike:1218:    break;    case protocolerror:    msg=sprintf("Protocol error with database %s",host_info());    break;    case noerror:    continue; // Normal production loop    }    ERROR(a2nls(lastmessage+=({msg})));    }    }; // We only get here if there is an error -  if(err==MAGICTERMINATE) { +  if(err==MAGICTERMINATE) { // Announce connection termination to server    ci->start()->add("X\0\0\0\4")->sendcmd(sendout);    terminating=1;    if(!sizeof(ci))    break;    }    if(stringp(err)) { -  .pgsql_util.pgsql_result or; +  .pgsql_util.sql_result or;    if(!objectp(or=portal))    or=this;    if(!or._delayederror)    or._delayederror=err;    if(objectp(portal))    portal->_releasesession();    portal=0;    if(!waitforauthready)    continue; // Only continue if authentication did not fail    }
pike.git/lib/modules/Sql.pmod/pgsql.pike:1577:    return DRIVERNAME"/"+(_runtimeparameter.server_version||"unknown");   }      //! @returns   //! An array of the databases available on the server.   //!   //! @param glob   //! If specified, list only those databases matching it.   array(string) list_dbs (void|string glob) {    array row,ret=({}); -  .pgsql_util.pgsql_result res=big_query("SELECT d.datname " +  .pgsql_util.sql_result res=big_query("SELECT d.datname "    "FROM pg_database d "    "WHERE d.datname ILIKE :glob "    "ORDER BY d.datname",    ([":glob":glob2reg(glob)]));    while(row=res->fetch_row())    ret+=({row[0]});    return ret;   }      //! @returns   //! An array containing the names of all the tables and views in the   //! path in the currently selected database.   //!   //! @param glob   //! If specified, list only the tables with matching names.   array(string) list_tables (void|string glob) {    array row,ret=({}); // This query might not work on PostgreSQL 7.4 -  .pgsql_util.pgsql_result res=big_query( // due to missing schemasupport +  .pgsql_util.sql_result res=big_query( // due to missing schemasupport    "SELECT CASE WHEN 'public'=n.nspname THEN '' ELSE n.nspname||'.' END "    " ||c.relname AS name "    "FROM pg_catalog.pg_class c "    " LEFT JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace "    "WHERE c.relkind IN ('r','v') AND n.nspname<>'pg_catalog' "    " AND n.nspname !~ '^pg_toast' AND pg_catalog.pg_table_is_visible(c.oid) "    " AND c.relname ILIKE :glob "    " ORDER BY 1",    ([":glob":glob2reg(glob)]));    while(row=res->fetch_row())
pike.git/lib/modules/Sql.pmod/pgsql.pike:1656:   //!   //! @param glob   //! If specified, list only the tables with matching names.   //! Setting it to @expr{*@} will include system columns in the list.   array(mapping(string:mixed)) list_fields(void|string table, void|string glob) {    array row, ret=({});    string schema=UNDEFINED;       sscanf(table||"*", "%s.%s", schema, table);    -  .pgsql_util.pgsql_result res = big_typed_query( +  .pgsql_util.sql_result res = big_typed_query(    "SELECT a.attname, a.atttypid, t.typname, a.attlen, "    " c.relhasindex, c.relhaspkey, CAST(c.reltuples AS BIGINT) AS reltuples, "    " (c.relpages "    " +COALESCE( "    " (SELECT SUM(tst.relpages) "    " FROM pg_catalog.pg_class tst "    " WHERE tst.relfilenode=c.reltoastrelid) "    " ,0) "    " )*8192::BIGINT AS datasize, "    " (COALESCE( "
pike.git/lib/modules/Sql.pmod/pgsql.pike:1763:   //! @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);   }      private inline void closestatement( -  .pgsql_util.PGassist|.pgsql_util.PGplugbuffer plugbuffer,string oldprep) { +  .pgsql_util.conxion|.pgsql_util.bufcon plugbuffer,string oldprep) {    .pgsql_util.closestatement(plugbuffer,oldprep);   }      private inline string int2hex(int i) {    return String.int2hex(i);   }      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) + //! @decl Sql.pgsql_util.sql_result big_query(string query) + //! @decl Sql.pgsql_util.sql_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.   //!   //! Bindings are supported natively straight across the network.   //! Special bindings supported are:   //! @mapping   //! @member int ":_cache"   //! Forces caching on or off for the query at hand.
pike.git/lib/modules/Sql.pmod/pgsql.pike:1801:   //! Note that this mode causes all but the first query result of a list   //! of semicolon separated statements to be discarded.   //! @member int ":_sync"   //! Forces synchronous parsing on or off for statements.   //! Setting this to off can cause surprises because statements could   //! be parsed before the previous statements have been executed.   //! This can speed up parsing by increased parallelism.   //! @endmapping   //!   //! @returns - //! A @[Sql.pgsql_util.pgsql_result] object (which conforms to the + //! A @[Sql.pgsql_util.sql_result] object (which conforms to the   //! @[Sql.sql_result] standard interface for accessing data). It is   //! recommended to use @[Sql.Sql()->query()] for simpler queries (because   //! it is easier to handle, but stores all the result in memory), and   //! @[Sql.Sql()->big_query()] for queries you expect to return huge amounts of   //! data (it's harder to handle, but fetches results on demand).   //!   //! @note   //! This function @b{can@} raise exceptions.   //!   //! @note
pike.git/lib/modules/Sql.pmod/pgsql.pike:1827:   //! This function, by default, does not support multiple queries in one   //! querystring.   //! I.e. it allows for but does not require a trailing semicolon, but it   //! simply ignores any commands after the first unquoted semicolon. This can   //! be viewed as a limited protection against SQL-injection attacks.   //! To make it support multiple queries in one querystring, use the   //! @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, + //! @[Sql.Sql()->query()], @[Sql.pgsql_util.sql_result] + .pgsql_util.sql_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;    if(waitforauthready)    waitauthready();    string cenc=_runtimeparameter[CLIENT_ENCODING];    switch(cenc) {
pike.git/lib/modules/Sql.pmod/pgsql.pike:1945:    closestatement(plugbuffer,np.preparedname);    m_delete(np,"preparedname");    }    }    if(sizeof(plugbuffer)) {    PD("%O\n",(string)plugbuffer);    plugbuffer->sendcmd(flushsend); // close expireds    } else    plugbuffer->sendcmd(); // close start()    tstart=gethrtime(); -  } else // pgsql_result autoassigns to portal +  } else // sql_result autoassigns to portal    tp=UNDEFINED; -  .pgsql_util.pgsql_result portal; -  portal=.pgsql_util.pgsql_result(this,c,q, +  .pgsql_util.sql_result portal; +  portal=.pgsql_util.sql_result(this,c,q,    portalbuffersize,_alltyped,from,forcetext);    portal._tprepared=tp;   #ifdef PG_STATS    portalsopened++;   #endif    clearmessage=1;    if(forcetext) { // FIXME What happens if portals are still open?    portal._unnamedportalkey=_unnamedportalmux->lock(1);    portal._portalname="";    portal->_openportal();
pike.git/lib/modules/Sql.pmod/pgsql.pike:2011:    }    throwdelayederror(portal);    return portal;   }      //! This is an alias for @[big_query()], since @[big_query()] already supports   //! streaming of multiple simultaneous queries through the same connection.   //!   //! @seealso   //! @[big_query()], @[big_typed_query()], @[Sql.Sql], @[Sql.sql_result] - .pgsql_util.pgsql_result streaming_query(string q, + .pgsql_util.sql_result streaming_query(string q,    void|mapping(string|int:mixed) bindings) {    return big_query(q,bindings);   }      //! This function returns an object that allows streaming and typed   //! results.   //!   //! @seealso   //! @[big_query()], @[Sql.Sql], @[Sql.sql_result] - .pgsql_util.pgsql_result big_typed_query(string q, + .pgsql_util.sql_result big_typed_query(string q,    void|mapping(string|int:mixed) bindings) {    return big_query(q,bindings,1);   }