Python tutorial- fetch data from Gadfly database

Fetch data from Gadfly database

Gadfly is a pure Python relational database written in Python. Its main features include compliance with the Python database API, cross-platforms, transaction log and recovery procedure, client-server mode, and security policies to prevent accidental data deletion.
To connect Gadfly database system, you need to install it module. It can be found at in zip file. To install it, you just unpack the zip file, use cd command from DOS prompt to enter the unpacked folder and run the following command: python install
After installing Gadfly, you can try the following code to create a new database, a new table, and inset some test data.
import os
import gadfly
conn= gadfly.gadfly()
conn.startup('cusdb', 'customerdb')
cur= conn.cursor()
# Create tables.
CREATE TABLE tblcustomerlist(
Name varchar(20),
Email varchar(25),
Tel varchar(20),
Address varchar(150)
query="INSERT INTO tblcustomerlist Values('Dara Yuk','', '855 256 724', 'No.252, st.265,Phnom Penh, Cambodia')"
To reconnect to the gadfly database, you don’t need to use startup() method. You can supply the database name and its path as arguments of gadfly() method directly.
import gadfly
conn= gadfly.gadfly('cusdb', 'customerdb')
cur= conn.cursor()
queryin="INSERT INTO tblcustomerlist Values('Khorn Channa','', '855 123 907', 'No.152, st.265 ,Phnom Penh, Cambodia')"
queryse="SELECT * FROM tblcustomerlist"

for row in cur.fetchall():
            print '%-20s%-25s%-20s%s' % (row[0],row[1],row[2],row[3])
The table below shows the common types used in SQLite and Gadfly.
Type used in SQLite Type used in  Gadfly Description
TEXT varchar For field that stores string value and Unicode characters
INTEGER integer For field that stores integer value
INTEGER integer For field that stores long integer value
REAL float For field that stores float value


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.