Devart Blog

Disabling Direct Mode In LiteDAC and UniDAC

Posted by on August 7th, 2015

LiteDAC and UniDAC interact with SQLite in 2 approaches. The first approach is that an application uses functions of the linked SQLite library. For Windows OS it is sqlite3.dll, for Mac OS and iOS – libsqlite3.dylib, for Android – libsqlite.so. The second approach allows to connect to the database from the application directly, using so called Direct Mode. Direct Mode provides interaction with SQLite avoiding any external libraries linking. It is implemented by embedding the code of the SQLite library directly to the application. This approach allows to work with SQLite in cases, when using third-party libraries is impossible due to a number of reasons. For example, when developing applications for iOS or Mac OS, the Apple corporation prohibits deployment of any libraries along with the application.

However, there are situations, when it is preferably to use the first mode. Thus, when developing applications for Android, there is no need to worry about SQLite client library presence, since it is included into this OS distribution. On the other hand, during project implementation, strict requirements may be imposed on the compiled application size. Such requirements are especially relevant for mobile development. Therefore, it is highly desirable to have an opportunity to disable modules, that won’t be used in the application, before compilation. LiteDAC and UniDAC allow to exclude the code of the SQLite client library, that implements Direct Mode, from a ready application. As a result, the size of the developed application may be decreased.

To exclude support for Direct Mode from the project, do the following:

  1. Add the path to the [DAC Installation Folder]\Source] folder to the Search Path property
  2. Compile the application with the NOSTATIC option.

Pay attention, that the Search Path option and compiler options are set for each supported platform separately!

NOSTATIC

A simple sample application using LiteDAC can show the gain in the retrieved application size:

Platform Normal Compilation Compilation with NOSTATIC Size difference
Win32 4 268 Kb 3 752 Kb 516 Kb
Win64 7 292 Kb 6 122 Kb 1 170 Kb
iOS32 20 540 Kb 19 883 Kb 657 Kb
iOS64 22 532 Kb 21 428 Kb 1 104 Kb
Android 20 181 Kb 19 490 Kb 691 Kb

Thus, the use of the NOSTATIC conditional compilation directive allows to exclude the Direct Mode module from the compilation in cases when it is not used.

Note, that if you set the Direct property to True when using the NOSTATIC directive, the ‘Direct Mode disabled’ error will occur.

4 Responses to “Disabling Direct Mode In LiteDAC and UniDAC”

  1. jorge gaspar Says:

    if I deactivate direct mode in sqlite, the Encryption Key option . I can still use the ?

  2. DAC Team Says:

    Hello, Jorge!
    If the SQLite library you are using has support for encryption, then yes – you will be able to use the Encryption Key option after disabling Direct Mode. However, the Encryption Algorithm option will be unavailable in this case.

  3. Ian Tetriss Says:

    Hello,

    I have a feeling that Lazarus doesn’t support Direct Mode; I cannot find any static library of SQLite.
    Is that true?

    Thanks

  4. DAC Team Says:

    Hello, Ian! You are right. Currently, LiteDAC and UniDAC have no support for SQLite Direct Mode in Lazarus. You can post a suggestion at our Uservoice forum. If your suggestion gets enough votes, we will consider the possibility to implement it in one of the next versions.

Leave a Reply