FileDocCategorySizeDatePackage
JDBCStatement.javaAPI DocAndroid 1.5 API7250Wed May 06 22:41:06 BST 2009SQLite.JDBC2y

JDBCStatement

public class JDBCStatement extends Object implements Statement

Fields Summary
protected JDBCConnection
conn
protected JDBCResultSet
rs
protected int
updcnt
private ArrayList
batch
Constructors Summary
public JDBCStatement(JDBCConnection conn)

    this.conn = conn;
    this.updcnt = 0;
    this.rs = null;
    this.batch = null;    
    
Methods Summary
public voidaddBatch(java.lang.String sql)

    if (batch == null) {
        batch = new ArrayList<String>(1);
    }
    batch.add(sql);
    
public voidcancel()

    if (conn == null || conn.db == null) {
        throw new SQLException("stale connection");
    }
    conn.db.interrupt();
    
public voidclearBatch()

    if (batch != null) {
        batch.clear();
        batch = null;
    }
    
public voidclearWarnings()

    
public voidclose()

    clearBatch();
    conn = null;
    
public booleanexecute(java.lang.String sql)

    return executeQuery(sql) != null;
    
public booleanexecute(java.lang.String sql, int autokeys)

    if (autokeys != Statement.NO_GENERATED_KEYS) {
        throw new SQLException("not supported");
    }
    return execute(sql);
    
public booleanexecute(java.lang.String sql, int[] colIndexes)

    throw new SQLException("not supported");
    
public booleanexecute(java.lang.String sql, java.lang.String[] colIndexes)

    throw new SQLException("not supported");
    
public int[]executeBatch()

    if (batch == null) {
        return new int[0];
    }
    int[] ret = new int[batch.size()];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = EXECUTE_FAILED;
    }
    int errs = 0;
    for (int i = 0; i < ret.length; i++) {
        try {
        execute((String) batch.get(i));
        ret[i] = updcnt;
        } catch (SQLException e) {
        ++errs;
        }
    }
    if (errs > 0) {
        throw new BatchUpdateException("batch failed", ret);
    }
    return ret;
    
java.sql.ResultSetexecuteQuery(java.lang.String sql, java.lang.String[] args, boolean updonly)

    SQLite.TableResult tr = null;
    if (rs != null) {
        rs.close();
        rs = null;
    }
    updcnt = -1;
    if (conn == null || conn.db == null) {
        throw new SQLException("stale connection");
    }
    int busy = 0;
    boolean starttrans = !conn.autocommit && !conn.intrans;
    while (true) {
        try {
        if (starttrans) {
            conn.db.exec("BEGIN TRANSACTION", null);
            conn.intrans = true;
        }
        if (args == null) {
            if (updonly) {
            conn.db.exec(sql, null);
            } else {
            tr = conn.db.get_table(sql);
            }
        } else {
            if (updonly) {
            conn.db.exec(sql, null, args);
            } else {
            tr = conn.db.get_table(sql, args);
            }
        }
        updcnt = (int) conn.db.changes();
        } catch (SQLite.Exception e) {
        if (conn.db.is3() &&
            conn.db.last_error() == SQLite.Constants.SQLITE_BUSY &&
            conn.busy3(conn.db, ++busy)) {
            try {
            if (starttrans && conn.intrans) {
                conn.db.exec("ROLLBACK", null);
                conn.intrans = false;
            }
            } catch (SQLite.Exception ee) {
            }
            try {
            int ms = 20 + busy * 10;
            if (ms > 1000) {
                ms = 1000;
            }
            synchronized (this) {
                this.wait(ms);
            }
            } catch (java.lang.Exception eee) {
            }
            continue;
        }
        throw new SQLException(e.toString());
        }
        break;
    }
    if (!updonly && tr == null) {
        throw new SQLException("no result set produced");
    }
    if (!updonly && tr != null) {
        rs = new JDBCResultSet(new TableResultX(tr), this);
    }
    return rs;
    
public java.sql.ResultSetexecuteQuery(java.lang.String sql)

    return executeQuery(sql, null, false);
    
public intexecuteUpdate(java.lang.String sql)

    executeQuery(sql, null, true);
    return updcnt;
    
public intexecuteUpdate(java.lang.String sql, int autokeys)

    if (autokeys != Statement.NO_GENERATED_KEYS) {
        throw new SQLException("not supported");
    }
    return executeUpdate(sql);
    
public intexecuteUpdate(java.lang.String sql, int[] colIndexes)

    throw new SQLException("not supported");
    
public intexecuteUpdate(java.lang.String sql, java.lang.String[] colIndexes)

    throw new SQLException("not supported");
    
public java.sql.ConnectiongetConnection()

    return conn;
    
public intgetFetchDirection()

    return ResultSet.FETCH_UNKNOWN;
    
public intgetFetchSize()

    return 1;
    
public java.sql.ResultSetgetGeneratedKeys()

    throw new SQLException("not supported");
    
public intgetMaxFieldSize()

    return 0;
    
public intgetMaxRows()

    return 0;
    
public booleangetMoreResults()

    if (rs != null) {
        rs.close();
        rs = null;
    }
    return false;
    
public booleangetMoreResults(int x)

    throw new SQLException("not supported");
    
public intgetQueryTimeout()

    return conn.timeout;
    
public java.sql.ResultSetgetResultSet()

    return rs;
    
public intgetResultSetConcurrency()

    return ResultSet.CONCUR_READ_ONLY;
    
public intgetResultSetHoldability()

    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
    
public intgetResultSetType()

    return ResultSet.TYPE_SCROLL_INSENSITIVE;
    
public intgetUpdateCount()

    return updcnt;
    
public java.sql.SQLWarninggetWarnings()

    return null;
    
public voidsetCursorName(java.lang.String name)

    throw new SQLException("not supported");
    
public voidsetEscapeProcessing(boolean enable)

    throw new SQLException("not supported");
    
public voidsetFetchDirection(int fetchDirection)

    throw new SQLException("not supported");
    
public voidsetFetchSize(int fetchSize)

    throw new SQLException("not supported");
    
public voidsetMaxFieldSize(int max)

    throw new SQLException("not supported");
    
public voidsetMaxRows(int max)

    throw new SQLException("not supported");
    
public voidsetQueryTimeout(int seconds)

    conn.timeout = seconds * 1000;
    if (conn.timeout < 0) {
        conn.timeout = 120000;
    } else if (conn.timeout < 1000) {
        conn.timeout = 5000;
    }