Branch: Tag:

2000-02-24

2000-02-24 03:54:42 by Martin Nilsson <mani@lysator.liu.se>

Copyright update and new rxml error code.

Rev: server/modules/tags/foldlist.pike:1.13
Rev: server/modules/tags/sqltag.pike:1.47
Rev: server/modules/tags/tablify.pike:1.43

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>   
92:   "]);   #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);
147:    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;
185:   {    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) });
201:    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 {
211:       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;    }
224:   {    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="";
280:    return ret+"<true>";    }    -  return rxml_error(tag, "No SQL return values.", id); +  if(args->quiet) return ""; +  RXML.run_error("No SQL return values.");   }      
321:    "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,