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.   //   // 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.43 2000/02/02 20:42:30 per Exp $"; + constant cvs_version="$Id: sqltag.pike,v 1.44 2000/02/05 04:29:04 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";    - import Sql; -  +    Configuration conf;         // Module interface functions    - array register_module() - { -  return ({ MODULE_PARSER|MODULE_PROVIDER, -  "SQL module", -  "This module gives the three tags &lt;SQLQUERY&gt;, " -  "&lt;SQLOUTPUT&gt;, and &lt;SQLTABLE&gt;.<br>\n", -  0, 1 }); - } + constant module_type=MODULE_PARSER|MODULE_PROVIDER; + constant module_name="SQL tag module"; + constant module_desc="This module gives the three tags &lt;SQLQUERY&gt;, " +  "&lt;SQLOUTPUT&gt;, and &lt;SQLTABLE&gt;.<br>\n";      TAGDOCUMENTATION   #ifdef manual   constant tagdoc=(["sqltable":"<desc tag>SQL table</desc>",    "sqlquery":"<desc tag>SQL query</desc>","sqloutput":"<desc cont>SQL output</desc>"]);   /*    "Usage:<ul>\n"    "<table border=0>\n"    "<tr><td valign=top><b>&lt;sqloutput&gt;</b></td>"    "<td>Executes an SQL query, and "
Roxen.git/server/modules/tags/sqltag.pike:91:      array|string|object do_sql_query(string tag, mapping args, RequestID id)   {    if (!args->query)    return rxml_error(tag, "No query.", id);       if (args->parse)    args->query = parse_rxml(args->query, id);       string host = query("hostname"); -  object(sql) con; +  Sql.sql con;    array(mapping(string:mixed)) result;    function sql_connect = id->conf->sql_connect;    mixed error;      #ifdef SQL_TAG_COMPAT    string database = query("database");    string user = query("user");    string password = query("password");       if (args->host) {
Roxen.git/server/modules/tags/sqltag.pike:125: Inside #if defined(SQL_TAG_COMPAT)
   }    if (args->password) {    password = args->password;    sql_connect = 0;    }       if (sql_connect)    error = catch(con = sql_connect(host));    else {    host = (lower_case(host) == "localhost")?"":host; -  error = catch(con = sql(host, database, user, password)); +  error = catch(con = Sql.sql(host, database, user, password));    }   #else    if (args->host)    host=args->host;       if(sql_connect)    error = catch(con = sql_connect(host));    else -  error = catch(con = sql(lower_case(host)=="localhost"?"":host)); +  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>";
Roxen.git/server/modules/tags/sqltag.pike:173:    if(tag=="sqlquery") args["dbobj"]=con;    return result;   }         // -------------------------------- Tag handlers ------------------------------------      array|string container_sqloutput(string tag, mapping args, string contents,    RequestID id)   { -  if(args->help) return register_module()[2]; // FIXME +     NOCACHE();       string|array res=do_sql_query(tag, args, id);    if(stringp(res)) return res;       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"] )
Roxen.git/server/modules/tags/sqltag.pike:195:       return ret;    }       if (args["do-once"])    return do_output_tag( args, ({([])}), contents, id )+ "<true>";       return rxml_error(tag, "No SQL return values.", id);   }    + 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)   { -  if(args->help) return register_module()[2]; // FIXME +     NOCACHE();       string|array res=do_sql_query(tag, args, id);    if(stringp(res)) return res;       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);       return "<true>";   }      string tag_sqltable(string tag, mapping args, RequestID id)   { -  if(args->help) return register_module()[2]; // FIXME +     NOCACHE();       string|object res=do_sql_query(tag, args, id);    if(stringp(res)) return res;       int ascii=!!args->ascii;    string ret="";       if (res) {    string nullvalue=args->nullvalue||"";
Roxen.git/server/modules/tags/sqltag.pike:263:       return ret+"<true>";    }       return rxml_error(tag, "No SQL return values.", id);   }         // ------------------- Callback functions -------------------------    - object(sql) sql_object(void|string host) + Sql.sql sql_object(void|string host)   {    string host = stringp(host)?host:query("hostname"); -  object(sql) con; +  Sql.sql con;    function sql_connect = conf->sql_connect;    mixed error;    /* Is this really a good idea? /mast    error = catch(con = sql_connect(host));    if(error)    return 0;    return con;    */    return sql_connect(host);   }