This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 269507 - When using SQLite, Foreign Keys constraint is Ignored
Summary: When using SQLite, Foreign Keys constraint is Ignored
Status: RESOLVED INVALID
Alias: None
Product: db
Classification: Unclassified
Component: SQL Editor (show other bugs)
Version: 8.2
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: matthias42
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-07 22:59 UTC by g.mann
Modified: 2017-01-08 11:18 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
A video of the sql statements executing and providing faulty results. (437 bytes, application/octet-stream)
2017-01-07 22:59 UTC, g.mann
Details
First set of statements executed in the video. (437 bytes, application/octet-stream)
2017-01-07 23:00 UTC, g.mann
Details
Second set of statements executed in video (233 bytes, application/octet-stream)
2017-01-07 23:01 UTC, g.mann
Details
A video of the sql statements executing and providing faulty results. (2.44 MB, video/avi)
2017-01-07 23:03 UTC, g.mann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description g.mann 2017-01-07 22:59:42 UTC
Created attachment 163355 [details]
A video of the sql statements executing and providing faulty results.

I am learning to use SQLite through this website:
http://www.sqlitetutorial.net/
although I am using the netbeans database system instead of the standalone command line program they use.


According to the website, http://www.sqlitetutorial.net/sqlite-foreign-key/:
----

INSERT INTO suppliers (supplier_name, group_id)
VALUES
 ('HP', 2);

This statement works perfectly fine.

Third, try to insert a new supplier into the suppliers table with the supplier group that does not exist in the supplier_groups table.

INSERT INTO suppliers (supplier_name, group_id)
VALUES
 ('ABC Inc.', 4);

SQLite checked the foreign key constraint, rejected the action, and issued an error message: “constraint failed”.

----

Instead of throwing an error message, the statement executed without throwing an error, and entered the bad information into the "suppliers" database.

I made a video of what happens, and attached it. The sql statements used to make the video are attached as well.

I am using an SQLite jdbc driver, and I assigned it the URL "jdbc:sqlite:" in order to have the database run in memory. I am not sure whether the driver is the problem, or Netbeans, but I thought I would start here.
Comment 1 g.mann 2017-01-07 23:00:37 UTC
Created attachment 163356 [details]
First set of statements executed in the video.
Comment 2 g.mann 2017-01-07 23:01:15 UTC
Created attachment 163357 [details]
Second set of statements executed in video
Comment 3 g.mann 2017-01-07 23:03:44 UTC
Created attachment 163358 [details]
A video of the sql statements executing and providing faulty results.
Comment 4 matthias42 2017-01-08 11:17:51 UTC
This is not a netbeans bug. Background:

In a "regular" setting the DB and the driver are separated and the DB will take care of interpreting SQL and handling the DB operations. It will also take care to offer the "right" DB semantics (ACID for example).

In this case though you use a JDBC driver to access an sqlite file and don't deal with sqlite (at least most probable). The driver in this case needs to simulate the sqlite behavior and it looks as if referential constraints are not simulated.

Foreign keys seem to be an optional component (see section 2 of the following document):

https://www.sqlite.org/foreignkeys.html

So if you want to learn about DBs and full SQL I suggest to use another DB: derby/javadb and h2 are two in the java ecosystem.