vendredi 16 octobre 2015

Android SQLiteDataBase

I created a database with two tables called orders and customer.

db = this.openOrCreateDatabase("DailyFresh", MODE_PRIVATE, null);
    // db.execSQL("drop table if exists customer");
    db.execSQL("create table if not exists customer(cust_id integer not null " 
            + ",name text, phone text,city text, primary key(cust_id));");
    db.execSQL("create table if not exists orders(order_id integer not null " + "primary key" + ",cust_id integer"
            + ",date text, amount integer," + "foreign key(cust_id) REFERENCES customer(cust_id));");

This is my code. My problem is that the primary key constraint and the foreign key constraint are not maintained when the values are entered in to the table.

String addc = "insert into customer(cust_id,name,phone,city) values("
                    + Scid
                    + ",'"
                    + Sname
                    + "','"
                    + Sphone
                    + "','"
                    + Scity
                    + "');";

            db.execSQL(addc);

This is my insert query. I can't show you the table because the database is on my device and I'm running the code directly on the device. But when I retrieve the values from the database the same value is shown to be entered multiple times. Please be kind. I'm new to android.

Aucun commentaire:

Enregistrer un commentaire