You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a workaround, I tried using a literal to avoid expressions but this did not work:
//Successvarquery="SELECT * FROM STOCKS_CORN_LOCATION"letstatement= db.prepare(query)
while ((statement.next())!=nil){letrow= statement.columnNames
println(row)}//Failurevarquery="SELECT 2011301_ON FROM STOCKS_CORN_LOCATION"letstatement= db.prepare(query)
while ((statement.next())!=nil){letrow= statement.columnNames
println(row)}
The text was updated successfully, but these errors were encountered:
ericcgu
changed the title
Query Fails when Field leads with a Number
Query Fails when Field Contains a Number
Jan 20, 2015
ericcgu
changed the title
Query Fails when Field Contains a Number
Expression fails when Field Contains a Number
Jan 20, 2015
When was the last time you updated your SQLite.swift submodule? I can get the following to run just fine on master:
letdb=Database()
db.trace(println)letusers=db["users"]letfield=Expression<String>("19500301_OFF")
db.create(table: users){ $0.column(field)}
users.insert(field <-"Hello")!
for user in users.select(field){println(user[field])}
Console output:
CREATE TABLE "users" ("19500301_OFF" TEXT NOT NULL)
INSERT INTO "users" ("19500301_OFF") VALUES ('Hello')
SELECT "19500301_OFF" FROM "users"
Hello
Ah, you know what, I think your issue is in your raw SQL syntax:
SELECT 2011301_ON FROM STOCKS_CORN_LOCATION
The above is invalid. You must quote identifiers (generally using ") that contain spaces or begin with numbers. SQLite.swift automatically quotes expressions for you, so as long as you're using the type-safe interface, things should just work. If you're writing raw SQL, however, you'll need to be careful to quote things yourself wherever necessary.
After numerous testing, I believe that Query fails when Column heading contains a Number:
Here is my repo: If anyone can shed some light, I would appreciate it:
https://github.com/ericcgu/RWEGSeed/blob/NumericalColumnNames/Seed/RWEGFrequencyByLocationTableViewController.swift
As a workaround, I tried using a literal to avoid expressions but this did not work:
The text was updated successfully, but these errors were encountered: