Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70558
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: why my cur.executescript can not run? |
| Date | 2014-04-23 20:05 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <CAOmh461B32OV9+-rUQUYz9iMF8bjt_dxUzv4P7tSrP+yjS3reg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9476.1398297951.18130.python-list@python.org> (permalink) |
On Wed, 23 Apr 2014 19:23:42 +0800, length power <elearn2014@gmail.com>
declaimed the following:
>When cur.execute be used, i get right output.
>
>import sqlite3
>con=sqlite3.connect(":memory:")
>cur=con.cursor()
>sql1="attach database 'g:\\workspace\\data\\Cinfo.sqlite' as Cinfo;"
>sql2="select * from Cinfo.ipo;"
>cur.execute(sql1)
>cur.execute(sql2)
>con.commit()
>x=cur.fetchall()print(x)
>
>When i change it into cur.executescript, nothing can get.
>
>import sqlite3
>con=sqlite3.connect(":memory:")
>cur=con.cursor()
>sql_script="""
>attach database 'g:\\workspace\\data\\Cinfo.sqlite' as Cinfo;
>select * from Cinfo.ipo;"""
>cur.executescript(sql_script)
>con.commit()
>x=cur.fetchall()print(x)
>
>I want to know why?
>
Can't answer your main question, but ... I'd put the .commit() AFTER
the .fetchall() -- since I don't think the DB-API promises results to be
available after a transaction commit().
ALSO -- note that in the quoted text, your "print(x)" seems to have
been appended to the prior assignment statement -- so something is flaky
with your line endings.
A third hypothesis: EACH statement in your script may be producing a
result-set, and the .fetchall is only retrieving the (empty) result-set
from the ATTACH statement.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: why my cur.executescript can not run? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-04-23 20:05 -0400
csiph-web