Using SQLite

software development

#1

Hello,

I’ve recently just installed SQLite 3.3.8 (the latest version) on my server, with pysqlite, and it works fine when I SSH into the server and a python shell.

However, I’ve realized that when my *.py scripts are being executed through CGI, that it is the old version of SQLite that is being run (2.x), which is installed by default on the server.

How do I solve this? Has anybody successfully used SQLite on DreamHost?

J.


#2

You have to use the sqlite3 command. sqlite will refer to SQLite 2.


#3

Thank you for your answer!

However, I have no idea how that translates in the context of pysqlite (the Python bindings for SQLite). I mean, I am not actually calling sqlite, it’s pysqlite that does all the work …

Any ideas?


#4

Howdy Jeremie,
Hey I just make a small Python test CGI. Here is the URL:

http://www.gordontillman.info/html/comp/python/test_sqlite.py

It’s really simple. Just imports the module and queries all of the non-callable dictionary keys from that module and prints out the result. It also spits out it’s own source so you can see what I’m doing.

Looks like it’s using sqlite version 3.2.1. My domain is running on “shekel”, so if you are on a different host your results may vary.

–gordon


#5

Dear Gordon,

Thank you very much for your script! It helped me indeed diagnose the problem. When I run it on my server, I get the following info:

sqlite_version 3.2.1
sqlite_version_info (3, 2, 1)

So I do have the same version as you.

But when I type ‘import pysqlite2’ from a python shell under SSH, I get version 3.3.8 (the sqlite that I installed in my home directory).

Do you know how I can make pysqlite2 use that sqlite version, instead of the one installed on the server? It seems setting PYTHONPATH would do the trick, but I don’t know how to do that in a way that the CGI will take it into account.

Thanks for your time!

Jérémie


#6

Jeremie I don’t have a way to test this idea, but… could you do something like this near the top of your python CGI:

import sys
sys.path.insert(0,path_to_your_sqlite)
from pysqlite2 import dbapi2 as sqlite

It’s my understanding that the PYTHONPATH equates to sys.path once you are in the script, so I’m wondering if prepending the path to your version of the sqlite module to sys.path before you import sqlite would do the trick.

–gordy