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

version» Context lines:

Roxen.git/server/modules/tags/sqltag.pike:1: - // This is a roxen module. Copyright © 1997-1999, Idonex AB. + // This is a roxen module. Copyright © 1997-2000, Roxen IS.   //   // A module for Roxen, which gives the tags   // <sqltable>, <sqlquery> and <sqloutput>.   //   // Henrik Grubbström 1997-01-12    - constant cvs_version="$Id: sqltag.pike,v 1.46 2000/02/21 17:26:50 kuntri Exp $"; + constant cvs_version="$Id: sqltag.pike,v 1.47 2000/02/24 03:54:00 nilsson Exp $";   constant thread_safe=1;   #include <module.h>      // Compatibility with old versions of the sqltag module.   // #define SQL_TAG_COMPAT      inherit "module";   inherit "roxenlib";      Configuration conf;
Roxen.git/server/modules/tags/sqltag.pike:85: Inside #if defined(manual)
   you wish to dynamically build the query.   </attr>      <attr name=mysql-insert-id type=form-variable>    Set form-variable to the insert id used by Mysql for    auto-incrementing columns. Note: This is only available with Mysql.   </attr>   "]);   #endif    - array|string|object do_sql_query(string tag, mapping args, RequestID id) + array|object do_sql_query(string tag, mapping args, RequestID id)   {    if (!args->query) -  return rxml_error(tag, "No query.", id); +  RXML.parse_error("No query.");       if (args->parse)    args->query = parse_rxml(args->query, id);       string host = query("hostname");    Sql.sql con;    array(mapping(string:mixed)) result;    function sql_connect = id->conf->sql_connect;    mixed error;   
Roxen.git/server/modules/tags/sqltag.pike:140:   #else    if (args->host)    host=args->host;       if(sql_connect)    error = catch(con = sql_connect(host));    else    error = catch(con = Sql.sql(lower_case(host)=="localhost"?"":host));   #endif    -  if (error) { -  if (!args->quiet) { -  if (args->log_error && QUERY(log_error)) { -  report_error(sprintf("SQLTAG: Couldn't connect to SQL server:\n" -  "%s\n", describe_backtrace(error))); -  } -  return "<h3>Couldn't connect to SQL server</h3><br>\n" + -  html_encode_string(error[0]) + "<false>"; -  } -  return rxml_error(tag, "Couldn't connect to SQL server. "+html_encode_string(error[0]), id); -  } +  if (error && !args->quiet) +  RXML.run_error("Couldn't connect to SQL server. "+html_encode_string(error[0]));       if (error = catch(result = tag=="sqltable"?con->big_query(args->query):con->query(args->query))) {    error = html_encode_string(sprintf("Query %O failed. %s", args->query,    con->error()||"")); -  if (!args->quiet) { -  if (args->log_error && QUERY(log_error)) { -  report_error(sprintf("SQLTAG: Query %O failed:\n" -  "%s\n", -  args->query, describe_backtrace(error))); +  if (!args->quiet) +  RXML.run_error(error);    } -  return "<h3>"+error+"</h3>\n<false>"; -  } -  return rxml_error(tag, error, id); -  } +        if(tag=="sqlquery") args["dbobj"]=con;    return result;   }         // -------------------------------- Tag handlers ------------------------------------      array|string container_sqloutput(string tag, mapping args, string contents,    RequestID id)   {    NOCACHE();    -  string|array res=do_sql_query(tag, args, id); -  if(stringp(res)) return res; +  array res=do_sql_query(tag, args, id);       if (res && sizeof(res)) {    array ret = ({ do_output_tag(args, res, contents, id) });    id->misc->defines[" _ok"] = 1; // The effect of <true>, since res isn't parsed.       if( args["rowinfo"] )    id->variables[args->rowinfo]=sizeof(res);       return ret;    }       if (args["do-once"])    return do_output_tag( args, ({([])}), contents, id )+ "<true>";    -  return rxml_error(tag, "No SQL return values.", id); +  if(args->quiet) return ""; +  RXML.run_error("No SQL return values.");   }      class TagSqlplugin {    inherit RXML.Tag;    constant name = "emit";    constant plugin_name = "sql";       array get_dataset(mapping m, RequestID id) {    array|string res=do_sql_query("sqloutput", m, id); -  if(stringp(res)) { -  // rxml_error(res); -  return ({}); -  } +     if(m->rowinfo) id->variables[m->rowinfo] = sizeof(res);    return res;    }   }      string tag_sqlquery(string tag, mapping args, RequestID id)   {    NOCACHE();    -  string|array res=do_sql_query(tag, args, id); -  if(stringp(res)) return res; +  array res=do_sql_query(tag, args, id);       if(args["mysql-insert-id"])    if(args->dbobj && args->dbobj->master_sql)    id->variables[args["mysql-insert-id"]] = args->dbobj->master_sql->insert_id();    else -  return rxml_error(tag, "No insert_id present.", id); +  RXML.parse_error("No insert_id present.");    -  return "<true>"; +  return "<true />";   }      string tag_sqltable(string tag, mapping args, RequestID id)   {    NOCACHE();    -  string|object res=do_sql_query(tag, args, id); -  if(stringp(res)) return res; +  object res=do_sql_query(tag, args, id);       int ascii=!!args->ascii;    string ret="";       if (res) {    string nullvalue=args->nullvalue||"";    array(mixed) row;       if (!ascii) {    ret="<tr>";
Roxen.git/server/modules/tags/sqltag.pike:273:    }    }       if (!ascii)    ret=make_container("table", args-(["host":"", "database":"", "user":"", "password":"",    "query":"", "nullvalue":""]), ret);       return ret+"<true>";    }    -  return rxml_error(tag, "No SQL return values.", id); +  if(args->quiet) return ""; +  RXML.run_error("No SQL return values.");   }         // ------------------- Callback functions -------------------------      Sql.sql sql_object(void|string host)   {    string host = stringp(host)?host:query("hostname");    Sql.sql con;    function sql_connect = conf->sql_connect;
Roxen.git/server/modules/tags/sqltag.pike:314:    defvar("hostname", "localhost", "Default SQL database host",    TYPE_STRING, "Specifies the default host to use for SQL queries.\n"    "This argument can also be used to specify which SQL server to "    "use by specifying an \"SQL URL\":<ul>\n"    "<pre>[<i>sqlserver</i>://][[<i>user</i>][:<i>password</i>]@]"    "[<i>host</i>[:<i>port</i>]]/<i>database</i></pre></ul><br>\n"    "Valid values for \"sqlserver\" depend on which "    "SQL servers your pike has support for, but the following "    "might exist: msql, mysql, odbc, oracle, postgres.\n");    -  defvar("log_error", 0, "Log errors to the event log", -  TYPE_FLAG, "Enable this to log database connection and SQL " -  "errors to the event log.\n"); -  +    #ifdef SQL_TAG_COMPAT    defvar("database", "", "Default SQL database (deprecated)",    TYPE_STRING,    "Specifies the name of the default SQL database.\n");    defvar("user", "", "Default username (deprecated)",    TYPE_STRING,    "Specifies the default username to use for access.\n");    defvar("password", "", "Default password (deprecated)",    TYPE_STRING,    "Specifies the default password to use for access.\n");