Branch: Tag:

2008-08-25

2008-08-25 12:04:53 by Stephen R. van den Berg <srb@cuci.nl>

pgsql: Repair big_query() to return all results as strings.
Use big_typed_query() to return native Pike types.

Rev: CHANGES:1.130
Rev: lib/modules/Sql.pmod/pgsql.pike:1.34
Rev: lib/modules/Sql.pmod/pgsql_util.pmod:1.8
Rev: lib/modules/Sql.pmod/postgres.pike:1.38
Rev: src/modules/_PGsql/PGsql.cmod:1.27

55:      #define ERROR(X ...) predef::error(X)    - int _alltext; - int _booltext; +    int _nextportal;   int _closesent;   int _fetchlimit=FETCHLIMIT;
170:   //! @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"
207:    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)
745:    _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;) {
760:    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;
1001:    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"});
1466:   //!   //! @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;
1549:    } // 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
1705:   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); + }