使用用户名在Android中创建SQLite表名

时间:2017-11-06 10:31:14

标签: android sqlite

我想使用username在SQLite中创建表。但是当用户名有点(。)或以数字开头时,程序因SQLite错误而崩溃(例如username = araz.13

我该如何解决这个问题? 这是我的代码

void CreateProfileDB(String Username) {

    String TBLname = Username + "Tbl";
    String CreateTBL = "CREATE TABLE IF NOT EXISTS " + TBLname + " ("
            + ID + " INTEGER PRIMARY KEY, "
            + Book + " TEXT NOT NULL, " + Lesson + " TEXT NOT NULL, "
            + Question + " TEXT NOT NULL, " + Answer + " TEXT NOT NULL, "
            + Accent + " TEXT, " + Option1 + " TEXT, "
            + Option2 + " TEXT, " + Option3 + " TEXT, "
            + Option4 + " TEXT, " + Option5 + " TEXT, "
            + TrueOption + " TEXT, " + EnglishSen1 + " TEXT, "
            + EnglishSen2 + " TEXT, " + EnglishSen3 + " TEXT, "
            + PersianSen1 + " TEXT, " + PersianSen2 + " TEXT, "
            + PersianSen3 + " TEXT, " + FirstShow + " TEXT, "
            + LastShow + " TEXT, " + NoOfShow + " INTEGER, "
            + StepNo + " INTEGER, " + TrueNo + " INTEGER, "
            + WrongNo + " INTEGER, " + NextShow + " TEXT);";

    SQLiteDatabase PDB = this.getWritableDatabase();
    PDB.execSQL(CreateTBL);

1 个答案:

答案 0 :(得分:1)

你可以quote表名。

但最好使用单个表并将用户名添加为列。