I have a lengthy SQL INSERT command that I would essentially like to convert to a local Xamarin database, using SQLite. Is there any easy way around this or do I manually have to create an object from each value which is then entered into the local SQLite database?
-
do you mean a one time task to seed a new SQLite DB, or some sort of operation that will need to be repeated?Jason– Jason2017-03-27 20:41:19 +00:00Commented Mar 27, 2017 at 20:41
-
@Jason I'm looking to seed my data somehowDan M– Dan M2017-03-27 20:45:29 +00:00Commented Mar 27, 2017 at 20:45
-
1you can use SQLite Manager (a FF plugin) to create a db, and then include that in your project. You can try to modify your Insert query to work with SQLite, or just export the data from SQL and then import using SQLMgrJason– Jason2017-03-27 20:51:04 +00:00Commented Mar 27, 2017 at 20:51
-
Why don't you just execute the command?CL.– CL.2017-03-28 07:55:15 +00:00Commented Mar 28, 2017 at 7:55
Add a comment
|
1 Answer
If you want to pre-seed your database and ship it with the app, then as Jason suggested, you can use SQLite Manager.
If you want the mobile app to seed the database on first load, you will need to create the objects (tables) first and run the below for each table you have.
SQLiteConnection conn = ....
conn.CreateTable<TableClass>();
Then if you just want to run the insert queries you have, you can use the Execute method.
public int Execute(string query, params object[] args)
However SQLite isn't as powerful as MS SQL and if your insert queries are complex, you will have to modify them and possibly your DB Schema, depending upon column types.