Search in sources :

Example 1 with ConnException

use of org.sqlite.ConnException in project sqlite-jna by gwenn.

the class Conn method setSavepoint.

@Override
public Savepoint setSavepoint(final String name) throws SQLException {
    final Savepoint savepoint = new Savepoint() {

        @Override
        public int getSavepointId() throws SQLException {
            throw new ConnException(c, "named savepoint", ErrCodes.WRAPPER_SPECIFIC);
        }

        @Override
        public String getSavepointName() {
            return name;
        }

        @Override
        public String toString() {
            return name;
        }
    };
    org.sqlite.parser.ast.Savepoint sp = new org.sqlite.parser.ast.Savepoint(name);
    getConn().fastExec(sp.toSql());
    return savepoint;
}
Also used : ConnException(org.sqlite.ConnException) Savepoint(java.sql.Savepoint)

Example 2 with ConnException

use of org.sqlite.ConnException in project sqlite-jna by gwenn.

the class Conn method rollback.

@Override
public void rollback() throws SQLException {
    final org.sqlite.Conn c = getConn();
    if (getAutoCommit())
        throw new ConnException(c, "database in auto-commit mode", ErrCodes.WRAPPER_SPECIFIC);
    c.fastExec("ROLLBACK; BEGIN");
}
Also used : ConnException(org.sqlite.ConnException)

Example 3 with ConnException

use of org.sqlite.ConnException in project sqlite-jna by gwenn.

the class Conn method commit.

@Override
public void commit() throws SQLException {
    final org.sqlite.Conn c = getConn();
    if (c.getAutoCommit())
        throw new ConnException(c, "database in auto-commit mode", ErrCodes.WRAPPER_SPECIFIC);
    c.fastExec("COMMIT; BEGIN");
}
Also used : ConnException(org.sqlite.ConnException)

Example 4 with ConnException

use of org.sqlite.ConnException in project sqlite-jna by gwenn.

the class Conn method setReadOnly.

@Override
public void setReadOnly(boolean readOnly) throws SQLException {
    checkOpen();
    final boolean ro = c.isReadOnly(null);
    final boolean qo = c.isQueryOnly(null);
    if (ro == readOnly && qo == readOnly) {
        return;
    }
    if (ro && !readOnly) {
        addWarning(new SQLWarning("readOnly mode cannot be reset"));
    } else {
        if (!c.getAutoCommit()) {
            throw new ConnException(c, "setReadOnly is called during a transaction", ErrCodes.WRAPPER_SPECIFIC);
        }
        c.setQueryOnly(null, readOnly);
    }
}
Also used : SQLWarning(java.sql.SQLWarning) ConnException(org.sqlite.ConnException)

Example 5 with ConnException

use of org.sqlite.ConnException in project sqlite-jna by gwenn.

the class Conn method setSavepoint.

// A SAVEPOINT can be started either within or outside of a BEGIN...COMMIT.
// When a SAVEPOINT is the outer-most savepoint and it is not within a BEGIN...COMMIT
// then the behavior is the same as BEGIN DEFERRED TRANSACTION.
@Override
public Savepoint setSavepoint() throws SQLException {
    final int id = savepointId++;
    final Savepoint savepoint = new Savepoint() {

        @Override
        public int getSavepointId() {
            return id;
        }

        @Override
        public String getSavepointName() throws SQLException {
            throw new ConnException(c, "un-named savepoint", ErrCodes.WRAPPER_SPECIFIC);
        }

        @Override
        public String toString() {
            return String.valueOf(id);
        }
    };
    // SAVEPOINT 1; fails
    getConn().fastExec("SAVEPOINT \"" + id + '"');
    return savepoint;
}
Also used : ConnException(org.sqlite.ConnException) Savepoint(java.sql.Savepoint) Savepoint(java.sql.Savepoint)

Aggregations

ConnException (org.sqlite.ConnException)5 Savepoint (java.sql.Savepoint)2 SQLWarning (java.sql.SQLWarning)1