|
Pages: [1]
|
 |
|
Author
|
Topic: Usefull add-on (Read 1110 times)
|
|
François
|
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 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
|
Hep, Here is the codes I modified to %db.r to let 'db-insert return the newly created value: 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
|
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.
|
|
|
|
|
Logged
|
|
|
|
|
François
|
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
|
Did you include them in 1.3?
Yes (6th bullet point under "General Enhancements" section of RebDB 1.3 Release Notes).
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2233 Posts in 581 Topics by 1886 Members
Latest Member: antigopit
|