Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > BOOK: Python Projects
|
BOOK: Python Projects
This is the forum to discuss the Wrox book Python Projects Laura Cassell, Alan Gauld; ISBN: 978-1-118-90866-2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Python Projects section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2015, 01:59 PM
Registered User
 
Join Date: Mar 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Foreign key constraints in sqlite3

When I try the example (step 3, add an item) on p. 152, I don't get the exception saying the foreign key constraint failed. The database just happily adds the item.

In Ch. 3 p. 151, the text says: "Notice, too, that you set the Foreign_Keys pragma in the initDB() function to ensure that all transactions are checked for referential integrity."

However, the code for initDB() looks like this:
Code:
def initDB(filename=None):
    global db, cursor
    if not filename:
        filename = 'lendy.db'
    try:
        db = sql.connect(filename)
        cursor = db.cursor()
    except:
        print("Error connecting to ", filname)
        cursor = None
        raise
I don't see anything invoking the Foreign_Keys pragma... is something missing?
 
Old March 29th, 2015, 04:08 AM
Wrox Author
 
Join Date: Feb 2015
Posts: 25
Thanks: 0
Thanked 3 Times in 3 Posts
Default

There is an error in the book - a missing line with the required PRAGMA statement.
My apologies. Check the code on the download site, it is correct.

If in doubt always look at the download code, the code in the book was cut n pasted,
then reformated from that code so the download code is effectively the baseline.

Alan G.

Last edited by Alan G; March 29th, 2015 at 04:10 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
primary n foreign key Saif Ali Forum and Wrox.com Feedback 0 December 31st, 2013 01:39 AM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
foreign key constraints - referential integrity DTSDeveloper SQL Server DTS 0 September 6th, 2005 01:10 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM
Foreign Key Problem re_anu SQL Server 2000 1 September 26th, 2003 10:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.