Entry
Connecting to gadfly database
Jul 5th, 2000 10:01
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 201, Oleg Broytmann
"""
Packages: database
"""
"""
> 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 -----