2338d3 | 1998-10-01 | Johan Schön | | |
bde4a5 | 1999-06-11 | Martin Stjernholm | | * $Id: sqltag.pike,v 1.35 1999/06/11 13:50:45 mast Exp $
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | *
* A module for Roxen Challenger, which gives the tags
* <SQLQUERY> and <SQLOUTPUT>.
*
* Henrik Grubbström 1997-01-12
*/
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | constant cvs_version="$Id: sqltag.pike,v 1.35 1999/06/11 13:50:45 mast Exp $";
|
07bf51 | 1997-08-31 | Peter Bortas | | constant thread_safe=1;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | #include <module.h>
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | |
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | inherit "module";
inherit "roxenlib";
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | import Array;
import Sql;
|
a03ea4 | 1998-09-29 | Johan Schön | | object conf;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | |
array register_module()
{
|
2a9ddf | 1998-07-15 | Johan Schön | | return( ({ MODULE_PARSER|MODULE_PROVIDER,
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | "SQL-module",
"This module gives the three tags <SQLQUERY>, "
"<SQLOUTPUT>, and <SQLTABLE>.<br>\n"
"Usage:<ul>\n"
"<table border=0>\n"
"<tr><td valign=top><b><sqloutput></b></td>"
"<td>Executes an SQL-query, and "
"replaces #-quoted fieldnames with the results. # is "
|
edf5b8 | 1998-11-02 | Martin Stjernholm | | "quoted as ##. The content between <sqloutput> and "
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | "</sqloutput> is repeated once for every row in the "
"result.</td></tr>\n"
"<tr><td valign=top><b><sqlquery></b></td>\n"
"<td>Executes an SQL-query, but "
"doesn't do anything with the result. This is useful if "
"you do queries like INSERT and CREATE.</td></tr>\n"
"<tr><td valign=top><b><sqltable></td>"
"<td>Executes an SQL-query, and makes "
"an HTML-table from the result.</td></tr>\n"
"</table></ul>\n"
"The following attributes are used by the above tags:<ul>\n"
"<table border=0>\n"
"<tr><td valign=top><b>query</b></td>"
|
edf5b8 | 1998-11-02 | Martin Stjernholm | | "<td>The actual SQL-query. (<b>REQUIRED</b>)</td></tr>\n"
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | "<tr><td valign=top><b>host<b></td>"
"<td>The hostname of the machine the SQL-server runs on.<br>\n"
"This argument can also be used to specify which SQL-server "
"to use by specifying an \"SQL-URL\":<br><ul>\n"
"<pre>[<i>sqlserver</i>://][[<i>user</i>][:<i>password</i>]@]"
"[<i>host</i>[:<i>port</i>]]/<i>database</i></pre><br>\n"
"</ul>Valid values for \"sqlserver\" depend on which "
"sql-servers your pike has support for, but the following "
"might exist: msql, mysql, odbc, oracle, postgres.</td></tr>\n"
"<tr><td valign=top><b>database</b></td>"
"<td>The name of the database to use.</td></tr>\n"
"<tr><td valign=top><b>user</b></td>"
"<td>The name of the user to access the database with.</td></tr>\n"
"<tr><td valign=top><b>password</b></td>"
"<td>The password to access the database.</td></tr>\n"
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | | "<tr><td valign=top><b>parse</b></td>"
"<td>If specified, the query will be parsed by the "
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | "RXML-parser</td></tr>\n"
"<tr><td valign=top><b>quiet</b></td>"
"<td>If specified, SQL-errors will be kept quiet.</td></tr>\n"
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | "</table></ul><p>\n"
"The <sqltable> tag has an additional attribute "
"<b>ascii</b>, which generates a tab-separated table (usefull "
|
655b72 | 1997-10-15 | Henrik Grubbström (Grubba) | | "with eg the <diagram> tag).<p>\n"
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | "\n"
"<b>NOTE</b>: Specifying passwords in the documents may prove "
"to be a security hole if the module is not loaded for some "
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | | "reason.<br>\n"
"<b>SEE ALSO</b>: The <FORMOUTPUT> tag can be "
|
edf5b8 | 1998-11-02 | Martin Stjernholm | | "useful to generate the queries.<br>\n",
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | 0,
1 }) );
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | mixed sqloutput_tag(string tag_name, mapping args, string contents,
object request_id, object f,
mapping defines, object fd)
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | {
|
8756ae | 1998-03-08 | Per Hedbor | | if(args->help) return register_module()[2];
|
3f094d | 1998-08-10 | Per Hedbor | | request_id->misc->cacheable=0;
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | mixed res;
|
3f094d | 1998-08-10 | Per Hedbor | |
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | if (args->query) {
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | |
if (args->parse) {
|
8ec574 | 1997-12-04 | Henrik Grubbström (Grubba) | | args->query = parse_rxml(args->query, request_id, f, defines);
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | | }
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string host = query("hostname");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #ifdef SQL_TAG_COMPAT
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string database = query("database");
string user = query("user");
string password = query("password");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #else /* SQL_TAG_COMPAT */
string database, user, password;
#endif /* SQL_TAG_COMPAT */
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | object(sql) con;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | array(mapping(string:mixed)) result;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | function sql_connect = request_id->conf->sql_connect;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | mixed error;
if (args->host) {
host = args->host;
user = "";
password = "";
}
if (args->database) {
database = args->database;
user = "";
password = "";
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
if (args->user) {
user = args->user;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
if (args->password) {
password = args->password;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | if (sql_connect) {
error = catch(con = sql_connect(host));
} else {
host = (lower_case(host) == "localhost")?"":host;
error = catch(con = sql(host, database, user, password));
}
if (error) {
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | if (!args->quiet) {
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | | if (args->log_error && QUERY(log_error)) {
report_error(sprintf("SQLTAG: Couldn't connect to SQL-server:\n"
"%s\n", describe_backtrace(error)));
}
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | res = ("<h3>Couldn't connect to SQL-server</h1><br>\n" +
html_encode_string(error[0]) + "<false>");
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | } else {
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | res = "<false>";
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | }
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | } else if (error = catch(result = con->query(args->query))) {
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | if (!args->quiet) {
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | | if (args->log_error && QUERY(log_error)) {
report_error(sprintf("SQLTAG: Query %O failed:\n"
"%s\n",
args->query, describe_backtrace(error)));
}
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | res = ("<h3>Query \"" + html_encode_string(args->query)
+ "\" failed: " + html_encode_string(con->error())
+ "</h1>\n<false>");
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | } else {
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | res = "<false>";
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | }
|
b2b1fb | 1998-02-02 | Mattias Wingstedt | | } else if (result && sizeof(result))
{
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | res = ({do_output_tag( args, result, contents, request_id )});
id->misc->defines[" _ok"] = 1;
|
c39496 | 1999-05-14 | Zsolt Varga | |
if( args["rowinfo"] )
request_id->variables[args->rowinfo]=sizeof(result);
|
07245f | 1997-09-28 | Henrik Grubbström (Grubba) | | } else {
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | res = "<false>";
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
} else {
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | res = "<!-- No query! --><false>";
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
bde4a5 | 1999-06-11 | Martin Stjernholm | | return(res);
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
string sqlquery_tag(string tag_name, mapping args,
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | | object request_id, object f,
mapping defines, object fd)
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | {
|
8756ae | 1998-03-08 | Per Hedbor | | if(args->help) return register_module()[2];
|
3f094d | 1998-08-10 | Per Hedbor | |
request_id->misc->cacheable=0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | if (args->query) {
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | |
if (args->parse) {
|
3aa2c8 | 1997-12-04 | Henrik Grubbström (Grubba) | | args->query = parse_rxml(args->query, request_id, f, defines);
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | | }
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string host = query("hostname");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #ifdef SQL_TAG_COMPAT
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string database = query("database");
string user = query("user");
string password = query("password");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #else /* SQL_TAG_COMPAT */
string database, user, password;
#endif /* SQL_TAG_COMPAT */
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | object(sql) con;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | mixed error;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | function sql_connect = request_id->conf->sql_connect;
|
07245f | 1997-09-28 | Henrik Grubbström (Grubba) | | array(mapping(string:mixed)) res;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | |
if (args->host) {
host = args->host;
user = "";
password = "";
}
if (args->database) {
database = args->database;
user = "";
password = "";
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
if (args->user) {
user = args->user;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
if (args->password) {
password = args->password;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | if (sql_connect) {
error = catch(con = sql_connect(host));
} else {
host = (lower_case(host) == "localhost")?"":host;
error = catch(con = sql(host, database, user, password));
}
if (error) {
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | if (!args->quiet) {
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | | if (args->log_error && QUERY(log_error)) {
report_error(sprintf("SQLTAG: Couldn't connect to SQL-server:\n"
"%s\n", describe_backtrace(error)));
}
|
335344 | 1998-07-21 | Per Hedbor | | return("<h3>Couldn't connect to SQL-server</h1><br>\n" +
html_encode_string(error[0])+"<false>");
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | } else {
return("<false>");
}
|
07245f | 1997-09-28 | Henrik Grubbström (Grubba) | | } else if (error = catch(res = con->query(args->query))) {
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | if (!args->quiet) {
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | | if (args->log_error && QUERY(log_error)) {
report_error(sprintf("SQLTAG: Query %O failed:\n"
"%s\n",
args->query, describe_backtrace(error)));
}
|
335344 | 1998-07-21 | Per Hedbor | | return("<h3>Query \"" + html_encode_string(args->query)+"\" failed: "
+ html_encode_string(con->error()) + "</h1>\n<false>");
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | } else {
return("<false>");
}
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
78f8c1 | 1998-07-22 | Fredrik Noring | | if(args["mysql-insert-id"])
if(con->master_sql)
request_id->variables[args["mysql-insert-id"]] =
con->master_sql->insert_id();
else
return "<!-- No insert_id present. --><false>";
|
ced796 | 1998-11-04 | Rob Young | | return("<true>");
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | } else {
|
26b7da | 1997-09-30 | Henrik Grubbström (Grubba) | | return("<!-- No query! --><false>");
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
}
string sqltable_tag(string tag_name, mapping args,
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | | object request_id, object f,
mapping defines, object fd)
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | {
|
c7f4e5 | 1997-10-15 | Henrik Grubbström (Grubba) | | int ascii;
|
8756ae | 1998-03-08 | Per Hedbor | | if(args->help) return register_module()[2];
|
3f094d | 1998-08-10 | Per Hedbor | |
request_id->misc->cacheable=0;
|
c7f4e5 | 1997-10-15 | Henrik Grubbström (Grubba) | | if (args->ascii) {
ascii = 1;
}
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | if (args->query) {
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | |
if (args->parse) {
|
3aa2c8 | 1997-12-04 | Henrik Grubbström (Grubba) | | args->query = parse_rxml(args->query, request_id, f, defines);
|
961fd3 | 1997-11-29 | Henrik Grubbström (Grubba) | | }
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string host = query("hostname");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #ifdef SQL_TAG_COMPAT
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string database = query("database");
string user = query("user");
string password = query("password");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #else /* SQL_TAG_COMPAT */
string database, user, password;
#endif /* SQL_TAG_COMPAT */
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | object(sql) con;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | mixed error;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | function sql_connect = request_id->conf->sql_connect;
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | object(sql_result) result;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string res;
if (args->host) {
host = args->host;
user = "";
password = "";
}
if (args->database) {
database = args->database;
user = "";
password = "";
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
if (args->user) {
user = args->user;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | sql_connect = 0;
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
if (args->password) {
password = args->password;
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | 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));
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | if (error) {
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | if (!args->quiet) {
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | | if (args->log_error && QUERY(log_error)) {
report_error(sprintf("SQLTAG: Couldn't connect to SQL-server:\n"
"%s\n", describe_backtrace(error)));
}
|
335344 | 1998-07-21 | Per Hedbor | | return("<h3>Couldn't connect to SQL-server</h1><br>\n" +
html_encode_string(error[0])+"<false>");
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | } else {
return("<false>");
}
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | } else if (error = catch(result = con->big_query(args->query))) {
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | if (!args->quiet) {
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | | if (args->log_error && QUERY(log_error)) {
report_error(sprintf("SQLTAG: Query %O failed:\n"
"%s\n",
args->query, describe_backtrace(error)));
}
|
335344 | 1998-07-21 | Per Hedbor | | return ("<h3>Query \"" + html_encode_string(args->query) +
"\" failed: " + html_encode_string(con->error()) + "</h1>\n" +
"<false>");
|
2ca4ca | 1998-02-10 | Henrik Grubbström (Grubba) | | } else {
return("<false>");
}
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | if (result) {
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | string nullvalue="";
array(mixed) row;
if (args->nullvalue) {
nullvalue=(string)args->nullvalue;
}
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | if (ascii) {
res = "";
} else {
res = "<table";
foreach(indices(args) - ({ "host", "database", "user", "password",
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | "query", "nullvalue" }),
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | string attr) {
string val = args[attr];
if (val != attr) {
res += " "+attr+"=\""+val+"\"";
} else {
res += " "+attr;
}
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | res += "><tr>";
foreach(map(result->fetch_fields(), lambda (mapping m) {
return(m->name);
} ), string name) {
res += "<th>"+name+"</th>";
}
res += "</tr>\n";
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
07245f | 1997-09-28 | Henrik Grubbström (Grubba) | |
|
c39496 | 1999-05-14 | Zsolt Varga | | if( args["rowinfo"] )
request_id->variables[args->rowinfo]=result->num_rows();
|
0e05a3 | 1997-05-20 | Henrik Grubbström (Grubba) | | while (row = result->fetch_row()) {
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | if (ascii) {
res += (Array.map(row, lambda(mixed value) {
return((string)value);
}) * "\t") + "\n";
} else {
res += "<tr>";
foreach(row, mixed value) {
value = (string)value;
res += "<td>"+(value==""?nullvalue:value)+"</td>";
}
res += "</tr>\n";
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
}
|
a60c30 | 1997-10-15 | Henrik Grubbström (Grubba) | | if (ascii) {
res += "<true>";
} else {
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | res += "</table><true>";
}
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | |
return(res);
} else {
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | if (ascii) {
|
a60c30 | 1997-10-15 | Henrik Grubbström (Grubba) | | return("<false>");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | }
|
26b7da | 1997-09-30 | Henrik Grubbström (Grubba) | | return("<!-- No result from query --><false>");
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
} else {
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | if (ascii) {
|
a60c30 | 1997-10-15 | Henrik Grubbström (Grubba) | | return("<false>");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | }
|
26b7da | 1997-09-30 | Henrik Grubbström (Grubba) | | return("<!-- No query! --><false>");
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
}
|
07245f | 1997-09-28 | Henrik Grubbström (Grubba) | | string sqlelse_tag(string tag_name, mapping args, string contents,
object request_id, mapping defines)
{
|
26b7da | 1997-09-30 | Henrik Grubbström (Grubba) | | return(make_container("else", args, contents));
|
07245f | 1997-09-28 | Henrik Grubbström (Grubba) | | }
|
0d90ed | 1998-01-17 | Henrik Grubbström (Grubba) | | #if 0
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | 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))));
}
|
0d90ed | 1998-01-17 | Henrik Grubbström (Grubba) | | #endif /* 0 */
|
2a9ddf | 1998-07-15 | Johan Schön | |
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | |
mapping query_tag_callers()
{
return( ([ "sql":sqlquery_tag, "sqlquery":sqlquery_tag,
|
0d90ed | 1998-01-17 | Henrik Grubbström (Grubba) | | "sqltable":sqltable_tag,
#if 0
"dumpid":dumpid_tag
#endif /* 0 */
]) );
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
mapping query_container_callers()
{
|
07245f | 1997-09-28 | Henrik Grubbström (Grubba) | | return( ([ "sqloutput":sqloutput_tag, "sqlelse":sqlelse_tag ]) );
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
2a9ddf | 1998-07-15 | Johan Schön | | * Callback functions
*/
|
a03ea4 | 1998-09-29 | Johan Schön | | object(sql) sql_object(void|string host)
|
2a9ddf | 1998-07-15 | Johan Schön | | {
|
a03ea4 | 1998-09-29 | Johan Schön | | string host = stringp(host)?host:query("hostname");
|
2a9ddf | 1998-07-15 | Johan Schön | | object(sql) con;
|
a03ea4 | 1998-09-29 | Johan Schön | | function sql_connect = conf->sql_connect;
|
2a9ddf | 1998-07-15 | Johan Schön | | mixed error;
error = catch(con = sql_connect(host));
if(error)
return 0;
return con;
}
string query_provides()
{
return "sql";
}
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | * Setting the defaults
*/
void create()
{
defvar("hostname", "localhost", "Default SQL-database host",
|
47d81d | 1997-09-05 | Henrik Grubbström (Grubba) | | TYPE_STRING, "Specifies the default host to use for SQL-queries.\n"
"This argument can also be used to specify which SQL-server to "
"use by specifying an \"SQL-URL\":<ul>\n"
"<pre>[<i>sqlserver</i>://][[<i>user</i>][:<i>password</i>]@]"
"[<i>host</i>[:<i>port</i>]]/<i>database</i></pre></ul><br>\n"
|
a2533f | 1997-09-23 | Henrik Grubbström (Grubba) | | "Valid values for \"sqlserver\" depend on which "
|
47d81d | 1997-09-05 | Henrik Grubbström (Grubba) | | "sql-servers your pike has support for, but the following "
"might exist: msql, mysql, odbc, oracle, postgres.\n");
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | |
|
e4c088 | 1998-07-23 | Henrik Grubbström (Grubba) | | defvar("log_error", 0, "Enable the log_error attribute",
|
7763b4 | 1998-07-23 | Henrik Grubbström (Grubba) | | TYPE_FLAG|VAR_MORE, "Enables the attribute \"log_error\" "
"which causes errors to be logged to the event-log.\n");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #ifdef SQL_TAG_COMPAT
|
c7f4e5 | 1997-10-15 | Henrik Grubbström (Grubba) | | defvar("database", "", "Default SQL-database (deprecated)",
TYPE_STRING|VAR_MORE,
"Specifies the name of the default SQL-database.\n");
defvar("user", "", "Default username (deprecated)",
TYPE_STRING|VAR_MORE,
"Specifies the default username to use for access.\n");
defvar("password", "", "Default password (deprecated)",
TYPE_STRING|VAR_MORE,
"Specifies the default password to use for access.\n");
|
f5effc | 1997-10-15 | Henrik Grubbström (Grubba) | | #endif /* SQL_TAG_COMPAT */
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | |
void start(int level, object _conf)
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | {
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | if (_conf) {
conf = _conf;
}
|
2a9ddf | 1998-07-15 | Johan Schön | |
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
void stop()
{
}
string status()
{
|
fa4005 | 1997-06-20 | Henrik Grubbström (Grubba) | | if (catch {
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | object o;
if (conf->sql_connect) {
o = conf->sql_connect(QUERY(hostname));
} else {
o = Sql.sql(QUERY(hostname)
|
c7f4e5 | 1997-10-15 | Henrik Grubbström (Grubba) | | #ifdef SQL_TAG_COMPAT
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | , QUERY(database), QUERY(user), QUERY(password)
|
c7f4e5 | 1997-10-15 | Henrik Grubbström (Grubba) | | #endif /* SQL_TAG_COMPAT */
|
12ac99 | 1997-11-26 | Henrik Grubbström (Grubba) | | );
}
|
6ef16f | 1997-06-24 | Henrik Grubbström (Grubba) | | return(sprintf("Connected to %s-server on %s<br>\n",
|
fa4005 | 1997-06-20 | Henrik Grubbström (Grubba) | | o->server_info(), o->host_info()));
}) {
return("<font color=red>Not connected.</font><br>\n");
}
|
78c997 | 1997-02-20 | Henrik Grubbström (Grubba) | | }
|