在这种情况下,我想在离线模式下创建本地数据库。
我想将交易和项目交易数据添加到我的本地数据库。
这是我的商品交易数据
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 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, "")
}
这是我的transactionHelper。在这段代码中,我想从ItemTransactions类复制数据。 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 (?,?,?,?,?,?,?,?,?,?,?,?,?)
我对该错误感到困惑。因为我没有交易类。
对不起,我的英语写作很差
答案 0 :(得分:0)
transaction
是SQL中的关键字,不能用作标识符。
考虑将您的transaction
属性重命名为其他名称,以防止SugarORM使用它来生成错误的SQL。