Branch: Tag:

2001-01-19

2001-01-19 16:37:43 by Per Hedbor <ph@opera.com>

Added get_my_sql and get_my_table( string defenition ) methods. Example usage, from the auth_httpcookie module:
void start()
{
sql = get_my_sql();
table = get_my_table(
"cookie varchar(40) PRIMARY KEY NOT NULL, "
"password varchar(40) NOT NULL, "
"name varchar(40) NOT NULL"
);
}

Then, later on:

sql->query( "SELECT name,password FROM "+
table+" WHERE cookie=%s", cookie );

Rev: server/base_server/module.pike:1.104

1:   // This file is part of Roxen Webserver.   // Copyright © 1996 - 2000, Roxen IS. - // $Id: module.pike,v 1.103 2001/01/04 07:30:37 nilsson Exp $ + // $Id: module.pike,v 1.104 2001/01/19 16:37:43 per Exp $      #include <module_constants.h>   #include <module.h>
10:   mapping(string:array(int)) error_log=([]);      constant is_module = 1; - constant module_type = MODULE_ZERO; - constant module_name = "Unnamed module"; - constant module_doc = "Undocumented"; - constant module_unique = 1; + // constant module_type = MODULE_ZERO; + // constant module_name = "Unnamed module"; + // constant module_doc = "Undocumented"; + constant module_unique = 1;         private string _module_identifier;
49:    _module_identifier = sprintf ("%s,%s",    name    || this_object()->module_name_locale -  || module_name, cname); +  || this_object()->module_name, cname);    }    return _module_identifier;   }
63:   array register_module()   {    return ({ -  module_type, -  this_object()->module_name_locale || module_name, -  this_object()->module_doc_locale || module_doc, +  this_object()->module_type, +  this_object()->module_name_locale || this_object()->module_name, +  this_object()->module_doc_locale || this_object()->module_doc,    0,    module_unique,    });
162:    return (this_object()->register_module()[2]);   }    + string sname( ) + { +  return my_configuration()->otomod[ this_object() ]; + } +    ModuleInfo my_moduleinfo( )   //! Returns the associated @ref{ModuleInfo} object   { -  string f = my_configuration()->otomod[ this_object() ]; +  string f = sname();    if( f ) return roxen.find_module( (f/"#")[0] );   }   
532:    }    return compile_string((pre||"")+file->read())[index];   } +  +  +  + string get_my_table( string defenition ) + { +  string res = replace(sname(),"#","_"); +  if( catch(get_my_sql()->query( "SELECT * FROM "+res+" LIMIT 1" )) ) +  get_my_sql()->query( "CREATE TABLE "+res+" ("+defenition+")" ); +  return res; + } +  +  + Sql.Sql get_my_sql() + { +  return connect_to_my_mysql( 0, "roxen" ); + }