Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite: SQL error or missing database when inserting data into table

Tags:

sqlite

I am trying to insert new data into a SQLite table.

  • I know for sure that the insertion code is correct because I use it for different tables and it works fine.

  • I know for sure that the database and the table are created and exist because I can see them in the SQLite Browser.

But something in the SQLite syntax of creation or insertion is wrong because I receive this exception:

SQL error or missing database

Here is my code:

CREATE TABLE IF NOT EXISTS Theory_answers ("questionID" INTEGER,"answerID" INTEGER,"answerText" TEXT, "isTrue" INTEGER);

INSERT INTO Theory_answers (questionID, answerID, answerText,isTrue) VALUES ("1","1",text,"0");
like image 632
Luda Avatar asked Aug 11 '13 15:08

Luda


People also ask

What is insert or ignore in SQLite?

The INSERT OR IGNORE INTO statement ignores the error message. The SELECT statement shows that the last two statements did not modify the fourth row. Since SQLite version 3.7. 11 it is possible to insert multiple rows using one INSERT statement.

Is used to insert new rows into SQLite database tables?

SQLite INSERT INTO Statement is used to add new rows of data into a table in the database.

How many entries can SQLite handle?

Maximum Number Of Pages In A Database FileThe largest possible setting for SQLITE_MAX_PAGE_COUNT is 4294967294. When used with the maximum page size of 65536, this gives a maximum SQLite database size of about 281 terabytes. The max_page_count PRAGMA can be used to raise or lower this limit at run-time.


1 Answers

should this be....

VALUES ("1","1",text,"0") -> VALUES (1,1,'text',0)

Or

VALUES ("1","1","text","0") <-- if you need to double quote all values?

Looking at this link, it suggests inserts are done with single quote around the text and no quotes around the numbers...

sqlite> INSERT INTO Books(Id, Title, Author, ISBN) ...> VALUES(1, 'War and Peace', 'Leo Tolstoy', '978-0345472403');

like image 66
Christian Phillips Avatar answered Nov 24 '22 07:11

Christian Phillips