InstantDB Project
About InstantDB
Project Mail Lists
Short History
Reporting Bugs
Screen Shots
3rd Party Examples
FAQs

Software
Downloads
Documentation
CVS Repositories
Roadmap
License

About Enhydra.org
Who We Are
News, Articles & Events
Getting Involved
Contact Us

Community
Demos
Contributions
Resources
Case Studies
On The Edge! -NEW-
Commercial Vendors


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: InstantDB: Re: Referential Integrity not enforced sometimes.


Hi Thom,
   I guess its got to do with the Foreign key definitions not being
persistent.

   Hence I decided to extend the idbTrigger class and add code to the
onAdd() & onUpdate() APIs to do the Ref. Integrity for me.

   But I encountered some problems here too. The foll. is the stdout
dump generated by my trigger class.

~~~~~~~~~~stdout dump starts here~~~~~~~~~~~~~~~~~~~~
main DROP TABLE employee
main CREATE TABLE employee (emplID int AUTO INCREMENT, name CHAR(40),
salary CURRENCY, hired DATE, age FLOAT, comment BINARY)
main DROP TABLE employee_client
main CREATE TABLE employee_client (emplID int AUTO INCREMENT, name
CHAR(40), salary CURRENCY, hired DATE, age FLOAT, comment BINARY)
foreign key (emplID) references employee (emplID)
main INSERT INTO employee (emplId, name, salary, hired, age, comment)
VALUES(22,'Bugs', '23', '3 Jan 1998', 27.5, 'in every cartoon')
main INSERT INTO employee_client (emplId, name, salary, hired, age,
comment) VALUES(23,'Bugs', '23', '3 Jan 1998', 11.1, 'balaji')

[1000, Bugs, 23, 883765800000, 11.1, [B@7b9f9129]

select * from employee where emplID=1000
main select * from employee where emplID=1000
found an FK match...
Database netcollector is shutting down...
Database netcollector shutdown complete.
~~~~~~~~~~stdout dump ends here~~~~~~~~~~~~~~~~~~~~

   Inside the onAdd() API, I just added a sql query to the parent table
(employee) to check for the inserted emplID value and throw an exception
(and hence rollback the insert) if no records are returned.

   Iam printing the 'rows' vector that is being passed as the first
parameter to the onAdd() API. Notice the foll lines in the dump.

	main INSERT INTO employee_client (emplId, name, salary, hired, age,
comment) VALUES(23,'Bugs', '23', '3 Jan 1998', 11.1, 'balaji')

	[1000, Bugs, 23, 883765800000, 11.1, [B@7b9f9129]

   Iam inserting '23' for emplID, but am getting a '1000' in the vector.

   So I end up not checking for my required 'emplID' value.

   Any help on this ?

thanx,
balaji

Thom Nelson wrote:
> 
> The source for ScriptTool is available in Examples/ScriptTool.java.  You
> can compare what ScriptTool is doing with what your code is doing.  I
> can't think of anything off hand which would cause this problem.  Have
> you tried creating the tables and inserting data all in one shot in your
> own code?  I expect that you will see the error then.
> 
> It could be that in some (or all) cases, the foreign key definitions are
> not being persisted,  though they are being kept in memory after the
> initial table creation.
> 
> Thom
> 
> Balaji Krishnamurthy wrote:
> >
> > Forgot to add that the constraint is not enforced again if I separate
> > the 'create' and 'insert' statements between 2 executions of the
> > ScriptTool class.
> >
> > If I put them in the same sql1.txt file and run it in one shot I get
> > this 'FK insert error...'.
> >
> > But if I create the tables in one run and insert the row in another it
> > goes inside the table without complaining.
> >
> > Any idea as to what is happening ?
> >
> > thanx in advance,
> > balaji
> >
> > Balaji Krishnamurthy wrote:
> > >
> > > Hi,
> > >    Iam a new user to InstantDb. (Iam using version 3.26)
> > >
> > >    I tried out the sql1.txt (after minor modifications) using the
> > > ScriptTool class.
> > >
> > >    I tried the foreign key constraint on a table and found that it is
> > > enforced only if an insert is made using the ScriptTool class. (i.e
> > > inside the sql1.txt or a similar file)
> > >
> > >    It was not being enforced if I use my own Java code to load the idb
> > > driver and insert records using JDBC calls.
> > >
> > >    I get the following exception while using ScriptTool class.
> > >
> > > java.sql.SQLException: java.sql.SQLException: FK insert error. Value, 9,
> > > does no
> > > t exist in column tester.id
> > >         at org.enhydra.instantdb.db.SQLProg.execute(SQLProg.java:288)
> > >         at
> > > org.enhydra.instantdb.jdbc.idbStatement.execute(idbStatement.java, Co
> > > mpiled Code)
> > >         at
> > > org.enhydra.instantdb.jdbc.idbStatement.executeUpdate(idbStatement.ja
> > > va:103)
> > >         at org.enhydra.instantdb.SampleThread.run(ScriptTool.java,
> > > Compiled Code
> > > )
> > >         at java.lang.Thread.run(Unknown Source)
> > > id,fullName,email,login,password
> > >
> > >    But it does not complain in my own code.
> > >
> > >    I find the record being inserted into the client table without any
> > > corresponding record in the parent table.
> > >
> > >    Is there is something that I could do to get this constraint enforced
> > > in my code too ?
> > >
> > > thanx,
> > > balaji
> > -----------------------------------------------------------------------------
> > To unsubscribe from this mailing list, send email to majordomo@enhydra.org
> > with the text "unsubscribe instantdb" in the body of the email.
> > If you have other questions regarding this mailing list, send email to
> > the list admin at owner-instantdb@enhydra.org.
> -----------------------------------------------------------------------------
> To unsubscribe from this mailing list, send email to majordomo@enhydra.org
> with the text "unsubscribe instantdb" in the body of the email.
> If you have other questions regarding this mailing list, send email to
> the list admin at owner-instantdb@enhydra.org.
-----------------------------------------------------------------------------
To unsubscribe from this mailing list, send email to majordomo@enhydra.org
with the text "unsubscribe instantdb" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-instantdb@enhydra.org.