Roxen.git
/
server
/
base_server
/
module.pike
version
»
Context lines:
10
20
40
80
file
none
3
Roxen.git/server/base_server/module.pike:1:
// This file is part of Roxen WebServer. // Copyright © 1996 - 2001, Roxen IS.
-
// $Id: module.pike,v 1.
119
2001/08/01
11
:
07
:
59
per Exp $
+
// $Id: module.pike,v 1.
120
2001/08/01
17
:
10
:
32
per Exp $
#include <module_constants.h> #include <module.h> #include <request_trace.h> constant __pragma_save_parent__ = 1; inherit "basic_defvar"; mapping(string:array(int)) error_log=([]);
Roxen.git/server/base_server/module.pike:349:
Stdio.File file=Stdio.File(); if(!file->open(path,"r")) return 0; if(index[sizeof(index)-2..sizeof(index)-1]=="()") { return compile_string((pre||"")+file->read())[index[..sizeof(index)-3]](); } return compile_string((pre||"")+file->read())[index]; } static private mapping __my_tables = ([]);
-
static
array(mapping(string:mixed)) sql_query( string query, mixed ... args )
+
array(mapping(string:mixed)) sql_query( string query, mixed ... args )
//! Do a SQL-query using @[get_my_sql], the table names in the query //! should be written as &table; instead of table. As an example, if //! the tables 'meta' and 'data' have been created with create_tables //! or get_my_table, this query will work: //! //! SELECT &meta;.id AS id, &data;.data as DATA //! FROM &data;, &meta; WHERE &my.meta;.xsize=200 //! { return get_my_sql()->query( replace( query, __my_tables ), @args ); }
-
-
static
object sql_big_query( string query, mixed ... args )
+
object sql_big_query( string query, mixed ... args )
//! Identical to @[sql_query], but the @[Sql.sql()->big_query] method //! will be used instead of the @[Sql.sql()->query] method. { return get_my_sql()->big_query( replace( query, __my_tables ), @args ); }
-
+
array(mapping(string:mixed)) sql_query_ro( string query, mixed ... args )
+
//! Do a read-only SQL-query using @[get_my_sql], the table names in the query
+
//! should be written as &table; instead of table. As an example, if
+
//! the tables 'meta' and 'data' have been created with create_tables
+
//! or get_my_table, this query will work:
+
//!
+
//! SELECT &meta;.id AS id, &data;.data as DATA
+
//! FROM &data;, &meta; WHERE &my.meta;.xsize=200
+
//!
+
{
+
return get_my_sql(1)->query( replace( query, __my_tables ), @args );
+
}
+
+
object sql_big_query_ro( string query, mixed ... args )
+
//! Identical to @[sql_query_ro], but the @[Sql.sql()->big_query] method
+
//! will be used instead of the @[Sql.sql()->query] method.
+
{
+
return get_my_sql(1)->big_query( replace( query, __my_tables ), @args );
+
}
+
static void create_sql_tables( mapping(string:array(string)) defenitions ) //! Create multiple tables in one go. See @[get_my_table] { foreach( indices( defenitions ), string t ) get_my_table( t, defenitions[t] ); }
-
+
static string sql_table_exists( string name )
+
{
+
if(strlen(name))
+
name = "_"+name;
+
+
string res = hash(_my_configuration->name)->digits(36)
+
+ "_" + replace(sname(),"#","_") + name;
+
+
return catch(sql->query( "SELECT * FROM "+res+" LIMIT 1" ))?0:res;
+
}
+
+
static string get_my_table( string|array(string) name, void|array(string)|string defenition ) //! @decl string get_my_table( string name, array(string) types ) //! @decl string get_my_table( string name, string defenition ) //! @decl string get_my_table( string defenition ) //! @decl string get_my_table( array(string) defenition ) //! //! Returns the name of a table in the 'shared' database that is //! unique for this module. It is possible to select another database //! by using @[set_my_db] before calling this function.
Roxen.git/server/base_server/module.pike:425:
string oname; if( !defenition ) { defenition = name; oname = name = ""; } else if(strlen(name)) name = "_"+(oname = name); Sql.Sql sql = get_my_sql();
+
string res = hash(_my_configuration->name)->digits(36) + "_" + replace(sname(),"#","_") + name; if( !sql ) { report_error("Failed to get SQL handle, permission denied for "+my_db+"\n"); return 0; } if( arrayp( defenition ) ) defenition *= ", ";
Roxen.git/server/base_server/module.pike:447:
{ mixed error = catch { get_my_sql()->query( "CREATE TABLE "+res+" ("+defenition+")" ); }; if( error ) { if( strlen( name ) ) name = " "+name;
-
report_
notice
( "Failed to create table"+name+": "+
+
report_
error
( "Failed to create table"+name+": "+
describe_error( error ) ); return 0; } return __my_tables[ "&"+oname+";" ] = res; } // // Update defenition if it has changed. // mixed error = // catch // { // get_my_sql()->query( "ALTER TABLE "+res+" ("+defenition+")" );
Roxen.git/server/base_server/module.pike:482:
static string my_db = "shared"; static void set_my_db( string to ) //! Select the database in which tables will be created with //! get_my_table, and also the one that will be returned by //! @[get_my_sql] { my_db = to; }
-
static
Sql.Sql get_my_sql( int|void read_only )
+
Sql.Sql get_my_sql( int|void read_only )
//! Return a SQL-object for the database set with @[set_my_db], //! defaulting to the 'shared' database. If read_only is specified, //! the database will be opened in read_only mode. //! //! See also @[DBManager.get] { return DBManager.cached_get( my_db, _my_configuration, read_only ); }