Figen Güngör
Figen Güngör

Reputation: 12559

Database Access in Lua

I am trying to access a database that I created in SQLiteStudio and I exported it into my project folder. However, I am getting this error:

"File is encrypted or is not a database."

Here is my code:

 --Include sqlite
 require "sqlite3"
 --Open data.db.  If the file doesn't exist it will be created
 local path = system.pathForFile("library.sql", system.ResourceDirectory)
 db = sqlite3.open( path )   

 --Handle the applicationExit event to close the db
 local function onSystemEvent( event )
    if( event.type == "applicationExit" ) then              
        db:close()
    end
end


--print the sqlite version to the terminal
print( "version " .. sqlite3.version() )

--print all the table contents
for row in db:nrows("SELECT * FROM book") do
 local text = row.bookName
 local t = display.newText(text, 20, 30 * row.id, null, 16)
 t:setTextColor(255,0,255)
end

--setup the system listener to catch applicationExit
Runtime:addEventListener( "system", onSystemEvent )

Can you tell me why I am getting this error?

Upvotes: 0

Views: 853

Answers (1)

Oliver
Oliver

Reputation: 29493

The database is a .db file. You are using a SQL command "script" (or something else). If you create an empty database from command line you should be able to run that script (in sql-command-line or such) and recreate the database. Find where SQLiteStudio saved the actual database, a .db file.

Upvotes: 2

Related Questions