I am trying to insert data from array into my table. If the insert is done I think, its suppose to print it in the console, but it is not. So I tried db.trace(println) and it shows me
SELECT * FROM "formatedData1"
My createDatabase function:
func createDatabase(){
var data = db["formatedData1"]
db.create(table: data, ifNotExists: true){ d in
d.column(type, primaryKey: true)
d.column(ada)
d.column(code)
d.column(name)
d.column(proof)
d.column(size)
d.column(case_size)
d.column(price)
}
for var i = 0; i < self.dataArrayMut.count; ++i{
data.insert(type <- (self.dataArrayMut[i].valueForKey("Type") as! String), ada <- (self.dataArrayMut[i].valueForKey("ADA") as! String), code <- (self.dataArrayMut[i].valueForKey("Code") as! String), name <- (self.dataArrayMut[i].valueForKey("Name") as! String), proof <- (self.dataArrayMut[i].valueForKey("Proof") as! String), size <- (self.dataArrayMut[i].valueForKey("Size") as! String), case_size <- (self.dataArrayMut[i].valueForKey("CaseSize") as! String), price <- (self.dataArrayMut[i].valueForKey("Price") as! String))
}
db.trace(println)
}
Then I tried to run queries on the table to see if the data exists.
1st query:
//Select * From data
let all = Array(data)
println(all.description)
And when I print it I get
[SQLite.Row, SQLite.Row, SQLite.Row, SQLite.Row, SQLite.Row, SQLite.Row, SQLite.Row, SQLite.Row]
2nd Query
//Select name From data where type = rum
let query = data.select(name)
.filter(type == "Rum")
println(query)
And when I print it I get
"formatedData1"
3rd Query I wanted to print all rows only from two columns.
for datas in data.select(type, name){
println("type: \(data[type]), name: \(data[name])")
}
And It prints
SELECT "Type", "Name" FROM "formatedData1"
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
type: SQLite.Expression<Swift.String>, name: SQLite.Expression<Swift.String>
Sorry for long question but any help would be highly appreciated.