Package org.sqlite

Class SQLiteConfig


  • public class SQLiteConfig
    extends Object
    SQLite Configuration

    See also https://www.sqlite.org/pragma.html

    Author:
    leo
    • Constructor Detail

      • SQLiteConfig

        public SQLiteConfig()
        Default constructor.
      • SQLiteConfig

        public SQLiteConfig​(Properties prop)
        Creates an SQLite configuration object using values from the given property object.
        Parameters:
        prop - The properties to apply to the configuration.
    • Method Detail

      • isEnabledSharedCache

        public boolean isEnabledSharedCache()
        Checks if the shared cache option is turned on.
        Returns:
        True if turned on; false otherwise.
      • isEnabledLoadExtension

        public boolean isEnabledLoadExtension()
        Checks if the load extension option is turned on.
        Returns:
        True if turned on; false otherwise.
      • getOpenModeFlags

        public int getOpenModeFlags()
        Returns:
        The open mode flags.
      • setPragma

        public void setPragma​(SQLiteConfig.Pragma pragma,
                              String value)
        Sets a pragma's value.
        Parameters:
        pragma - The pragma to change.
        value - The value to set it to.
      • isExplicitReadOnly

        public boolean isExplicitReadOnly()
        Returns:
        true if explicit read only transactions are enabled
      • setExplicitReadOnly

        public void setExplicitReadOnly​(boolean readOnly)
        Enable read only transactions after connection creation if explicit read only is true.
        Parameters:
        readOnly - whether to enable explicit read only
      • setSharedCache

        public void setSharedCache​(boolean enable)
        Enables or disables the sharing of the database cache and schema data structures between connections to the same database.
        Parameters:
        enable - True to enable; false to disable.
        See Also:
        www.sqlite.org/c3ref/enable_shared_cache.html
      • enableLoadExtension

        public void enableLoadExtension​(boolean enable)
        Enables or disables extension loading.
        Parameters:
        enable - True to enable; false to disable.
        See Also:
        www.sqlite.org/c3ref/load_extension.html
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
        Sets the read-write mode for the database.
        Parameters:
        readOnly - True for read-only; otherwise read-write.
      • setCacheSize

        public void setCacheSize​(int numberOfPages)
        Changes the maximum number of database disk pages that SQLite will hold in memory at once per open database file.
        Parameters:
        numberOfPages - Cache size in number of pages.
        See Also:
        www.sqlite.org/pragma.html#pragma_cache_size
      • enableCountChanges

        @Deprecated
        public void enableCountChanges​(boolean enable)
        Deprecated.
        Enables or disables the count-changes flag. When enabled, INSERT, UPDATE and DELETE statements return the number of rows they modified.
        Parameters:
        enable - True to enable; false to disable.
        See Also:
        www.sqlite.org/pragma.html#pragma_count_changes
      • setDefaultCacheSize

        public void setDefaultCacheSize​(int numberOfPages)
        Sets the suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file. The cache size set here persists across database connections.
        Parameters:
        numberOfPages - Cache size in number of pages.
        See Also:
        www.sqlite.org/pragma.html#pragma_cache_size
      • enforceForeignKeys

        public void enforceForeignKeys​(boolean enforce)
        Whether to enforce foreign key constraints. This setting affects the execution of all statements prepared using the database connection, including those prepared before the setting was changed.
        Parameters:
        enforce - True to enable; false to disable.
        See Also:
        www.sqlite.org/pragma.html#pragma_foreign_keys
      • enableFullColumnNames

        @Deprecated
        public void enableFullColumnNames​(boolean enable)
        Deprecated.
        Enables or disables the full_column_name flag. This flag together with the short_column_names flag determine the way SQLite assigns names to result columns of SELECT statements.
        Parameters:
        enable - True to enable; false to disable.
        See Also:
        www.sqlite.org/pragma.html#pragma_full_column_names
      • enableFullSync

        public void enableFullSync​(boolean enable)
        Enables or disables the fullfsync flag. This flag determines whether or not the F_FULLFSYNC syncing method is used on systems that support it. The default value of the fullfsync flag is off. Only Mac OS X supports F_FULLFSYNC.
        Parameters:
        enable - True to enable; false to disable.
        See Also:
        www.sqlite.org/pragma.html#pragma_fullfsync
      • incrementalVacuum

        public void incrementalVacuum​(int numberOfPagesToBeRemoved)
        Sets the incremental_vacuum value; the number of pages to be removed from the freelist. The database file is truncated by the same amount.
        Parameters:
        numberOfPagesToBeRemoved - The number of pages to be removed.
        See Also:
        www.sqlite.org/pragma.html#pragma_incremental_vacuum
      • setJournalSizeLimit

        public void setJournalSizeLimit​(int limit)
        Sets the journal_size_limit. This setting limits the size of the rollback-journal and WAL files left in the file-system after transactions or checkpoints.
        Parameters:
        limit - Limit value in bytes. A negative number implies no limit.
        See Also:
        www.sqlite.org/pragma.html#pragma_journal_size_limit
      • useLegacyFileFormat

        public void useLegacyFileFormat​(boolean use)
        Sets the value of the legacy_file_format flag. When this flag is enabled, new SQLite databases are created in a file format that is readable and writable by all versions of SQLite going back to 3.0.0. When the flag is off, new databases are created using the latest file format which might not be readable or writable by versions of SQLite prior to 3.3.0.
        Parameters:
        use - True to turn on legacy file format; false to turn off.
        See Also:
        www.sqlite.org/pragma.html#pragma_legacy_file_format
      • setLegacyAlterTable

        public void setLegacyAlterTable​(boolean flag)
        Sets the value of the legacy_alter_table flag. When this flag is on, the ALTER TABLE RENAME command (for changing the name of a table) works as it did in SQLite 3.24.0 (2018-06-04) and earlier.When the flag is off, using the ALTER TABLE RENAME command will mean that all references to the table anywhere in the schema will be converted to the new name.
        Parameters:
        flag - True to turn on legacy alter table behaviour; false to turn off.
        See Also:
        • setPageSize

          public void setPageSize​(int numBytes)
          Sets the page size of the database. The page size must be a power of two between 512 and 65536 inclusive.
          Parameters:
          numBytes - A power of two between 512 and 65536 inclusive.
          See Also:
          www.sqlite.org/pragma.html#pragma_page_size
        • setReadUncommitted

          public void setReadUncommitted​(boolean useReadUncommittedIsolationMode)
          Enables or disables useReadUncommittedIsolationMode.
          Parameters:
          useReadUncommittedIsolationMode - True to turn on; false to disable. disabled otherwise.
          See Also:
          www.sqlite.org/pragma.html#pragma_read_uncommitted
        • enableRecursiveTriggers

          public void enableRecursiveTriggers​(boolean enable)
          Enables or disables the recursive trigger capability.
          Parameters:
          enable - True to enable the recursive trigger capability.
          See Also:
          www.sqlite.org/pragma.html#pragma_recursive_triggers
        • enableReverseUnorderedSelects

          public void enableReverseUnorderedSelects​(boolean enable)
          Enables or disables the reverse_unordered_selects flag. This setting causes SELECT statements without an ORDER BY clause to emit their results in the reverse order of what they normally would. This can help debug applications that are making invalid assumptions about the result order.
          Parameters:
          enable - True to enable reverse_unordered_selects.
          See Also:
          www.sqlite.org/pragma.html#pragma_reverse_unordered_selects
        • enableShortColumnNames

          public void enableShortColumnNames​(boolean enable)
          Enables or disables the short_column_names flag. This flag affects the way SQLite names columns of data returned by SELECT statements.
          Parameters:
          enable - True to enable short_column_names.
          See Also:
          www.sqlite.org/pragma.html#pragma_short_column_names
        • setSynchronous

          public void setSynchronous​(SQLiteConfig.SynchronousMode mode)
          Changes the setting of the "synchronous" flag.
          Parameters:
          mode - One of SQLiteConfig.SynchronousMode:
          • OFF - SQLite continues without syncing as soon as it has handed data off to the operating system
          • NORMAL - the SQLite database engine will still sync at the most critical moments, but less often than in FULL mode
          • FULL - the SQLite database engine will use the xSync method of the VFS to ensure that all content is safely written to the disk surface prior to continuing. This ensures that an operating system crash or power failure will not corrupt the database.
          See Also:
          www.sqlite.org/pragma.html#pragma_synchronous
        • setHexKeyMode

          public void setHexKeyMode​(SQLiteConfig.HexKeyMode mode)
          Changes the setting of the "hexkey" flag.
          Parameters:
          mode - One of SQLiteConfig.HexKeyMode:
          • NONE - SQLite uses a string based password
          • SSE - the SQLite database engine will use pragma hexkey = '' to set the password
          • SQLCIPHER - the SQLite database engine calls pragma key = "x''" to set the password
        • setTempStore

          public void setTempStore​(SQLiteConfig.TempStore storeType)
          Changes the setting of the "temp_store" parameter.
          Parameters:
          storeType - One of SQLiteConfig.TempStore:
          • DEFAULT - the compile-time C preprocessor macro SQLITE_TEMP_STORE is used to determine where temporary tables and indices are stored
          • FILE - temporary tables and indices are stored in a file.
        • MEMORY - temporary tables and indices are kept in as if they were pure in-memory databases memory
        • See Also:
          www.sqlite.org/pragma.html#pragma_temp_store
        • setTempStoreDirectory

          public void setTempStoreDirectory​(String directoryName)
          Changes the value of the sqlite3_temp_directory global variable, which many operating-system interface backends use to determine where to store temporary tables and indices.
          Parameters:
          directoryName - Directory name for storing temporary tables and indices.
          See Also:
          www.sqlite.org/pragma.html#pragma_temp_store_directory
        • setUserVersion

          public void setUserVersion​(int version)
          Set the value of the user-version. The user-version is not used internally by SQLite. It may be used by applications for any purpose. The value is stored in the database header at offset 60.
          Parameters:
          version - A big-endian 32-bit signed integer.
          See Also:
          www.sqlite.org/pragma.html#pragma_user_version
        • setApplicationId

          public void setApplicationId​(int id)
          Set the value of the application-id. The application-id is not used internally by SQLite. Applications that use SQLite as their application file-format should set the Application ID integer to a unique integer so that utilities such as file(1) can determine the specific file type. The value is stored in the database header at offset 68.
          Parameters:
          id - A big-endian 32-bit unsigned integer.
          See Also:
          www.sqlite.org/pragma.html#pragma_application_id
        • setTransactionMode

          public void setTransactionMode​(String transactionMode)
          Sets the mode that will be used to start transactions.
          Parameters:
          transactionMode - One of DEFERRED, IMMEDIATE or EXCLUSIVE.
          See Also:
          https://www.sqlite.org/lang_transaction.html
        • setDatePrecision

          public void setDatePrecision​(String datePrecision)
          Parameters:
          datePrecision - One of SECONDS or MILLISECONDS
        • setDateClass

          public void setDateClass​(String dateClass)
          Parameters:
          dateClass - One of INTEGER, TEXT or REAL
        • setDateStringFormat

          public void setDateStringFormat​(String dateStringFormat)
          Parameters:
          dateStringFormat - Format of date string
        • setBusyTimeout

          public void setBusyTimeout​(int milliseconds)
          Parameters:
          milliseconds - Connect to DB timeout in milliseconds
        • getBusyTimeout

          public int getBusyTimeout()