Using SQLite in p3d...

I’m currently using SQLite to read contents from a local database file, which works perfectly fine outside of a p3d package. When I packed the game up into a p3d package and tried running it, it doesn’t seem like SQLite could find the file as it outputs the following:

sqlite3.OperationalError: unable to open database file

I’m assuming it has to deal with SQLite not working well with the VFS? If so, is it even possible for SQLite to load up the database file?

Hi, I dunno the specific’s of the SQLite code, but I do know that in my own attempts of loading maps outside p3d’s I’ve had to to the following:

On second thought, I may have misunderstood your question… Is the SQLite DB file inside the p3d? in which case you should have no problem… is it located inside the directory when you pack it?

import os
import sys
from pandac.PandaModules import Filename

if sys.platform == 'win32':
	#- Windows uses \ which means slash is '\\' instead
	slash = '\\'
	#- Linux and Mac use standard / slashes
	slash = '/'

#- I expected this toOsSpecific code to give an panda3d file path..
#- But alas it returns weirdly, so we will fix the path afterwords
#- We are assigning our 'Main Directory' if you will, to = Filename(os.getcwd() + slash).toOsSpecific()

if sys.platform == 'win32':
	#- If the path is windows we need to fix some stuff

	#- Replace the windows \\ slashes with unix / slashes ='\\', '/')
	#- Replace the windows 'C:' bracket with '/c'
	#- Note: this will only work if you have a C: drive running the p3d file! ='C:', '/c')

	#- Otherwise we just tack a unix slash on the end: = + slash

print 'Path to the p3d file's directory is: %s' %

The database file and everything else are all in one p3d package, but it still doesn’t work.

P3d files are read only (at least the main one you are running from). Also, most file extensions don’t even get saved to p3d files unless you request it when making the file, so the database is likely also missing

It’s also likely that SQLlite is using a C++ layer to open the file, which means it won’t be able to hook into Panda’s VFS automatically. So, yeah, storing a SQL database within the p3d file seems problematic.

If your goal is to provide some read-only data to your application, maybe you can pre-process the data into another form (for instance, a .py file with a big list assignment) that can be easily read at runtime.


You’re right. The database file was not included in the p3d package. But even added, it still doesn’t work. I’ve even tried different path configurations like /mf, relative and absolute and still nothing.

Okay, so it does have to do with Panda’s VFS and if that’s really the case, I’ll just have to dump the content into a .py file like you said.

Anyways, thanks a lot guys!