pike.git
/
lib
/
modules
/
Sql.pmod
/
pgsql_util.pmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:28:
#define PURGED 7 // If this is extended, change the type of _state #define NOERROR 0 // Error states networkparser #define PROTOCOLERROR 1 #define PROTOCOLUNSUPPORTED 2 #define LOSTERROR "Database connection lost" //! The instance of the pgsql dedicated backend.
-
final Pike.Backend local_backend
= Pike.SmallBackend()
;
+
final Pike.Backend local_backend;
-
+
private Pike.Backend cb_backend;
private Thread.Mutex backendmux = Thread.Mutex(); private Thread.ResourceCount clientsregistered = Thread.ResourceCount(); constant emptyarray = ({}); constant describenodata = (["datarowdesc":emptyarray, "datarowtypes":emptyarray, "datatypeoid":emptyarray]); private constant censoroptions = (<"use_ssl", "force_ssl", "cache_autoprepared_statements", "reconnect", "text_query", "is_superuser", "server_encoding", "server_version", "integer_datetimes",
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:89:
* not be able to deliver results belonging to other parallel queries * running on the same filedescriptor. * * However, considering that the current heuristic increases query-speed * in the majority of the real-world cases, it would be considered a good * tradeoff. */ private Regexp execfetchlimit = iregexp("^\a*((UPDA|DELE)TE|INSERT)\a|\aLIMIT\a+[1-9][; \t\f\r\n]*$");
+
private void default_backend_runs() { // Runs as soon as the
+
cb_backend = Pike.DefaultBackend; // DefaultBackend has started
+
}
+
+
private void create() {
+
// Run callbacks from our local_backend until DefaultBackend has started
+
cb_backend = local_backend = Pike.SmallBackend();
+
call_out(default_backend_runs, 0);
+
}
+
private Regexp iregexp(string expr) { Stdio.Buffer ret = Stdio.Buffer(); foreach (expr; ; int c) if (c >= 'A' && c <= 'Z') ret->add('[', c, c + 'a' - 'A', ']'); else if (c == '\a') // Replace with generic whitespace ret->add("[ \t\f\r\n]"); else ret->add_int8(c); return Regexp(ret->read());
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:174:
case VARCHAROID: case CTIDOID: case UUIDOID: return 1; //binary } return 0; // text } private inline mixed callout(function(mixed ...:void) f, float|int delay, mixed ... args) {
-
return
local
_backend->call_out(f, delay, @args);
+
return
cb
_backend->call_out(f, delay, @args);
} // Some pgsql utility functions class bufcon { inherit Stdio.Buffer; private Thread.ResourceCountKey dirty; #ifdef PG_DEBUGRACE final bufcon `chain() {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1252:
if (!fetchlimit) { if (transtype != NOTRANS) pgsqlsess.intransaction = transtype == TRANSBEGIN; flushmode = _closeportal(plugbuffer) == SYNCSEND || transtype == TRANSEND ? SYNCSEND : FLUSHSEND; } else inflight += fetchlimit, flushmode = FLUSHSEND; plugbuffer->sendcmd(flushmode, this); }
+
inline private array setuptimeout() {
+
return local_backend->call_out(gottimeout, timeout);
+
}
+
//! @returns //! One result row at a time. //! //! When using COPY FROM STDOUT, this method returns one row at a time //! as a single string containing the entire row. //! //! @seealso //! @[eof()], @[send_row()] /*semi*/final array(mixed) fetch_row() { int|array datarow; if (arrayp(datarow = datarows->try_read())) return datarow; if (!eoffound) { if (!datarow) { PD("%O Block for datarow\n", _portalname);
-
array cid =
callout
(
gottimeout, timeout
);
+
array cid =
setuptimeout
();
PT(datarow = datarows->read()); local_backend->remove_call_out(cid); if (arrayp(datarow)) return datarow; } eoffound = 1; datarows->write(1); // Signal EOF for other threads } trydelayederror(); return 0;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1293:
//! When using COPY FROM STDOUT, this method returns one row at a time //! as a single string containing the entire row. //! //! @seealso //! @[eof()], @[fetch_row()] /*semi*/final array(array(mixed)) fetch_row_array() { if (eoffound) return 0; array(array|int) datarow = datarows->try_read_array(); if (!sizeof(datarow)) {
-
array cid =
callout
(
gottimeout, timeout
);
+
array cid =
setuptimeout
();
PT(datarow = datarows->read_array()); local_backend->remove_call_out(cid); } if (arrayp(datarow[-1])) return datarow; trydelayederror(); eoffound = 1; datarows->write(1); // Signal EOF for other threads return (datarow = datarow[..<1]); }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1333:
cs->sendcmd(SENDOUT); } else _releasesession(); } private void run_result_cb( function(sql_result, array(mixed), mixed ...:void) callback, array(mixed) args) { int|array datarow; for (;;) {
-
array cid =
callout
(
gottimeout, timeout
);
+
array cid =
setuptimeout
();
PT(datarow = datarows->read()); local_backend->remove_call_out(cid); if (!arrayp(datarow)) break; callout(callback, 0, this, datarow, @args); } eoffound = 1; callout(callback, 0, this, 0, @args); }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1362:
mixed ... args) { if (callback) Thread.Thread(run_result_cb, callback, args); } private void run_result_array_cb( function(sql_result, array(array(mixed)), mixed ...:void) callback, array(mixed) args) { array(array|int) datarow; for (;;) {
-
array cid =
callout
(
gottimeout, timeout
);
+
array cid =
setuptimeout
();
PT(datarow = datarows->read_array()); local_backend->remove_call_out(cid); if (!datarow || !arrayp(datarow[-1])) break; callout(callback, 0, this, datarow, @args); } eoffound = 1; if (sizeof(datarow)>1) callout(callback, 0, this, datarow = datarow[..<1], @args); callout(callback, 0, this, 0, @args);