Roxen.git / server / modules / database / sqltag.pike

version» Context lines:

Roxen.git/server/modules/database/sqltag.pike:1:   // This is a roxen module. Copyright © 1997 - 2009, Roxen IS.   //    - constant cvs_version = "$Id: sqltag.pike,v 1.123 2011/11/15 11:33:04 mast Exp $"; + constant cvs_version = "$Id$";   constant thread_safe = 1;   #include <module.h>      inherit "module";      //<locale-token project="mod_sqltag">LOCALE</locale-token>   //<locale-token project="mod_sqltag">SLOCALE</locale-token>   #define SLOCALE(X,Y) _STR_LOCALE("mod_sqltag",X,Y)   #define LOCALE(X,Y) _DEF_LOCALE("mod_sqltag",X,Y)   // end locale stuff
Roxen.git/server/modules/database/sqltag.pike:280: Inside #if defined(manual)
   <p>This is only applicable if a charset is being used and it isn't    \"unicode\" (or \"broken-unicode\").</p>   </attr>"   ]);   #endif         // --------------------------- Database query code --------------------------------      float compat_level; + Val.Null null_obj = Val.null;      #if ROXEN_COMPAT <= 1.3   string compat_default_host;   #endif   string default_db, default_recode_charset, default_conn_charset;      protected int allow_sql_urls, allow_module_dbs;      // 0 if all dbs are allowed. Includes default_db if set.   protected mapping(string:int(1..1)) allowed_dbs = ([]);
Roxen.git/server/modules/database/sqltag.pike:519:    con = get_rxml_sql_con (args->db, host, id, ro, 0, conn_charset);       function query_fn = (big_query ? con->big_query : con->query);    if( error = catch( result = (bindings ? query_fn(args->query, bindings) : query_fn(args->query))) ) {    error = sprintf("Query failed: %s\n",    con->error() || describe_error(error));    RXML.run_error(error);    }    }    -  if (ret_con) { -  // NOTE: Use of this feature may lead to circularities... -  args->dbobj=con; -  } +     if(result && args->rowinfo) {    int rows;    if(arrayp(result)) rows=sizeof(result);    if(objectp(result)) rows=result->num_rows();    RXML.user_set_var(args->rowinfo, rows);    if(objectp(result)) m_delete(args, "rowinfo");    } -  +  if (ret_con) { +  // NOTE: Use of this feature may lead to circularities... +  args->dbobj=con; +  }    return result;   }         // -------------------------------- Tag handlers ------------------------------------      #if ROXEN_COMPAT <= 1.3   class TagSQLOutput {    inherit RXML.Tag;    constant name = "sqloutput";
Roxen.git/server/modules/database/sqltag.pike:579: Inside #if ROXEN_COMPAT <= 1.3
   }    }   }   #endif      inherit "emit_object";      class SqlEmitResponse {    inherit EmitObject;    Sql.sql_result sqlres; -  private Locale.Charset.Decoder decoder; +  private Charset.Decoder decoder;    private array(string) cols;    private array(int(0..1)) charset_decode_col;    private int fetched;    -  mapping(string:mixed) really_get_row() { +  mapping(string:mixed) really_get_row(int|void inhibit_next_result) {    array val; -  if(sqlres && (val = sqlres->fetch_row())) +  while (sqlres) { +  if (val = sqlres->fetch_row()) {    fetched++; -  else { -  sqlres = 0; -  return 0; +  break;    } -  +  // Try the next set of results. +  sqlres = (!inhibit_next_result && sqlres->next_result && +  sqlres->next_result()); +  // FIXME: Add result set counter. +  } +  if (!sqlres) +  return 0;       if (compat_level > 4.5) {    if (!decoder) {    foreach (val; int i; string v) {    // Change in >= 5.0: Don't abuse RXML.nil for SQL NULL. RXML.nil    // means UNDEFINED in this context, i.e. that the variable    // doesn't exist at all. An SQL NULL otoh is just a special    // value in an existing variable, at least on the RXML level.      #if 0
Roxen.git/server/modules/database/sqltag.pike:613: Inside #if 0
   // wrapper in Sql.oracle handles the dbnull objects when it    // converts all types to strings. /mast       // Might be a dbnull object which considers    // itself false (e.g. in the oracle glue).    if ((x != 0) && stringp(x->type))    // Transform NULLString to "".    return x->type;   #endif    -  if (!v) val[i] = Val.null; +  if (!v) val[i] = null_obj;    }    }       else {    // Same null handling as above, but also decode charsets.    foreach (val; int i; string v) { -  if (!v) val[i] = Roxen.sql_null; +  if (!v) val[i] = null_obj;    else if (charset_decode_col[i]) {    if (mixed err = catch (val[i] = decoder->feed (v)->drain()))    if (objectp (err) && err->is_charset_decode_error)    RXML.run_error (err->message());    else    throw (err);    }    }    }    }
Roxen.git/server/modules/database/sqltag.pike:661:    if(!sqlres) return !!next_row;    return sqlres->num_rows() - fetched + !!next_row;    }       void create(Sql.sql_result _sqlres, string charset, string binary_cols) {    sqlres = _sqlres;    if (sqlres) {    cols = sqlres->fetch_fields()->name;       if (charset) { -  if (mixed err = catch (decoder = Locale.Charset.decoder (charset))) { +  if (mixed err = catch (decoder = Charset.decoder (charset))) {   #if defined (DEBUG) || defined (MODULE_DEBUG)    werror ("Error getting decoder for charset %O: %s",    charset, describe_error (err));   #endif    RXML.parse_error ("Unknown charset %O for decode.\n", charset);    }       if (binary_cols) {    charset_decode_col = allocate (sizeof (cols), 0);    multiset(string) bin_col_names =
Roxen.git/server/modules/database/sqltag.pike:688:    else    charset_decode_col = allocate (sizeof (cols), 1);    }    }    }   }      #define GET_CHARSET_AND_ENCODE_QUERY(args, recode_charset) do { \    if (!recode_charset) recode_charset = default_recode_charset; \    if (!(<0, "none", "unicode", "broken-unicode">)[recode_charset]) { \ -  Locale.Charset.Encoder encoder; \ +  Charset.Encoder encoder; \    if (mixed err = catch { \ -  encoder = Locale.Charset.encoder (recode_charset); \ +  encoder = Charset.encoder (recode_charset); \    }) { \    DO_IF_DEBUG ( \    werror ("Error getting encoder for charset %O: %s", \    recode_charset, describe_error (err))); \    RXML.parse_error ("Unknown charset %O for encode.\n", recode_charset); \    } \    if (mixed err = catch { \    args->query = encoder->feed (args->query)->drain(); \    }) \    if (objectp (err) && err->is_charset_encode_error) \
Roxen.git/server/modules/database/sqltag.pike:811:    if (string|array(string) cs = args->charset) {    if (stringp (cs))    cs = args->charset = array_sscanf (cs, "%[^ \t,]%*[ \t],%*[ \t]%s");    recode_charset = cs[0];    }    GET_CHARSET_AND_ENCODE_QUERY (args, recode_charset);       Sql.sql_result res = [object(Sql.sql_result)] do_sql_query(args, id, 1);       int ascii=!!args->ascii; -  string ret=""; +     -  if (res) { +  if (!res) { +  id->misc->defines[" _ok"] = 0; +  return 0; +  } +     res = SqlEmitResponse (res, recode_charset, 0);    -  +  do { +  string ret="";    string nullvalue=args->nullvalue||"";       array(string) cols = res->sqlres->fetch_fields()->name;       if (!ascii) {    ret="<tr>";    foreach (cols, string colname)    ret += "<th>" + Roxen.html_encode_string (colname) + "</th>";    ret += "</tr>\n";    }    -  while (mapping(string:mixed) entry = res->really_get_row()) { +  while (mapping(string:mixed) entry = res->really_get_row(1)) {    array row = rows (entry, cols);    if (ascii)    ret += map(row, lambda(mixed in) {    if(!in) return nullvalue;    return (string)in;    }) * "\t" + "\n";    else {    ret += "<tr>";    foreach(row, string|Roxen.SqlNull value)    // FIXME: Missing quoting here. -  ret += "<td>" + (value == Roxen.sql_null ? +  ret += "<td>" + (objectp (value) && value->is_val_null ?    nullvalue : value) + "</td>";    ret += "</tr>\n";    }    }       if (!ascii)    ret=Roxen.make_container("table",    args-(["host":"","database":"","user":"",    "password":"","query":"","db":"",    "nullvalue":"","dbobj":"",    "charset": ""]), ret);       id->misc->defines[" _ok"] = 1; -  result=ret; -  return 0; -  } +  if (result) +  result += ret; +  else +  result = ret;    -  id->misc->defines[" _ok"] = 0; -  return 0; +  // Check if there where any more results. +  } while (res->sqlres && res->sqlres->next_result && +  res->sqlres->next_result());    }    }   }         // ------------------------ Setting the defaults -------------------------      class DatabaseVar   {    inherit Variable.StringChoice;
Roxen.git/server/modules/database/sqltag.pike:962:   }         // --------------------- More interface functions --------------------------      multiset(string) query_provides() {return (<"rxml_sql">);}      void start()   {    compat_level = my_configuration() && my_configuration()->compat_level(); +  null_obj = compat_level >= 5.2 ? Val.null : Roxen.compat_5_1_null;      #if ROXEN_COMPAT <= 1.3    compat_default_host = query("hostname");   #endif    default_db = query("db");       default_conn_charset = 0;    sscanf (query ("charset"), "%[^ \t,]%*[ \t],%*[ \t]%s",    default_recode_charset, default_conn_charset);    if (!default_conn_charset) default_conn_charset = default_recode_charset;