0

While loading sql query its throwing error

near "CLUSTERED": syntax error

import SQLite3
var db: OpaquePointer?
let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
            .appendingPathComponent("HeroesDatabase.sqlite")
        if sqlite3_open(fileURL.path, &db) != SQLITE_OK {
            print("error opening database")
        }
        let sqlString = """
            CREATE TABLE Dim_Date
        (Calendar_Date DATE NOT NULL CONSTRAINT PK_Dim_Date PRIMARY KEY CLUSTERED,Calendar_Date_String VARCHAR(10) NOT NULL)
        """


 if sqlite3_exec(db, sqlString, nil, nil, nil) != SQLITE_OK {
            let errmsg = String(cString: sqlite3_errmsg(db)!)
            print("error creating table: \(errmsg)")//Here Error throws
        }

Actually i am trying to achieve this https://www.sqlshack.com/designing-a-calendar-table/

Amit
  • 556
  • 1
  • 7
  • 24
  • `CLUSTERED` is not a SQLite keyword. If you want a table with a clustered index, then use a `WITHOUT ROWID` table, if you're using SQLite version 3.8.2 or later. – Tim Biegeleisen Oct 08 '18 at 06:31
  • @TimBiegeleisen can you please put SQL query as comment. I am newbee hence i need helping hand. – Amit Oct 08 '18 at 06:37
  • 1
    Just read the accepted answer from the duplicate link. I didn't think it was worth paraphrasing that answer in my own answer here. – Tim Biegeleisen Oct 08 '18 at 06:38

0 Answers0