Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm working on the Firebase app and I want to save a list of more than 5000 retrieved PricesList items into SQLite.

Here is my Firebase code:

@Override
protected void onStart() {
    super.onStart();

    mRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            pricesArrayList.clear();

            for (DataSnapshot PricesListDataSnapshot : dataSnapshot.getChildren()) {

                PricesList pricesList = PricesListDataSnapshot.getValue(PricesList.class);
                pricesArrayList.add(pricesList);

                // I don't know what is the insertion code for SQLite

            }

            // here goes the code for retrieved data from SQLite after it was saved from Firebase

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

and here is the DB.class code

private class DBHelper extends SQLiteOpenHelper {
    private static final int VERSION = 1;
    private static final String DB_NAME = "MyDB1.db";
    public static final String id = "_id";
    public static final String ItemCode = "ItemCode";
    public static final String Product = "Product";

    DBHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String create_sql = "CREATE TABLE IF NOT EXISTS "
                + DB_NAME + '(' + id
                + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                + ItemCode + " TEXT ,"
                + Product + " TEXT ," +')';
        db.execSQL(create_sql);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + DB_NAME );
    }
}

What code should be used for storing listo of items in SQLite database? I'll be thankful to anyone how has the answer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
141 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...