pike.git
/
lib
/
modules
/
Sql.pmod
/
pgsql.pike
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/lib/modules/Sql.pmod/pgsql.pike:314:
/*semi*/final void cancelquery() { PD("CancelRequest\n"); .pgsql_util.conxion lcon=getsocket(2); lcon->add_int32(16)->add_int32(PG_PROTOCOL(1234,5678)) ->add_int32(backendpid)->add(cancelsecret)->sendcmd(FLUSHSEND); destruct(lcon); // Destruct explicitly to avoid delayed close #ifdef PG_DEBUGMORE PD("Closetrace %O\n",backtrace()); #endif if(c) {
-
.pgsql_util.
conxion
plugbuffer;
+
.pgsql_util.
conxsess
plugbuffer;
if(!catch(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,
pike.git/lib/modules/Sql.pmod/pgsql.pike:605:
Stdio.Buffer plugbuffer=Stdio.Buffer()->add_int32(PG_PROTOCOL(3,0)); if(user) plugbuffer->add("user\0",user,0); if(database) plugbuffer->add("database\0",database,0); _options.reconnect=undefinedp(_options.reconnect) || _options.reconnect; foreach(_options-.pgsql_util.censoroptions; string name; mixed value) plugbuffer->add(name,0,(string)value,0); plugbuffer->add_int8(0); PD("%O\n",(string)plugbuffer);
-
if(catch(ci->start()
->add_hstring(plugbuffer,4,4
)
->sendcmd(SENDOUT
)
))
{
+
object cs;
+
if
(catch(
cs =
ci->start())) {
if(_options.reconnect) _connectfail(); else destruct(waitforauthready); unnamedstatement=0; termlock=0; return;
-
+
} else {
+
CHAIN(cs)->add_hstring(plugbuffer, 4, 4);
+
cs->sendcmd(SENDOUT);
} } // Do not flush at this point, PostgreSQL 9.4 disapproves procmessage(); } private void procmessage() { mixed err; int terminating=0; err = catch { .pgsql_util.conxion ci=c; // cache value FIXME sensible?
pike.git/lib/modules/Sql.pmod/pgsql.pike:770:
msglen=0; #endif break; default: PD("Unknown Authentication Method %c\n",authtype); errtype=PROTOCOLUNSUPPORTED; break; } switch(errtype) { case NOERROR:
-
if(cancelsecret!="")
-
ci->start()->add_int8('p')->add_hstring(({sendpass,0}),4,4)
-
->sendcmd(SENDOUT);
+
if(cancelsecret!="")
{
+
object cs =
ci->start()
;
+
CHAIN(cs)
->add_int8('p')->add_hstring(({sendpass,
0}),
4,
4)
;
+
cs
->sendcmd(SENDOUT);
+
}
break; // No flushing here, PostgreSQL 9.4 disapproves default: case PROTOCOLUNSUPPORTED: ERROR("Unsupported authenticationmethod %c\n",authtype); break; } break; } case 'K': msglen-=4+4;backendpid=cr->read_int32();
pike.git/lib/modules/Sql.pmod/pgsql.pike:1152:
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) { // Announce connection termination to server
-
ci->start()->add("X\0\0\0\4")->sendcmd(SENDOUT);
+
object cs =
ci->start()
;
+
CHAIN(cs)
->add("X\0\0\0\4")
;
+
cs
->sendcmd(SENDOUT);
terminating=1; err=0; } else if(stringp(err)) { .pgsql_util.sql_result or; if(!objectp(or=portal)) or=this; if(!or._delayederror) or._delayederror=err; if(objectp(portal)) portal->_releasesession();
pike.git/lib/modules/Sql.pmod/pgsql.pike:1262:
if (!waitforauthready) waitforauthready=Thread.Condition(); lock=0; } if(c) { PD("Close old connection\n"); reconnected++;recon=1; #ifdef PG_STATS prepstmtused=0; #endif
-
termlock=unnamedstatement->lock(1);
+
if (unnamedstatement)
+
termlock
=
unnamedstatement->lock(1);
catch(c->close()); unnamedstatement = 0; termlock = 0; destruct(c); PD("Flushing old cache\n"); foreach(_prepareds;;mapping tp) m_delete(tp,"preparedname"); if(!_options.reconnect) ERROR("Lost connection to database %s:%d\n",_host,_port); }
pike.git/lib/modules/Sql.pmod/pgsql.pike:1701:
//! @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.
conxion
|.pgsql_util.
bufcon
plugbuffer,string oldprep) {
+
.pgsql_util.
bufcon
|.pgsql_util.
conxsess
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); }
pike.git/lib/modules/Sql.pmod/pgsql.pike:1884:
} else _prepareds[q]=tp=([]); } if(invalidatecache) { invalidatecache=0; foreach(_prepareds;;mapping np) { closestatement(plugbuffer,np.preparedname); m_delete(np,"preparedname"); } }
-
if(sizeof(plugbuffer)) {
-
PD("%O\n",(string)plugbuffer);
+
if(sizeof(
CHAIN(
plugbuffer))
)
{
+
PD("%O\n",(string)
CHAIN(
plugbuffer)
)
;
plugbuffer->sendcmd(FLUSHSEND); // close expireds } else plugbuffer->sendcmd(KEEP); // close start() tstart=gethrtime(); } else // sql_result autoassigns to portal tp=UNDEFINED; .pgsql_util.sql_result portal; portal=.pgsql_util.sql_result(this,c,q, portalbuffersize, _alltyped, from, forcetext, timeout, syncparse); 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(); _readyforquerycount++; Thread.MutexKey lock=unnamedstatement->lock(1);
-
c->start(1)->add_int8('Q')->add_hstring(({q,0}),4,4)
-
->sendcmd(FLUSHLOGSEND,portal);
+
.pgsql_util.conxsess cs =
c->start(1)
;
+
CHAIN(cs)
->add_int8('Q')->add_hstring(({q,
0}),
4,
4)
;
+
cs
->sendcmd(FLUSHLOGSEND,portal);
lock=0; PD("Simple query: %O\n",q); } else { object plugbuffer; if(!sizeof(preparedname) || !tp || !tp.preparedname) { if(!sizeof(preparedname)) preparedname= (portal._unnamedstatementkey = unnamedstatement->trylock(1)) ? "" : PTSTMTPREFIX+int2hex(ptstmtcount++); PD("Parse statement %O=%O\n",preparedname,q);
-
plugbuffer=c->start()->add_int8('P')
+
plugbuffer
=
c->start()
;
+
CHAIN(plugbuffer)
->add_int8('P')
->add_hstring(({preparedname,0,q,"\0\0\0"}),4,4) #if 0 // 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 // server v8.3.3 // In v8.4 and later, things speed up slightly when it is omitted. ->add(PGFLUSH) #endif ; } portal._preparedname=preparedname; if(!tp || !tp.datatypeoid) { PD("Describe statement %O\n",preparedname);
-
(plugbuffer
||
c->start())->add_int8('D')
-
->add_hstring(({'S',preparedname,0}),4,4)->sendcmd(FLUSHSEND,portal);
+
if
(
!
plugbuffer
)
+
plugbuffer =
c->start()
;
+
CHAIN(plugbuffer
)->add_int8('D')
+
->add_hstring(({'S',
preparedname,
0}),
4,
4)
;
+
plugbuffer
->sendcmd(FLUSHSEND,portal);
} else { if(plugbuffer) plugbuffer->sendcmd(KEEP); #ifdef PG_STATS skippeddescribe++; #endif portal->_setrowdesc(tp.datarowdesc,tp.datarowtypes); } if((portal._tprepared=tp) && tp.datatypeoid) { mixed e=catch(portal->_preparebind(tp.datatypeoid));