Snippet request: Connecting to databases
Oleg Broytmann
phd at phd.russ.ru
Fri Oct 22 11:06:30 EDT 1999
On Fri, 22 Oct 1999, Hans Nowak wrote:
> The request is kinda easy... I'm looking for snippets to connect to
> databases. Any OS goes, idem for database (SQL Server, Access, Oracle,
> ...). A simple demonstration of how to connect and how to read a record
> or so, would do, although additional information (about requirements and
> such; which modules are needed, etc) is always welcome.
Gadfly - pure Python SQL engine; could work on any platform as Python could.
----- create database -----
#! /usr/local/bin/python
import os, gadfly
os.mkdir("gf_test")
connection = gadfly.gadfly()
connection.startup("ph", "gf_test")
cursor = connection.cursor()
cursor.execute("create table ph (nm varchar, ph varchar)")
cursor.execute("insert into ph(nm, ph) values ('arw', '3367')")
cursor.execute("select * from ph")
for x in cursor.fetchall():
print x
connection.commit()
connection.close()
----- /create database -----
----- use database -----
#! /usr/local/bin/python
import gadfly
connection = gadfly.gadfly("ph", "gf_test")
cursor = connection.cursor()
cursor.execute("select * from ph")
for x in cursor.fetchall():
print x
connection.close()
----- /use database -----
Oleg.
----
Oleg Broytmann Foundation for Effective Policies phd at phd.russ.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-list
mailing list