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:48:
//! //! @seealso //! @[Sql.Sql], @[Sql.postgres] #pike __REAL_VERSION__ #include "pgsql.h" #define ERROR(X ...) predef::error(X)
-
int _alltext;
-
int _booltext;
+
int _nextportal; int _closesent; int _fetchlimit=FETCHLIMIT; private int unnamedportalinuse; private int portalsinflight; object _c; private string SSauthdata,cancelsecret; private int backendpid; private int backendstatus;
pike.git/lib/modules/Sql.pmod/pgsql.pike:163:
//! //! The options argument currently supports at least the following: //! @string //! @value "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 //! @value "force_ssl" //! If the database supports and allows SSL connections, the session //! will be SSL encrypted, if not, the connection will abort
-
//! @value "bool_results_as_text"
-
//! Make boolean values retrieved from the database backward compatible
-
//! with the old Postgres driver which returned all values as text.
-
//! When off, boolean values are represented by 0 and 1, when set,
-
//! boolean values are represented by "f" and "t".
-
//! @value "all_results_as_text"
-
//! Make all values backward compatible with the old Postgres driver
-
//! which returned all values as text. Implies bool_results_as_text.
+
//! @value "client_encoding" //! Character encoding for the client side, it defaults to use //! database encoding, e.g.: "SQL_ASCII" //! @value "standard_conforming_strings" //! When on, backslashes in strings must not be escaped any longer, //! @[quote] automatically adjusts quoting strategy accordingly //! @value "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
pike.git/lib/modules/Sql.pmod/pgsql.pike:200:
//! //! @seealso //! @[Postgres.postgres], @[Sql.Sql], @[postgres->select_db] protected void create(void|string _host, void|string _database, 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; options = _options || ([]);
-
_alltext = !!options->all_results_as_text;
-
_booltext = _alltext || !!options->bool_results_as_text;
+
if(search(host,":")>=0 && sscanf(_host,"%s:%d",host,port)!=2) ERROR("Error in parsing the hostname argument\n"); if(!port) port = PGSQL_DEFAULT_PORT; _querymutex=Thread.Mutex(); _stealmutex=Thread.Mutex(); reconnect(); } //! @decl string error()
pike.git/lib/modules/Sql.pmod/pgsql.pike:738:
if(_c.portal) { if(tprepared) storetiming(); #ifdef USEPGsql _c.decodedatarow(msglen);msglen=0; #else array a, datarowdesc; _c.portal->_bytesreceived+=msglen; datarowdesc=_c.portal->_datarowdesc; int cols=_c.getint16();
-
int atext = _alltext;
// cache locally for speed
?
-
int btext = _booltext; // cache locally for speed ?
+
int atext = _
c.portal->_
alltext; // cache locally for speed
a=allocate(cols,UNDEFINED); msglen-=2+4*cols; foreach(a;int i;) { int collen=_c.getint32(); if(collen>0) { msglen-=collen; mixed value; switch(datarowdesc[i]->type) { default:value=_c.getstring(collen); break; case CHAROID:value=_c.getbyte(); break; case BOOLOID:value=_c.getbyte();
-
if(
btext
)
+
if(
atext
)
value=value?"t":"f"; break; case INT8OID:value=_c.getint64(); break;
-
case FLOAT4OID:value=
(float)
_c.getstring(collen);
+
case FLOAT4OID:
+
value=_c.getstring(collen);
+
if(!atext)
+
value=(float)value;
break; case INT2OID:value=_c.getint16(); break; case OIDOID: case INT4OID:value=_c.getint32(); } if(atext&&!stringp(value)) value=(string)value; a[i]=value; }
pike.git/lib/modules/Sql.pmod/pgsql.pike:994:
} _closesent=0; _mstate=unauthenticated; qstate=queryidle; runtimeparameter=([]); array(string) plugbuf=({"",_c.plugint32(PG_PROTOCOL(3,0))}); if(user) plugbuf+=({"user\0",user,"\0"}); if(database) plugbuf+=({"database\0",database,"\0"});
-
foreach(options-(<"use_ssl","force_ssl"
,"bool_results_as_text",
-
"all_results_as_text"
>);
+
foreach(options-(<"use_ssl","force_ssl">);
string name;mixed value) plugbuf+=({name,"\0",(string)value,"\0"}); plugbuf+=({"\0"}); int len=4; foreach(plugbuf;;string s) len+=sizeof(s); plugbuf[0]=_c.plugint32(len); _c.write(plugbuf); PD("%O\n",plugbuf); { mixed err=catch(_decodemsg(readyforquery));
pike.git/lib/modules/Sql.pmod/pgsql.pike:1459:
//! This function @b{can@} raise exceptions. //! //! @note //! This function does not support multiple queries in one querystring. //! I.e. it allows for but does not require a trailing semicolon, but it //! simply ignores any commands after the first semicolon. This can be //! viewed as a limited protection against SQL-injection attacks. //! //! @seealso //! @[Sql.Sql], @[Sql.sql_result], @[Sql.pgsql_util.pgsql_result]
-
object big_query(string q,void|mapping(string|int:mixed) bindings) {
+
object big_query(string q,void|mapping(string|int:mixed) bindings
,
+
void|int _alltyped
) {
string preparedname=""; string portalname=""; int forcecache=-1; if(stringp(q) && String.width(q)>8) q=string_to_utf8(q); array(string|int) paramValues; if(bindings) { int pi=0,rep=0; paramValues=allocate(sizeof(bindings)); array(string) from=allocate(sizeof(bindings));
pike.git/lib/modules/Sql.pmod/pgsql.pike:1542:
if(sizeof(plugbuf)) _c.sendcmd(plugbuf,1); // close expireds PD("%O\n",plugbuf); } prepareds[q]=tp=([]); } tstart=gethrtime(); } // pgsql_result autoassigns to portal else tp=UNDEFINED;
-
.pgsql_util.pgsql_result(this,q,_fetchlimit,portalbuffersize);
+
.pgsql_util.pgsql_result(this,q,_fetchlimit,portalbuffersize
,_alltyped
);
if(unnamedportalinuse) portalname=PORTALPREFIX+(string)pportalcount++; else unnamedportalinuse++; _c.portal->_portalname=portalname; qstate=inquery; portalsinflight++; portalsopened++; clearmessage=1; mixed err; if(err = catch {
pike.git/lib/modules/Sql.pmod/pgsql.pike:1698:
} //! This is an alias for @[big_query()], since @[big_query()] already supports //! streaming of multiple simultaneous queries through the same connection. //! //! @seealso //! @[big_query], @[Sql.Sql], @[Sql.sql_result] 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
+
//! results.
+
//!
+
//! @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);
+
}