Skip to content
Snippets Groups Projects
Commit 597c1ef5 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Added support for compiled queries.

Rev: lib/modules/Sql.pmod/sql.pike:1.5
parent 4334784f
Branches
Tags
No related merge requests found
/* /*
* $Id: sql.pike,v 1.4 1997/03/30 19:07:40 grubba Exp $ * $Id: sql.pike,v 1.5 1997/04/23 00:29:03 grubba Exp $
* *
* Implements the generic parts of the SQL-interface * Implements the generic parts of the SQL-interface
* *
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
//. //.
//. File: sql.pike //. File: sql.pike
//. RCSID: $Id: sql.pike,v 1.4 1997/03/30 19:07:40 grubba Exp $ //. RCSID: $Id: sql.pike,v 1.5 1997/04/23 00:29:03 grubba Exp $
//. Author: Henrik Grubbström (grubba@infovav.se) //. Author: Henrik Grubbström (grubba@infovav.se)
//. //.
//. Synopsis: Implements the generic parts of the SQL-interface. //. Synopsis: Implements the generic parts of the SQL-interface.
...@@ -55,11 +55,11 @@ void create(void|string|object host, void|string db, ...@@ -55,11 +55,11 @@ void create(void|string|object host, void|string db,
} else { } else {
foreach(get_dir(Sql->dirname), string program_name) { foreach(get_dir(Sql->dirname), string program_name) {
if ((sizeof(program_name / "_result") == 1) && if ((sizeof(program_name / "_result") == 1) &&
(program_name != "sql.pike") && (sizeof(program_name / ".pike") > 1) &&
(program_name != "CVS")) { (program_name != "sql.pike")) {
/* Don't call ourselves... */ /* Don't call ourselves... */
array(mixed) err; array(mixed) err;
werror("Trying "+program_name+"...\n");
err = catch { err = catch {
program p = Sql[program_name]; program p = Sql[program_name];
...@@ -76,6 +76,7 @@ void create(void|string|object host, void|string db, ...@@ -76,6 +76,7 @@ void create(void|string|object host, void|string db,
} }
return; return;
}; };
werror(describe_backtrace(err)+"\n");
} }
} }
} }
...@@ -119,13 +120,28 @@ void select_db(string db) ...@@ -119,13 +120,28 @@ void select_db(string db)
master_sql->select_db(db); master_sql->select_db(db);
} }
//. - compile_query
//. Compiles the query (if possible). Otherwise returns it as is.
//. The resulting object can be used multiple times in query() and
//. big_query().
//. > q
//. SQL-query to compile.
string|object compile_query(string q)
{
if (functionp(master_sql->compile_query)) {
return(master_sql->compile_query(q));
}
return(q);
}
//. - query //. - query
//. Send an SQL query to the underlying SQL-server. The result is returned //. Send an SQL query to the underlying SQL-server. The result is returned
//. as an array of mappings indexed on the name of the columns. //. as an array of mappings indexed on the name of the columns.
//. Returns 0 if the query didn't return any result (e.g. INSERT or similar). //. Returns 0 if the query didn't return any result (e.g. INSERT or similar).
//. > q //. > q
//. Query to send to the SQL-server. //. Query to send to the SQL-server. This can either be a string with the
array(mapping(string:mixed)) query(string q) //. query, or a previously compiled query (see compile_query()).
array(mapping(string:mixed)) query(object|string q)
{ {
object res_obj; object res_obj;
...@@ -141,8 +157,9 @@ array(mapping(string:mixed)) query(string q) ...@@ -141,8 +157,9 @@ array(mapping(string:mixed)) query(string q)
//. the available memory, and returning some more info on the result. //. the available memory, and returning some more info on the result.
//. Returns 0 if the query didn't return any result (e.g. INSERT or similar). //. Returns 0 if the query didn't return any result (e.g. INSERT or similar).
//. > q //. > q
//. Query to send to the SQL-server. //. Query to send to the SQL-server. This can either be a string with the
object big_query(string q) //. query, or a previously compiled query (see compile_query()).
object big_query(object|string q)
{ {
if (functionp(master_sql->big_query)) { if (functionp(master_sql->big_query)) {
return(Sql.sql_result(master_sql->big_query(q))); return(Sql.sql_result(master_sql->big_query(q)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment