android sqlite插入行2次

时间:2014-02-06 12:03:04

标签: android sqlite

我在我的表中插入一行,但它插入了2次。我无法弄清楚这个问题。感谢您的帮助。这是我的代码

这是我的插入方法。

 public Table createTable(Table table) {
        ContentValues values = new ContentValues();
        values.put(DBOpenHelper.TABLE_TABLE_NAME, table.getName());
        values.put(DBOpenHelper.TABLE_TABLE_SALONID, table.getSalonid());
        values.put(DBOpenHelper.TABLE_TABLE_CAPACITY, table.getCapacity());
        values.put(DBOpenHelper.TABLE_TABLE_STATUS, table.getTablestatus());        
        values.put(DBOpenHelper.TABLE_TABLE_X, table.getX());
        values.put(DBOpenHelper.TABLE_TABLE_Y, table.getY());
        values.put(DBOpenHelper.TABLE_TABLE_TYPE, table.getTableType());

        values.put(DBOpenHelper.TABLE_TABLE_WIDTH, table.getWidth());
        values.put(DBOpenHelper.TABLE_TABLE_HEIGHT, table.getHeight());
        long insertid = database.insert(DBOpenHelper.TABLE_TABLE, null, values);
        table.setId(insertid);
        return table;
    }

这是我称之为的地方。

DBDataSource datasource = new DBDataSource(TableActivity.this);
                datasource.open();

                Table table = new Table();
                    table.setX(1);
                    table.setY(1);
                    table.setName("aaa");
                    table.setCapacity(2);
                    table.setSalonid(1);                
                    table.setTableType("square");
                    table.setWidth(70);
                    table.setHeight(70);
                    table = datasource.createTable(table);
                datasource.close();

                startActivity(new Intent(TableActivity.this,MainActivity.class));

这是我的表

private static final String TABLE_TABLE_CREATE = "CREATE TABLE "
            + TABLE_TABLE + " (" + TABLE_TABLE_ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT, " + TABLE_TABLE_NAME
            + " TEXT, "
            + TABLE_TABLE_SALONID + " INTEGER REFERENCES " +  TABLE_SALON+"("+TABLE_SALON_ID+"),"
            + TABLE_TABLE_CAPACITY + " INTEGER, "
            + TABLE_TABLE_STATUS+ " INTEGER, "
            + TABLE_TABLE_X+ " INTEGER, "
            + TABLE_TABLE_Y+ " INTEGER, "
            + TABLE_TABLE_TYPE+ " TEXT, "
            + TABLE_TABLE_WIDTH+ " INTEGER, "
            + TABLE_TABLE_HEIGHT+ " INTEGER "
            +")";

0 个答案:

没有答案