From: Tim Golden on
[joel.sjoo(a)gmail.com]

| Traceback (most recent call last):
| File "txttosql6.py", line 23, in ?
| row
| File "C:\Python24\Lib\site-packages\pymssql.py", line 120, in execute
| self.executemany(operation, (params,))
| File "C:\Python24\Lib\site-packages\pymssql.py", line 146, in
| executemany
| raise DatabaseError, "internal error: %s (%s)" %
| (self.__source.errmsg(), se
| lf.__source.stdmsg())
| pymssql.DatabaseError: internal error: None (None)

Are you calling .execute or .executemany? Your code below
has .execute, but the traceback is coming from .executemany.
If you're using the latter, you need to pass the whole list
at once:

..
..
..
mycursor = myconn.cursor()
# omit: for row in data:
mycursor.executemany (
"INSERT INTO python (id, namn, efternamn) VALUES (?, ?, ?)",
data
)

If that's not the problem, I can't easily see what it is.
I don't usually use pymssql, but I do have it installed,
so if I get a chance later, I'll give it a go.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
From: joel.sjoo@gmail.com on
i gott the same results with both executemany and execute. i will try
with some other sql modules. if you try tim so let me now if you cot it
to work.

many thanks for your help.

regards joel

From: Tim Golden on
[joel.sjoo(a)gmail.com]

| i gott the same results with both executemany and execute. i will try
| with some other sql modules. if you try tim so let me now if
| you cot it
| to work.

OK, the relevant thing here is the paramstyle. When I made that
misguided claim earlier that "?" was the most common parameter
character, I didn't check whether pymssql actually uses it.. And
it doesn't.

<code>
import pymssql
print pymssql.paramstyle
# pyformat

</code>

This means that you are expected to put %s everywhere you
want a substitution from your parameter list. Again, don't
bother quoting for strings etc. Therefore, the following
works for this db-module:

<code>
import pymssql
db = pymssql.connect (...)

#
# Fake some data as tho' it had come from
# your text file.
#
data = data = [[1, 'Tim', 'Golden'], [2, 'Fred', 'Smith']]

q = db.cursor ()
q.execute ("CREATE TABLE ztemp (id INT, first_name VARCHAR (60),
last_name VARCHAR (60))")

q.executemany ("INSERT INTO ztemp (id, first_name, last_name) VALUES
(%s, %s, %s)", data)

q.execute ("SELECT * FROM ztemp")
for row in q.fetchall ():
print row

q.execute ("DROP TABLE ztemp")

</code>

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
From: joel.sjoo@gmail.com on
Yes i got it to work now. Thank you for all help Tim and Steve. I hope
it will work for Oracle to :)

Regards Joel

First  |  Prev  | 
Pages: 1 2
Prev: py2exe and libxml
Next: Unicode / cx_Oracle problem