Query about using "DataHandlers" module

Andy Elvey andy.elvey at paradise.net.nz
Sun Jun 4 03:39:02 EDT 2000


Hi all.  I have a query about the use of the DataHandlers module
(available at "Vaults of Parnassus").

 I have attached a simple  example which uses this module (this example
works fine).  But .... when I amend the SQL code to say  'select * from
test where team == "Yankees" '  ,  the code still retrieves all teams -
the where statement is ignored.

  My question is - "does anyone have an example (or two!) of some Python
code similar to my example , but which has a select statement that has a
"where" clause in it?

 ( and -  are there any examples which use the DataHandlers module and
use * 2 tables*   with a join ... ? )

 Many thanks in advance for any help offered .... :-)

 ( and by the way .. this DataHandlers module is *great*  ..... :-)


-------------- next part --------------
#!/usr/bin/env python

# Illustrate the parsing a data file and creating SQL insert statements
# The table definition comes from an XML file

from DataHandlers.SQLTable import SQLTable
from DataHandlers.dbdefXMLParser import dbdefXMLParser
from DataHandlers.FileConnection import Connection

# create a parser
xml = dbdefXMLParser()
# return a dictionary of table definitions
tables = xml.parseFile( 'test.xml' )
# get the baseball table
tbl = tables['baseball']
# the data file is delimited by commas
tbl.setReader( 'Delimited' )
tbl.setDelimiter( ',' )
# open a file connection
fc = Connection()
fc.connect( 'teams.txt' )
# we need to do this fake query so we can get the cursor
# it actually means something when we are doing an SQL thing
cursor = fc.query('')
if not cursor:
    print 'Unable to execute query' 
    sys.exit(1)
# now walk thru the lines of data
while cursor.next():
    tbl.parse( cursor.getData())
    # print out the insert statements
    print tbl.getInsert()
    
print "Query data returned..."
cursor = fc.query( 'select * from test' )
while cursor.next():
    print cursor.getData( )

cursor.close()
    
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.xml
Type: text/xml
Size: 316 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20000604/2ced7da0/attachment.xml>
-------------- next part --------------
Orioles,Baltimore,Camden Yards,A,E
Red Sox,Boston,Fenway Park,A,E
Angels,Anaheim,Anaheim Stadium,A,W
White Sox,Chicago,Comiskey Park,A,W
Indians,Cleveland,Jacobs Field,A,E
Tigers,Detroit,Tiger Stadium,A,E
Royals,Kansas City,Royals Stadium,A,W
Brewers,Milwaukee,County Stadium,A,E
Twins,Minnesota,Hubert H. Humphrey Stadium,A,W
Yankees,New York,Yankee Stadium,A,E
Athletics,Oakland,Oakland Coliseum,A,W
Mariners,Seattle,Kingdome,A,W
Rangers,Texas,Arlington Stadium,A,W
Blue Jays,Toronto,Toronto Stadium,A,E
Braves,Atlanta,Fulton County Stadium,N,W
Cubs,Chicago,Wrigley Field,N,E
Reds,Cincinnati,Three Rivers Stadium,N,W
Astros,Houston,Astrodome,N,W
Dodgers,Los Angeles,Dodger Stadium,N,W
Expos,Montreal,Exposition Stadium,N,E
Mets,New York,Shea Stadium,N,E
Phillies,Philadelphia,Veterans Stadium,N,E
Pirates,Pittsburgh,Pirate Stadium,N,E
Cardinals,St. Louis,Busch Stadium,N,E
Padres,San Diego,Jack Murphy Stadium,N,W
Giants,San Francisco,Candlestick Park,N,W


More information about the Python-list mailing list