Branch: Tag:

1998-07-23

1998-07-23 18:41:58 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added log_error.

Rev: server/modules/tags/sqltag.pike:1.27

1:   /* -  * $Id: sqltag.pike,v 1.26 1998/07/22 16:11:33 noring Exp $ +  * $Id: sqltag.pike,v 1.27 1998/07/23 18:41:58 grubba Exp $    *    * A module for Roxen Challenger, which gives the tags    * <SQLQUERY> and <SQLOUTPUT>.
7:    * Henrik Grubbström 1997-01-12    */    - constant cvs_version="$Id: sqltag.pike,v 1.26 1998/07/22 16:11:33 noring Exp $"; + constant cvs_version="$Id: sqltag.pike,v 1.27 1998/07/23 18:41:58 grubba Exp $";   constant thread_safe=1;   #include <module.h>   
140:    }    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))); +  }    contents = ("<h3>Couldn't connect to SQL-server</h1><br>\n" +    html_encode_string(error[0]) + "<false>");    } else {
147:    }    } else if (error = catch(result = con->query(args->query))) {    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))); +  }    contents = ("<h3>Query \"" + html_encode_string(args->query)    + "\" failed: " + html_encode_string(con->error())    + "</h1>\n<false>");
217:    }    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</h1><br>\n" +    html_encode_string(error[0])+"<false>");    } else {
224:    }    } else if (error = catch(res = con->query(args->query))) {    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))); +  }    return("<h3>Query \"" + html_encode_string(args->query)+"\" failed: "    + html_encode_string(con->error()) + "</h1>\n<false>");    } else {
301:    }    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</h1><br>\n" +    html_encode_string(error[0])+"<false>");    } else {
308:    }    } else if (error = catch(result = con->big_query(args->query))) {    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))); +  }    return ("<h3>Query \"" + html_encode_string(args->query) +    "\" failed: " + html_encode_string(con->error()) + "</h1>\n" +    "<false>");
456:    "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, "Enable the \"log_error\" attribute", +  TYPE_FLAG|VAR_MORE, "Enables the attribute \"log_error\" " +  "which causes errors to be logged to the event-log.\n"); +    #ifdef SQL_TAG_COMPAT    defvar("database", "", "Default SQL-database (deprecated)",    TYPE_STRING|VAR_MORE,