I am new to iOS and SWIFT but making progress.
I use SQLITE database to store employee details. While querying data, I need to filter output with a WHERE clause restricting it to just one row. The query doesn't give any output, but if I remove the WHERE clause, it works. I need to be able to filter query output to a specific i-phone of user.
This is a static function within a class I use in many places across the App. My Code:
// ***********************************
static func queryPhoneOwner() {
let queryPhoneOwnerString = "SELECT EMPLOYEE_ID, FULL_NAME, LOCATION, UUID FROM MT_PHONE_OWNER WHERE UUID = ?"
var queryPhoneOwnerStatement: OpaquePointer? = nil
let db = DatabaseClass.openDatabase()
var vUUID: String = " "
if sqlite3_prepare_v2(db, queryPhoneOwnerString, -1, &queryPhoneOwnerStatement, nil) == SQLITE_OK {
if let uuid = UIDevice.current.identifierForVendor?.uuidString {
vUUID = uuid
}
sqlite3_bind_text(queryPhoneOwnerStatement, 1, vUUID, -1, nil)
while (sqlite3_step(queryPhoneOwnerStatement) == SQLITE_ROW) {
let queryResultCol1 = sqlite3_column_text(queryPhoneOwnerStatement, 0)
let vOwnerEmployeeId = String(cString: queryResultCol1!)
let queryResultCol2 = sqlite3_column_text(queryPhoneOwnerStatement, 1)
let vOwnerFullName = String(cString: queryResultCol2!)
let queryResultCol3 = sqlite3_column_text(queryPhoneOwnerStatement, 2)
let vOwnerLocation = String(cString: queryResultCol3!)
let queryResultCol4 = sqlite3_column_text(queryPhoneOwnerStatement, 3)
let vOwnerUuid = String(cString: queryResultCol4!)
// and the code continues..
// FYI, Table columns pasted here from table creation process: "CREATE TABLE IF NOT EXISTS MT_PHONE_OWNER (EMPLOYEE_ID VARCHAR(10) PRIMARY KEY, FULL_NAME VARCHAR(50), LOCATION VARCHAR(15), UUID VARCHAR2(45) NOT NULL)"
//********************************************