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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:235:   //! from the last statement.   //!   //! @note   //! The string returned is not newline-terminated.   //!   //! @param clear   //! To clear the error, set it to @expr{1@}.   //!   //! @seealso   //! @[big_query()] - string error(void|int clear) { + /*semi*/final string error(void|int clear) {    throwdelayederror(this);    string s=lastmessage*"\n";    if(clear)    lastmessage=({});    warningscollected=0;    return sizeof(s) && s;   }      //! This function returns a string describing what host are we talking to,   //! and how (TCP/IP or UNIX sockets).   //!   //! @seealso   //! @[server_info()] - string host_info() { + /*semi*/final string host_info() {    return sprintf("fd:%d TCP/IP %s:%d PID %d",    c?c->socket->query_fd():-1,_host,_port,backendpid);   }      //! Returns true if the connection seems to be open.   //!   //! @note   //! This function only checks that there's an open connection,   //! and that the other end hasn't closed it yet. No data is   //! sent over the connection.   //!   //! For a more reliable check of whether the connection   //! is alive, please use @[ping()].   //!   //! @seealso   //! @[ping()] - int is_open() { + /*semi*/final int is_open() {    catch {    return c->socket->is_open();    };    return 0;   }      //! @decl int ping()   //!   //! Check whether the connection is alive.   //!
pike.git/lib/modules/Sql.pmod/pgsql.pike:290:   //! @value 0   //! Everything ok.   //! @value 1   //! The connection has reconnected automatically.   //! @value -1   //! The server has gone away, and the connection is dead.   //! @endint   //!   //! @seealso   //! @[is_open()] - int ping() { + /*semi*/final int ping() {    return is_open() && !catch(c->start()->sendcmd(FLUSHSEND))    ? !!reconnected : -1;   }      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() { + /*semi*/final void cancelquery() {    PD("CancelRequest\n");    .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.conxion plugbuffer=c->start(1);
pike.git/lib/modules/Sql.pmod/pgsql.pike:334:      //! 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.   //!   //! @seealso   //! @[get_charset()], @[create()],   //! @url{http://www.postgresql.org/search/?u=%2Fdocs%2Fcurrent%2F&q=character+sets@} - void set_charset(string charset) { + /*semi*/final void set_charset(string charset) {    if(charset)    big_query(sprintf("SET CLIENT_ENCODING TO '%s'",quote(charset)));   }      //! @returns   //! The PostgreSQL name for the current connection charset.   //!   //! @seealso   //! @[set_charset()], @[getruntimeparameters()],   //! @url{http://www.postgresql.org/search/?u=%2Fdocs%2Fcurrent%2F&q=character+sets@} - string get_charset() { + /*semi*/final string get_charset() {    waitauthready();    return _runtimeparameter[CLIENT_ENCODING];   }      //! @returns   //! Currently active runtimeparameters for   //! the open session; these are initialised by the @tt{options@} parameter   //! during session creation, and then processed and returned by the server.   //! Common values are:   //! @mapping
pike.git/lib/modules/Sql.pmod/pgsql.pike:389:   //! The values can be changed during a session using SET commands to the   //! database.   //! For other runtimeparameters check the PostgreSQL documentation.   //!   //! @seealso   //! @url{http://www.postgresql.org/search/?u=%2Fdocs%2Fcurrent%2F&q=client+connection+defaults@}   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - mapping(string:string) getruntimeparameters() { + /*semi*/final mapping(string:string) getruntimeparameters() {    waitauthready();    return _runtimeparameter+([]);   }      //! @returns   //! A set of statistics for the current session:   //! @mapping   //! @member int "warnings_dropped"   //! Number of warnings/notices generated by the database but not   //! collected by the application by using @[error()] after the statements
pike.git/lib/modules/Sql.pmod/pgsql.pike:433:   //! requires multiple messages to be exchanged).   //! @member int "reconnect_count"   //! Number of times the connection to the database has been lost.   //! @member int "portals_in_flight"   //! Currently still open portals, i.e. running statements.   //! @endmapping   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - mapping(string:mixed) getstatistics() { + /*semi*/final mapping(string:mixed) getstatistics() {    mapping(string:mixed) stats=([    "warnings_dropped":warningsdropcount,    "current_prepared_statements":sizeof(_prepareds),    "current_prepared_statement_hits":totalhits,    "prepared_statement_count":pstmtcount,   #ifdef PG_STATS    "used_prepared_statements":prepstmtused,    "skipped_describe_count":skippeddescribe,    "portals_opened_count":portalsopened,   #endif
pike.git/lib/modules/Sql.pmod/pgsql.pike:461:      //! @param newdepth   //! Sets the new cachedepth for automatic caching of prepared statements.   //!   //! @returns   //! The previous cachedepth.   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int setcachedepth(void|int newdepth) { + /*semi*/final int setcachedepth(void|int newdepth) {    int olddepth=cachedepth;    if(!undefinedp(newdepth) && newdepth>=0)    cachedepth=newdepth;    return olddepth;   }      //! @param newtimeout   //! Sets the new timeout for long running queries.   //!   //! @returns   //! The previous timeout.   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int settimeout(void|int newtimeout) { + /*semi*/final int settimeout(void|int newtimeout) {    int oldtimeout=timeout;    if(!undefinedp(newtimeout) && newtimeout>0) {    timeout=newtimeout;    if(c)    c->timeout=timeout;    }    return oldtimeout;   }      //! @param newportalbuffersize   //! Sets the new portalbuffersize for buffering partially concurrent queries.   //!   //! @returns   //! The previous portalbuffersize.   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int setportalbuffersize(void|int newportalbuffersize) { + /*semi*/final int setportalbuffersize(void|int newportalbuffersize) {    int oldportalbuffersize=portalbuffersize;    if(!undefinedp(newportalbuffersize) && newportalbuffersize>0)    portalbuffersize=newportalbuffersize;    return oldportalbuffersize;   }      //! @param newfetchlimit   //! Sets the new fetchlimit to interleave queries.   //!   //! @returns   //! The previous fetchlimit.   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int setfetchlimit(void|int newfetchlimit) { + /*semi*/final int setfetchlimit(void|int newfetchlimit) {    int oldfetchlimit=_fetchlimit;    if(!undefinedp(newfetchlimit) && newfetchlimit>=0)    _fetchlimit=newfetchlimit;    return oldfetchlimit;   }      private string glob2reg(string glob) {    if(!glob||!sizeof(glob))    return "%";    return replace(glob,({"*","?","\\","%","_"}),({"%","_","\\\\","\\%","\\_"}));
pike.git/lib/modules/Sql.pmod/pgsql.pike:1171:    if(err && !stringp(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   //! through the generic SQL-interface. - void close() { + /*semi*/final void close() {    catch(cancelquery());    catch(c->sendterminate());    c=0;    destruct(waitforauthready);   }      protected void destroy() {    catch(close());    .pgsql_util.unregister_backend();   }    - void _connectfail(void|mixed err) { + final void _connectfail(void|mixed err) {    PD("Connect failed %O reconnectdelay %d\n",err,reconnectdelay);    destruct(waitforauthready);    if(!err || reconnectdelay) {    int tdelay;    switch(tdelay=reconnectdelay) {    case 0:    reconnectdelay=RECONNECTDELAY;    break;    default:    if(err)
pike.git/lib/modules/Sql.pmod/pgsql.pike:1268:    _portalsinflight=0;    return 1;   }      //! @decl void reload()   //!   //! For PostgreSQL this function performs the same function as @[resync()].   //!   //! @seealso   //! @[resync()], @[cancelquery()] - void reload() { + /*semi*/final void reload() {    resync();   }      private void reset_dbsession() {    big_query("ROLLBACK");    big_query("RESET ALL");    big_query("CLOSE ALL");    big_query("DISCARD TEMP");   }   
pike.git/lib/modules/Sql.pmod/pgsql.pike:1314:   //! If issued while inside a transaction, it will rollback the transaction,   //! close all open cursors, drop all temporary tables and reset all   //! session variables to their default values.   //!   //! @seealso   //! @[cancelquery()], @[reload()]   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - void resync() { + /*semi*/final void resync() {    mixed err;    if(is_open()) {    err = catch {    PD("Portalsinflight: %d\n",_portalsinflight);    if(!waitforauthready) {    readyforquery_cb=resync_cb;    sendsync();    }    return;    };
pike.git/lib/modules/Sql.pmod/pgsql.pike:1342:   //! restrictions of the Postgres frontend-backend protocol, you always   //! have to be connected to a database, so in fact this function just   //! allows you to connect to a different database on the same server.   //!   //! @note   //! This function @b{can@} raise exceptions if something goes wrong   //! (backend process not running, insufficient privileges...)   //!   //! @seealso   //! @[create()] - void select_db(string dbname) { + /*semi*/final void select_db(string dbname) {    database=dbname;    reconnect();    reconnected=0;   }      //! With PostgreSQL you can LISTEN to NOTIFY events.   //! This function allows you to detect and handle such events.   //!   //! @param condition   //! Name of the notification event we're listening
pike.git/lib/modules/Sql.pmod/pgsql.pike:1382:   //! @param selfnotify   //! Normally notify events generated by your own session are ignored.   //! If you want to receive those as well, set @ref{selfnotify@} to one.   //!   //! @param args   //! Extra arguments to pass to @ref{notify_cb@}.   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - void set_notify_callback(string condition, + /*semi*/final void set_notify_callback(string condition,    void|function(int,string,string,mixed ...:void) notify_cb,void|int selfnotify,    mixed ... args) {    if(!notify_cb)    m_delete(notifylist,condition);    else {    array old=notifylist[condition];    if(!old)    old=({notify_cb});    if(selfnotify||args)    old+=({selfnotify});
pike.git/lib/modules/Sql.pmod/pgsql.pike:1416:   //! @returns   //! The given string, but escapes/quotes all contained magic characters   //! according to the quoting rules of the current session for non-binary   //! arguments in textual SQL-queries.   //!   //! @note   //! Quoting must not be done for parameters passed in bindings.   //!   //! @seealso   //! @[big_query()], @[quotebinary()], @[create()] - string quote(string s) { + /*semi*/final string quote(string s) {    waitauthready();    string r=_runtimeparameter.standard_conforming_strings;    if(r && r=="on")    return replace(s, "'", "''");    return replace(s, ({ "'", "\\" }), ({ "''", "\\\\" }) );   }      //! @returns   //! The given string, but escapes/quotes all contained magic characters   //! for binary (bytea) arguments in textual SQL-queries.   //!   //! @note   //! Quoting must not be done for parameters passed in bindings.   //!   //! @seealso   //! @[big_query()], @[quote()]   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - string quotebinary(string s) { + /*semi*/final string quotebinary(string s) {    return replace(s, ({ "'", "\\", "\0" }), ({ "''", "\\\\", "\\000" }) );   }      //! This function creates a new database (assuming we   //! have sufficient privileges to do this).   //!   //! @param db   //! Name of the new database.   //!   //! @seealso   //! @[drop_db()] - void create_db(string db) { + /*semi*/final void create_db(string db) {    big_query(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()] - void drop_db(string db) { + /*semi*/final void drop_db(string db) {    big_query(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()] - string server_info () { + /*semi*/final string server_info () {    waitauthready();    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) { + /*semi*/final array(string) list_dbs (void|string glob) {    array row,ret=({});    .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) { + /*semi*/final array(string) list_tables (void|string glob) {    array row,ret=({}); // This query might not work on PostgreSQL 7.4    .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",
pike.git/lib/modules/Sql.pmod/pgsql.pike:1560:   //! @member int "is_shared"   //! @member int "has_index"   //! If the table has any indices   //! @member int "has_primarykey"   //! If the table has a primary key   //! @endmapping   //!   //! @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) { + /*semi*/final 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.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( "
pike.git/lib/modules/Sql.pmod/pgsql.pike:1745:   //! 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.sql_result] - .pgsql_util.sql_result big_query(string q, + /*semi*/final .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:1929:    }    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.sql_result streaming_query(string q, + /*semi*/final .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.sql_result big_typed_query(string q, + /*semi*/final .pgsql_util.sql_result big_typed_query(string q,    void|mapping(string|int:mixed) bindings) {    return big_query(q,bindings,1);   }