Prashant Aggarwal
Prashant Aggarwal

Reputation: 59

Use of undeclared type 'sqlite3_stmt'

I am trying to insert a value in Sqlite in Swift 3.0. But I am getting an error "Use of undeclared type 'sqlite3_stmt'. Can anyone help me to solve this problem or let me know if i am doing anything wrong ?

#import <sqlite3.h> (in bridging header)

var statement: sqlite3_stmt? = nil
var database = DBConnectionManager.getDatabaseObject()
var sQuery: String = "insert into tblfavoritemaster(category_type,quote_text,category_id) values('abc','test','3')"

    if sqlite3_prepare_v2(database, sQuery.utf8, -1, statement, nil) == SQLITE_OK {
        if sqlite3_step(statement) == SQLITE_DONE {
            print("Insert Successfully")
        }
    }

Upvotes: 1

Views: 1583

Answers (1)

Tushar Sharma
Tushar Sharma

Reputation: 2882

YOUR statement should be of type COpaquePointer and access it using &Statement

func insert() {
      var statement: COpaquePointer = nil

     let insertStatementString = "INSERT INTO Contact (Id, Name) VALUES (?, ?);"

      // 1
      if sqlite3_prepare_v2(db, insertStatementString, -1, &statement, nil) == SQLITE_OK {
        let id: Int32 = 1
        let name: NSString = "Ray"

        // 2
        sqlite3_bind_int(statement, 1, id)
        // 3
        sqlite3_bind_text(statement, 2, name.UTF8String, -1, nil)

        // 4
        if sqlite3_step(statement) == SQLITE_DONE {
          print("Successfully inserted row.")
        } else {
          print("Could not insert row.")
        }
      } else {
        print("INSERT statement could not be prepared.")
      }
      // 5
      sqlite3_finalize(statement)
    }

Upvotes: 3

Related Questions