sqliteshellsql-viewsqlitestudio

Why can't I create this SQLite view using the command line?


When I run the query below in SQLiteStudio, the view is successfully created.

CREATE VIEW BeatsEventsView AS
    SELECT BeatId,
           EventId,
           Hero,
           Beat,
           AdaptationPhase,
           Essence,
           Act,
           Events.[Desc]
      FROM BeatEvents,
           Beats,
           Events
     WHERE (BeatEvents.EventId = Events.Id) AND 
           (BeatEvents.BeatId = Beats.Id);

However, I get Error: near line 1: near "CREATE": syntax error if I put it into a file and run the command below.

sqlite3 $DB_FILE < $BASE_DIR/src/BeatsEventsView.sql.txt   

How can I create this view in a shell script?

Running the command file BeatsEventsView.sql.txt results in this output:

BeatsEventsView.sql.txt: UTF-8 Unicode (with BOM) text

Solution

  • Thanks to the help of @Shawn I fixed the error by adding

    -- -*- mode: sql; coding: utf-8 -*-

    at the beginning of the file so that it looks like shown below.

    -- -*- mode: sql; coding: utf-8 -*-
    CREATE VIEW BeatsEventsView AS
        SELECT BeatId,
               EventId,
    ...
    

    After saving it with Emacs, the file BeatsEventsView.sql.txt command now returns

    BeatsEventsView.sql.txt: ASCII text