title: Wrong SELECT output with SQLite3 and Swift
body: <p>I have a task to make a mobile app in Swift to store data about students. When entering the app, the database should be created. There should be a text field, from which a user can insert his name into the database, and a button to reload the page and look at all the names in DB. Also, the date of creation should be stored in the database.
  I have the following code:</p>
  
  <pre><code>import UIKit
  import SQLite3
  
  class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
      var db: OpaquePointer?
      var Students = [Student]()
  
      @IBOutlet weak var textFieldName: UITextField!
      @IBAction func buttonSave(_ sender: UIButton) {
          //getting values from textfields
          let name = textFieldName.text?.trimmingCharacters(in: .whitespacesAndNewlines)
          let d = Date()
          let formatter = DateFormatter()
          formatter.dateFormat = "dd.MM.yyyy"
          let date = formatter.string(from: d)
  
          //validating that values are not empty
          if(name?.isEmpty)!{
              textFieldName.layer.borderColor = UIColor.red.cgColor
              return
          }
  
          //creating a statement
          var stmt: OpaquePointer?
  
          //the insert query
          let queryString = "INSERT INTO Students (name, date) VALUES (?,?)"
  
          //preparing the query
          if sqlite3_prepare(db, queryString, -1, &amp;stmt, nil) != SQLITE_OK{
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("error preparing insert: \(errmsg)")
              return
          }
  
          //binding the parameters
          if sqlite3_bind_text(stmt, 1, name, -1, nil) != SQLITE_OK{
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("failure binding name: \(errmsg)")
              return
          }
  
          if sqlite3_bind_text(stmt, 2, date, -1, nil) != SQLITE_OK{
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("failure binding date: \(errmsg)")
              return
          }
  
          //executing the query to insert values
          if sqlite3_step(stmt) != SQLITE_DONE {
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("failure inserting student: \(errmsg)")
              return
          }
  
          //emptying the textfields
          textFieldName.text=""
          readValues()
  
          //displaying a success message
          print("Student saved successfully")
      }
  
      @IBOutlet weak var tableViewStudents: UITableView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
              .appendingPathComponent("StudentsDatabase.sqlite")
  
          if sqlite3_open(fileURL.path, &amp;db) != SQLITE_OK {
              print("error opening database")
          }
  
          if sqlite3_exec(db, "DROP TABLE Students", nil, nil, nil) != SQLITE_OK {
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("error deleting table: \(errmsg)")
          }
  
          if sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS Students (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, date TEXT)", nil, nil, nil) != SQLITE_OK {
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("error creating table: \(errmsg)")
          }
  
      }
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return Students.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
          let student: Student
          student = Students[indexPath.row]
          print(student.name)
          cell.textLabel?.text = student.name
          return cell
      }
  
      func readValues(){
          //first empty the list of heroes
          Students.removeAll()
  
          //this is our select query
          let queryString = "SELECT * FROM Students"
  
          //statement pointer
          var stmt:OpaquePointer?
  
          //preparing the query
          if sqlite3_prepare(db, queryString, -1, &amp;stmt, nil) != SQLITE_OK{
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("error preparing select: \(errmsg)")
              return
          }
  
          //traversing through all the records
          while(sqlite3_step(stmt) == SQLITE_ROW){
              let id = sqlite3_column_int(stmt, 0)
              let name = String(cString: sqlite3_column_text(stmt, 1))
              let date = String(cString: sqlite3_column_text(stmt, 2))
  
              //adding values to list
              Students.append(Student(id: Int(id), name: String(name), date: String(date)))
          }
          tableViewStudents.reloadData()
      }
  }
  
  class Student {
      var id: Int
      var name: String
      var date: String
  
      init(id: Int, name: String, date: String){
          self.id = id
          self.name = name
          self.date = date
      }
  }
  </code></pre>
  
  <p>The thing is, for some reason the name of a student doesn't appear in the table. Instead, only a slice of date is shown, sliced by the number of letters in the name of a student. So if I try to insert "John" on the 18th of May, it will return "18.0" - 4 symbols picked from the date.
  Any help on how to fix this is appreciated.</p>