1

In my android app, existing database using from asset.

Assume that I have a database in asset folder and name is "a.sqlite". and it has a table which is name "t". and I want to download a table which is name "t2.sql" from my server. after downloading "t2.sql" I want to insert all values of "t2" table to "t" table in android programmatically

Assume that this is main database table

| id | name  | dt1 | dt2 | dt3 | 
| 1  | Paul  | 21  | 98  | 91  |
| 2  | John  | 22  | 44  | 11  |
| 3  | George| 21  | 31  | 22  |
| 4  | Ringo | 20  | 10  | 15  | 

and I want to insert this sql table to main table

| id | name   | dt1 | dt2 | dt3 | 
| 1  | Paul_2  | 21  | 98  | 91  |
| 2  | John_2  | 22  | 44  | 11  |
| 3  | George_2| 21  | 31  | 22  |
| 4  | Ringo_2 | 20  | 10  | 15  | 

Also my sql table has CREATE TABLE statement and BEGIN TRANSACTION/COMMIT statements. It should be very easy because in Firefox SQLite manager I am using just import and this table join the my database. but how I can do in android I dont know

2
  • You can create a bulk insert for whatever the values you have and map it directly to t2 table by writing the sql and creating the table first. If you can provide me a sample table with some dummy attributes Ill show you how you can do it. Commented Apr 6, 2014 at 6:25
  • Ahmed I have added to question Commented Apr 7, 2014 at 14:16

1 Answer 1

0

What I have understood from your question is that you want to map all the values from one table to another. For that you have to get all the values from that table first and then dump it into another.

First what you need to do is to get the values from table t2.sql. Now I am assuming you know how to use the t2.sql file to get the table entities and data. Once you get that you simply need to bulk insert the records in t1.

Bulk insert all the values through the following snippet (pseudo code),

try
{
  db.beginTransaction();
  for each record in the list
  {
    do_some_processing();
    if (line represent a valid  entry)
    {
      db.insert(TABLE_T1, null, SOME_VALUE);
    }
    some_other_processing();
  }
  db.setTransactionSuccessful();
}
catch (SQLException e) {}
finally
{
  db.endTransaction();
}

Hope this helps you. If you need me to elaborate please let me know

Sign up to request clarification or add additional context in comments.

6 Comments

Okay I got it. You say make a list and fill it with "t2.sql" and insert all list to "t table". But I dont know one point which is t2.sql is download from server and it is separated from my database. So how can call and use it. Can I use it like a .csv file?
Following link will help you understand on how to do the Bulk Insert notes.theorbis.net/2010/02/…
Were you able to do it?
No :( not yet. I'm trying
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.