Branch: Tag:

1997-10-15

1997-10-15 18:50:36 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added ascii-attribute to the sqltable tag.

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

1:   /* -  * $Id: sqltag.pike,v 1.11 1997/09/30 14:33:21 grubba Exp $ +  * $Id: sqltag.pike,v 1.12 1997/10/15 18:50:36 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.11 1997/09/30 14:33:21 grubba Exp $"; + constant cvs_version="$Id: sqltag.pike,v 1.12 1997/10/15 18:50:36 grubba Exp $";   constant thread_safe=1;   #include <module.h>    -  + /* Compatibility with old versions of the sqltag module. */ + // #define SQL_TAG_COMPAT +    inherit "module";   inherit "roxenlib";   
63:    "<tr><td valign=top><b>password</b></td>"    "<td>The password to access the database.</td></tr>\n"    "</table></ul><p>\n" +  "The &lt;sqltable&gt; tag has an additional attribute " +  "<b>ascii</b>, which generates a tab-separated table (usefull " +  "for eg the &lt;diagram&gt; tag)."    "\n"    "<b>NOTE</b>: Specifying passwords in the documents may prove "    "to be a security hole if the module is not loaded for some "
80:   {    if (args->query) {    string host = query("hostname"); + #ifdef SQL_TAG_COMPAT    string database = query("database");    string user = query("user");    string password = query("password"); -  + #else /* SQL_TAG_COMPAT */ +  string database, user, password; + #endif /* SQL_TAG_COMPAT */    object(sql) con;    array(mapping(string:mixed)) result;    mixed error;
103:    if (args->password) {    password = args->password;    } -  host = lower_case(host); -  host = (host == "localhost")?"":host; +  host = (lowercase(host) == "localhost")?"":host;       if (error = catch(con = sql(host, database, user, password))) {    contents = "<h1>Couldn't connect to SQL-server</h1><br>\n" +
157:   {    if (args->query) {    string host = query("hostname"); + #ifdef SQL_TAG_COMPAT    string database = query("database");    string user = query("user");    string password = query("password"); -  + #else /* SQL_TAG_COMPAT */ +  string database, user, password; + #endif /* SQL_TAG_COMPAT */    object(sql) con;    mixed error;    array(mapping(string:mixed)) res;
180:    if (args->password) {    password = args->password;    } -  host = lower_case(host); -  host = (host == "localhost")?"":host; +  host = (lowercase(host) == "localhost")?"":host;       if (error = catch(con = sql(host, database, user, password))) {    return("<h1>Couldn't connect to SQL-server</h1><br>\n" +
202:   {    if (args->query) {    string host = query("hostname"); + #ifdef SQL_TAG_COMPAT    string database = query("database");    string user = query("user");    string password = query("password"); -  + #else /* SQL_TAG_COMPAT */ +  string database, user, password; + #endif /* SQL_TAG_COMPAT */    object(sql) con;    mixed error;    object(sql_result) result;    string res; -  +  int ascii;    -  +  if (args->ascii) { +  // ASCII-mode +  ascii = 1; +  } +     if (args->host) {    host = args->host;    user = "";
226:    if (args->password) {    password = args->password;    } -  host = lower_case(host); -  host = (host == "localhost")?"":host; +  host = (lowercase(host) == "localhost")?"":host;       if (error = catch(con = sql(host, database, user, password))) {    return("<h1>Couldn't connect to SQL-server</h1><br>\n" +
246:    nullvalue=(string)args->nullvalue;    }    +  if (ascii) { +  res = ""; +  } else {    res = "<table";    foreach(indices(args) - ({ "host", "database", "user", "password",    "query", "nullvalue" }),
264:    res += "<th>"+name+"</th>";    }    res += "</tr>\n"; +  }       while (row = result->fetch_row()) { -  +  if (ascii) { +  res += (Array.map(row, lambda(mixed value) { +  return((string)value); +  }) * "\t") + "\n"; +  } else {    res += "<tr>";    foreach(row, mixed value) {    value = (string)value;
273:    }    res += "</tr>\n";    } +  } +  if (!ascii) {    res += "</table><true>"; -  +  }       return(res);    } else { -  +  if (ascii) { +  return(""); +  }    return("<!-- No result from query --><false>");    }    } else { -  +  if (ascii) { +  return(""); +  }    return("<!-- No query! --><false>");    }   }
327:    "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"); + #ifdef SQL_TAG_COMPAT    defvar("database", "", "Default SQL-database",    TYPE_STRING, "Specifies the name of the default SQL-database.\n");    defvar("user", "", "Default username",    TYPE_STRING, "Specifies the default username to use for access.\n");    defvar("password", "", "Default password",    TYPE_STRING, "Specifies the default password to use for access.\n"); -  + #endif /* SQL_TAG_COMPAT */   }      /*