in this case i want to make local database when the apps on offline mode.
i want to add transaction and items transaction data to my local database.
this is my items transaction data
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, "")
}
this is my class transaction
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, "")
}
and this is my transactionHelper. in this code i want to copy data from class ItemTransactions. class ItemTransactions functions as save temporary data.
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()
}
}
i got error like this
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 (?,?,?,?,?,?,?,?,?,?,?,?,?)
I am confused with that error. because i don't have class Transaction.
sorry for my poor English writing
transaction
is a keyword in SQL and cannot be used as an identifier.
Consider renaming your transaction
property to something else to prevent SugarORM from using it to generate incorrect SQL.