• Welcome, Guest. Please login.
 
August 20, 2019, 08:52:08 pm

News:

Welcome to the SQLitening support forums!


Two databases

Started by Fim, October 04, 2017, 09:59:34 am

Previous topic - Next topic

Fim

Can I have two databases simultaneously on a server, such as "Winova.db3" and "Winova-test.db3" without doing anything special on the server? In my progarm, I open one or other database. I think right?

Fim W.
Fim W

Bern Ertl

As long as you have the hard drive space, you can have as many databases as you want.  The app I'm developing right now uses multiple databases to manage different things (licensing, users/logins, global data, individual project data).

Fim

Fim W

cj

October 04, 2017, 02:54:01 pm #3 Last Edit: October 16, 2017, 11:25:42 am by cj
2 databases cannot be open in the same thread without ATTACH so simultaneously is in question.

Each thread gets its own set of handles as demonstrated here by using multiple threads.
The other methods would be to slClose/slOpen each database or use multiple processes.

#INCLUDE "sqlitening.inc"
GLOBAL gs AS STRING
FUNCTION PBMAIN () AS LONG
LOCAL hThread AS LONG
THREAD CREATE Other(0) TO hThread
LOCAL s() AS STRING
slOpen "sample.db3","C"
slselAry "select count(*) from parts",s(),"Q9c"
addIt FUNCNAME$ + " " + JOIN$(s(),$CR)
DO:SLEEP 50:LOOP UNTIL THREADCOUNT = 1
? gs,,"Both"
'PBMAIN 10000
'Other 2
END FUNCTION

SUB AddIt(s AS STRING) THREADSAFE
gs+=s + $CR
END SUB

THREAD FUNCTION Other(BYVAL x AS LONG)
LOCAL s() AS STRING
slOpen "junk.db3","C"
slexe "create table if not exists t1(c1)
slexe "insert into t1 values('test')"
slselAry "select count(*) from t1",s(),"Q9c"
AddIt FUNCNAME$ + " " + JOIN$(s(),$CR)
END FUNCTION

cj

Note: slOpen automatically closes any previous open database.

#INCLUDE "sqlitening.inc"
GLOBAL gs AS STRING
FUNCTION PBMAIN () AS LONG
LOCAL hThread AS LONG
THREAD CREATE Other(0) TO hThread
LOCAL s() AS STRING
slOpen "sample.db3","C"
slselAry "select count(*) from parts",s(),"Q9c"
addIt FUNCNAME$ + " " + JOIN$(s(),$CR)
DO:SLEEP 50:LOOP UNTIL THREADCOUNT = 1
? gs,,"Both"
'PBMAIN 10000
'Other 2

'Switch databases
slOpen "junk.db3"
slselAry "select count(*) from t1",s(),"Q9c"
? JOIN$(s(),$CR)

slOpen "sample.db3"
slselAry "select count(*) from parts",s(),"Q9c"
? JOIN$(s(),$CR)  '10000
END FUNCTION

SUB AddIt(s AS STRING) THREADSAFE
gs+=s + $CR
END SUB

THREAD FUNCTION Other(BYVAL x AS LONG)
LOCAL s() AS STRING
slOpen "junk.db3","C"
slexe "create table if not exists t1(c1)
slexe "insert into t1 values('test')"
slselAry "select count(*) from t1",s(),"Q9c"
AddIt FUNCNAME$ + " " + JOIN$(s(),$CR)
END FUNCTION
                           

Fim

I did not intend to have two databases open at the same time. Instead, I had thought to be able to switch between them. But thanks for the tips.
/Fim W.
Fim W