Note that there are some explanatory texts on larger screens.

plurals
  1. POReading from SD card and inserting to SQL table is extremely slow
    primarykey
    data
    text
    <p>I have a problem that has been driving me crazy and I'd appreciate any thoughts you guys may have to offer. I import data from a CSV file (using openCSV) into a database, and previously this process has been completed in about 3-5 seconds including the download time from a server. The CSV file has 3035 records. I've tried separating the parsing from CSV and inserting to the table, but to no avail.</p> <p>As strange as it may sound suddenly something has changed within my application where now this process takes much much longer.</p> <p>After narrowing it down I've found that inserting into the table is extremely slow for SQLite. I've spent the last couple hours reverting back to older code to see if something has changed but to no luck. </p> <p>I came across some similar question whose answer suggest me to use InsertHelper, which I did. Which made absolutely no difference in the import time. Currently inserting data takes 60 seconds, where it used to take just a couple.</p> <pre><code>public void importFromCSV() { SQLiteDatabase db = this.getReadableDatabase(); db.execSQL("DELETE FROM EXAMS"); File SDCardRoot = Environment.getExternalStorageDirectory(); File file = new File(SDCardRoot.getAbsolutePath() + "/Finals/Data/timetable.csv"); CSVReader reader; int i = 0; try { reader = new CSVReader(new FileReader(file)); String [] nextLine; while ((nextLine = reader.readNext()) != null) { this.addExam(new Exam(nextLine[0], nextLine[1], nextLine[2], nextLine[3], nextLine[4], nextLine[5], nextLine[6], nextLine[7], nextLine[8], nextLine[9])); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void addExam(Exam exam) { SQLiteDatabase db = this.getReadableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_SESSION, exam.getSession()); values.put(KEY_AWARDING_BODY, exam.getAwardingBody()); values.put(KEY_QUALIFICATION, exam.getQualification()); values.put(KEY_TITLE, exam.getTitle()); values.put(KEY_EXAM_CODE, exam.getExamCode()); values.put(KEY_DURATION, exam.getDuration()); values.put(KEY_DATE, exam.getDate()); values.put(KEY_START_TIME, exam.getStartTime()); values.put(KEY_EXAM_NOTE, exam.getExamNote()); values.put(KEY_MY_NOTES, exam.getMyNotes()); db.insert(TABLE_NAME, null, values); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload