Welcome, guest | Sign In | My Account | Store | Cart

Dependencies 1) Windows Machine, 2) Python2.2 with win32 extensions installed 3) Apache Webserver for win32 This code queries the Northwind Database's "Order Details" Table..Make sure the path of the DB is correct and the query u are using is also accurate cause this does not give any error outputs but writes it in Apache's error.log file... copy this file in the cgi-bin directory and call it from the web browser as http://localhost/cgi-bin/ADO.py (file name). The only problem is the currency field, I cannot obtain the currency field properly it is obtained as a tuple !! hope u can help me ! :)

Python, 37 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ADO.py
#!C:\Python22\python
print "Content-type:text/html\n\n"
import win32com.client

NUM_ROWS=2155
#db='E:\Workarea\\Northwind.mdb'
db='C:\\Program Files\\Microsoft Office\\Office\\Samples\\Northwind.mdb'
def connect(qry):
	con=win32com.client.Dispatch('ADODB.Connection')
	rs=win32com.client.Dispatch('ADODB.recordset')
	con.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+db)
	sql=qry +";"
	rs=con.Execute(sql)
	con.Close
	return rs

def display (NUM_ROWS):
	print "<table border=1>"
	print "<th>Order ID</th>"
	print "<th>Product</th>"
	print "<th>Unit Price</th>"
	print "<th>Quantity</th>"
	print "<th>Discount</th>"
	for k in range(0,NUM_ROWS):
		print "<tr>"
		for i in s:
			print "<td>",i[k],"</td>"
		print "</tr>"

	print "</table>"

rs=win32com.client.Dispatch('ADODB.recordset')
rs=connect("select * from [Order details]")
s=rs[0].GetRows(NUM_ROWS)
display(NUM_ROWS)
rs[0].Close

www.activestate.com (form python with win32extensions) or www.python.org (for the latest stable python) and www.apache.org (the web server) bye u can always mail me 4 ur query

please try and help me with the currency filed in the database !! :)

Created by Souman Deb on Thu, 24 Apr 2003 (PSF)
Python recipes (4591)
Souman Deb's recipes (1)

Required Modules

Other Information and Tasks