SQLite语法错误代码1

时间:2014-07-16 17:22:28

标签: android sqlite

所以我正在为我的第一个Android应用程序编写数据库,但是这里的代码出了问题。

public class MySQLHelper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "SWMdatabase";
private static final String TABLE_WALLET = "Wallet";
private static final String TABLE_TRANSACTION = "Transaction";

private static final String KEY_WALLET_ID = "_WalletId";
private static final String KEY_TRANS_ID = "_TransId";

private static final String KEY_CREATED_ON = "CreatedOn";
private static final String KEY_WALLET_NAME = "WalletName";

private static final String KEY_WALLET_SUM = "WalletSum";
private static final String KEY_AMOUNT = "Amount";

public MySQLHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Database onCreate and onUpgrade
// --------------------------------------------------

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_WALLET_TABLE = "CREATE TABLE " + TABLE_WALLET + " ( "
            + KEY_WALLET_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + KEY_WALLET_NAME + " TEXT NOT NULL, " 
            + KEY_WALLET_SUM + " REAL NOT NULL )";

    db.execSQL(CREATE_WALLET_TABLE);

    String CREATE_TRANSACTION_TABLE = "CREATE TABLE " + TABLE_TRANSACTION + " ( " 
            + KEY_TRANS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
            + KEY_AMOUNT + " REAL NOT NULL, " 
            + KEY_WALLET_ID + " INTEGER NOT NULL, "
            + KEY_CREATED_ON + " TEXT NOT NULL )";

    db.execSQL(CREATE_TRANSACTION_TABLE);

}

它抛出一个SQLiteException语法错误'near“Transaction”,我不知道如何以及为什么。我还仔细检查了CREATE_TRANSACTION_TABLE无数次,但还是想不通。

1 个答案:

答案 0 :(得分:1)

您无法使用reserved words 交易来创建表格。

请参阅此帖子Are there any reserved words in SQLite?