Branch: Tag:

1997-09-28

1997-09-28 17:25:16 by Henrik Grubbström (Grubba) <grubba@grubba.org>

SQLELSE added. Thanks to Bill Welliver <hww3@riverweb.com> for the suggestion.

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

1:   /* -  * $Id: sqltag.pike,v 1.8 1997/09/23 11:05:05 grubba Exp $ +  * $Id: sqltag.pike,v 1.9 1997/09/28 17:25:16 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.8 1997/09/23 11:05:05 grubba Exp $"; + constant cvs_version="$Id: sqltag.pike,v 1.9 1997/09/28 17:25:16 grubba Exp $";   constant thread_safe=1;   #include <module.h>   
26:    return( ({ MODULE_PARSER,    "SQL-module",    "This module gives the three tags &lt;SQLQUERY&gt;, " -  "&lt;SQLOUTPUT&gt; and &lt;SQLTABLE&gt;.<br>\n" +  "&lt;SQLOUTPUT&gt;, &lt;SQLELSE&gt; and &lt;SQLTABLE&gt;.<br>\n"    "Usage:<ul>\n"    "<table border=0>\n"    "<tr><td valign=top><b>&lt;sqloutput&gt;</b></td>"
108:       if (error = catch(con = sql(host, database, user, password))) {    contents = "<h1>Couldn't connect to SQL-server</h1><br>\n" + -  ((master()->describe_backtrace(error)/"\n")*"<br>\n") + -  contents; +  ((master()->describe_backtrace(error)/"\n")*"<br>\n");    } else if (error = catch(result = con->query(args->query))) {    contents = "<h1>Query \"" + args->query + "\" failed: " +    con->error() + "</h1>\n" + -  ((master()->describe_backtrace(error)/"\n")*"<br>\n") + -  contents; +  ((master()->describe_backtrace(error)/"\n")*"<br>\n");    } else if (result) {    string nullvalue="";    array(string) content_array = contents/"#";
145:    }    }    contents = res_array * ""; +  request_id->misc->sqlelse = 0; +  } else { +  request_id->misc->sqlelse = 1;    }    } else {    contents = "<!-- No query! -->" + contents;
162:    string password = query("password");    object(sql) con;    mixed error; +  array(mapping(string:mixed)) res;       if (args->host) {    host = args->host;
185:    if (error = catch(con = sql(host, database, user, password))) {    return("<h1>Couldn't connect to SQL-server</h1><br>\n" +    ((master()->describe_backtrace(error)/"\n")*"<br>\n")); -  } else if (error = catch(con->query(args->query))) { +  } else if (error = catch(res = con->query(args->query))) {    return("<h1>Query \"" + args->query + "\" failed: " +    con->error() + "</h1>\n" +    ((master()->describe_backtrace(error)/"\n")*"<br>\n"));    } -  +  request_id->misc->sqlelse = !res;    } else {    return("<!-- No query! -->");    }
263:    res += "<th>"+name+"</th>";    }    res += "</tr>\n"; +     while (row = result->fetch_row()) {    res += "<tr>";    foreach(row, mixed value) {
273:    }    res += "</table>";    +  request_id->misc->sqlelse = 0;    return(res);    } else { -  +  request_id->misc->sqlelse = 1;    return("<!-- No result from query -->");    }    } else {
282:    }   }    + string sqlelse_tag(string tag_name, mapping args, string contents, +  object request_id, mapping defines) + { +  if (request_id->misc->sqlelse) { +  return(contents); +  } +  return(""); + } +    string dumpid_tag(string tag_name, mapping args,    object request_id, mapping defines)   {
301:      mapping query_container_callers()   { -  return( ([ "sqloutput":sqloutput_tag ]) ); +  return( ([ "sqloutput":sqloutput_tag, "sqlelse":sqlelse_tag ]) );   }      /*