I'm trying to access TABLE_NAME
from ProductTable
in ProductImageTable
to put it in the query. I've searched everywhere on how to access it and so far I've found nothing. I would appreciate some help, please:)
Here's a snippet of the code:
abstract inner class ProductTable : Table() {
val TABLE_NAME: String = "product"
}
abstract inner class ProductImageTable : Table() {
val SQL_CREATE_TABLE : String = "CREATE TABLE $TABLE_NAME" +
" ($_ID$ID_TYPE_AUTO_INC$COMMA_SEP" +
"$COLUMN_PRODUCT_UUID$TEXT_TYPE_NOT_NULL$COMMA_SEP" +
"$COLMUN_LOCAL_IMAGE_FILE$TEXT_TYPE_NOT_NULL_EMPTY$COMMA_SEP" +
"$COLUMN_SERVER_IMAGE_URL$TEXT_TYPE_NOT_NULL_EMPTY$COMMA_SEP" +
"FOREIGN KEY($COLUMN_PRODUCT_UUID) REFERENCES ${ProductTable.TABLE_NAME}(${ProductTable.COLUMN_PRODUCT_UUID}) ON UPDATE CASCADE ON DELETE CASCADE)"
}
Try
abstract inner class ProductImageTable : ProductTable() {
if you inherit from that class where that field is then you should be able to access it.
Also you could make your TABLE_NAME val a const
(see https://stackoverflow.com/a/37596023/2399024 for mor infos about const):
const val TABLE_NAME: String = "product"
BTW: Maybe you might want to use https://developer.android.com/jetpack/androidx/releases/room instead of manually doing sql query stuff
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.