1

I am working on the sqlite3 to save and get data.

And i followed two tutorial to link1 link2

in both of the links data is saved and get by using binding statements like to save :-

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

    if sqlite3_step(statement) != SQLITE_DONE {
        let errmsg = String(cString: sqlite3_errmsg(db)!)
        print("failure inserting foo: \(errmsg)")
    }

and to get:-

        let id = sqlite3_column_int64(statement, 0)
        print("id = \(id); ", terminator: "")

        if let cString = sqlite3_column_text(statement, 1) {
            let name = String(cString: cString)
            print("name = \(name)")
        } 

But as in my projects there are many tables for to save and get get data i don't want to use seperate get and save function for each table.

How should i make common functions so that for each time saving data in any table i just have to send values.

for this approach i get to know about the generics process. But i dont know how to use it.

kindly help me out

Parv Bhasker
  • 1,773
  • 1
  • 20
  • 39

0 Answers0