我正在DAO界面上处理复杂的SQL查询,并且尝试从嵌套在以下5种不同类型的对象中的每个“客户”表中获取属性:“ GasSafetyRecord”,“ OfflineSyncBulkCertificateDLGSR”等等。嵌套属性称为“ customer_object”,如下所示:
@Embedded(prefix = "customer_object") var customer_object: OfflineSyncBulkCustomer? = null
我想从查询中访问该对象内的“电子邮件”字段,如下所示...
@Query("SELECT id, transactional_id, IFNULL(customer_name, \"\") AS customer_name, IFNULL(created_t, date) AS date, IFNULL(updated_at, updated_at_t) AS updated_at, unique_serial_no, type_of_cert, archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, email as customer_objectemail FROM(SELECT id, transactional_id, customer_objectemail as email, customer_name, date, NULL AS created_t, updated_at, NULL AS updated_at_t, unique_serial_no, \"OfflineDLGSR\" AS type_of_cert, 0 AS archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM OfflineSyncBulkCertificateDLGSR UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, NULL AS date, created_t, NULL AS updated_at, updated_at_t, unique_serial_no, \"DLGSR\" AS type_of_cert, archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM GasSafetyRecord UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, date, NULL AS created_t, updated_at, NULL AS updated_at_t, unique_serial_no, \"OfflineGWAN\" AS type_of_cert, 0 AS archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM OfflineSyncBulkCertificatesGWAN UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, NULL AS date, created_t, NULL AS updated_at, updated_at_t, unique_serial_no, \"GWAN\" AS type_of_cert, archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM GasWarningAdvisoryNotice UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, date, NULL AS created_t, updated_at, NULL AS updated_at_t, unique_serial_no, \"OfflineJS\" AS type_of_cert, 0 AS archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM OfflineSyncBulkCertificatesJobSheet UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, NULL AS date, created_t, NULL AS updated_at, updated_at_t, unique_serial_no, \"JS\" AS type_of_cert, archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM JobSheet UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, date, NULL AS created_t, updated_at, NULL AS updated_at_t, unique_serial_no, \"OfflineSMR\" AS type_of_cert, 0 AS archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM OfflineSyncBulkCertificateSMR UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, NULL AS date, created_t, NULL AS updated_at, updated_at_t, unique_serial_no, \"SMR\" AS type_of_cert, archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM ServiceMaintenanceRecord UNION SELECT id, transactional_id, customer_objectemail as email, customer_name, date, NULL AS created_t, updated_at, NULL AS updated_at_t, unique_serial_no, \"OfflineLRA\" AS type_of_cert, 0 AS archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM OfflineSyncBulkCertificatesLRA UNION SELECT id, transactional_id, customer_objectemail as email, NULL AS customer_name, NULL AS date, created_t, NULL AS updated_at, updated_at_t, unique_serial_no, \"LRA\" AS type_of_cert, archived, customer_address_line_one, customer_address_line_two, customer_city, customer_postcode, customer_county, customer_objectemail FROM LegionellaRiskAssessment) ORDER BY `updated_at` DESC LIMIT :limit")
fun allLiveCertificates(limit: Int = 300): LiveData<List<Certificate>>
我尝试过执行“ customer_objectemail”,但在将其解析为该数据对象时,似乎总是返回null:
data class Certificate(var id: Int,
var transactional_id: String? = null,
var customer_name: String? = null,
var date: String? = null,
var created_at: Long? = null,
var updated_at: Long? = null,
var unique_serial_no: String? = null,
var type_of_cert: String? = null,
var archived: Boolean = false,
var customer_address_line_one: String? = null,
var customer_address_line_two: String? = null,
var customer_city: String? = null,
var customer_postcode: String? = null,
var customer_county: String? = null,
var email: String? = null)
除了“电子邮件”外,每个字段都被填充。
有人能看到我做错了什么吗?