topten Posted July 4, 2015 Share Posted July 4, 2015 (edited) I have several sqlite databases and I am using this function to load a databseFunc _LoadDatabase($Database_File = -1, $Database_Structure = -1, $Table_Name = -1, $_Automatic_Unload = 1) _SQLite_Startup() _DefaultAnalyser($Database_File, 'DataBase.db3') _DefaultAnalyser($Database_Structure, 'id INTEGER PRIMARY KEY,data TEXT,parameters TEXT') _DefaultAnalyser($Table_Name, 'Database') _DefaultAnalyser($_Automatic_Unload, 1) If $_Automatic_Unload Then OnAutoItExitRegister('_UnloadDatabase') If Not FileExists($Database_File) Then _SQLite_Open($Database_File) _SQLite_Exec(-1, "CREATE TABLE " & $Table_Name & " (" & $Database_Structure & ")") $_Just_Created = True ;I made This Variable to know that I should Insert The Values or Update Them........ ;Since we cannot insert the same id twice(will cause error because it is Declared as PRIMARY KEY) Else _SQLite_Open($Database_File) EndIf If @error Then Return SetError(1, @error, -1) Return 1 EndFunc ;==>_LoadDatabaseWhen I load one databse it works ok, but when I am using the same function to load the second database it becomes unresponsive - is it possible to use several databases simultaneously, something like:_LoadDatabase (1.db)_LoadDatabase (2.db) Edited July 4, 2015 by topten Link to comment Share on other sites More sharing options...
JohnOne Posted July 4, 2015 Share Posted July 4, 2015 Read remarks in help file regarding _SQLite_Open. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jchd Posted July 4, 2015 Share Posted July 4, 2015 You can use as many databases as needed, simultaneously, by using the handle returned by _SQLite_Open and passing it as the first argument in _SQLite_* functions.You can also attach a database to an already open one: see SQL attach. Which way is best suited to your use case depends on the context and which operations you have to perform. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Luigi Posted July 4, 2015 Share Posted July 4, 2015 More or less..._SQLite_Startup() Global $g_hDataBase1 = _SQLite_Open($Database_File_1) Global $g_hDataBase2 = _SQLite_Open($Database_File_2) Func _LoadDatabase($Database_File = -1, $Database_Structure = -1, $Table_Name = -1, $_Automatic_Unload = 1) _DefaultAnalyser($Database_File, 'DataBase.db3') _DefaultAnalyser($Database_Structure, 'id INTEGER PRIMARY KEY,data TEXT,parameters TEXT') _DefaultAnalyser($Table_Name, 'Database') _DefaultAnalyser($_Automatic_Unload, 1) If $_Automatic_Unload Then OnAutoItExitRegister('_UnloadDatabase') If Not FileExists($Database_File) Then ; do not use -1... use variable's database _SQLite_Exec($g_hDataBase1, "CREATE TABLE " & $Table_Name & " (" & $Database_Structure & ")") _SQLite_Exec($g_hDataBase2, "CREATE TABLE " & $Table_Name & " (" & $Database_Structure & ")") $_Just_Created = True ;I made This Variable to know that I should Insert The Values or Update Them........ ;Since we cannot insert the same id twice(will cause error because it is Declared as PRIMARY KEY) Else _SQLite_Open($Database_File) EndIf If @error Then Return SetError(1, @error, -1) Return 1 EndFunc ;==>_LoadDatabase Func on_exit() _SQLite_Close($g_hDataBase1) _SQLite_Close($g_hDataBase2) EndFunc topten 1 Visit my repository Link to comment Share on other sites More sharing options...
topten Posted July 5, 2015 Author Share Posted July 5, 2015 Thank you everyone for your great advise, Sending special thanx to Luigi (it is great that you've made an example in the context of the function I use) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now