please let me ask some questions about how to use the UniDAC components in a multithreading application.
First: What is the proper way of using TUniLoader? Do I have to do some commit after calling Load? Currently, I use the following code:
Code: Select all
conn := TUniConnection.Create (NIL);
conn.ProviderName := 'SQLite';
conn.Database := ...
conn.SpecificOptions.Values['ForceCreateDataBase'] := 'True';
conn.SpecificOptions.Values['DateFormat'] := 'yyyy-mm-dd';
conn.SpecificOptions.Values['TimeFormat'] := 'hh24:mi:ss';
conn.SpecificOptions.Values['UseUnicode'] := 'True';
conn.SpecificOptions.Values['EnableSharedCache'] := 'True';
conn.AutoCommit := TRUE;
conn.Connect;
loader := TUniLoader.Create (NIL);
loader.Connection := conn;
loader.TableName := 'xyz';
loader.CreateColumns;
loader.OnPutData := @OnSaveSunPath; // data is inserted there
loader.Options.QuoteNames := TRUE;
loader.Load;
loader.Free;
conn.Free;
Second: According to this document Sqlite should by default operate in serialized mode which is thread-safe without any restrictions. For speed reasons, I wanted to create only a single instance of TUniConnection and use it within all threads. However, when concurrent database writes occur, I get frequent errors "cannot commit - no transaction is active". This happens regardless of whether or not I use manual commits.
So my question is: do I have to create a new instance of TUniConnection in each thread?
It would be kind if I could get some hints about what I'm doing wrong. Thank you.