Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't distribute your app with a huge txt-file and import it on the users device. This takes time and is annoying.</p> <p>Rather distribute your app with a pre-populated database and copy it over from the <code>res</code>-folder. You can use <a href="https://github.com/jgilfelt/android-sqlite-asset-helper" rel="nofollow">android-sqlite-asset-helper</a> to automate this.</p> <p>Also, yes. The Database is always stored on the internal memory and you can't access it on a non-rooted device (unless you're using the AVD).</p> <hr> <p>To import your txt-contents into a database, create a script or something that parses the contents and executes the corresponding SQL-queries. Again, your App should ship with the database, not the raw-file!</p> <hr> <p>I was a little bored and hacked together a short Python-Script to read all entries from your txt-file and insert them into a SQLite Database:</p> <pre><code>import sqlite3 import re counter = 0; pattern = re.compile('^([^\^]+)\^([\w\s]+)\^(yes|no)\^\w+$'); conn = sqlite3.connect("imported.db"); cursor = conn.cursor(); # Create the Table: conn.execute(''' CREATE TABLE Bands ( name TEXT, genre TEXT, popular INTEGER, selected INTEGER );'''); # Now, insert: with open('bands.txt', 'r') as f: for line in f: match = pattern.search(line); if match: cursor.execute(''' INSERT INTO Bands (name, genre, popular, selected) VALUES (?,?,?,0)''', ( match.group(1), match.group(2), (1 if match.group(3) == 'yes' else 0) ) ); counter+=1; conn.commit(); conn.close(); print "Imported ", counter, " bands!"; </code></pre> <p>This will assume that the txt-file is named <code>bands.txt</code>, each value is separated by a <code>/</code> and each entry will be on it's own line. The resulting database-file is <code>imported.db</code>.</p> <p>Also, I use <code>INTEGER</code> for all <code>True|False</code>-fields (popular, selected). These will then hold a <code>0</code> for false and a <code>1</code> for true.</p> <p>Last but not least, the RegEx only allows "yes" and "no" for the <code>popular</code>-value.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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