Code example for SQLiteStatement

Methods: bindLong, clearBindings, close, execute

0
        mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL);");
        SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
 
        // Try to insert NULL, which violates the constraint 
        try { 
            statement.clearBindings();
            statement.execute();
            fail("expected exception not thrown");
        } catch (SQLiteConstraintException e) {
            // expected 
        } 
 
        // Make sure the statement can still be used 
        statement.bindLong(1, 1);
        statement.execute();
        statement.close();
 
        Cursor c = mDatabase.query("test", null, null, null, null, null, null);
        int numCol = c.getColumnIndexOrThrow("num");
        c.moveToFirst();
        long num = c.getLong(numCol);