When I see the examples for pysqlite, there are two use cases for the SQLite library.
from sqlite3 import dbapi2 as sqlite3
and
import sqlite3
Why there are two ways to support the sqlite3 api? What's the difference between the two? Are they the same? In normal use, which would be preferred.
I knew that they are different in terms of namespace, and I wanted ask if they are the same in terms of usage, I mean, do they have the same API set?
Source code: Lib/sqlite3/ SQLite is a C library that provides a lightweight disk-based database that doesn't require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage.
Step 1 − Go to SQLite download page, and download precompiled binaries from Windows section. Step 2 − Download sqlite-shell-win32-*. Step 3 − Create a folder C:\>sqlite and unzip above two zipped files in this folder, which will give you sqlite3.
#!/usr/bin/python import sqlite3 conn = sqlite3. connect('test. db') print "Opened database successfully"; Here, you can also supply database name as the special name :memory: to create a database in RAM.
callback is not a function in sqlite.
They are the same. In the Lib/
directory of my Python installation (v2.6), the sqlite3
package contains a __init__.py
file with this:
from dbapi2 import *
Which means that the two ways of importing are absolutely identical.
That said, I definitely recommend just using import sqlite3
- as this is the documented approach.
They are not the same.
In the first case, you are importing the dbapi2 symbol from the sqlite3 module into the current namespace.
In the last case, you just import the sqlite3 module in the namespace.
The difference is that in the first case you can directly use dbapi2 (aliased as sqlite3) class, which in the latter case, you would have to reference to sqlite3.dbapi2
all the time you want to reference it.
See for more information the python documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With