SQLiteLog: (1) near "TRANSACTION": 语法错误

SQLiteLog: (1) near "TRANSACTION": syntax error

在这种情况下,我想在应用程序处于离线模式时创建本地数据库。
我想将交易和项目交易数据添加到我的本地数据库。
这是我的物品交易数据

class ItemTransactionOffline(_bp: Double, _co: String, _cur: String, _dper: Int, _dpri: Int, _p: Int,
                             _qty: Int, _sp: Double, _tbp: Double, _tsp: Double, _trx: Int, _uo: String): SugarRecord() {
    var base_price: Double = 0.0
    var created_on: String = ""
    var currency: String = ""
    var discount_percent: Int = 0
    var discount_price: Int = 0
    var product: Int = 0
    var quantity: Int = 0
    var sell_price: Double = 0.0
    var total_base_price: Double = 0.0
    var total_sell_price: Double = 0.0
    var transaction: Int = 0
    var updated_on: String = ""

    init {
        this.sell_price = _sp
        this.base_price = _bp
        this.quantity = _qty
        this.updated_on =  _uo
        this.transaction = _trx
        this.total_sell_price = _tsp
        this.total_base_price = _tbp
        this.currency = _cur
        this.discount_percent = _dper
        this.discount_price = _dpri
        this.created_on = _co
        this.product = _p
    }

    constructor(): this(0.0, "", "", 0, 0, 0, 0, 0.0, 0.0, 0.0, 0, "")
}

这是我的class交易

class TransactionOffline(_idC: Int, _co: String, _cos: Any?, _del: Boolean, _ip: Boolean, _po: Any?, _store: Int,
                         _tp: Int, _ub: Any?, _uo: String): SugarRecord() {
    var id_cashier: Int = 0
    var created_on: String = ""
    var customer: Any? = null
    var deleted: Boolean = false
    var is_paid: Boolean = false
    var paid_on: Any? = null
    var store: Int = 0
    var total_price: Int = 0
    var updated_by: Any? = null
    var updated_on: String = ""

    init {
        this.id_cashier = _idC
        this.updated_on = _uo
        this.total_price = _tp
        this.store = _store
        this.is_paid = _ip
        this.created_on = _co
        this.customer = _cos
        this.paid_on = _po
        this.deleted = _del
        this.updated_by = _ub
    }
    constructor(): this(0, "", null, false, false, null, 0, 0, null, "")
}

这是我的交易助手。在此代码中,我想从 class ItemTransactions 复制数据。 class ItemTransactions 用作保存临时数据。

class TransactionHelper{
    fun addTransaction(items: MutableList<ItemTransactions>){
        val idCashier = 1
        val date = SimpleDateFormat("yyyy-MM-dd ")
        val datenow = Date()
        val currentDate = date.format(datenow)
        val trx = TransactionOffline(idCashier, currentDate, null, false, true, null, 1, Transaction.getTotalBayar().toInt(), null, currentDate)
        trx.save()
        val id_trx = trx.id.toInt()
        Log.w("id-transaksi-local", "$id_trx")
        items.forEach {
            addItemTransaction(id_trx, it)
        }
    }

    fun addItemTransaction(id: Int, item: ItemTransactions){
        val itemTRX = ItemTransactionOffline(item.base_price, item.created_on, item.currency, item.discount_percent,
                item.discount_price, item.product, item.quantity, item.sell_price, item.total_base_price,
                item.total_sell_price, id, item.updated_on)
        itemTRX.save()
    }
}

我遇到这样的错误

android.database.sqlite.SQLiteException: near "TRANSACTION": syntax error (code 1): , while compiling: INSERT OR REPLACE  INTO ITEM_TRANSACTION_OFFLINE(PRODUCT,CURRENCY,UPDATEDON,DISCOUNTPRICE,TRANSACTION,TOTALSELLPRICE,QUANTITY,ID,DISCOUNTPERCENT,TOTALBASEPRICE,SELLPRICE,CREATEDON,BASEPRICE) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)

我对那个错误很困惑。因为我没有 class 交易。
抱歉我的英语写得不好

transaction是SQL中的关键字,不能用作标识符。

考虑将您的 transaction 属性 重命名为其他名称,以防止 SugarORM 使用它生成不正确的 SQL.