slang-users mailing list

[2005 Date Index] [2005 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Slang modules and threads?


Paul Boekholt <p.boekholt@xxxxxxxxx> wrote:
>Great!  Looking at the module, it doesn't seem to provide a way to open
>more than one database.  From what I can tell, the database handle is in a
>static variable:
>
>static sqlite3 *db = 0;
>
>Now, it's possible to import modules more than once into different
>namespaces.  However, some testing reveals that static variables defined
>by the module are not duplicated - if I change it in one namespace it
>also gets changed in the other.  Some more testing reveals that making it
>an intrinsic variable doesn't help.  So I would like to ask: is there a
>simple way to make this module handle multiple databases?  This question

A simple way is to use an array sqlite3* objects, e.g.,

   #define MAX_OPEN_DB 256
   static sqlite3 *Open_dbs[MAX_OPEN_DB];
   static unsigned int Num_Open_Dbs = 0;
   
   static unsigned int open_a_db (void)
   {
      sqlite3 *db = ...;
        .
        .
      if (Num_Open_Dbs == MAX_OPEN_DB)
        {
           /* error */
	      .
	      .
	}
      
      Open_dbs[Num_Open_Dbs++] = db;
   }

This also means that the intrinsics should be modified to take some
sort of a handle to the approriate db object, e.g., and index into the
above array would suffice.  I personally would use SLang_MMT_Type
object for this.  There are a number of places in slang where this
technique is used including the pcre module.

--John

_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html


[2005 date index] [2005 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]