Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

python - How do i correctly query a sql ce 4.0 database file using adodbapi?

I have the following method:

def open(self, filename):
    if not os.path.exists(filename):
        raise IOError("Cannot find Game Database file {0}").__format__(filename)

    connstr = "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0; 
               Data Source={0};".format(filename)
    conn = adodbapi.connect(connstr)
    curs = conn.cursor()
    query = "Select * from Patient;"
    curs.execute(query)
    results = curs.fetchall()
    for r in results:
        print r

When this runs, the following error is rased on curs.execute(query):

(<class 'adodbapi.adodbapi.DatabaseError'>, u"(-2147352567, 'Exception occurred.', (0, u'Microsoft Cursor Engine', u'Multiple-step operation generated errors. Check each status value.', None, 0, -2147217887), None)
Command:
Select * from Patient;
Parameters:
[]")

I can run this exact query in compactView successfully.

What obvious syntactic sugar am i not seeing? ( running: win7 pro x64, python 2.7.x, pywin32 and adodbapi installed successfully. The connection string seems to work -- i can connect and get a cursor just fine)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using adodbapi-2.6.0.7 I solved this using the following:

connection.connector.CursorLocation = 2

For example:

import adodbapi

file = r'FILEPATH'
connection_string = (
    'Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; Data Source={};'.format(file))
print(connection_string)
connection = adodbapi.connect(connection_string)
connection.connector.CursorLocation = 2
connection.get_table_names()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...