Class CoreStatement

  • All Implemented Interfaces:
    Codes
    Direct Known Subclasses:
    JDBC3Statement

    public abstract class CoreStatement
    extends java.lang.Object
    implements Codes
    • Field Detail

      • sql

        protected java.lang.String sql
      • batchPos

        protected int batchPos
      • batch

        protected java.lang.Object[] batch
      • resultsWaiting

        protected boolean resultsWaiting
      • generatedKeysStat

        private java.sql.Statement generatedKeysStat
      • generatedKeysRs

        private java.sql.ResultSet generatedKeysRs
      • INSERT_PATTERN

        private static final java.util.regex.Pattern INSERT_PATTERN
    • Method Detail

      • getDatabase

        public DB getDatabase()
      • checkOpen

        protected final void checkOpen()
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException - If the database is not opened.
      • isOpen

        boolean isOpen()
                throws java.sql.SQLException
        Returns:
        True if the database is opened; false otherwise.
        Throws:
        java.sql.SQLException
      • exec

        protected boolean exec()
                        throws java.sql.SQLException
        Calls sqlite3_step() and sets up results. Expects a clean stmt.
        Returns:
        True if the ResultSet has at least one row; false otherwise.
        Throws:
        java.sql.SQLException - If the given SQL statement is null or no database is open.
      • exec

        protected boolean exec​(java.lang.String sql)
                        throws java.sql.SQLException
        Executes SQL statement and throws SQLExceptions if the given SQL statement is null or no database is open.
        Parameters:
        sql - SQL statement.
        Returns:
        True if the ResultSet has at least one row; false otherwise.
        Throws:
        java.sql.SQLException - If the given SQL statement is null or no database is open.
      • internalClose

        protected void internalClose()
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • notifyFirstStatementExecuted

        protected void notifyFirstStatementExecuted()
      • executeQuery

        public abstract java.sql.ResultSet executeQuery​(java.lang.String sql,
                                                        boolean closeStmt)
                                                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • checkIndex

        protected void checkIndex​(int index)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • clearGeneratedKeys

        protected void clearGeneratedKeys()
                                   throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • updateGeneratedKeys

        public void updateGeneratedKeys()
                                 throws java.sql.SQLException
        SQLite's last_insert_rowid() function is DB-specific. However, in this implementation we ensure the Generated Key result set is statement-specific by executing the query immediately after an insert operation is performed. The caller is simply responsible for calling updateGeneratedKeys on the statement object right after execute in a synchronized(connection) block.
        Throws:
        java.sql.SQLException
      • getGeneratedKeys

        public java.sql.ResultSet getGeneratedKeys()
                                            throws java.sql.SQLException
        This implementation uses SQLite's last_insert_rowid function to obtain the row ID. It cannot provide multiple values when inserting multiple rows. Suggestion is to use a RETURNING clause instead.
        Throws:
        java.sql.SQLException
        See Also:
        Statement.getGeneratedKeys()