2006-04-21 07:40:58 -03:00
|
|
|
# pysqlite2/__init__.py: the pysqlite2 package.
|
|
|
|
#
|
2010-08-30 11:05:50 -03:00
|
|
|
# Copyright (C) 2005 Gerhard Häring <gh@ghaering.de>
|
2006-04-21 07:40:58 -03:00
|
|
|
#
|
|
|
|
# This file is part of pysqlite.
|
|
|
|
#
|
|
|
|
# This software is provided 'as-is', without any express or implied
|
|
|
|
# warranty. In no event will the authors be held liable for any damages
|
|
|
|
# arising from the use of this software.
|
|
|
|
#
|
|
|
|
# Permission is granted to anyone to use this software for any purpose,
|
|
|
|
# including commercial applications, and to alter it and redistribute it
|
|
|
|
# freely, subject to the following restrictions:
|
|
|
|
#
|
|
|
|
# 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
# claim that you wrote the original software. If you use this software
|
|
|
|
# in a product, an acknowledgment in the product documentation would be
|
|
|
|
# appreciated but is not required.
|
|
|
|
# 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
# misrepresented as being the original software.
|
|
|
|
# 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
2021-10-28 16:55:27 -03:00
|
|
|
"""
|
2022-03-28 15:44:41 -03:00
|
|
|
The sqlite3 extension module provides a DB-API 2.0 (PEP 249) compliant
|
2021-10-28 16:55:27 -03:00
|
|
|
interface to the SQLite library, and requires SQLite 3.7.15 or newer.
|
|
|
|
|
2021-11-15 18:22:42 -04:00
|
|
|
To use the module, start by creating a database Connection object:
|
2021-10-28 16:55:27 -03:00
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
cx = sqlite3.connect("test.db") # test.db will be created or opened
|
|
|
|
|
2021-11-15 18:22:42 -04:00
|
|
|
The special path name ":memory:" can be provided to connect to a transient
|
2021-10-28 16:55:27 -03:00
|
|
|
in-memory database:
|
|
|
|
|
|
|
|
cx = sqlite3.connect(":memory:") # connect to a database in RAM
|
|
|
|
|
2021-11-15 18:22:42 -04:00
|
|
|
Once a connection has been established, create a Cursor object and call
|
|
|
|
its execute() method to perform SQL queries:
|
2021-10-28 16:55:27 -03:00
|
|
|
|
|
|
|
cu = cx.cursor()
|
|
|
|
|
|
|
|
# create a table
|
|
|
|
cu.execute("create table lang(name, first_appeared)")
|
|
|
|
|
|
|
|
# insert values into a table
|
|
|
|
cu.execute("insert into lang values (?, ?)", ("C", 1972))
|
|
|
|
|
|
|
|
# execute a query and iterate over the result
|
|
|
|
for row in cu.execute("select * from lang"):
|
|
|
|
print(row)
|
|
|
|
|
|
|
|
cx.close()
|
|
|
|
|
|
|
|
The sqlite3 module is written by Gerhard Häring <gh@ghaering.de>.
|
|
|
|
"""
|
|
|
|
|
2006-08-17 17:24:18 -03:00
|
|
|
from sqlite3.dbapi2 import *
|