List of usage examples for android.database.sqlite SQLiteException getMessage
public String getMessage()
From source file:com.demo.android.smsapp.activities.SMSChatActivity.java
private void getChatWithNumber() { try {/*w w w . j a v a2 s . c o m*/ Uri uri = Uri.parse("content://sms/"); String[] columns = new String[] { "_id", "address", "person", "date", "body", "type" }; Cursor cursor = getContentResolver().query(uri, columns, "address='" + number + "'", null, "date asc"); cursor.moveToFirst(); Log.e("total:", cursor.getCount() + ""); String id, address, body, person, type, date; for (int i = 0; i < cursor.getCount(); i++) { address = cursor.getString(cursor.getColumnIndex("address")); body = cursor.getString(cursor.getColumnIndexOrThrow("body")); person = cursor.getString(cursor.getColumnIndex("person")); type = cursor.getString(cursor.getColumnIndex("type")); date = cursor.getString(cursor.getColumnIndexOrThrow("date")); id = cursor.getString(cursor.getColumnIndexOrThrow("_id")); smsModels.add(SMSModel.getSMSModelObject(id, address, body, type, date)); Log.e("readSMS", "Number:" + address + ",Person:" + person + ",Message: " + body + ",type:" + type + ",date:" + date + ",id:" + id); cursor.moveToNext(); } } catch (SQLiteException ex) { Log.e("SQLiteException", ex.getMessage()); } }
From source file:com.phonegap.Storage.java
/** * Execute SQL statement.// w w w.j av a 2 s . c o m * * @param query The SQL query * @param params Parameters for the query * @param tx_id Transaction id */ public void executeSql(String query, String[] params, String tx_id) { try { Cursor myCursor = this.myDb.rawQuery(query, params); this.processResults(myCursor, tx_id); myCursor.close(); } catch (SQLiteException ex) { ex.printStackTrace(); System.out.println("Storage.executeSql(): Error=" + ex.getMessage()); // Send error message back to JavaScript this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','" + tx_id + "');"); } }
From source file:com.polyvi.xface.extension.XStorageExt.java
/** * SQL?.//from www . j av a2 s. com * * @param query * SQL? * @param params * SQL?? * @param tx_id * id * @param callbackCtx * */ private void executeSql(String query, String[] params, String tx_id, XCallbackContext callbackCtx) { try { if (isDDL(query)) { mMyDb.execSQL(query); String jsScript = "xFace.require('xFace/extension/android/storage').completeQuery('" + tx_id + "', '');"; mWebContext.getApplication().loadJavascript(jsScript); } else { Cursor myCursor = mMyDb.rawQuery(query, params); processResults(myCursor, tx_id, callbackCtx); myCursor.close(); } } catch (SQLiteException ex) { XLog.e(CLASS_NAME, "Storage.executeSql(): Error=" + ex.getMessage()); String jsScript = "xFace.require('xFace/extension/android/storage').failQuery('" + ex.getMessage() + "','" + tx_id + "');"; callbackCtx.sendExtensionResult(jsScript); } }
From source file:org.apache.cordova.legacywebsql.LegacyWebSql.java
/** * Execute SQL statement.//from ww w. jav a 2s. c om * * @param query * The SQL query * @param params * Parameters for the query * @param tx_id * Transaction id */ public void executeSql(String query, String[] params, String tx_id) { try { if (isDDL(query)) { this.myDb.execSQL(query); this.webView.sendJavascript( "cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');"); } else { Cursor myCursor = this.myDb.rawQuery(query, params); this.processResults(myCursor, tx_id); myCursor.close(); } } catch (SQLiteException ex) { ex.printStackTrace(); System.out.println("Storage.executeSql(): Error=" + ex.getMessage()); // Send error message back to JavaScript this.webView.sendJavascript("cordova.require('cordova/plugin/android/storage').failQuery('" + ex.getMessage() + "','" + tx_id + "');"); } }
From source file:org.skt.runtime.original.Storage.java
/** * Execute SQL statement./*from w w w.j a v a2 s .co m*/ * * @param query * The SQL query * @param params * Parameters for the query * @param tx_id * Transaction id */ public void executeSql(String query, String[] params, String tx_id) { try { if (isDDL(query)) { this.myDb.execSQL(query); this.sendJavascript( "srt.sktrequire('srt/plugin/android/storage').completeQuery('" + tx_id + "', '');"); } else { Cursor myCursor = this.myDb.rawQuery(query, params); this.processResults(myCursor, tx_id); myCursor.close(); } } catch (SQLiteException ex) { ex.printStackTrace(); System.out.println("Storage.executeSql(): Error=" + ex.getMessage()); // Send error message back to JavaScript this.sendJavascript("srt.sktrequire('srt/plugin/android/storage').failQuery('" + ex.getMessage() + "','" + tx_id + "');"); } }
From source file:com.facebook.stetho.inspector.protocol.module.Database.java
@ChromeDevtoolsMethod public JsonRpcResult executeSQL(JsonRpcPeer peer, JSONObject params) { ExecuteSQLRequest request = mObjectMapper.convertValue(params, ExecuteSQLRequest.class); try {/*from w ww . j a va 2s . co m*/ return mDatabasePeerManager.executeSQL(request.databaseId, request.query, new DatabasePeerManager.ExecuteResultHandler<ExecuteSQLResponse>() { @Override public ExecuteSQLResponse handleRawQuery() throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); // This is done because the inspector UI likes to delete rows if you give them no // name/value list response.columnNames = Arrays.asList("success"); response.values = Arrays.asList((Object) "true"); return response; } @Override public ExecuteSQLResponse handleSelect(Cursor result) throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); response.columnNames = Arrays.asList(result.getColumnNames()); response.values = flattenRows(result, MAX_EXECUTE_RESULTS); return response; } @Override public ExecuteSQLResponse handleInsert(long insertedId) throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); response.columnNames = Arrays.asList("ID of last inserted row"); response.values = Arrays.asList((Object) insertedId); return response; } @Override public ExecuteSQLResponse handleUpdateDelete(int count) throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); response.columnNames = Arrays.asList("Modified rows"); response.values = Arrays.asList((Object) count); return response; } }); } catch (SQLiteException e) { Error error = new Error(); error.code = 0; error.message = e.getMessage(); ExecuteSQLResponse response = new ExecuteSQLResponse(); response.sqlError = error; return response; } }
From source file:com.phonegap.plugin.sqlitePlugin.SQLitePlugin.java
/** * Execute SQL statement.//from w w w . j a va2 s . co m * * @param query * The SQL query * @param params * Parameters for the query * @param tx_id * Transaction id */ public void executeSql(String query, String[] params, String tx_id) { String cmd = query.toLowerCase(); try { if (cmd.startsWith("insert")) { SQLiteStatement myStatement = this.myDb.compileStatement(query); long insertId = myStatement.executeInsert(); this.sendJavascript("dddb.completeQuery('" + tx_id + "', [{'insertId':'" + insertId + "', 'rowsAffected':'1'}]);"); /* Test fix for #22, requires API 11+: ** } else if (cmd.startsWith("update") || cmd.startsWith("delete")) { SQLiteStatement myStatement = this.myDb.compileStatement(query); int rowsAffected = myStatement.executeUpdateDelete(); this.sendJavascript("dddb.completeQuery('" + tx_id + "', [{'rowsAffected':'" + rowsAffected + "'}]);"); * END of Test fix for #22, requires API 11+ */ } else if (isDDL(query)) { this.myDb.execSQL(query); this.sendJavascript("dddb.completeQuery('" + tx_id + "', '');"); } else { Cursor myCursor = this.myDb.rawQuery(query, params); this.processResults(myCursor, tx_id); myCursor.close(); } } catch (SQLiteException ex) { ex.printStackTrace(); System.out.println("SQLitePlugin.executeSql(): Error=" + ex.getMessage()); // Send error message back to JavaScript this.sendJavascript("dddb.fail('" + ex.getMessage() + "','" + tx_id + "');"); } }
From source file:com.phonegap.plugins.sqlitePlugin.SQLitePlugin.java
public void executeSqlBatch(String[] queryarr, String[][] paramsarr, String[] queryIDs, String tx_id) { try {//from w w w. j a v a 2s. c o m this.myDb.beginTransaction(); String query = ""; String query_id = ""; String[] params; int len = queryarr.length; for (int i = 0; i < len; i++) { query = queryarr[i]; params = paramsarr[i]; query_id = queryIDs[i]; Cursor myCursor = this.myDb.rawQuery(query, params); this.processResults(myCursor, query_id, tx_id); myCursor.close(); } this.myDb.setTransactionSuccessful(); } catch (SQLiteException ex) { ex.printStackTrace(); Log.v("executeSqlBatch", "SQLitePlugin.executeSql(): Error=" + ex.getMessage()); this.sendJavascript( "SQLitePluginTransaction.txErrorCallback('" + tx_id + "', '" + ex.getMessage() + "');"); } finally { this.myDb.endTransaction(); Log.v("executeSqlBatch", tx_id); this.sendJavascript("SQLitePluginTransaction.txCompleteCallback('" + tx_id + "');"); } }
From source file:com.taobao.weex.devtools.inspector.protocol.module.Database.java
@ChromeDevtoolsMethod public JsonRpcResult executeSQL(JsonRpcPeer peer, JSONObject params) { ExecuteSQLRequest request = mObjectMapper.convertValue(params, ExecuteSQLRequest.class); String databaseId = request.databaseId; String query = request.query; DatabaseDriver databaseDriver = getDatabasePeer(databaseId); try {//from www .java2 s . co m return databaseDriver.executeSQL(request.databaseId, request.query, new DatabaseDriver.ExecuteResultHandler<ExecuteSQLResponse>() { @Override public ExecuteSQLResponse handleRawQuery() throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); // This is done because the inspector UI likes to delete rows if you give them no // name/value list response.columnNames = Collections.singletonList("success"); response.values = Collections.singletonList("true"); return response; } @Override public ExecuteSQLResponse handleSelect(Cursor result) throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); response.columnNames = Arrays.asList(result.getColumnNames()); response.values = flattenRows(result, MAX_EXECUTE_RESULTS); return response; } @Override public ExecuteSQLResponse handleInsert(long insertedId) throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); response.columnNames = Collections.singletonList("ID of last inserted row"); response.values = Collections.singletonList(String.valueOf(insertedId)); return response; } @Override public ExecuteSQLResponse handleUpdateDelete(int count) throws SQLiteException { ExecuteSQLResponse response = new ExecuteSQLResponse(); response.columnNames = Collections.singletonList("Modified rows"); response.values = Collections.singletonList(String.valueOf(count)); return response; } }); } catch (SQLiteException e) { Error error = new Error(); error.code = 0; error.message = e.getMessage(); ExecuteSQLResponse response = new ExecuteSQLResponse(); response.sqlError = error; return response; } }
From source file:com.digicorp.plugin.sqlitePlugin.SQLitePlugin.java
/** * Executes a batch request and sends the results via sendJavascriptCB(). * * @param dbname/*from w ww.ja v a 2s . c o m*/ * The name of the database. * * @param queryarr * Array of query strings * * @param jsonparams * Array of JSON query parameters * * @param queryIDs * Array of query ids * * @param tx_id * Transaction id * */ private void executeSqlBatch(String dbname, String[] queryarr, JSONArray[] jsonparams, String[] queryIDs, String tx_id) { SQLiteDatabase mydb = this.getDatabase(dbname); if (mydb == null) return; try { mydb.beginTransaction(); String query = ""; String query_id = ""; int len = queryarr.length; for (int i = 0; i < len; i++) { query = queryarr[i]; query_id = queryIDs[i]; if (query.toLowerCase().startsWith("insert") && jsonparams != null) { SQLiteStatement myStatement = mydb.compileStatement(query); for (int j = 0; j < jsonparams[i].length(); j++) { if (jsonparams[i].get(j) instanceof Float || jsonparams[i].get(j) instanceof Double) { myStatement.bindDouble(j + 1, jsonparams[i].getDouble(j)); } else if (jsonparams[i].get(j) instanceof Number) { myStatement.bindLong(j + 1, jsonparams[i].getLong(j)); } else if (jsonparams[i].isNull(j)) { myStatement.bindNull(j + 1); } else { myStatement.bindString(j + 1, jsonparams[i].getString(j)); } } long insertId = myStatement.executeInsert(); String result = "{'insertId':'" + insertId + "'}"; this.sendJavascriptCB("window.SQLitePluginTransactionCB.queryCompleteCallback('" + tx_id + "','" + query_id + "', " + result + ");"); } else { String[] params = null; if (jsonparams != null) { params = new String[jsonparams[i].length()]; for (int j = 0; j < jsonparams[i].length(); j++) { if (jsonparams[i].isNull(j)) params[j] = ""; else params[j] = jsonparams[i].getString(j); } } Cursor myCursor = mydb.rawQuery(query, params); if (query_id.length() > 0) this.processResults(myCursor, query_id, tx_id); myCursor.close(); } } mydb.setTransactionSuccessful(); } catch (SQLiteException ex) { ex.printStackTrace(); Log.v("executeSqlBatch", "SQLitePlugin.executeSql(): Error=" + ex.getMessage()); this.sendJavascriptCB("window.SQLitePluginTransactionCB.txErrorCallback('" + tx_id + "', '" + ex.getMessage() + "');"); } catch (JSONException ex) { ex.printStackTrace(); Log.v("executeSqlBatch", "SQLitePlugin.executeSql(): Error=" + ex.getMessage()); this.sendJavascriptCB("window.SQLitePluginTransactionCB.txErrorCallback('" + tx_id + "', '" + ex.getMessage() + "');"); } finally { mydb.endTransaction(); Log.v("executeSqlBatch", tx_id); this.sendJavascriptCB("window.SQLitePluginTransactionCB.txCompleteCallback('" + tx_id + "');"); } }