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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:289:   //! 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;   }    - final protected object getsocket(void|int nossl) { + final protected .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   //! through the generic SQL-interface.   void cancelquery() {    PD("CancelRequest\n"); -  object lcon=getsocket(1); +  .pgsql_util.PGassist 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 -  object plugbuffer=c->start(1); -  foreach(qportals->peek_array();;object portal) +  .pgsql_util.PGassist plugbuffer=c->start(1); +  foreach(qportals->peek_array();;int|.pgsql_util.pgsql_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   //! A PostgreSQL charset name.
pike.git/lib/modules/Sql.pmod/pgsql.pike:537:      protected void connect_cb() {    PD("%O\n",_runtimeparameter);   }      protected void reconnect_cb() {    lastmessage+=({sprintf("Reconnected to database %s",host_info())});    runcallback(backendpid,"_reconnect","");   }    - protected array(string) showbindings(object portal) { + protected 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)
pike.git/lib/modules/Sql.pmod/pgsql.pike:562:   }      protected 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(object portal) { + protected 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() {    if(waitforauthready) {    Thread.MutexKey lock=waitforauth->lock();    catch(waitforauthready->wait(lock));    lock=0;    }   }    - final void _processloop(object ci) { + final void _processloop(.pgsql_util.PGassist ci) {    int terminating=0;    int|.pgsql_util.pgsql_result portal;    mixed err;    { -  object plugbuffer=Stdio.Buffer()->add_int32(PG_PROTOCOL(3,0)); +  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",    "text_query","is_superuser","server_encoding","server_version",    "integer_datetimes","session_authorization">);    string name;mixed value)
pike.git/lib/modules/Sql.pmod/pgsql.pike:1234:   }      //! Closes the connection to the database, any running queries are   //! terminated instantly.   //!   //! @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?->sendterminate();    c=0;   }      void destroy() {    close();    .pgsql_util.unregister_backend();   }      void _connectfail(void|mixed err) {    PD("Connect failed %O reconnectdelay %d\n",err,reconnectdelay);
pike.git/lib/modules/Sql.pmod/pgsql.pike:1271:    if(!waitforauthready)    waitforauthready=Thread.Condition();    lock=0;    PD("Schedule reconnect in %ds\n",tdelay);    _delayederror=0;    .pgsql_util.local_backend->call_out(reconnect,tdelay,1);    } else if(err)    _delayederror=err;   }    - protected int reconnect(void|int force,void|object tt) { + protected 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:1539:    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=({}); -  object res=big_query("SELECT d.datname " +  .pgsql_util.pgsql_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 -  object res=big_query( // due to missing schemasupport +  .pgsql_util.pgsql_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:1618:   //!   //! @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);    -  object res = big_typed_query( +  .pgsql_util.pgsql_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:1724:   //! @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(object plugbuffer,string oldprep) { + final inline void closestatement( +  .pgsql_util.PGassist|.pgsql_util.PGplugbuffer plugbuffer,string oldprep) {    .pgsql_util.closestatement(plugbuffer,oldprep);   }      protected inline string int2hex(int i) {    return String.int2hex(i);   }      final inline void throwdelayederror(object parent) {    .pgsql_util.throwdelayederror(parent);   }
pike.git/lib/modules/Sql.pmod/pgsql.pike:1784:   //! 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] - object big_query(string q,void|mapping(string|int:mixed) bindings, + .pgsql_util.pgsql_result big_query(string q, +  void|mapping(string|int:mixed) bindings,    void|int _alltyped) {    throwdelayederror(this);    string preparedname="";    int forcecache=-1;    int forcetext=options.text_query;    if(waitforauthready)    waitauthready();    string cenc=_runtimeparameter[CLIENT_ENCODING];    switch(cenc) {    case UTF8CHARSET:
pike.git/lib/modules/Sql.pmod/pgsql.pike:1898:    }    }    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    tp=UNDEFINED; -  object portal; +  .pgsql_util.pgsql_result portal;    portal=.pgsql_util.pgsql_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="";
pike.git/lib/modules/Sql.pmod/pgsql.pike:1959:    }    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] - object streaming_query(string q,void|mapping(string|int:mixed) bindings) { + .pgsql_util.pgsql_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] - object big_typed_query(string q,void|mapping(string|int:mixed) bindings) { + .pgsql_util.pgsql_result big_typed_query(string q, +  void|mapping(string|int:mixed) bindings) {    return big_query(q,bindings,1);   }