simple sql.py :  » Network » PyWX » PyWX-1.0b2 » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » PyWX 
PyWX » PyWX 1.0b2 » examples » simple-sql.py
import Ns, sys


psql_fmt = """\
<p>%s:
<blockquote><b>
%s
</b></blockquote>
</p>
"""

failed_string = """\
<blockquote><p>
<font color=red><i>(failed)</i></font>
</p></blockquote>
"""

def psql(msg,sql):
    print psql_fmt % (msg,sql,)


print 'Content-type: text/html\n'

print '''\
<body bgcolor=white>

<h2>Simple SQL commands</h2>
<i>Warning:</i>
You need to have an SQL database installed with AOLserver in order to
run this script.
<p>
This script runs a bunch of SQL commands through the AOLserver
database interface system.
<p>
<hr>
'''

conn = Ns.GetConn()

try:
    db = Ns.DbHandle(Ns.DbPoolDefault(conn.Server()))
except:
    print 'Can\'t get handle -- do you have a database installed??'

sql = 'CREATE TABLE pywx_test (i INTEGER, j INTEGER)'
psql('Creating table pywx_test', sql)

try:
    db.DML(sql)
except:
    print failed_string

for i in range(0, 3):
    sql = 'INSERT INTO pywx_test VALUES (%d, %d)' % (i, i)

    psql('Inserting (%d, %d) into pywx_test' % (i,i), sql)

    try:
        db.DML(sql)
    except:
        print failed_string

sql = 'SELECT i,j FROM pywx_test'

psql('Selecting from pywx_test', sql)

try:
    results = db.Select(sql)

    while db.GetRow(results) == Ns.OK:
        print 'Got row: %s, %s<br>' % (results['i'], results['j'])
except:
    print failed_string

sql = 'DROP TABLE pywx_test'
psql('Dropping table pywx_test', sql)

try:
    db.DML(sql)
except:
    print failed_string

del db

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.