Class SqlJetDb


  • public class SqlJetDb
    extends SqlJetEngine

    Connection to database. This class currently is main entry point in SQLJet API.

    It allows to perform next tasks:

    • Open existed and create new SQLite database.
    • Get and modify database's schema.
    • Control transactions.
    • Read, search and modify data in database.
    • Get and set database's options.

    • Field Detail

      • IN_MEMORY

        public static final java.io.File IN_MEMORY
        File name for in memory database.
    • Constructor Detail

      • SqlJetDb

        public SqlJetDb​(java.io.File file,
                        boolean writable)

        Creates connection to database but not open it. Doesn't open database file until not called method SqlJetEngine.open().

        File could be null or have special value IN_MEMORY. If file is null then will be created temporary file which will be deleted at close. If file is IN_MEMORY then file doesn't created and instead database will placed in memory. If regular file is specified but doesn't exist then it will be tried to created.

        Parameters:
        file - path to data base. Could be null or IN_MEMORY.
        writable - if true then will allow data modification.
      • SqlJetDb

        public SqlJetDb​(java.io.File file,
                        boolean writable,
                        ISqlJetFileSystem fs)
    • Method Detail

      • open

        public static SqlJetDb open​(java.io.File file,
                                    boolean write)
                             throws SqlJetException

        Opens connection to data base. It does not create any locking on database. First lock will be created when be called any method which requires real access to options or schema.

        File could be null or have special value IN_MEMORY. If file is null then will be created temporary file which will be deleted at close. If file is IN_MEMORY then file doesn't created and instead database will placed in memory. If regular file is specified but doesn't exist then it will be tried to created.

        Parameters:
        file - path to data base. Could be null or IN_MEMORY.
        write - open for writing if true.
        Throws:
        SqlJetException - if any trouble with access to file or database format.
      • open

        public static SqlJetDb open​(java.io.File file,
                                    boolean write,
                                    java.lang.String fsName)
                             throws SqlJetException
        Parameters:
        file -
        write -
        fsName -
        Returns:
        SqlJetDb object for opened database
        Throws:
        SqlJetException
      • runWithLock

        public java.lang.Object runWithLock​(ISqlJetRunnableWithLock op)
                                     throws SqlJetException
        Do some actions with locking database's internal threads synchronization mutex. It is related only with synchronization of access to one connection from multiple threads. It is not related with transactions and locks of database file. For concurrent access to database from threads or processes use transactions.
        Parameters:
        op - operation to run
        Returns:
        result of the ISqlJetRunnableWithLock.runWithLock(SqlJetDb) call.
        Throws:
        SqlJetException - in case operation fails to run.
      • pragma

        public java.lang.Object pragma​(java.lang.String sql)
                                throws SqlJetException
        Executes pragma statement. If statement queries pragma value then pragma value will be returned.
        Throws:
        SqlJetException
      • createTable

        public ISqlJetTableDef createTable​(java.lang.String sql)
                                    throws SqlJetException
        Create table from SQL clause.
        Parameters:
        sql - CREATE TABLE ... sentence.
        Returns:
        definition of create table.
        Throws:
        SqlJetException
      • createIndex

        public ISqlJetIndexDef createIndex​(java.lang.String sql)
                                    throws SqlJetException
        Create index from SQL clause.
        Parameters:
        sql - CREATE INDEX ... sentence.
        Returns:
        definition of created index.
        Throws:
        SqlJetException
      • dropTable

        public void dropTable​(java.lang.String tableName)
                       throws SqlJetException
        Drop table.
        Parameters:
        tableName - name of table to drop.
        Throws:
        SqlJetException
      • dropIndex

        public void dropIndex​(java.lang.String indexName)
                       throws SqlJetException
        Drop index.
        Parameters:
        indexName - name of the index to drop.
        Throws:
        SqlJetException
      • dropView

        public void dropView​(java.lang.String viewName)
                      throws SqlJetException
        Drop view.
        Parameters:
        viewName - name of the view to drop.
        Throws:
        SqlJetException
      • dropTrigger

        public void dropTrigger​(java.lang.String triggerName)
                         throws SqlJetException
        Drop trigger.
        Parameters:
        triggerName - name of the trigger to drop.
        Throws:
        SqlJetException
      • createVirtualTable

        public ISqlJetVirtualTableDef createVirtualTable​(java.lang.String sql)
                                                  throws SqlJetException
        Creates virtual table from SQL clause.
        Parameters:
        sql - CREATE VIRTUAL TABLE ... sentence.
        Returns:
        definition of create virtual table.
        Throws:
        SqlJetException
      • createView

        public ISqlJetViewDef createView​(java.lang.String sql)
                                  throws SqlJetException
        Creates view from SQL clause.
        Parameters:
        sql - CREATE VIEW X AS SELECT ... sentence.
        Returns:
        definition of the view being created.
        Throws:
        SqlJetException
      • createTrigger

        public ISqlJetTriggerDef createTrigger​(java.lang.String sql)
                                        throws SqlJetException
        Creates trigger from SQL clause.
        Parameters:
        sql - CREATE TRIGGER ... sentence.
        Returns:
        definition of the trigger being created.
        Throws:
        SqlJetException
      • getTemporaryDatabase

        public SqlJetDb getTemporaryDatabase​(boolean inMemory)
                                      throws SqlJetException
        Opens temporary on-disk database which life span is less or equal to that of this object. Temporary database is closed and deleted as soon as this database connection is closed. Temporary file is used to store temporary database. Subsequent calls to this method will return the same temporary database In case previously create temporary database is closed by the user, then another one is created by this method.
        Parameters:
        inMemory - when true open temporary database in memory.
        Returns:
        temporary database being created or existing temporary database.
        Throws:
        SqlJetException