Hello,
I have 2 simple tables:
- block table (set of blocks)
- connection tables (connections between blocks)
I would like to setup a database to prevent creating connection to/from
non-existant blocks.
For example: If I start with empty database, the script below should fail (but
instead... the connection between nonexistant blocks is created).
What's wrong?
If I delete a block, all connection related to this block should be deleted
automaticaly. This works fine with "cascade=True" option.
Thanks,
Zoran
------
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
from sqlobject import *
class Block(SQLObject):
name = StringCol()
class Connection(SQLObject):
src = ForeignKey('Block', cascade=True)
dst = ForeignKey('Block', cascade=True)
db_filename = os.path.abspath(sys.argv[1]) print db_filename
# load database
connection_string = 'sqlite:' + db_filename connection =
connectionForURI(connection_string)
sqlhub.processConnection = connection
# create tables
Block.createTable(ifNotExists=True)
Connection.createTable(ifNotExists=True)
# create dumb connection
# it should not work, because there is no blocks!!!
Connection(src=150, dst=250)
----
Dump database just created:
sqlite> .dump
BEGIN TRANSACTION;
CREATE TABLE block (
id INTEGER PRIMARY KEY,
name TEXT
);
CREATE TABLE connection (
id INTEGER PRIMARY KEY,
src_id INT CONSTRAINT src_id_exists REFERENCES block(id) ON DELETE CASCADE,
dst_id INT CONSTRAINT dst_id_exists REFERENCES block(id) ON DELETE CASCADE
);
INSERT INTO "connection" VALUES(1,150,250); COMMIT;
sqlite>
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss