public static List<String> statementsFrom(Reader reader) throws IOException { SQLFile file = new SQLFile(); file.parse(reader); return file.getStatements(); }
@Test public void testSkippingTrailingComments() throws IOException { String rawLine = "CREATE TABLE 'testTable'"; String comment = "-- adding some comment that should get stripped off"; String nextLine = "_id INTEGER PRIMARY KEY AUTOINCREMENT;"; String lineCommand = rawLine + comment + "\n" + nextLine; List<String> statements = SQLFile.statementsFrom(new StringReader(lineCommand)); assertEquals(rawLine + " " + nextLine, statements.get(0)); }
StringBuilder statement = new StringBuilder(); while ((line = reader.readLine()) != null) { line = stripOffTrailingComment(line).trim();
@Test public void testReadMultiLineCommand() throws IOException { String firstLine = "CREATE TABLE 'testTable'"; String secondLine = "_id INTEGER PRIMARY KEY AUTOINCREMENT;"; String singleLineCommand = firstLine + " " + secondLine; String multiLineCommand = firstLine + "\n" + secondLine; List<String> statementsFromMultiline = SQLFile.statementsFrom(new StringReader(multiLineCommand)); assertEquals(singleLineCommand, statementsFromMultiline.get(0)); }
public static List<String> statementsFrom(File sqlfile) throws IOException { FileReader reader = null; try { reader = new FileReader(sqlfile); SQLFile file = new SQLFile(); file.parse(reader); return file.getStatements(); } finally { if (reader != null) { reader.close(); } } } }
private List<String> readStatements(String fileName) throws IOException { return SQLFile.statementsFrom(getSqlFileReader(fileName)); }
for (String insert : SQLFile.statementsFrom(reader)) { if (TextUtils.isEmpty(insert.trim())) { continue;