Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70558 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2014-04-23 20:05 -0400 |
| Last post | 2014-04-23 20:05 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: why my cur.executescript can not run? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-04-23 20:05 -0400
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-04-23 20:05 -0400 |
| Subject | Re: why my cur.executescript can not run? |
| Message-ID | <mailman.9476.1398297951.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web