/** * Query. * * @param db * the db * @param conditions * the conditions * @param type * the type * @param listener * the listener */ private static void query(SQLiteDatabase db, String conditions, QueryType type, OnResultListener listener) { SQLiteUpdateTaskHelper.query(db, conditions, type, listener); }
/** * Execute SQL. * * @param database * the database * @param fileInputStream * the file input stream */ public static void executeSQL(final SQLiteDatabase database, InputStream fileInputStream) { List<String> commands = readSQLFromFile(fileInputStream); executeSQL(database, commands); }
/** * Read SQL from file. * * @param fileName * the file name * @return the list */ public static List<String> readSQLFromFile(String fileName) { try { return readSQLFromFile(new FileInputStream(fileName)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } }
/** * Execute SQL. * * @param database * the database * @param commands * the commands */ public static void executeSQL(final SQLiteDatabase database, List<String> commands) { for (String command : commands) { executeSQL(database, command); } // commands.forEach(command -> { // executeSQL(database, command); // }); }
/** * Retrieve all table as a Map of (name, sql). * * @param db * the db * @return the all tables */ public static Map<String, String> getAllTables(SQLiteDatabase db) { return SQLiteUpdateTaskHelper.getAllTables(db); }
/** * Retrieve all indexes as a Map of (name, sql). * * @param db * the db * @return indexes */ public static Map<String, String> getAllIndexes(SQLiteDatabase db) { return SQLiteUpdateTaskHelper.getAllIndexes(db); }
/** * Read SQL from file. * * @param fileName * the file name * @return the list */ public static List<String> readSQLFromFile(String fileName) { try { return readSQLFromFile(new FileInputStream(fileName)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } }
/** * Execute SQL. * * @param database * the database * @param commands * the commands */ public static void executeSQL(final SQLiteDatabase database, List<String> commands) { for (String command : commands) { executeSQL(database, command); } // commands.forEach(command -> { // executeSQL(database, command); // }); }
/** * Retrieve all table as a Map of (name, sql). * * @param db * the db * @return the all tables */ public static Map<String, String> getAllTables(SQLiteDatabase db) { final Map<String, String> result = new LinkedHashMap<>(); query(db, null, QueryType.TABLE, new OnResultListener() { @Override public void onRow(SQLiteDatabase db, String name, String sql) { if (StringUtils.hasText(sql)) { result.put(name, StringUtils.nvl(sql).trim()); } } }); return result; }
/** * Execute SQL. * * @param database * the database * @param fileInputStream * the file input stream */ public static void executeSQL(final SQLiteDatabase database, InputStream fileInputStream) { List<String> commands = readSQLFromFile(fileInputStream); executeSQL(database, commands); }
@Override public void execute(SQLiteDatabase database, int previuosVersion, int currentVersion) { List<String> executionList=null; if (inputStream==null) { File f = new File(schemaDefinitionFile); executionList = SQLiteUpdateTaskHelper.readSQLFromFile(schemaDefinitionFile); Logger.info("Load DDL from " + f.getAbsolutePath()); } else { executionList = SQLiteUpdateTaskHelper.readSQLFromFile(inputStream); Logger.info("Load DDL from stream"); } for (String item : executionList) { Logger.info(item); database.execSQL(item); } }
/** * Execute SQL. * * @param database * the database * @param context * the context * @param rawResourceId * the raw resource id */ public static void executeSQL(final SQLiteDatabase database, Context context, int rawResourceId) { String[] c = IOUtils.readTextFile(context, rawResourceId).split(";"); List<String> commands = Arrays.asList(c); executeSQL(database, commands); }
/** * Retrieve all indexes as a Map of (name, sql). * * @param db * the db * @return the all indexes */ public static Map<String, String> getAllIndexes(SQLiteDatabase db) { final Map<String, String> result = new LinkedHashMap<>(); query(db, null, QueryType.INDEX, new OnResultListener() { @Override public void onRow(SQLiteDatabase db, String name, String sql) { if (StringUtils.hasText(sql)) { result.put(name, StringUtils.nvl(sql).trim()); } } }); return result; }
/** * Drop all table with specific prefix. * * @param db * the db * @param prefix * the prefix */ public static void dropTablesWithPrefix(SQLiteDatabase db, String prefix) { Logger.info("MASSIVE TABLE DROP OPERATION%s", StringUtils.ifNotEmptyAppend(prefix, " WITH PREFIX ")); drop(db, QueryType.TABLE, prefix); }
@Override public void execute(SQLiteDatabase database, int previuosVersion, int currentVersion) { List<String> executionList=null; if (inputStream==null) { File f = new File(schemaDefinitionFile); executionList = SQLiteUpdateTaskHelper.readSQLFromFile(schemaDefinitionFile); Logger.info("Load DDL from " + f.getAbsolutePath()); } else { executionList = SQLiteUpdateTaskHelper.readSQLFromFile(inputStream); Logger.info("Load DDL from stream"); } for (String item : executionList) { Logger.info(item); database.execSQL(item); } }
/** * Execute SQL. * * @param database * the database * @param context * the context * @param rawResourceId * the raw resource id */ public static void executeSQL(final SQLiteDatabase database, Context context, int rawResourceId) { String[] c = IOUtils.readTextFile(context, rawResourceId).split(";"); List<String> commands = Arrays.asList(c); executeSQL(database, commands); }
/** * Retrieve all table as a Map of (name, sql). * * @param db * the db * @return the all tables */ public static Map<String, String> getAllTables(SQLiteDatabase db) { final Map<String, String> result = new LinkedHashMap<>(); query(db, null, QueryType.TABLE, new OnResultListener() { @Override public void onRow(SQLiteDatabase db, String name, String sql) { if (StringUtils.hasText(sql)) { result.put(name, StringUtils.nvl(sql).trim()); } } }); return result; }
/** * Drop all table with specific prefix. * * @param db * the db * @param prefix * the prefix */ public static void dropTablesWithPrefix(SQLiteDatabase db, String prefix) { Logger.info("MASSIVE TABLE DROP OPERATION%s", StringUtils.ifNotEmptyAppend(prefix, " WITH PREFIX ")); drop(db, QueryType.TABLE, prefix); }