title: Failure preparing: bad parameter or other API misuse in SQLite swift while inserting data
body: <pre><code>let db = Database.openDatabase()
  
  let insertStatementString = "INSERT INTO SignupDetails VALUES (\((self.txtUsername.text!.trimmingCharacters(in: .whitespaces))), \((self.txtPassword.text!.trimmingCharacters(in: .whitespaces))))"
  
  Database.insertIntoSignupDetails(db: db, insertStatementString: insertStatementString)
  
  sqlite3_close(db)
  </code></pre>
  
  <p>The above code contains my query for insert data into the database using SQLite.</p>
  
  <p>I have created a table as shown as below:-</p>
  
  <pre><code>let db = Database.openDatabase()
  let createTableString =
      """
          CREATE TABLE IF NOT EXISTS SignupDetails(
          username CHAR(255),
          password CHAR(255));
          """
  
  Database.createTable(db: (db != nil) ? db : OpaquePointer(UserDefaults.standard.object(forKey: Constant.db) as! String), createTableString: createTableString)
  
  sqlite3_close(db)
  </code></pre>
  
  <p>and I have also successfully executed the following code for table creation:-</p>
  
  <pre><code>static func createTable(db: OpaquePointer?, createTableString: String) {    
      var createTableStatement: OpaquePointer? = nil
  
      if sqlite3_prepare_v2(db, createTableString, -1, &amp;createTableStatement, nil) == SQLITE_OK {
          if sqlite3_step(createTableStatement) == SQLITE_DONE {
              print("table created.")
          } else {
              print("table could not be created.")
          }
      } else {
          print("CREATE TABLE statement could not be prepared.")
      }
  
      sqlite3_finalize(createTableStatement)
  }
  </code></pre>
  
  <p>But my problem is when I am trying to insert data into that existing table<br>
  getting the error shown as below :-</p>
  
  <p>Code:-</p>
  
  <pre><code>    var insertStatement: OpaquePointer?
  
  
      guard sqlite3_prepare_v2(db, insertStatementString, -1, &amp;insertStatement, nil) == SQLITE_OK else {
          let errmsg = String(cString: sqlite3_errmsg(db))
          print("failure preparing: \(errmsg)")
          return
      }
  
      if sqlite3_step(insertStatement) == SQLITE_OK {
          print("Successfully inserted row.")
      } else {
          print("Could not insert row.")
      }
  
      sqlite3_finalize(insertStatement)
  </code></pre>
  
  <p>Error:-</p>
  
  <p>failure preparing: bad parameter or other API misuse     </p>