2014-08-16
2014-08-16 01:25:04 by Martin Nilsson <nilsson@opera.com>
-
11b13bac9aa6ee37adc3a6554f6e4d2b73d0d9c9
(737 lines)
(+402/-335)
[
Show
| Annotate
]
Branch: 8.0
Less crazy coding style.
13:
//! Some pgsql utility functions
class PGassist
- { int(-1..1) peek(int timeout) { }
+ {
+ int(-1..1) peek(int timeout) { }
string read(int len,void|int(0..1) not_all) { }
31:
object portal;
void setportal(void|object newportal)
- { portal=newportal;
+ {
+ portal=newportal;
}
inline int(-1..1) bpeek(int timeout)
- { return peek(timeout);
+ {
+ return peek(timeout);
}
int flushed=-1;
inline final int getbyte()
- { if(!flushed && !bpeek(0))
+ {
+ if(!flushed && !bpeek(0))
sendflush();
return getchar();
}
final string getstring(void|int len)
- { String.Buffer acc=String.Buffer();
+ {
+ String.Buffer acc=String.Buffer();
if(!undefinedp(len))
- { string res;
+ {
+ string res;
do
- { if(!flushed && !bpeek(0))
+ {
+ if(!flushed && !bpeek(0))
sendflush();
res=read(len,!flushed);
if(res)
- { if(!sizeof(res))
+ {
+ if(!sizeof(res))
return acc->get();
acc->add(res);
}
70:
}
inline final int getint16()
- { int s0=getbyte();
+ {
+ int s0=getbyte();
int r=(s0&0x7f)<<8|getbyte();
return s0&0x80 ? r-(1<<15) : r ;
}
inline final int getint32()
- { int r=getint16();
+ {
+ int r=getint16();
r=r<<8|getbyte();
return r<<8|getbyte();
}
inline final int getint64()
- { int r=getint32();
+ {
+ int r=getint32();
return r<<32|getint32()&0xffffffff;
}
#endif
inline final string plugbyte(int x)
- { return String.int2char(x&255);
+ {
+ return String.int2char(x&255);
}
inline final string plugint16(int x)
- { return sprintf("%c%c",x>>8&255,x&255);
+ {
+ return sprintf("%c%c",x>>8&255,x&255);
}
inline final string plugint32(int x)
- { return sprintf("%c%c%c%c",x>>24&255,x>>16&255,x>>8&255,x&255);
+ {
+ return sprintf("%c%c%c%c",x>>24&255,x>>16&255,x>>8&255,x&255);
}
inline final string plugint64(int x)
- { return sprintf("%c%c%c%c%c%c%c%c",x>>56&255,x>>48&255,x>>40&255,x>>32&255,
+ {
+ return sprintf("%c%c%c%c%c%c%c%c",x>>56&255,x>>48&255,x>>40&255,x>>32&255,
x>>24&255,x>>16&255,x>>8&255,x&255);
}
final void sendflush()
- { sendcmd(({}),1);
+ {
+ sendcmd(({}),1);
}
final void sendcmd(string|array(string) data,void|int flush)
- { if(arrayp(data))
+ {
+ if(arrayp(data))
cmdbuf+=data;
else
cmdbuf+=({data});
switch(flush)
- { case 3:
+ {
+ case 3:
cmdbuf+=({FLUSH});
flushed=1;
break;
126:
PD("Flush\n");
case 2:
flushed=1;
- { int i=write(cmdbuf);
+ {
+ int i=write(cmdbuf);
if(portal && portal._pgsqlsess)
{ portal._pgsqlsess._packetssent++;
portal._pgsqlsess._bytessent+=i;
137:
}
final void sendterminate()
- { PD("Terminate\n");
+ {
+ PD("Terminate\n");
sendcmd(({"X",plugint32(4)}),2);
close();
}
151:
}
class PGconn
- { inherit PGassist:pg;
+ {
+ inherit PGassist:pg;
#ifdef UNBUFFEREDIO
inherit Stdio.File:std;
inline int getchar()
- { return std::read(1)[0];
+ {
+ return std::read(1)[0];
}
#else
inherit Stdio.FILE:std;
inline int getchar()
- { return std::getchar();
+ {
+ return std::getchar();
}
#endif
inline int(-1..1) peek(int timeout)
- { return std::peek(timeout);
+ {
+ return std::peek(timeout);
}
inline string read(int len,void|int(0..1) not_all)
- { return std::read(len,not_all);
+ {
+ return std::read(len,not_all);
}
inline int write(string|array(string) data)
- { return std::write(data);
+ {
+ return std::write(data);
}
int close()
- { return std::close();
+ {
+ return std::close();
}
void create(Stdio.File stream,object t)
- { std::create();
+ {
+ std::create();
std::assign(stream);
pg::create();
}
191: Inside #if constant(SSL.File)
#if constant(SSL.File)
class PGconnS
- { inherit SSL.File:std;
+ {
+ inherit SSL.File:std;
inherit PGassist:pg;
Stdio.File rawstream;
inline int(-1..1) peek(int timeout)
- { return rawstream.peek(timeout); // This is a kludge
+ {
+ return rawstream.peek(timeout); // This is a kludge
} // Actually SSL.File should provide a peek() method
inline string read(int len,void|int(0..1) not_all)
- { return std::read(len,not_all);
+ {
+ return std::read(len,not_all);
}
inline int write(string|array(string) data)
- { return std::write(data);
+ {
+ return std::write(data);
}
void create(Stdio.File stream, SSL.Context ctx)
- { rawstream=stream;
+ {
+ rawstream=stream;
std::create(stream,ctx);
std::set_blocking();
if (!std::connect()) {
262:
private object fetchmutex;
protected string _sprintf(int type, void|mapping flags)
- { string res=UNDEFINED;
+ {
+ string res=UNDEFINED;
switch(type)
- { case 'O':
+ {
+ case 'O':
res=sprintf("pgsql_result numrows: %d eof: %d querylock: %d"
- " inflight: %d\nportalname: %O datarows: %d laststatus: %s\n",
+ " inflight: %d\nportalname: %O datarows: %d"
+ " laststatus: %s\n",
numrows,eoffound,!!_qmtxkey,_inflight,
_portalname,sizeof(_datarowdesc),
_statuscmdcomplete||"");
277:
void create(object pgsqlsess,string query,int fetchlimit,
int portalbuffersize,int alltyped,array params,int forcetext)
- { _pgsqlsess = pgsqlsess;
+ {
+ _pgsqlsess = pgsqlsess;
_query = query;
_datarows = ({ }); numrows = UNDEFINED;
fetchmutex = Thread.Mutex();
298:
//! This function is PostgreSQL-specific, and thus it is not available
//! through the generic SQL-interface.
string status_command_complete()
- { return _statuscmdcomplete;
+ {
+ return _statuscmdcomplete;
}
//! Returns the number of affected rows by this query.
310:
//! This function is PostgreSQL-specific, and thus it is not available
//! through the generic SQL-interface.
int affected_rows()
- { int rows;
+ {
+ int rows;
if(_statuscmdcomplete)
sscanf(_statuscmdcomplete,"%*s %d",rows);
return rows;
319:
//! @seealso
//! @[Sql.sql_result()->num_fields()]
int num_fields()
- { return sizeof(_datarowdesc);
+ {
+ return sizeof(_datarowdesc);
}
//! @seealso
//! @[Sql.sql_result()->num_rows()]
int num_rows()
- { int numrows;
+ {
+ int numrows;
if(_statuscmdcomplete)
sscanf(_statuscmdcomplete,"%*s %d",numrows);
return numrows;
334:
//! @seealso
//! @[Sql.sql_result()->eof()]
int eof()
- { return eoffound;
+ {
+ return eoffound;
}
//! @seealso
//! @[Sql.sql_result()->fetch_fields()]
array(mapping(string:mixed)) fetch_fields()
- { return _datarowdesc+({});
+ {
+ return _datarowdesc+({});
}
private void releasesession()
- { if(_pgsqlsess)
- { if(copyinprogress)
- { PD("CopyDone\n");
+ {
+ if(_pgsqlsess)
+ {
+ if(copyinprogress)
+ {
+ PD("CopyDone\n");
_pgsqlsess._c.sendcmd("c\0\0\0\4",1);
}
if(_pgsqlsess.is_open())
356:
_pgsqlsess=UNDEFINED;
}
- void destroy()
- { catch // inside destructors, exceptions don't work
- { releasesession();
+ private void destroy()
+ {
+ catch // inside destructors, exceptions don't work
+ {
+ releasesession();
};
}
inline private array(mixed) getdatarow()
- { array(mixed) datarow=_datarows[0];
+ {
+ array(mixed) datarow=_datarows[0];
_datarows=_datarows[1..];
return datarow;
}
375: Inside #if undefined(NO_LOCKING)
Thread.MutexKey stealmtxkey = _pgsqlsess._stealmutex.lock();
do
if(_qmtxkey = _pgsqlsess._querymutex.current_locking_key())
- { pgsql_result portalb;
+ {
+ pgsql_result portalb;
if(portalb=_pgsqlsess._c.portal)
- { _pgsqlsess._nextportal++;
+ {
+ _pgsqlsess._nextportal++;
if(portalb->_interruptable)
portalb->fetch_row(2);
else
- { PD("Waiting for the querymutex\n");
+ {
+ PD("Waiting for the querymutex\n");
if((_qmtxkey=_pgsqlsess._querymutex.lock(2)))
- { if(copyinprogress)
+ {
+ if(copyinprogress)
error("COPY needs to be finished first\n");
error("Driver bug, please report, "
"conflict while interleaving SQL-operations\n");
432:
if(!buffer && sizeof(_datarows))
return getdatarow();
if(copyinprogress)
- { fetchmtxkey = UNDEFINED;
+ {
+ fetchmtxkey = UNDEFINED;
if(stringp(buffer) || arrayp(buffer))
- { int totalsize=4;
+ {
+ int totalsize=4;
if(arrayp(buffer))
foreach(buffer;;string value)
totalsize+=sizeof(value);
450:
}
mixed err;
if(buffer!=2 && (err=delayederror))
- { delayederror=UNDEFINED;
+ {
+ delayederror=UNDEFINED;
throw(err);
}
err = catch
- { if(_portalname)
- { if(buffer!=2 && !_qmtxkey)
- { steallock();
+ {
+ if(_portalname)
+ {
+ if(buffer!=2 && !_qmtxkey)
+ {
+ steallock();
if(_fetchlimit)
_pgsqlsess._sendexecute(_fetchlimit);
}
472:
_buffer=buffer;
#endif
switch(_pgsqlsess._decodemsg())
- { case copyinresponse:
+ {
+ case copyinresponse:
copyinprogress=1;
return UNDEFINED;
case dataready:
_pgsqlsess._mstate=dataprocessed;
_rowsreceived++;
switch(buffer)
- { case 0:
+ {
+ case 0:
case 1:
if(_fetchlimit)
_fetchlimit=
487:
_pgsqlsess._fetchlimit);
}
switch(buffer)
- { case 2:
+ {
+ case 2:
case 3:
continue;
case 1:
509:
_inflight=0;
releasesession();
switch(buffer)
- { case 1:
+ {
+ case 1:
case 2:
return UNDEFINED;
case 3:
521:
if(_inflight)
continue;
if(_pgsqlsess._nextportal)
- { switch(buffer)
- { case 1:
+ {
+ switch(buffer)
+ {
+ case 1:
case 2:
_qmtxkey = UNDEFINED;
return UNDEFINED;
532:
}
_fetchlimit=FETCHLIMITLONGRUN;
if(sizeof(_datarows))
- { _qmtxkey = UNDEFINED;
+ {
+ _qmtxkey = UNDEFINED;
return getdatarow();
}
buffer=3;
556:
return UNDEFINED;
}
- };
+ }