Re: [sqlite] Lets try this again. Sqlite Python libraries throwing exception on unique constraint.

2014-10-13 Thread Keith Medcalf

And 2.7.8:

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> conn=sqlite3.connect(":memory:")
>>> conn.execute("""
... CREATE TABLE `UpdateFrom` (
... `VersionName` TEXT NOT NULL UNIQUE,
... `VersionNumber` INTEGER NOT NULL,
... `UpdateFrom` INTEGER NOT NULL,
... `MetafileURL` TEXT NOT NULL,
... `PatchURL` TEXT NOT NULL,
... `SHA1` TEXT NOT NULL
... );""")

>>> versionName=0
>>> versionNumber=0
>>> updateFrom=0
>>> metafileURL=0
>>> patchURL=0
>>> sha1=0
>>> params = versionName, versionNumber, updateFrom, metafileURL, patchURL, sha1
>>> conn.execute("INSERT INTO UpdateFrom VALUES(?,?,?,?,?,?)", params)

>>>
>>> for row in conn.execute('select * from updatefrom'):
...  print row
...
(u'0', 0, 0, u'0', u'0', u'0')
>>>

On Monday, 13 October, 2014 11:14, Clemens Ladisch  said:

>Jeffrey Parker wrote:

>> I am working with sqlite3 in python 2.7.8 and I am running into a
>> strange error where I get the below exception when running an insert 
>> into statement on an empty table.
>
>The following code executes fine in Python 2.7.5:
>
>import sqlite3
>conn=sqlite3.connect(":memory:")
>conn.execute("""
>CREATE TABLE `UpdateFrom` (
>`VersionName` TEXT NOT NULL UNIQUE,
>`VersionNumber` INTEGER NOT NULL,
>`UpdateFrom` INTEGER NOT NULL,
>`MetafileURL` TEXT NOT NULL,
>`PatchURL` TEXT NOT NULL,
>`SHA1` TEXT NOT NULL
>);""")
>versionName=0
>versionNumber=0
>updateFrom=0
>metafileURL=0
>patchURL=0
>sha1=0
>params = versionName, versionNumber, updateFrom, metafileURL, patchURL,
>sha1
>conn.execute("INSERT INTO UpdateFrom VALUES(?,?,?,?,?,?)", params)



___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Lets try this again. Sqlite Python libraries throwing exception on unique constraint.

2014-10-13 Thread Dan Kennedy

On 10/13/2014 11:44 PM, Jeffrey Parker wrote:

Hello,

I am working with sqlite3 in python 2.7.8 and I am running into a strange
error where I get the below exception when running an insert into statement
on an empty table. I know this is probably more to do with the python
libraries but I thought that I would ask the question here in case someone
has any recommendations.

sqlite3.IntegrityError: column VersionName is not unique

The insert still works and when I do the next insert into that table there
is no exception.


It sounds like you are attempting to insert a duplicate row.

You could temporarily add a SELECT statement before the INSERT to check 
if a record with the specified "versionName" is already present in the 
table.


Dan.





There are multiple insert statements and multiple tables. The insert
statements look like below.

params = versionName, versionNumber, updateFrom, metafileURL, patchURL, sha1
conn.execute("INSERT INTO UpdateFrom VALUES(?,?,?,?,?,?)", params)

and the table looks like below.

CREATE TABLE `UpdateFrom` (

`VersionName` TEXT NOT NULL UNIQUE,

`VersionNumber` INTEGER NOT NULL,

`UpdateFrom` INTEGER NOT NULL,

`MetafileURL` TEXT NOT NULL,

`PatchURL` TEXT NOT NULL,

`SHA1` TEXT NOT NULL

);
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Lets try this again. Sqlite Python libraries throwing exception on unique constraint.

2014-10-13 Thread Clemens Ladisch
Jeffrey Parker wrote:
> I am working with sqlite3 in python 2.7.8 and I am running into a strange
> error where I get the below exception when running an insert into statement
> on an empty table.

The following code executes fine in Python 2.7.5:

import sqlite3
conn=sqlite3.connect(":memory:")
conn.execute("""
CREATE TABLE `UpdateFrom` (
`VersionName` TEXT NOT NULL UNIQUE,
`VersionNumber` INTEGER NOT NULL,
`UpdateFrom` INTEGER NOT NULL,
`MetafileURL` TEXT NOT NULL,
`PatchURL` TEXT NOT NULL,
`SHA1` TEXT NOT NULL
);""")
versionName=0
versionNumber=0
updateFrom=0
metafileURL=0
patchURL=0
sha1=0
params = versionName, versionNumber, updateFrom, metafileURL, patchURL, sha1
conn.execute("INSERT INTO UpdateFrom VALUES(?,?,?,?,?,?)", params)


Regards,
Clemens
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Lets try this again. Sqlite Python libraries throwing exception on unique constraint.

2014-10-13 Thread Jeffrey Parker
Hello,

I am working with sqlite3 in python 2.7.8 and I am running into a strange
error where I get the below exception when running an insert into statement
on an empty table. I know this is probably more to do with the python
libraries but I thought that I would ask the question here in case someone
has any recommendations.

sqlite3.IntegrityError: column VersionName is not unique

The insert still works and when I do the next insert into that table there
is no exception.

There are multiple insert statements and multiple tables. The insert
statements look like below.

params = versionName, versionNumber, updateFrom, metafileURL, patchURL, sha1
conn.execute("INSERT INTO UpdateFrom VALUES(?,?,?,?,?,?)", params)

and the table looks like below.

CREATE TABLE `UpdateFrom` (

`VersionName` TEXT NOT NULL UNIQUE,

`VersionNumber` INTEGER NOT NULL,

`UpdateFrom` INTEGER NOT NULL,

`MetafileURL` TEXT NOT NULL,

`PatchURL` TEXT NOT NULL,

`SHA1` TEXT NOT NULL

);
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users