1

Below I am sharing my existing code which I have used for executing the where IN condition but now I am stuck in how to pass the values in the request.

public func getName(list: [String], class: String) -> [String] {
    let queryStatementString = "SELECT terms FROM termo WHERE terms IN =? AND class=?"
    var queryStatement: OpaquePointer? = nil
    var arr : [String] = []
    
    if sqlite3_prepare_v2(db, queryStatementString, -1, &queryStatement, nil) == SQLITE_OK {
        if sqlite3_bind_text(queryStatement, 1,terminalNameList, -1, SQLITE_TRANSIENT) != SQLITE_OK {
            let errmsg = String(cString: sqlite3_errmsg(db)!)
            print("failure binding foo: \(errmsg)")
        }
        while sqlite3_step(queryStatement) == SQLITE_ROW {
            let ter = String(describing: String(cString: sqlite3_column_text(queryStatement, 0)))
            arr.append(ter)
        }
    } else {
        print("SELECT statement could not be prepared")
    }
    sqlite3_finalize(queryStatement)
    return arr
}

The below is my SQL query which I need to execute

let queryStatementString = "SELECT terms FROM termo WHERE terms IN =? AND class=?"

Here I am trying to pass the values

if sqlite3_bind_text(queryStatement, 1, list, -1, SQLITE_TRANSIENT) != 
 SQLITE_OK {
            let errmsg = String(cString: sqlite3_errmsg(db)!)
            print("failure binding foo: \(errmsg)")
        }

Please guys help me, Thanks in advance

Yatish Agrawal
  • 452
  • 5
  • 15
  • 1
    What is this question about? Is it about how to make a query with SQLite per se? What are the objective-c and sqlite.swift tags for? – El Tomato Jun 20 '21 at 22:24
  • I am using SQLite in the swift in which I am stuck in the Where In a statement, so I am looking for the solution – Yatish Agrawal Jun 21 '21 at 04:45

1 Answers1

0

You can take the help of below example to build a select query with where clause

  let query = users.select(email)           // SELECT "email" FROM "users"
             .filter(name != nil)     // WHERE "name" IS NOT NULL
             .order(email.desc, name) // ORDER BY "email" DESC, "name"
             .limit(5, offset: 1)     // LIMIT 5 OFFSET 1

You can find more info here

MrinmoyMk
  • 551
  • 7
  • 21