[Twisted-Python] Questions about class KeyFactory.

Hi,
I my a bit afraid im asking a stupid question here, I'll do it anyways :)
(from twisted/enterprise/row.py) class KeyFactory: ... warnings.warn("This is deprecated. Use the underlying database to generate keys, or just roll your own.", DeprecationWarning) ...
As the warnings says this class is deprecated. Use the underlying database. I was wondering if anybody have some example code for this. Im using a PgDB.
Here's my rowObject: class DummyRow(row.RowObject): rowColumns = [ ("testId", "int"), ("testName","varchar"), ("testData","varchar") ] rowKeyColumns = [("testId","int")] rowTableName = "dummytable"
And my sql code:
CREATE TABLE dummytable ( testId SERIAL PRIMARY KEY, testName varchar(64), testData varchar );
So when using a sequencer to generate an unique key for testId, I dont need to supply testId in my insert sql statement. But twisted complains if i dont use the assignKeyAttr function, PG complains if I use it with a value thats already used (ofcourse).
My insert code
b = DummyRow() b.assignKeyAttr("testId", 3) b.testName = "myTestName" b.testData = "My test data string" manager.insertRow(b).addCallback(onInsert)
Again if was wondering if somebody had some sample code to help me solve my problem or a point in the right direction.
Thanks in advance,
--Thomas

What happens if you set the id to a zero value of some sort, such as 0, '', NULL ?
-----Original Message----- From: twisted-python-bounces@twistedmatrix.com [mailto:twisted-python-bounces@twistedmatrix.com] On Behalf Of Thomas Kristensen Sent: den 8 december 2004 12:31 To: twisted-python@twistedmatrix.com Subject: [Twisted-Python] Questions about class KeyFactory.
Hi,
I my a bit afraid im asking a stupid question here, I'll do it anyways :)

What happens if you set the id to a zero value of some sort, such as 0, '', NULL ?
I have tried that aswell, they either gives an invalid sql, or is rejected by PG :(
b.assignKeyAttr("testId", None) = libpq.OperationalError: ERROR: null value in column "testid" violates not-null constraint
b.assignKeyAttr("testId", 0) = libpq.OperationalError: ERROR: duplicate key violates unique constraint "dummytable_pkey"
b.assignKeyAttr("testId", "NULL") = libpq.OperationalError: ERROR: null value in column "testid" violates not-null constraint
b.assignKeyAttr("testId", "") = libpq.OperationalError: ERROR: syntax error at or near "," at character 62
--tkk

On Dec 8, 2004, at 8:52 AM, Thomas Kristensen wrote:
What happens if you set the id to a zero value of some sort, such as 0, '', NULL ?
I have tried that aswell, they either gives an invalid sql, or is rejected by PG :(
b.assignKeyAttr("testId", None) = libpq.OperationalError: ERROR: null value in column "testid" violates not-null constraint
I have quite a lot of local changes to twisted.enterprise that I would be happy to share. The code is a mess right now though and kinda pgsql specific so if you want it keep that in mind.
With my changes you would do:
b.assignKeyAttr("testId", PgDefaultColumn())
or
b.assignKeyAttr("testId", PgSequenceColumn("mytable_testId_seq"))
There are a lot of other changes but those are the ones most relevant to your problem.
rich
participants (3)
-
Rich Cavanaugh
-
Simon
-
Thomas Kristensen