Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > BOOK: Python Projects
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 27th, 2015, 01:59 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #2 (permalink)  
Old March 29th, 2015, 04:08 AM
Wrox Author
Points: 119, Level: 2
Points: 119, Level: 2 Points: 119, Level: 2 Points: 119, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2015
Location: Stirling, Scotland
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..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.