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

version» Context lines:

Roxen.git/server/modules/tags/sqltag.pike:1:   /* -  * $Id: sqltag.pike,v 1.10 1997/09/28 17:27:20 grubba Exp $ +  * $Id: sqltag.pike,v 1.11 1997/09/30 14:33:21 grubba Exp $    *    * A module for Roxen Challenger, which gives the tags    * <SQLQUERY> and <SQLOUTPUT>.    *    * Henrik Grubbström 1997-01-12    */    - constant cvs_version="$Id: sqltag.pike,v 1.10 1997/09/28 17:27:20 grubba Exp $"; + constant cvs_version="$Id: sqltag.pike,v 1.11 1997/09/30 14:33:21 grubba Exp $";   constant thread_safe=1;   #include <module.h>      inherit "module";   inherit "roxenlib";      import Array;   import Sql;      /*    * Module interface functions    */      array register_module()   {    return( ({ MODULE_PARSER,    "SQL-module",    "This module gives the three tags &lt;SQLQUERY&gt;, " -  "&lt;SQLOUTPUT&gt;, &lt;SQLELSE&gt; and &lt;SQLTABLE&gt;.<br>\n" +  "&lt;SQLOUTPUT&gt;, and &lt;SQLTABLE&gt;.<br>\n"    "Usage:<ul>\n"    "<table border=0>\n"    "<tr><td valign=top><b>&lt;sqloutput&gt;</b></td>"    "<td>Executes an SQL-query, and "    "replaces #-quoted fieldnames with the results. # is "    "quoted as ##. The content inbetween &lt;sqloutput&gt; and "    "&lt;/sqloutput&gt; is repeated once for every row in the "    "result.</td></tr>\n"    "<tr><td valign=top><b>&lt;sqlquery&gt;</b></td>\n"    "<td>Executes an SQL-query, but "
Roxen.git/server/modules/tags/sqltag.pike:106:    host = lower_case(host);    host = (host == "localhost")?"":host;       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");    } 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"); -  } else if (result) { +  } else if (result && sizeof(result)) {    string nullvalue="";    array(string) content_array = contents/"#";    array(string) res_array=allocate(sizeof(content_array)*sizeof(result));    int j = 0;       if (args->nullvalue) {    nullvalue = (string)args->nullvalue;    }       foreach(result, mapping(string:mixed) row) {
Roxen.git/server/modules/tags/sqltag.pike:135:    /* Dual #'s to get one */    res_array[j] = "#";    } else {    res_array[j] = "<!-- Missing field " + content_array[i] + " -->";    }    } else {    res_array[j] = content_array[i];    }    }    } -  contents = res_array * ""; -  request_id->misc->sqlelse = 0; +  contents = (res_array * "") + "<true>";    } else { -  request_id->misc->sqlelse = 1; +  contents = "<false>";    }    } else { -  contents = "<!-- No query! -->" + contents; +  contents = "<!-- No query! --><false>";    }    return(contents);   }      string sqlquery_tag(string tag_name, mapping args,    object request_id, mapping defines)   {    if (args->query) {    string host = query("hostname");    string database = query("database");
Roxen.git/server/modules/tags/sqltag.pike:185:    host = (host == "localhost")?"":host;       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(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; +  return(res?"<true>":"<false>");    } else { -  return("<!-- No query! -->"); +  return("<!-- No query! --><false>");    } -  return(""); +    }      string sqltable_tag(string tag_name, mapping args,    object request_id, mapping defines)   {    if (args->query) {    string host = query("hostname");    string database = query("database");    string user = query("user");    string password = query("password");
Roxen.git/server/modules/tags/sqltag.pike:268:    res += "</tr>\n";       while (row = result->fetch_row()) {    res += "<tr>";    foreach(row, mixed value) {    value = (string)value;    res += "<td>"+(value==""?nullvalue:value)+"</td>";    }    res += "</tr>\n";    } -  res += "</table>"; +  res += "</table><true>";    -  request_id->misc->sqlelse = 0; +     return(res);    } else { -  request_id->misc->sqlelse = 1; -  return("<!-- No result from query -->"); +  return("<!-- No result from query --><false>");    }    } else { -  return("<!-- No query! -->"); +  return("<!-- No query! --><false>");    }   }      string sqlelse_tag(string tag_name, mapping args, string contents,    object request_id, mapping defines)   { -  if (request_id->misc->sqlelse) { -  request_id->misc->sqlelse = 0; -  return(contents); +  return(make_container("else", args, contents));   } -  return(""); - } +       string dumpid_tag(string tag_name, mapping args,    object request_id, mapping defines)   {    return(sprintf("<pre>ID:%O\n</pre>\n",    mkmapping(indices(request_id), values(request_id))));   }      /*    * Hook in the tags