0% found this document useful (0 votes)
3 views5 pages

SQLITE3

SQLite is a lightweight disk-based database library that allows access through a variant of SQL without needing a separate server. The sqlite3 module provides a DB-API 2.0 compliant interface and includes functions for connecting to databases, registering type converters, and checking SQL statement completeness. Key features include version information, type parsing options, and the ability to handle in-memory databases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

SQLITE3

SQLite is a lightweight disk-based database library that allows access through a variant of SQL without needing a separate server. The sqlite3 module provides a DB-API 2.0 compliant interface and includes functions for connecting to databases, registering type converters, and checking SQL statement completeness. Key features include version information, type parsing options, and the ability to handle in-memory databases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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. It’s also possible
to prototype an application using SQLite and then port the code to a
larger database such as PostgreSQL or Oracle.

The sqlite3 module was written by Gerhard Häring. It provides a SQL


interface compliant with the DB-API 2.0 specification described
by PEP 249.

Module functions and constants:

sqlite3.version
The version number of this module, as a string. This is not the
version of the SQLite library.

sqlite3.version_info
The version number of this module, as a tuple of integers. This is
not the version of the SQLite library.

sqlite3.sqlite_version

The version number of the run-time SQLite library, as a string.

sqlite3.sqlite_version_info
The version number of the run-time SQLite library, as a tuple of
integers.
sqlite3.PARSE_DECLTYPES
This constant is meant to be used with the detect_types parameter
of the connect() function.

Setting it makes the sqlite3 module parse the declared type for
each column it returns. It will parse out the first word of the
declared type, i. e. for “integer primary key”, it will parse out
“integer”, or for “number(10)” it will parse out “number”. Then for
that column, it will look into the converters dictionary and use the
converter function registered for that type there.

sqlite3.PARSE_COLNAMES

This constant is meant to be used with the detect_types parameter


of the connect() function.

Setting this makes the SQLite interface parse the column name for
each column it returns. It will look for a string formed [mytype] in
there, and then decide that ‘mytype’ is the type of the column. It
will try to find an entry of ‘mytype’ in the converters dictionary
and then use the converter function found there to return the value.
The column name found in Cursor.description does not include the
type,i.e.ifyouuse something like 'as "Expiration date [datetime]"' in
your SQL, then we will parse out everything until the first '[' for
the column name and strip the preceeding space: the column name
would simply be “Expiration date”.

sqlite3.connect(database[, timeout, detect_types, isolation_level, check_


same_thread, factory, cached_statements, uri])
Opens a connection to the SQLite database file database. By
default returns a Connection object, unless a custom factory is
given.

database is a path-like object giving the pathname (absolute or


relative to the current working directory) of the database file to be
opened. You can use ":memory:" to open a database connection to
a database that resides in RAM instead of on disk.

When a database is accessed by multiple connections, and one of


the processes modifies the database, the SQLite database is locked
until that transaction is committed. The timeout parameter specifies
how long the connection should wait for the lock to go away until
raising an exception. The default for the timeout parameter is 5.0
(five seconds).

sqlite3.register_converter(typename, callable)
Registers a callable to convert a bytestring from the database into a
custom Python type. The callable will be invoked for all database
values that are of the type typename. Confer the
parameter detect_types of the connect() function for how the type
detection works. Note that typename and the name of the type in
your query are matched in case-insensitive manner.

sqlite3.register_adapter(type, callable)
Registers a callable to convert the custom Python type type into
one of SQLite’s supported types. The callable callable accepts as
single parameter the Python value, and must return a value of the
following types: int, float, str or bytes.

sqlite3.complete_statement(sql)
Returns True if the string sql contains one or more complete SQL
statements terminated by semicolons. It does not verify that the
SQL is syntactically correct, only that there are no unclosed string
literals and the statement is terminated by a semicolon.

You might also like