Trouble with SQL and Entry box

Tim Roberts timr at probo.com
Thu Aug 2 02:07:08 EDT 2001


"Cguru" <cguru at bigfoot.com> wrote:
>This is what I have...
>       rs = pg.DB('blah')
>
>	query17 = "select companyname from clients"

It's good practice to end ALL queries with a semicolon.

>	var1 = rs.query(query17)
>        self.ent17 = Entry (master)
>	#self.ent17.configure(textvariable = query17)
>	self.ent17.insert(END,var1)
>        self.ent17.place(in_=master,x=120,y=30)
>
>It doesnt' do what I expect it to do.

The "query" method returns a tuple of tuples.  You get one tuple for each
database row returned, where each tuple contains all the columns in your
query.  In your case, if there are 5 companyes in the "clients" table,
you'll get:
  (
    ( 'IBM', ),
    ( 'Microsoft', ),
    ( 'GM', ),
    ( 'Ford', ),
    ( 'Motorola', )
  )

If you want to put the first column of the first row into your text box,
you should be able to use:

   self.ent17.insert(END,var1[0][0])

--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list