Rebol Talk Forum  |  REBOL Discussions  |  REBOL Sand Box  |  RebDB  |  Topic: Usefull add-on
Pages: [1] Print
Author Topic: Usefull add-on  (Read 1185 times)
François
Newbie
*
Offline Offline

Posts: 7


View Profile
Usefull add-on
« on: March 02, 2004, 01:35:01 PM »

Hello,

It would be nice if the 'db-insert function returns the newly created record.
This is especially usefull when using the 'next function to generate the Primary Key.
Indeed, I am mapping an object with chidren objects to the DB and I want to make "cascading" insert.

I have:  Parent -1---*-> Child

Code:
db-insert parent-table [next <parent's fields>]
foreach child parent/children [
   db-insert child-table [next <I need the parent id as foreign key!!> <child's fields>]
]

If 'db-insert returns the newly created entity with its generated id, I can use it as foreign key.

Regards

François
Logged
François
Newbie
*
Offline Offline

Posts: 7


View Profile
Usefull add-on
« Reply #1 on: March 02, 2004, 02:19:11 PM »

Hep,

Here is the codes I modified to %db.r to let 'db-insert return the newly created value:
Code:
1227    if value = 'next [
1228        value: either tables/:table/rows > 0 [
1229        1 + to integer! copy/part skip tables/:table/file tables/:table/rows - 1 * tables/:table/length + offset size
1230    ][1]
1231         replace vals 'next value; added line
1232    ]
...
1254    either echo? [
1255        if trace? [stop-trace]
1256        print "^/1 row inserted"
1257    ][vals]; returning the newly created record

You might well include the change in the next version  :huh:

François
Logged
Ashley
Newbie
*
Offline Offline

Posts: 37


View Profile
Usefull add-on
« Reply #2 on: March 02, 2004, 06:42:59 PM »

Quote
You might well include the change in the next version
Good addition, I will. BTW, I like the foreign key example, I think I'll base the next tutorial around it. Smiley
Logged
François
Newbie
*
Offline Offline

Posts: 7


View Profile
Usefull add-on
« Reply #3 on: May 15, 2004, 11:39:46 AM »

Hello Ashkey,

What about the changes I suggested?
Did you include them in 1.3?
Because I am using v1.2 with those changes and I can not migrate to 1.3 without them.

Regards

François
Logged
Ashley
Newbie
*
Offline Offline

Posts: 37


View Profile
Usefull add-on
« Reply #4 on: May 17, 2004, 09:09:55 PM »

Quote
Did you include them in 1.3?
Yes (6th bullet point under "General Enhancements" section of RebDB 1.3 Release Notes).
Logged
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL Sand Box  |  RebDB  |  Topic: Usefull add-on
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 12, 2008, 12:37:44 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2251 Posts in 589 Topics by 2420 Members
Latest Member: pharmacytovvv

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc