Re: [pysqlite] [APSW 3.6.5-r1] Why does this INSERT fail?

Roger Binns <[email protected]> Fri, 26 Dec 2008 15:02:51 -0800
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Fred wrote:
> I can't figure out why this INSERT fails. Maybe some fresh eyes can 
> pick the cause of the error:

We can't tell you because the code is not standalone and you didn't
include any information on what the exception is.

> matches = record.finditer(response)

record is not defined by this code.

> 	sql = "INSERT INTO person (name,address,tel,web,email) VALUES (?,?,?,?,?)"
..
> 		cursor.execute(sql,(name,address,tel,web,email))

You may find it convenient to use named bindings when all the values are
in local variables.  locals() returns a dict of local variables, so the
above could be written as:

   cursor.execute("INSERT INTO person (name, address, tel, web, email)
VALUES (:name, :address, :tel, :web, :email)", locals())

> 	except:
> 		#Here : why does it fail?
> 		print "Failed %s" % sql

It is generally a very bad idea to catch all exceptions since exceptions
are things that are not ordinary.  Instead only catch the ones you know
how to deal with.  In any event we can't help unless you tell us what
the exception was.  Just removing the except clause and letting Python
handle it printing out what happened will be sufficient information.

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklVYpcACgkQmOOfHg372QSZVgCeOHHrpctMdOOh89W1ZD3RG2Zr
iKUAn3L8b6l2I6+nbZt/eseR/QsHsWol
=49yP
-----END PGP SIGNATURE-----