- Pattern continuation = Pattern.compile("\\\\\\s*$");
-
- String line;
- String sqlStatement = null;
- int line_no = 1;
- while ((line = reader.readLine()) != null) {
- if (line.startsWith("--")) {
- line_no++;
- continue;
- }
- if (line.isEmpty()) {
- line_no++;
- continue;
- }
- if (sqlStatement == null)
- sqlStatement = line;
- else
- sqlStatement = sqlStatement.concat(line);
-
- Matcher m = continuation.matcher(line);
- if (m.matches()) {
- line_no++;
- continue;
- }
-
- try {
- db.execSQL(sqlStatement);
- sqlStatement = null;
- }
- catch (Exception e) {
- throw new RuntimeException(
- String.format("Error applying %s, line %d", rev_file, line_no), e);
- }
- line_no++;
- }
-
- if (sqlStatement != null)
- throw new RuntimeException(
- String.format("Error applying %s: EOF after continuation", rev_file));
-
- db.setTransactionSuccessful();
- }
- catch (IOException e) {
- Log.e("db", String.format("Error opening raw resource for %s", rev_file));
- e.printStackTrace();
- }
- finally {
- db.endTransaction();
- }
+ @Override
+ public void onConfigure(SQLiteDatabase db) {
+ super.onConfigure(db);
+ // force a check by Room to ensure everything is OK
+ // TODO: remove when all DB access is via Room
+ DB.get()
+ .compileStatement("SELECT COUNT(*) FROM profiles");