0

I am trying to create tables in an SQLite database with sqlite3.

The command $ sqlite3 mydb < mytables.sql produce the following error: Incomplete SQL: ??C.

mytables.sql is:

CREATE TABLE SizeCulture (
    SizeCultureID INTEGER PRIMARY KEY ASC,
    SizeID INTEGER NULL,
    CultureID TEXT NULL,
    Name TEXT NULL,
    Description TEXT NULL,
    Abbreviation TEXT NULL,
);

CREATE TABLE Size(
    SizeID INTEGER PRIMARY KEY ASC ,
    Creation TEXT NOT NULL,
    Modification TEXT NOT NULL,
    Deleted INTEGER NOT NULL,
);
/****** Object:  Table [Ordering].[BarCode]    Script Date: 11/09/2011 14:58:19 ******/
CREATE TABLE BarCode(
    BarCodeID INTEGER PRIMARY KEY ASC NOT NULL,
    BarCodeValue TEXT NOT NULL,
);

This was modified from a script generated by SQL Server, where some tables need to be replicated on an Android device.

The above is just a set of repeating create table statements. From what I understand, SQLite follows standard SQL (like MySQL or postgres).

2 Answers 2

2

Though I can't test it at the moment, I think it's the trailing commas that are confusing it (for example, the comma at the end of Abbreviation TEXT NULL,). Try removing all those trailing commas.

Edit: To be clear, I'm talking about all of these commas:

Abbreviation TEXT NULL,
...
Deleted INTEGER NOT NULL,
...
BarCodeValue TEXT NOT NULL,
Sign up to request clarification or add additional context in comments.

5 Comments

Tried that. I'm still getting the same error. There a few tables that reference a another table as the last line (or 2 lines in some cases).
@Mike: It works fine if you remove the stray trailing commas. Is there more to the SQL file than you're showing us?
@muistooshort The only thing that is not shown is 130 lines of creates statements for brevity. Create statements are that is in the fiel. I have removed the trailing commas, comments, and foreign key statements. I'm in the process of checking each create statement.
I ran the above command on the Android emulator through appropriate java classes, yet it only created the first table. Trying to create a test database through the OSX Terminal still results in the above error.
Make sure every statement has a semicolon at the end of it. I know it may not be a problem in your case, but I got the same error so if one of your create statements is missing it, it will fail.
0

I had the same problem, but for a different reason (so I'm commenting because Google led me here). Turns out you can also encounter this error if your file has a weird encoding (like UCS-2 instead of UTF8).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.