Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One option which I did:</p> <ul> <li>Store each of the schema and data population files as scripts in resources</li> <li>Created a wrapper class that runs those scripts from resources</li> <li>One of the resource files is a well known (by name) manifest, it has a list of the scripts to run in which order.</li> <li>I have a poperties table in the database which stores what's the last script that ran.</li> </ul> <p>That means:</p> <ul> <li>On creation (first run) - it runs all scripts in succession</li> <li>When app is updates - it runs all scripts that haven't run yet. The update carries more scripts in resources.</li> </ul> <p>The scripts update schema and modify/munge existing customer data - of course without data loss.</p> <p>BTW, I did this on iOS with the intent of sharing those sqlite scripts between android, winphone and other platforms. You just need the wrapper class on each platform that runs the sequences.</p> <p>It also means I can run the scripts in order from the cmdline to create a db if needed ...</p> <p><strong>EDIT:</strong></p> <p>For example, in my sample app, Update1.sql is a file added as a resource. It has two sql batches in it. My wrapper opens the manifest file, get's the list of scripts to run, queries the database to see the last script ran, then creates an array of scripts to run. When it runs Update1.sql which is in the list, my wrapper class executes all the statements in that file thats embedded as a resource. For example, here's my Update1.sql</p> <pre><code>alter table messages add column user text; create table log ( id integer primary key autoincrement, information text ); </code></pre> <p>Now, let's say the new table created needs some data in it. (in my case a log table doesn't). That scripts could contain a series of insert into statements right after the create table.</p> <p>Executing multiple batches in a script requires the use of the tail argument in prepare. I have C/objective-c code if you would like to see it but I haven't written the android wrapper yet ...</p>
 

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