User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 425,916 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,776 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 571 | Replies: 2
Reply
Join Date: Feb 2008
Posts: 111
Reputation: dinilkarun is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dinilkarun dinilkarun is offline Offline
Junior Poster

Query Column names with spaces in MS ACCESS using Python

  #1  
Jul 22nd, 2008
we are able to query successfully from a Column called "ParentUUD" (without space) using query in python for MS ACCESS DB.

"SELECT Name FROM PartVersion WHERE ParentUUID='"+ str(lstUUID[0]) +"'"

we have a column whose name is "Parent UUID" (with space)
We are trying to query the column from PYTHON. we are getting error.I think the error is due to space in the column name.

Please tellus the method to query the MS access DB with column names with spaces.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 203
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 29
jlm699's Avatar
jlm699 jlm699 is offline Offline
Posting Whiz in Training

Re: Query Column names with spaces in MS ACCESS using Python

  #2  
Jul 22nd, 2008
This is not a Python issue, it is an Access issue. If you can perform the query in Access it will work through Python you just need to be careful as to how you format your query. If you paste the query that you would use from within Access, we can help.
Let's Go Pens!

** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
Reply With Quote  
Join Date: Dec 2006
Posts: 447
Reputation: woooee is on a distinguished road 
Rep Power: 2
Solved Threads: 62
woooee woooee is offline Offline
Posting Pro in Training

Re: Query Column names with spaces in MS ACCESS using Python

  #3  
Jul 22nd, 2008
Putting a quote around the field name works with SQLite. I don't know about MS Access. This is the well known example that has been changed to use a field name with a space in it (always a bad idea).
import sqlite3 as sqlite

##----------------------------------------------------------------------
def add_rec(cur, con):
   cur.execute("INSERT INTO test ('name last', age) values ('Putin',   50)")
   cur.execute("INSERT INTO test ('name last', age) values ('Putin',   50)")
   cur.execute("INSERT INTO test ('name last', age) values ('Putin',   50)")
   cur.execute("INSERT INTO test ('name last', age) values ('Yeltsin',   72)")
   cur.execute("INSERT INTO test ('name last', age) values ('Baby',   1)")

   con.commit()

#==========================================================================
if __name__ == "__main__":
   con = sqlite.connect("test_db" )
   cur = con.cursor()

##--- Note: 'name last'
   cur.execute("CREATE TABLE test ('name last' VARCHAR(20), age INT)")

   add_rec(cur, con)           ## add some recs

   cur.execute('SELECT * FROM test')
   for row in cur:
      print "name =", row[0], " age =", row[1]
   
   print "select test"
   cur.execute('SELECT age FROM test where "name last"="Yeltsin"')
   for row in cur:
       print row
Last edited by woooee : Jul 22nd, 2008 at 6:30 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Python Forum

All times are GMT -4. The time now is 8:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC