Sqlite3 database problems, what am I doing wrong here?

I’m having the worst time getting this to work. What am I doing wrong? This appears to work until I try and read the table with nrows() at which point I get the error: No such table: words. The two previous results print 1, which I’m assuming means they executed successfully. I see data.db in the project Documents folder, but it’s empty. 

local table_name = “words”

local sqlite = require( “sqlite3” )

local path = system.pathForFile( “data.db”, system.DocumentsDirectory )

local db = sqlite3.open( path )

local results = db:exec( [[CREATE TABLE IF NOT EXISTS]]…table_name…[[ 

        (id INTEGER PRIMARY KEY autoincrement, word, solved, index ); ]] )

print( “Create table results:”, results )

results = db:exec( "INSERT INTO "…table_name…“VALUES (NULL, ‘HELLO’, ‘false’, ‘1’ )” )

print( “Insert row results:”, results )

for row in db:nrows( "SELECT * FROM " … table_name ) do

    print( row.word )

end 

Hi, You need to specify the column names that you insert into http://www.w3schools.com/sql/sql_insert.asp

Ah, also the data types - string, integer when you create the table columns :slight_smile:

Thanks for the replies. I see what you are saying. I followed this article here: http://www.coronalabs.com/blog/2012/04/03/tutorial-database-access-in-corona/. The examples in this article worked in another project. 

Hi, You need to specify the column names that you insert into http://www.w3schools.com/sql/sql_insert.asp

Ah, also the data types - string, integer when you create the table columns :slight_smile:

Thanks for the replies. I see what you are saying. I followed this article here: http://www.coronalabs.com/blog/2012/04/03/tutorial-database-access-in-corona/. The examples in this article worked in another project.