List of usage examples for android.database SQLException SQLException
public SQLException()
From source file:com.futureplatforms.kirin.test.DatabasesBackendTest_inactive.java
protected void setUp() throws Exception { mOpeningConfig = new JSONObject(); mOpeningConfig.put("filename", ":memory:"); mOpeningConfig.put("version", 1); txId = "tx." + mTxCounter; mTxCounter++;// w w w .j a v a 2 s.c o m mOpeningConfig.put("txId", txId); mOpeningConfig.put("onCreateToken", "onCreate"); mOpeningConfig.put("onUpdateToken", "onUpdate"); mOpeningConfig.put("onOpenedToken", "onOpened"); mOpeningConfig.put("onErrorToken", "onError"); /* * backend.beginTransaction_({ dbName: (string) databaseName, txId: * (string) transactionId, onSuccessToken: (string) * transaction_onSuccess_token, onErrorToken: (string) * transaction_onError_token, readOnly: (bool) readOnly }); */ mTransactionConfig = new JSONObject(); mTransactionConfig.put("dbName", "testDatabase"); mTransactionConfig.put("txId", txId); mResults = new Object[][] { new Object[] { 1, 2, 3 }, new Object[] { 4, 5, 6 } }; mKirinHelper = new DummyKirinHelper(); mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); mExecutedSQL = new ArrayList<String>(); mOpenTransactions = 0; mBackend = new DatabasesBackend(getContext(), mPrefs, mKirinHelper, null, null) { @Override protected void beginNativeTransaction(SQLiteDatabase db) { mOpenTransactions++; } @Override protected void endNativeTransaction(SQLiteDatabase db) { mOpenTransactions--; } @Override protected void setNativeTransactionSuccessful(SQLiteDatabase db) { // NOP. } @Override protected Cursor rawQuery(SQLiteDatabase db, String sql, String[] params) { mExecutedSQL.add(sql); if (sql.contains("ERROR")) { throw new SQLException(); } mCursor = new MatrixCursor(new String[] { "foo", "bar", "baz" }); for (Object[] row : mResults) { mCursor.addRow(row); } return mCursor; } @Override protected void execSQL(SQLiteDatabase db, String sql, Object[] params) { mExecutedSQL.add(sql); if (sql.contains("ERROR")) { throw new SQLException(); } } }; }
From source file:com.futureplatforms.kirin.extensions.databases.DatabasesBackend.java
protected Cursor execStatement(SQLiteDatabase db, DBStatement s) { if (s.mType == StatementType.file) { // TODO make this work a KirinFileSystem. String filename = "generated-javascript" + s.mSql; //;mJS.getPathToJavascriptDir() + s.mSql; try {// ww w. j ava 2s.c om String block = IOUtils.loadTextAsset(mContext, filename); String[] lines = block.split("\\s*;\\s*"); Object[] args = new Object[0]; for (String line : lines) { execSQL(db, line, args); } return null; } catch (IOException e) { Log.e(C.TAG, "Problem loading assets file: " + filename, e); throw new SQLException(); } } else if (s.mOnSuccess == null) { execSQL(db, s.mSql, s.mParams); return null; } else { return rawQuery(db, s.mSql, s.mParams); } }