Java Code Examples for com.facebook.react.bridge.ReadableArray#isNull()
The following examples show how to use
com.facebook.react.bridge.ReadableArray#isNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLiteAndroidDatabase.java From react-native-sqlite-storage with MIT License | 6 votes |
private void bindArgsToStatement(SQLiteStatement myStatement, ReadableArray sqlArgs) { if (sqlArgs == null) return; for (int i = 0; i < sqlArgs.size(); i++) { ReadableType type = sqlArgs.getType(i); if (type == ReadableType.Number) { double tmp = sqlArgs.getDouble(i); if (tmp == (long) tmp) { myStatement.bindLong(i + 1, (long) tmp); } else { myStatement.bindDouble(i + 1, tmp); } } else if (sqlArgs.isNull(i)) { myStatement.bindNull(i + 1); } else { myStatement.bindString(i + 1, sqlArgs.getString(i)); } } }
Example 2
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 6 votes |
private void bindArgsToStatement(SQLiteStatement myStatement, ReadableArray sqlArgs) { for (int i = 0; i < sqlArgs.size(); i++) { ReadableType type = sqlArgs.getType(i); if (type == ReadableType.Number){ double tmp = sqlArgs.getDouble(i); if (tmp == (long) tmp) { myStatement.bindLong(i + 1, (long) tmp); } else { myStatement.bindDouble(i + 1, tmp); } } else if (sqlArgs.isNull(i)) { myStatement.bindNull(i + 1); } else { myStatement.bindString(i + 1, SQLitePluginConverter.getString(sqlArgs,i,"")); } } }
Example 3
Source File: ChartBaseManager.java From react-native-mp-android-chart with MIT License | 5 votes |
ArrayList<U> createEntries(ReadableArray yValues) { ArrayList<U> entries = new ArrayList<>(yValues.size()); for (int j = 0; j < yValues.size(); j++) { if (!yValues.isNull(j)) { entries.add(createEntry(yValues, j)); } } return entries; }
Example 4
Source File: BottomSheetBehaviorManager.java From react-native-bottom-sheet-behavior with MIT License | 4 votes |
private void setBottomSheetState(BottomSheetBehaviorView view, @Nullable ReadableArray args) { if (!args.isNull(0)) { int newState = args.getInt(0); setState(view, newState); } }
Example 5
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 4 votes |
private boolean executeAndPossiblyThrow(Action action, ReadableMap args, CallbackContext cbc){ String dbname; switch (action) { case echoStringValue: String echo_value = SQLitePluginConverter.getString(args,"value",""); cbc.success(echo_value); break; case open: dbname = SQLitePluginConverter.getString(args,"name",""); // open database and start reading its queue this.startDatabase(dbname, args, cbc); break; case close: dbname = SQLitePluginConverter.getString(args,"path",""); // put request in the q to close the db this.closeDatabase(dbname, cbc); break; case attach: dbname = SQLitePluginConverter.getString(args,"path",""); String dbAlias = SQLitePluginConverter.getString(args,"dbAlias",""); String dbNameToAttach = SQLitePluginConverter.getString(args,"dbName",""); this.attachDatabase(dbname,dbNameToAttach,dbAlias,cbc); break; case delete: dbname = SQLitePluginConverter.getString(args,"path",""); deleteDatabase(dbname, cbc); break; case executeSqlBatch: case backgroundExecuteSqlBatch: String [] queries; String [] queryIDs = null; ReadableArray[] queryParams = null; ReadableMap dbArgs = (ReadableMap) SQLitePluginConverter.get(args,"dbargs",null); dbname = SQLitePluginConverter.getString(dbArgs,"dbname",""); ReadableArray txArgs = (ReadableArray) SQLitePluginConverter.get(args,"executes",null); if (txArgs.isNull(0)) { queries = new String[0]; } else { int len = txArgs.size(); queries = new String[len]; queryIDs = new String[len]; queryParams = new ReadableArray[len]; for (int i = 0; i < len; i++) { ReadableMap queryArgs = (ReadableMap) SQLitePluginConverter.get(txArgs,i,null); queries[i] = SQLitePluginConverter.getString(queryArgs,"sql",""); queryIDs[i] = SQLitePluginConverter.getString(queryArgs,"qid",""); queryParams[i] = (ReadableArray) SQLitePluginConverter.get(queryArgs,"params",null); } } // put db query in the queue to be executed in the db thread: DBQuery q = new DBQuery(queries, queryIDs, queryParams, cbc); DBRunner r = dbrmap.get(dbname); if (r != null) { try { r.q.put(q); } catch(Exception ex) { FLog.e(TAG, "couldn't add to queue", ex); cbc.error("couldn't add to queue"); } } else { cbc.error("database not open"); } break; } return true; }
Example 6
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 4 votes |
/** * Get rows results from query cursor. * * @return results in string form */ private WritableMap executeSqlStatementNDK(String query, ReadableArray queryArgs, CallbackContext cbc) throws Exception { WritableMap rowsResult = Arguments.createMap(); boolean hasRows; SQLiteStatement myStatement = null; try { try { myStatement = mydb.prepareStatement(query); if (queryArgs != null) { for (int i = 0; i < queryArgs.size(); ++i) { ReadableType type = queryArgs.getType(i); if (type == ReadableType.Number){ double tmp = queryArgs.getDouble(i); if (tmp == (long) tmp) { myStatement.bindLong(i + 1, (long) tmp); } else { myStatement.bindDouble(i + 1, tmp); } } else if (queryArgs.isNull(i)) { myStatement.bindNull(i + 1); } else { myStatement.bindTextNativeString(i + 1, SQLitePluginConverter.getString(queryArgs,i,"")); } } } hasRows = myStatement.step(); } catch (Exception ex) { FLog.e(TAG, "SQLitePlugin.executeSql[Batch]() failed", ex); throw ex; } // If query result has rows if (hasRows) { WritableArray rowsArrayResult = Arguments.createArray(); String key; int colCount = myStatement.getColumnCount(); // Build up JSON result object for each row do { WritableMap row = Arguments.createMap(); for (int i = 0; i < colCount; ++i) { key = myStatement.getColumnName(i); switch (myStatement.getColumnType(i)) { case SQLColumnType.NULL: row.putNull(key); break; case SQLColumnType.REAL: row.putDouble(key, myStatement.getColumnDouble(i)); break; case SQLColumnType.INTEGER: row.putDouble(key, myStatement.getColumnLong(i)); break; case SQLColumnType.BLOB: case SQLColumnType.TEXT: default: row.putString(key, myStatement.getColumnTextNativeString(i)); } } rowsArrayResult.pushMap(row); } while (myStatement.step()); rowsResult.putArray("rows", rowsArrayResult); } } finally { if (myStatement != null) { myStatement.dispose(); } } return rowsResult; }
Example 7
Source File: SQLiteAndroidDatabase.java From react-native-sqlite-storage with MIT License | 4 votes |
/** * Get rows results from query cursor. * * @return results in string form */ private WritableMap executeSqlStatementQuery(SQLiteDatabase mydb, String query, ReadableArray queryParams, CallbackContext cbc) throws Exception { WritableMap rowsResult = Arguments.createMap(); Cursor cur; try { String[] params = new String[0]; if (queryParams != null) { int size = queryParams.size(); params = new String[size]; for (int j = 0; j < size; j++) { if (queryParams.isNull(j)) params[j] = ""; else params[j] = queryParams.getString(j); } } cur = mydb.rawQuery(query, params); } catch (Exception ex) { FLog.e(SQLitePlugin.TAG, "SQLiteAndroidDatabase.executeSql[Batch]() failed", ex); throw ex; } // If query result has rows if (cur != null && cur.moveToFirst()) { WritableArray rowsArrayResult = Arguments.createArray(); String key = ""; int colCount = cur.getColumnCount(); // Build up JSON result object for each row do { WritableMap row = Arguments.createMap(); for (int i = 0; i < colCount; ++i) { key = cur.getColumnName(i); bindRow(row, key, cur, i); } rowsArrayResult.pushMap(row); } while (cur.moveToNext()); rowsResult.putArray("rows", rowsArrayResult); } if (cur != null) { cur.close(); } return rowsResult; }
Example 8
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 4 votes |
private boolean executeAndPossiblyThrow(Action action, ReadableMap args, CallbackContext cbc){ String dbname; switch (action) { case echoStringValue: String echo_value = SQLitePluginConverter.getString(args,"value",""); cbc.success(echo_value); break; case open: dbname = SQLitePluginConverter.getString(args,"name",""); // open database and start reading its queue this.startDatabase(dbname, args, cbc); break; case close: dbname = SQLitePluginConverter.getString(args,"path",""); // put request in the q to close the db this.closeDatabase(dbname, cbc); break; case attach: dbname = SQLitePluginConverter.getString(args,"path",""); String dbAlias = SQLitePluginConverter.getString(args,"dbAlias",""); String dbNameToAttach = SQLitePluginConverter.getString(args,"dbName",""); this.attachDatabase(dbname,dbNameToAttach,dbAlias,cbc); break; case delete: dbname = SQLitePluginConverter.getString(args,"path",""); deleteDatabase(dbname, cbc); break; case executeSqlBatch: case backgroundExecuteSqlBatch: String [] queries; String [] queryIDs = null; ReadableArray [] queryParams = null; ReadableMap dbArgs = (ReadableMap) SQLitePluginConverter.get(args,"dbargs",null); dbname = SQLitePluginConverter.getString(dbArgs,"dbname",""); ReadableArray txArgs = (ReadableArray) SQLitePluginConverter.get(args,"executes",null); if (txArgs.isNull(0)) { queries = new String[0]; } else { int len = txArgs.size(); queries = new String[len]; queryIDs = new String[len]; queryParams = new ReadableArray[len]; for (int i = 0; i < len; i++) { ReadableMap queryArgs = (ReadableMap) SQLitePluginConverter.get(txArgs,i,null); queries[i] = SQLitePluginConverter.getString(queryArgs,"sql",""); queryIDs[i] = SQLitePluginConverter.getString(queryArgs,"qid",""); queryParams[i] = (ReadableArray) SQLitePluginConverter.get(queryArgs,"params",null); } } // put db query in the queue to be executed in the db thread: DBQuery q = new DBQuery(queries, queryIDs, queryParams, cbc); DBRunner r = dbrmap.get(dbname); if (r != null) { try { r.q.put(q); } catch(Exception ex) { FLog.e(TAG, "couldn't add to queue", ex); cbc.error("couldn't add to queue"); } } else { cbc.error("database not open"); } break; } return true; }
Example 9
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 4 votes |
/** * Execute Sql Statement Query * * @param mydb - database * @param query - SQL query to execute * @param queryParams - parameters to the query * @param cbc - callback object * * @throws Exception * @return results in string form */ private WritableMap executeSqlStatementQuery(SQLiteDatabase mydb, String query, ReadableArray queryParams, CallbackContext cbc) throws Exception { WritableMap rowsResult = Arguments.createMap(); Cursor cur = null; try { try { String[] params = new String[0]; if (queryParams != null) { int size = queryParams.size(); params = new String[size]; for (int j = 0; j < size; j++) { if (queryParams.isNull(j)) { params[j] = ""; } else { params[j] = SQLitePluginConverter.getString(queryParams, j, ""); } } } cur = mydb.rawQuery(query, params); } catch (Exception ex) { FLog.e(TAG, "SQLitePlugin.executeSql[Batch]() failed", ex); throw ex; } // If query result has rows if (cur != null && cur.moveToFirst()) { WritableArray rowsArrayResult = Arguments.createArray(); String key; int colCount = cur.getColumnCount(); // Build up result object for each row do { WritableMap row = Arguments.createMap(); for (int i = 0; i < colCount; ++i) { key = cur.getColumnName(i); bindRow(row, key, cur, i); } rowsArrayResult.pushMap(row); } while (cur.moveToNext()); rowsResult.putArray("rows", rowsArrayResult); } } finally { closeQuietly(cur); } return rowsResult; }