•
•
•
•
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
![]() |
•
•
Join Date: Feb 2008
Posts: 111
Reputation:
Rep Power: 1
Solved Threads: 0
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.
"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.
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. **
** 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. **
•
•
Join Date: Dec 2006
Posts: 447
Reputation:
Rep Power: 2
Solved Threads: 62
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: automate logging
- Next Thread: class question


Linear Mode