0

每个示例都使用常量表属性,而不是仅在名称中写入表属性。我知道这样做是一种更好的做法,但是否可以只编写查询?

例子:

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_NAME + " TEXT NOT NULL, " +
                KEY_HOTNESS + " TEXT NOT NULL);"
        );  
    }

我想要的是

        @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL('CREATE TABLE "databasename" (' +
                "keyrowid" INTEGER PRIMARY KEY AUTOINCREMENT, ' +
                "keyname" TEXT NOT NULL, ' +
                "keyhotness" TEXT NOT NULL);'
        );  
    }

当然我的在 sytnax 中是不正确的,因为 ' 和 " 的问题。我找不到使这项工作的方法,是否有可能或者我们必须使用常量?谢谢!

4

1 回答 1

3

It's one in the same thing. Constants are used to reduce chances of having any typo errors while writing any query. If you feel that you won't make any error then go ahead and use it.

As far as the mentioned query is concerned use this

db.execSQL("CREATE TABLE tablename (keyrowid INTEGER PRIMARY KEY AUTOINCREMENT, keyname TEXT NOT NULL, keyhotness TEXT NOT NULL)";
于 2013-11-05T16:22:06.603 回答