Roxen.git / server / base_server / module.pike

version» Context lines:

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.126 2001/08/23 18:40:14 mast Exp $ + // $Id: module.pike,v 1.127 2001/08/23 21:00:53 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:407:    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, + static int create_sql_tables( mapping(string:array(string)) defenitions,    string|void comment, -  int no_unique_names ) +  int|void no_unique_names )   //! Create multiple tables in one go. See @[get_my_table] -  + //! Returns the number of tables that were actually created.   { -  +  int ddc;    if( !no_unique_names )    foreach( indices( defenitions ), string t ) -  get_my_table( t, defenitions[t], comment ); +  ddc+=get_my_table( t, defenitions[t], comment, 1 );    else    {    Sql.Sql sql = get_my_sql();    foreach( indices( defenitions ), string t )    { -  sql->query("CREATE TABLE IF NOT EXISTS "+t+" ("+defenitions[t]*","+")" ); +  if( !catch { +  sql->query("CREATE TABLE "+t+" ("+defenitions[t]*","+")" ); +  } ) +  ddc++;    DBManager.is_module_table( this_object(), my_db, t, comment );    }    } -  +  return ddc;   }      static string sql_table_exists( string name )   //! Return the real name of the table 'name' if it exists.   {    if(strlen(name))    name = "_"+name;       string res = hash(_my_configuration->name)->digits(36)    + "_" + replace(sname(),"#","_") + name;       return catch(get_my_sql()->query( "SELECT * FROM "+res+" LIMIT 1" ))?0:res;   }       - static string get_my_table( string|array(string) name, + static string|int get_my_table( string|array(string) name,    void|array(string)|string defenition, -  string|void comment ) +  string|void comment, +  int|void flag )   //! @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.   //!   //! You can use @[create_sql_tables] instead of this function if you want   //! to create more than one table in one go.   //! -  + //! If @[flag] is true, return 1 if a table was created, and 0 otherwise. + //!   //! In the first form, @[name] is the (postfix of) the name of the   //! table, and @[types] is an array of defenitions, as an example:   //! -  + //!   //! @code{   //! cache_table = get_my_table( "cache", ({   //! "id INT UNSIGNED AUTO_INCREMENT",   //! "data BLOB",   //! }) );   //! @}   //!   //! In the second form, the whole table defenition is instead sent as   //! a string. The cases where the name is not included (the third and   //! fourth form) is equivalent to the first two cases with the name ""
Roxen.git/server/base_server/module.pike:480:   //! @note   //! This function may not be called from create   //   // If it exists, but it's defenition is different, the table will be   // altered with a ALTER TABLE call to conform to the defenition. This   // might not work if the database the table resides in is not a MySQL   // database (normally it is, but it's possible, using @[set_my_db],   // to change this).   {    string oname; +  int ddc;    if( !defenition )    {    defenition = name;    oname = name = "";    }    else if(strlen(name))    name = "_"+(oname = name);       Sql.Sql sql = get_my_sql();   
Roxen.git/server/base_server/module.pike:503:    if( !sql )    {    report_error("Failed to get SQL handle, permission denied for "+my_db+"\n");    return 0;    }    if( arrayp( defenition ) )    defenition *= ", ";       if( catch(sql->query( "SELECT * FROM "+res+" LIMIT 1" )) )    { +  ddc++;    mixed error =    catch    {    get_my_sql()->query( "CREATE TABLE "+res+" ("+defenition+")" );    DBManager.is_module_table( this_object(), my_db, res,    oname+"\0"+comment );    };    if( error )    {    if( strlen( name ) )    name = " "+name;    report_error( "Failed to create table"+name+": "+    describe_error( error ) );    return 0;    } -  +  if( flag ) +  { +  __my_tables[ "&"+oname+";" ] = res; +  return ddc; +  }    return __my_tables[ "&"+oname+";" ] = res;    }   // // Update defenition if it has changed.   // mixed error =   // catch   // {   // get_my_sql()->query( "ALTER TABLE "+res+" ("+defenition+")" );   // };   // if( error )   // {   // if( strlen( name ) )   // name = " for "+name;   // report_notice( "Failed to update table defenition"+name+": "+   // describe_error( error ) );   // } -  +  if( flag ) +  { +  __my_tables[ "&"+oname+";" ] = res; +  return ddc; +  }    return __my_tables[ "&"+oname+";" ] = res;   }      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]   {