Branch: Tag:

2009-04-10

2009-04-10 17:19:53 by Stephen R. van den Berg <srb@cuci.nl>

Fix formatting and whitespace.

Rev: lib/modules/Sql.pmod/pgsql.h:1.5
Rev: lib/modules/Sql.pmod/pgsql.pike:1.62
Rev: lib/modules/Sql.pmod/pgsql_util.pmod:1.18
Rev: src/modules/_PGsql/PGsql.cmod:1.34

113:      #define USERERROR(msg) throw(({(msg), backtrace()[..<1]}))    - protected string _sprintf(int type, void|mapping flags) { -  string res=UNDEFINED; -  switch(type) { -  case 'O': + protected string _sprintf(int type, void|mapping flags) + { string res=UNDEFINED; +  switch(type) +  { case 'O':    res=sprintf(DRIVERNAME"(%s@%s:%d/%s,%d)",    user,host,port,database,backendpid);    break;
149:      //! @decl void create()   //! @decl void create(string host, void|string database, void|string user,@ - //! void|string password, void|mapping(string:mixed) options) + //! void|string password, void|mapping(string:mixed) options)   //!   //! With no arguments, this function initialises (reinitialises if a   //! connection has been set up previously) a connection to the
176:   //! Currently supports at least the following:   //! @mapping   //! @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 + //! 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 + //! If the database supports and allows SSL connections, the session + //! will be SSL encrypted, if not, the connection will abort   //! @member int cache_autoprepared_statements - //! If set to zero, it disables the automatic statement prepare and - //! cache logic; caching prepared statements can be problematic - //! when stored procedures and tables are redefined which leave stale - //! references in the already cached prepared statements + //! If set to zero, it disables the automatic statement prepare and + //! cache logic; caching prepared statements can be problematic + //! when stored procedures and tables are redefined which leave stale + //! references in the already cached prepared statements   //! @member string client_encoding - //! Character encoding for the client side, it defaults to using - //! the default encoding specified by the database, e.g.: "SQL_ASCII" + //! Character encoding for the client side, it defaults to using + //! the default encoding specified by the database, e.g.: "SQL_ASCII"   //! @member string standard_conforming_strings - //! When on, backslashes in strings must not be escaped any longer, - //! @[quote()] automatically adjusts quoting strategy accordingly + //! When on, backslashes in strings must not be escaped any longer, + //! @[quote()] automatically adjusts quoting strategy accordingly   //! @member string escape_string_warning - //! When on, a warning is issued if a backslash (\) appears in an - //! ordinary string literal and @[standard_conforming_strings] is off, - //! defaults to on + //! When on, a warning is issued if a backslash (\) appears in an + //! ordinary string literal and @[standard_conforming_strings] is off, + //! defaults to on   //! @endmapping   //! For the numerous other options please check the PostgreSQL manual.   //!
211:   //! @[Postgres.postgres], @[Sql.Sql], @[select_db()],   //! @url{http://search.postgresql.org/search?u=%2Fdocs%2F&q=client+connection+defaults@}   protected void create(void|string _host, void|string _database, -  void|string _user, void|string _pass, void|mapping(string:mixed) _options) { -  pass = _pass; _pass = "CENSORED"; +  void|string _user, void|string _pass, void|mapping(string:mixed) _options) + { pass = _pass; _pass = "CENSORED";    if(pass)    String.secure(pass);    user = _user; database = _database; host = _host || PGSQL_DEFAULT_HOST;
245:   //!   //! @seealso   //! @[big_query()] - string error(void|int clear) { -  string s=lastmessage*"\n"; + string error(void|int clear) + { string s=lastmessage*"\n";    if(clear)    lastmessage=({});    warningscollected=0;
258:   //!   //! @seealso   //! @[server_info()] - string host_info() { -  return sprintf("fd:%d TCP/IP %s:%d PID %d", + string host_info() + { return sprintf("fd:%d TCP/IP %s:%d PID %d",    _c?_c.query_fd():-1,host,port,backendpid);   }    - final private object getsocket(void|int nossl) { -  object lcon = Stdio.File(); + final private object getsocket(void|int nossl) + { object lcon = Stdio.File();    if(!lcon.connect(host,port))    return UNDEFINED;       object fcon;   #if constant(SSL.sslfile) -  if(!nossl && (options->use_ssl || options->force_ssl)) { -  PD("SSLRequest\n"); +  if(!nossl && (options->use_ssl || options->force_ssl)) +  { PD("SSLRequest\n");    { object c=.pgsql_util.PGassist();    lcon.write(({c.plugint32(8),c.plugint32(PG_PROTOCOL(1234,5679))}));    } -  switch(lcon.read(1)) { -  case "S": +  switch(lcon.read(1)) +  { case "S":    SSL.context context = SSL.context();    context->random = Crypto.Random.random_string;    fcon=.pgsql_util.PGconnS(lcon, context);
308:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - void cancelquery() { -  if(qstate==inquery) { -  qstate=cancelpending; + void cancelquery() + { if(qstate==inquery) +  { qstate=cancelpending;    object lcon;    PD("CancelRequest\n");    if(!(lcon=getsocket(1)))
351:   //! Common values are:   //! @mapping   //! @member string client_encoding - //! Character encoding for the client side, e.g.: "SQL_ASCII" + //! Character encoding for the client side, e.g.: "SQL_ASCII"   //! @member string server_encoding - //! Character encoding for the server side as determined when the - //! database was created, e.g.: "SQL_ASCII" + //! Character encoding for the server side as determined when the + //! database was created, e.g.: "SQL_ASCII"   //! @member string DateStyle - //! Date parsing/display, e.g.: "ISO, DMY" + //! Date parsing/display, e.g.: "ISO, DMY"   //! @member string TimeZone - //! Default timezone used by the database, e.g.: "localtime" + //! Default timezone used by the database, e.g.: "localtime"   //! @member string standard_conforming_strings - //! When on, backslashes in strings must not be escaped any longer + //! When on, backslashes in strings must not be escaped any longer   //! @member string session_authorization - //! Displays the authorisationrole which the current session runs under + //! Displays the authorisationrole which the current session runs under   //! @member string is_superuser - //! Indicates if the current authorisationrole has database-superuser - //! privileges + //! Indicates if the current authorisationrole has database-superuser + //! privileges   //! @member string integer_datetimes - //! Reports wether the database supports 64-bit-integer dates and times + //! Reports wether the database supports 64-bit-integer dates and times   //! @member string server_version - //! Shows the server version, e.g.: "8.3.3" + //! Shows the server version, e.g.: "8.3.3"   //! @endmapping   //!   //! The values can be changed during a session using SET commands to the
432:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - mapping(string:mixed) getstatistics() { -  mapping(string:mixed) stats=([ + mapping(string:mixed) getstatistics() + { mapping(string:mixed) stats=([    "warnings_dropped":warningsdropcount,    "skipped_describe_count":skippeddescribe,    "used_prepared_statements":prepstmtused,
462:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int setcachedepth(void|int newdepth) { -  int olddepth=cachedepth; + int setcachedepth(void|int newdepth) + { int olddepth=cachedepth;    if(!zero_type(newdepth) && newdepth>=0)    cachedepth=newdepth;    return olddepth;
478:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int settimeout(void|int newtimeout) { -  int oldtimeout=timeout; + int settimeout(void|int newtimeout) + { int oldtimeout=timeout;    if(!zero_type(newtimeout) && newtimeout>0)    timeout=newtimeout;    return oldtimeout;
494:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int setportalbuffersize(void|int newportalbuffersize) { -  int oldportalbuffersize=portalbuffersize; + int setportalbuffersize(void|int newportalbuffersize) + { int oldportalbuffersize=portalbuffersize;    if(!zero_type(newportalbuffersize) && newportalbuffersize>0)    portalbuffersize=newportalbuffersize;    return oldportalbuffersize;
510:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - int setfetchlimit(void|int newfetchlimit) { -  int oldfetchlimit=_fetchlimit; + int setfetchlimit(void|int newfetchlimit) + { int oldfetchlimit=_fetchlimit;    if(!zero_type(newfetchlimit) && newfetchlimit>=0)    _fetchlimit=newfetchlimit;    return oldfetchlimit;   }    - final private string glob2reg(string glob) { -  if (!glob||!sizeof(glob)) + final private string glob2reg(string glob) + { if(!glob||!sizeof(glob))    return "%";    return replace(glob,({"*","?","\\","%","_"}),({"%","_","\\\\","\\%","\\_"}));   }    - final private string a2nls(array(string) msg) { -  return msg*"\n"+"\n"; + final private string a2nls(array(string) msg) + { return msg*"\n"+"\n";   }    - final private string pinpointerror(void|string query,void|string offset) { -  if(!query) + final private string pinpointerror(void|string query,void|string offset) + { if(!query)    return "";    int k=(int)offset;    if(k<=0)
536:    return MARKSTART+(k>1?query[..k-2]:"")+MARKERROR+query[k-1..]+MARKEND;   }    - final int _decodemsg(void|state waitforstate) { + final int _decodemsg(void|state waitforstate) + {   #ifdef DEBUG    { array line;   #ifdef DEBUGMORE
545: Inside #if defined(DEBUG)
   PD("Waiting for state %O %O\n",waitforstate,line&&line[sizeof(line)-2]);    }   #endif -  while(_mstate!=waitforstate) { -  if(_mstate!=unauthenticated) { -  if(qstate==cancelpending) +  while(_mstate!=waitforstate) +  { if(_mstate!=unauthenticated) +  { if(qstate==cancelpending)    qstate=canceled,sendclose(); -  if(_c.flushed && qstate==inquery && !_c.bpeek(0)) { -  int tcurr=time(); +  if(_c.flushed && qstate==inquery && !_c.bpeek(0)) +  { int tcurr=time();    int told=tcurr+timeout;    sessionblocked++;    while(!_c.bpeek(told-tcurr)) -  if((tcurr=time())-told>=timeout) { -  sendclose();cancelquery(); +  if((tcurr=time())-told>=timeout) +  { sendclose();cancelquery();    break;    }    }
566:    _bytesreceived+=1+msglen;    enum errortype { noerror=0, protocolerror, protocolunsupported };    errortype errtype=noerror; -  switch(msgtype) { -  void storetiming() { -  tprepared->trun=gethrtime()-tprepared->trunstart; +  switch(msgtype) +  { void storetiming() +  { tprepared->trun=gethrtime()-tprepared->trunstart;    m_delete(tprepared,"trunstart");    tprepared = UNDEFINED;    }; -  void getcols() { -  int bintext=_c.getbyte(); +  void getcols() +  { int bintext=_c.getbyte();    array a;    int cols=_c.getint16();    msglen-=4+1+2+2*cols;    foreach(a=allocate(cols,([]));;mapping m)    m->type=_c.getint16(); -  if(_c.portal) { // Discard column info, and make it line oriented -  a=({(["type":bintext?BYTEAOID:TEXTOID,"name":"line"])}); +  if(_c.portal) // Discard column info, and make it line oriented +  { a=({(["type":bintext?BYTEAOID:TEXTOID,"name":"line"])});    _c.portal->_datarowdesc=a;    }    _mstate=gotrowdescription;    }; -  array(string) getstrings() { -  string s; +  array(string) getstrings() +  { string s;    if(msglen<1)    errtype=protocolerror;    s=_c.getstring(msglen);
597:    s=s[..msglen-1];msglen=0;    return s/"\0";    }; -  mapping(string:string) getresponse() { -  mapping(string:string) msgresponse=([]); +  mapping(string:string) getresponse() +  { mapping(string:string) msgresponse=([]);    msglen-=4;    foreach(getstrings();;string f)    if(sizeof(f))
610:    { string sendpass;    int authtype;    msglen-=4+4; -  switch(authtype=_c.getint32()) { -  case 0:PD("Ok\n"); +  switch(authtype=_c.getint32()) +  { case 0:PD("Ok\n");    _mstate=authenticated;    break;    case 2:PD("KerberosV5\n");
658:    errtype=protocolunsupported;    break;    } -  switch(errtype) { -  case noerror: +  switch(errtype) +  { case noerror:    if(_mstate==unauthenticated)    _c.sendcmd(({"p",_c.plugint32(4+sizeof(sendpass)+1),    sendpass,"\0"}),1);
678:    case 'S':PD("ParameterStatus\n");    msglen-=4;    { array(string) ts=getstrings(); -  if(sizeof(ts)==2) { -  _runtimeparameter[ts[0]]=ts[1]; +  if(sizeof(ts)==2) +  { _runtimeparameter[ts[0]]=ts[1];    PD("%s=%s\n",ts[0],ts[1]);    }    else
718:    _c.portal?_c.portal->_portalname:"DISCARDED");    msglen-=4+2;    { array a; -  foreach(a=allocate(_c.getint16());int i;) { -  string s; +  foreach(a=allocate(_c.getint16());int i;) +  { string s;    msglen-=sizeof(s=_c.getstring())+1;    mapping(string:mixed) res=(["name":s]);    msglen-=4+2+4+2+4+2;
752:    break;    case 'D':PD("DataRow\n");    msglen-=4; -  if(_c.portal) { -  if(tprepared) +  if(_c.portal) +  { if(tprepared)    storetiming();   #ifdef USEPGsql    _c.decodedatarow(msglen);msglen=0;
766:    string cenc=_runtimeparameter[CLIENT_ENCODING];    a=allocate(cols,UNDEFINED);    msglen-=2+4*cols; -  foreach(a;int i;) { -  int collen=_c.getint32(); -  if(collen>0) { -  msglen-=collen; +  foreach(a;int i;) +  { int collen=_c.getint32(); +  if(collen>0) +  { msglen-=collen;    mixed value;    switch(datarowdesc[i]->type)    { default:value=_c.getstring(collen);
828:    if(msglen<1)    errtype=protocolerror;    string s=_c.getstring(msglen-1); -  if(_c.portal) { -  if(tprepared) +  if(_c.portal) +  { if(tprepared)    storetiming();    _c.portal->_statuscmdcomplete=s;    }
854:    msglen-=4;    if(msglen<0)    errtype=protocolerror; -  if(_c.portal) { -  _c.portal->_bytesreceived+=msglen; +  if(_c.portal) +  { _c.portal->_bytesreceived+=msglen;    _c.portal->_datarows+=({({_c.getstring(msglen)})});    }    msglen=0;
876:    msgresponse=getresponse();    warningsdropcount+=warningscollected;    warningscollected=0; -  switch(msgresponse->C) { -  case "P0001": +  switch(msgresponse->C) +  { case "P0001":    lastmessage=({sprintf("%s: %s",msgresponse->S,msgresponse->M)});    USERERROR(a2nls(lastmessage    +({pinpointerror(_c.portal->query,msgresponse->P)})));
899:    pinpointerror(msgresponse->q,msgresponse->p)});    if(msgresponse->W)    lastmessage+=({msgresponse->W}); -  switch(msgresponse->S) { -  case "PANIC":werror(a2nls(lastmessage)); +  switch(msgresponse->S) +  { case "PANIC":werror(a2nls(lastmessage));    }    USERERROR(a2nls(lastmessage));    }
909:    case 'N':PD("NoticeResponse\n");    { mapping(string:string) msgresponse;    msgresponse=getresponse(); -  if(clearmessage) { -  warningsdropcount+=warningscollected; +  if(clearmessage) +  { warningsdropcount+=warningscollected;    clearmessage=warningscollected=0;    lastmessage=({});    }
924:    int pid=_c.getint32();    string condition,extrainfo=UNDEFINED;    { array(string) ts=getstrings(); -  switch(sizeof(ts)) { -  case 0:errtype=protocolerror; +  switch(sizeof(ts)) +  { case 0:errtype=protocolerror;    break;    default:errtype=protocolerror;    case 2:extrainfo=ts[1];
937:    break;    }    default: -  if(msgtype!=-1) { -  PD("Unknown message received %c\n",msgtype); +  if(msgtype!=-1) +  { PD("Unknown message received %c\n",msgtype);    msglen-=4;PD("%O\n",_c.getstring(msglen));msglen=0;    errtype=protocolunsupported;    } -  else { -  array(string) msg=lastmessage; -  if(!reconnect(1)) { -  sleep(RECONNECTDELAY); -  if(!reconnect(1)) { -  sleep(RECONNECTBACKOFF); +  else +  { array(string) msg=lastmessage; +  if(!reconnect(1)) +  { sleep(RECONNECTDELAY); +  if(!reconnect(1)) +  { sleep(RECONNECTBACKOFF);    reconnect(1);    }    }
960:    }    if(msglen)    errtype=protocolerror; -  switch(errtype) { -  case protocolunsupported: +  switch(errtype) +  { case protocolunsupported:    ERROR("Unsupported servermessage received %c\n",msgtype);    break;    case protocolerror:
983:   }      #ifndef UNBUFFEREDIO - private int read_cb(mixed foo, string d) { -  _c.unread(d); + private int read_cb(mixed foo, string d) + { _c.unread(d);    do _decodemsg();    while(_c.bpeek(0)==1);    return 0;
997:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - void close() { -  cancelquery(); + void close() + { cancelquery();    if(_c)    _c.sendterminate();   }    - void destroy() { -  close(); + void destroy() + { close();   }    - private int reconnect(void|int force) { -  Thread.MutexKey connectmtxkey; -  if(_c) { -  reconnected++; + private int reconnect(void|int force) + { Thread.MutexKey connectmtxkey; +  if(_c) +  { reconnected++;    prepstmtused=0;   #ifdef DEBUG    ERROR("While debugging, reconnects are forbidden\n");
1024:    if(!(connectmtxkey = _stealmutex.trylock(2)))    return 0; // Recursive reconnect, bailing out    } -  if(!(_c=getsocket())) { -  string msg=sprintf("Couldn't connect to database on %s:%d",host,port); -  if(force) { -  lastmessage+=({msg}); +  if(!(_c=getsocket())) +  { string msg=sprintf("Couldn't connect to database on %s:%d",host,port); +  if(force) +  { lastmessage+=({msg});    return 0;    }    else
1060:    return 0;    }    PD("%O\n",_runtimeparameter); -  if(force) { -  lastmessage+=({sprintf("Reconnected to database %s",host_info())}); +  if(force) +  { lastmessage+=({sprintf("Reconnected to database %s",host_info())});    runcallback(backendpid,"_reconnect","");    }    return 1;
1073:   //!   //! @seealso   //! @[resync()], @[cancelquery()] - void reload() { -  resync(); + void reload() + { resync();   }      //! @decl void resync()
1099:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - void resync(void|int special) { -  mixed err; + void resync(void|int special) + { mixed err;    int didsync; -  if(err = catch { -  sendclose(1); +  if(err = catch +  { sendclose(1);    PD("Portalsinflight: %d\n",portalsinflight); -  if(!portalsinflight) { -  if(!earlyclose) { -  PD("Sync\n"); +  if(!portalsinflight) +  { if(!earlyclose) +  { PD("Sync\n");    _c.sendcmd(({"S",_c.plugint32(4)}),2);    }    didsync=1; -  if(!special) { -  _decodemsg(readyforquery); -  switch(backendstatus) { -  case 'T':case 'E': -  foreach(prepareds;;mapping tp) { -  m_delete(tp,"datatypeoid"); +  if(!special) +  { _decodemsg(readyforquery); +  switch(backendstatus) +  { case 'T':case 'E': +  foreach(prepareds;;mapping tp) +  { m_delete(tp,"datatypeoid");    m_delete(tp,"datarowdesc");    }    big_query("ROLLBACK");
1127:    }    }    earlyclose=0; -  }) { -  earlyclose=0; +  }) +  { earlyclose=0;    PD("%O\n",err);    if(!reconnect(1))    ERROR(a2nls(lastmessage));
1151:   //!   //! @seealso   //! @[create()] - void select_db(string dbname) { -  database=dbname; + void select_db(string dbname) + { database=dbname;    reconnect();    reconnected=0;   }
1172:   //! Function to be called on receiving a notification-event of   //! condition @ref{condition@}.   //! The callback function is invoked with - //! @expr{void notify_cb(pid,condition,extrainfo, .. args);@} + //! @expr{void notify_cb(pid,condition,extrainfo, .. args);@}   //! @ref{pid@} is the process id of the database session that originated   //! the event. @ref{condition@} contains the current condition.   //! @ref{extrainfo@} contains optional extra information specified by
1193:   //! through the generic SQL-interface.   void set_notify_callback(string condition,    void|function(int,string,string,mixed ...:void) notify_cb,void|int selfnotify, -  mixed ... args) { -  if(!notify_cb) +  mixed ... args) + { if(!notify_cb)    m_delete(notifylist,condition); -  else { -  array old=notifylist[condition]; +  else +  { array old=notifylist[condition];    if(!old)    old=({notify_cb});    if(selfnotify||args)
1208:    }   }    - final private void runcallback(int pid,string condition,string extrainfo) { -  array cb; + final private void runcallback(int pid,string condition,string extrainfo) + { array cb;    if((cb=notifylist[condition]||notifylist[""])    && (pid!=backendpid || sizeof(cb)>1 && cb[1]))    cb[0](pid,condition,extrainfo,@cb[2..]);
1245:   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface. - string quotebinary(string s) { -  return replace(s, ({ "'", "\\", "\0" }), ({ "''", "\\\\", "\\000" }) ); + string quotebinary(string s) + { return replace(s, ({ "'", "\\", "\0" }), ({ "''", "\\\\", "\\000" }) );   }      //! This function creates a new database (assuming we
1257:   //!   //! @seealso   //! @[drop_db()] - void create_db(string db) { -  big_query("CREATE DATABASE :db",([":db":db])); + void create_db(string db) + { big_query("CREATE DATABASE :db",([":db":db]));   }      //! This function destroys a database and all the data it contains (assuming
1271:   //!   //! @seealso   //! @[create_db()] - void drop_db(string db) { -  big_query("DROP DATABASE :db",([":db":db])); + void drop_db(string db) + { big_query("DROP DATABASE :db",([":db":db]));   }      //! @returns
1292:   //!   //! @param glob   //! If specified, list only those databases matching it. - array(string) list_dbs (void|string glob) { -  array row,ret=({}); + array(string) list_dbs (void|string glob) + { array row,ret=({});    object res=big_query("SELECT d.datname "    "FROM pg_database d "    "WHERE d.datname ILIKE :glob "
1310:   //!   //! @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 + 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    "SELECT CASE WHEN 'public'=n.nspname THEN '' ELSE n.nspname||'.' END "    " ||c.relname AS name "
1334:   //!   //! @mapping   //! @member string schema - //! Schema the table belongs to + //! Schema the table belongs to   //! @member string table - //! Name of the table + //! Name of the table   //! @member string kind - //! Type of table + //! Type of table   //! @member string owner - //! Tableowner + //! Tableowner   //! @member int rowcount - //! Estimated rowcount of the table + //! Estimated rowcount of the table   //! @member int datasize - //! Estimated total datasize of the table in bytes + //! Estimated total datasize of the table in bytes   //! @member int indexsize - //! Estimated total indexsize of the table in bytes + //! Estimated total indexsize of the table in bytes   //! @member string name - //! Name of the column + //! Name of the column   //! @member string type - //! A textual description of the internal (to the server) column type-name + //! A textual description of the internal (to the server) column type-name   //! @member int typeoid - //! The OID of the internal (to the server) column type + //! The OID of the internal (to the server) column type   //! @member string length - //! Size of the columndatatype + //! Size of the columndatatype   //! @member mixed default - //! Default value for the column + //! Default value for the column   //! @member int is_shared   //! @member int has_index - //! If the table has any indices + //! If the table has any indices   //! @member int has_primarykey - //! If the table has a primary key + //! 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) { -  array row, ret=({}); + array(mapping(string:mixed)) list_fields(void|string table, void|string glob) + { array row, ret=({});    string schema=UNDEFINED;       sscanf(table||"*", "%s.%s", schema, table);
1433:    "relhaspkey":"has_primarykey",    "reltuples":"rowcount",    ]); -  foreach(colnames;int i;mapping m) { -  string nf,field=m->name; +  foreach(colnames;int i;mapping m) +  { string nf,field=m->name;    if(nf=renames[field])    field=nf;    colnames[i]=field;
1443:      #define delifzero(m,field) if(!(m)[field]) m_delete(m,field)    -  while(row=res->fetch_row()) { -  mapping m=mkmapping(colnames,row); +  while(row=res->fetch_row()) +  { mapping m=mkmapping(colnames,row);    delifzero(m,"is_shared");    delifzero(m,"has_index");    delifzero(m,"has_primarykey");
1454:    return ret;   }    - private int oidformat(int oid) { -  switch(oid) { -  case BOOLOID: + private int oidformat(int oid) + { switch(oid) +  { case BOOLOID:    case BYTEAOID:    case CHAROID:    case INT8OID:
1472:    case UUIDOID:    return 1; //binary    } -  return 0; // text +  return 0; // text   }    - final void _sendexecute(int fetchlimit) { -  string portalname=_c.portal->_portalname; + final void _sendexecute(int fetchlimit) + { string portalname=_c.portal->_portalname;    PD("Execute portal %s fetchlimit %d\n",portalname,fetchlimit);    _c.sendcmd(({"E",_c.plugint32(4+sizeof(portalname)+1+4),portalname,    "\0",_c.plugint32(fetchlimit)}),!!fetchlimit); -  if(!fetchlimit) { -  _c.portal->_fetchlimit=0; // disables further Executes +  if(!fetchlimit) +  { _c.portal->_fetchlimit=0; // disables further Executes    earlyclose=1; -  if(sizeof(portalname)) { -  PD("Close portal %s & Sync\n",portalname); +  if(sizeof(portalname)) +  { PD("Close portal %s & Sync\n",portalname);    _c.sendcmd(({"C",_c.plugint32(4+1+sizeof(portalname)+1),    "P",portalname,"\0"}));    }
1494:    _c.portal->_inflight+=fetchlimit;   }    - final private void sendclose(void|int hold) { -  string portalname; -  if(_c.portal && (portalname=_c.portal->_portalname)) { -  _c.portal->_portalname = UNDEFINED; + final private void sendclose(void|int hold) + { string portalname; +  if(_c.portal && (portalname=_c.portal->_portalname)) +  { _c.portal->_portalname = UNDEFINED;    _c.setportal();    portalsinflight--;   #ifdef DEBUGMORE
1505:   #endif    if(!sizeof(portalname))    unnamedportalinuse--; -  if(sizeof(portalname)) { -  if(!earlyclose) { -  PD("Close portal %s\n",portalname); +  if(sizeof(portalname)) +  { if(!earlyclose) +  { PD("Close portal %s\n",portalname);    _c.sendcmd(({"C",_c.plugint32(4+1+sizeof(portalname)+1),    "P",portalname,"\0"}),!hold||portalsinflight?1:0);    }
1516:    }   }    - final private string trbackendst(int c) { -  switch(c) { -  case 'I':return "idle"; + final private string trbackendst(int c) + { switch(c) +  { case 'I':return "idle";    case 'T':return "intransaction";    case 'E':return "infailedtransaction";    }
1536:   //! @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 string status_commit() + { return trbackendst(backendstatus);   }    - final private array(string) closestatement(mapping tp) { -  string oldprep=tp->preparedname; + final private array(string) closestatement(mapping tp) + { string oldprep=tp->preparedname;    array(string) ret=({}); -  if(oldprep) { -  PD("Close statement %s\n",oldprep); +  if(oldprep) +  { PD("Close statement %s\n",oldprep);    ret=({"C",_c.plugint32(4+1+sizeof(oldprep)+1),    "S",oldprep,"\0"});    }
1591:   //! @[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, -  void|int _alltyped) { -  string preparedname=""; +  void|int _alltyped) + { string preparedname="";    string portalname="";    int forcecache=-1;    string cenc=_runtimeparameter[CLIENT_ENCODING];
1606:    }    array(string|int) paramValues;    array(string) from,to; -  if(bindings) { -  int pi=0,rep=0; +  if(bindings) +  { int pi=0,rep=0;    paramValues=allocate(sizeof(bindings));    from=allocate(sizeof(bindings));    to=allocate(sizeof(bindings)); -  foreach(bindings; mixed name; mixed value) { -  if(stringp(name)) { // Throws if mapping key is empty string -  if(name[0]!=':') +  foreach(bindings; mixed name; mixed value) +  { if(stringp(name)) // Throws if mapping key is empty string +  { if(name[0]!=':')    name=":"+name; -  if(name[1]=='_') { // Special option parameter -  switch(name) { -  case ":_cache":forcecache=(int)value; +  if(name[1]=='_') // Special option parameter +  { switch(name) +  { case ":_cache":forcecache=(int)value;    break;    }    continue;
1647:    ERROR("Querystring %O contains invalid literal nul-characters\n",q);    mapping(string:mixed) tp;    int tstart; -  if(forcecache==1 || forcecache!=0 && sizeof(q)>=MINPREPARELENGTH) { -  array(string) plugbuf=({}); -  if(tp=prepareds[q]) { -  if(tp->preparedname) +  if(forcecache==1 || forcecache!=0 && sizeof(q)>=MINPREPARELENGTH) +  { array(string) plugbuf=({}); +  if(tp=prepareds[q]) +  { if(tp->preparedname)    prepstmtused++, preparedname=tp->preparedname;    else if((tstart=tp->trun)    && tp->tparse*FACTORPLAN>=tstart
1658:    || options->cache_autoprepared_statements))    preparedname=PREPSTMTPREFIX+(string)pstmtcount++;    } -  else { -  if(totalhits>=cachedepth) { -  foreach(prepareds;string ind;tp) { -  int oldhits=tp->hits; +  else +  { if(totalhits>=cachedepth) +  { foreach(prepareds;string ind;tp) +  { int oldhits=tp->hits;    totalhits-=oldhits-(tp->hits=oldhits>>1); -  if(oldhits<=1) { -  plugbuf+=closestatement(tp); +  if(oldhits<=1) +  { plugbuf+=closestatement(tp);    m_delete(prepareds,ind);    }    }
1674:    else    prepareds[q]=tp=([]);    } -  if(invalidatecache) { -  invalidatecache=0; -  foreach(prepareds;;mapping np) { -  plugbuf+=closestatement(np); +  if(invalidatecache) +  { invalidatecache=0; +  foreach(prepareds;;mapping np) +  { plugbuf+=closestatement(np);    m_delete(np,"preparedname");    }    } -  if(sizeof(plugbuf)) { -  _c.sendcmd(plugbuf,1); // close expireds +  if(sizeof(plugbuf)) +  { _c.sendcmd(plugbuf,1); // close expireds    PD("%O\n",plugbuf);    }    tstart=gethrtime();
1699:    portalsinflight++; portalsopened++;    clearmessage=1;    mixed err; -  if(err = catch { -  if(!sizeof(preparedname) || !tp || !tp->preparedname) { -  PD("Parse statement %s\n",preparedname); +  if(err = catch +  { if(!sizeof(preparedname) || !tp || !tp->preparedname) +  { PD("Parse statement %s\n",preparedname);    // Even though the protocol doesn't require the Parse command to be    // followed by a flush, it makes a VERY noticeable difference in    // performance if it is omitted; seems like a flaw in the PostgreSQL
1710:    preparedname,"\0",q,"\0",_c.plugint16(0)}),3);    PD("Query: %O\n",q);    } // sends Parameter- and RowDescription for 'S' -  if(!tp || !tp->datatypeoid) { -  PD("Describe statement %s\n",preparedname); +  if(!tp || !tp->datatypeoid) +  { PD("Describe statement %s\n",preparedname);    _c.sendcmd(({"D",_c.plugint32(4+1+sizeof(preparedname)+1),    "S",preparedname,"\0"}),1);    } -  else { -  skippeddescribe++; +  else +  { skippeddescribe++;    _c.portal->_datatypeoid=tp->datatypeoid;    _c.portal->_datarowdesc=tp->datarowdesc;    }
1725:    +2+sizeof(paramValues)*(2+4)+2+2;    plugbuf+=({portalname,"\0",preparedname,"\0",    _c.plugint16(sizeof(paramValues))}); -  if(!tp || !tp->datatypeoid) { -  _decodemsg(gotparameterdescription); +  if(!tp || !tp->datatypeoid) +  { _decodemsg(gotparameterdescription);    if(tp)    tp->datatypeoid=_c.portal->_datatypeoid;    }
1738:    foreach(dtoid;;int textbin)    plugbuf+=({_c.plugint16(oidformat(textbin))});    plugbuf+=({_c.plugint16(sizeof(paramValues))}); -  foreach(paramValues;int i;mixed value) { -  if(zero_type(value)) +  foreach(paramValues;int i;mixed value) +  { if(zero_type(value))    plugbuf+=({_c.plugint32(-1)}); // NULL -  else if(stringp(value) && !sizeof(value)) { -  int k=0; -  switch(dtoid[i]) { -  default: +  else if(stringp(value) && !sizeof(value)) +  { int k=0; +  switch(dtoid[i]) +  { default:    k=-1; // cast empty strings to NULL for non-string types    case BYTEAOID:    case TEXTOID:
1816:    case CHAROID:    if(intp(value))    len++,plugbuf+=({_c.plugint32(1),_c.plugbyte(value)}); -  else { -  value=(string)value; +  else +  { value=(string)value;    switch(sizeof(value))    { default:    ERROR("\"char\" types must be 1 byte wide, got %O\n",
1842:    break;    }    } -  if(!tp || !tp->datarowdesc) { -  if(tp && dontcacheprefix->match(q)) // Don't cache FETCH/COPY +  if(!tp || !tp->datarowdesc) +  { if(tp && dontcacheprefix->match(q)) // Don't cache FETCH/COPY    m_delete(prepareds,q),tp=0;    _decodemsg(gotrowdescription);    if(tp)
1866:    _sendexecute(_fetchlimit    && !limitpostfix->match(q) // Optimisation for LIMIT 1    && FETCHLIMITLONGRUN); -  if(tp) { -  _decodemsg(bindcomplete); +  if(tp) +  { _decodemsg(bindcomplete);    int tend=gethrtime();    if(tend==tstart)    m_delete(prepareds,q); -  else { -  tp->hits++; +  else +  { tp->hits++;    totalhits++; -  if(!tp->preparedname) { -  if(sizeof(preparedname)) +  if(!tp->preparedname) +  { if(sizeof(preparedname))    tp->preparedname=preparedname;    tstart=tend-tstart;    if(!tp->tparse || tp->tparse>tstart)
1885:    }    tprepared=tp;    } -  }) { -  PD("%O\n",err); +  }) +  { PD("%O\n",err);    resync(1);    backendstatus=UNDEFINED; -  if(to && sizeof(to)) { -  string val; +  if(to && sizeof(to)) +  { string val;    int i;    lastmessage+=({"Parameter bindings:"});    foreach(to;i;val)
1899:    }    throw(err);    } -  { object tportal=_c.portal; // Make copy, because it might dislodge -  tportal->fetch_row(1); // upon initial fetch_row() +  { object tportal=_c.portal; // Make copy, because it might dislodge +  tportal->fetch_row(1); // upon initial fetch_row()    return tportal;    }   }
1910:   //!   //! @seealso   //! @[big_query()], @[big_typed_query()], @[Sql.Sql], @[Sql.sql_result] - object streaming_query(string q,void|mapping(string|int:mixed) bindings) { -  return big_query(q,bindings); + object 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
1919:   //!   //! @seealso   //! @[big_query()], @[Sql.Sql], @[Sql.sql_result] - object big_typed_query(string q,void|mapping(string|int:mixed) bindings) { -  return big_query(q,bindings,1); + object big_typed_query(string q,void|mapping(string|int:mixed) bindings) + { return big_query(q,bindings,1);   }