Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB General » View Thread |
Messages 1 to 10 of 19 total |
Retreive last GUID from TTable Append |
Tue, Jul 6 2021 10:30 AM | Permanent Link |
Mirco Malagoli | Hi,
what is the correct method to retreive last inserted GUID from a table (defined as Default CURRENT_GUID)? Until now I used Table.Append() Table.FieldByName= ... Table.FieldByName= ... Table.Post() myGUID= Table.FieldByName("GUID")->AsString but sometime i receive a NULL value and other time a wrong value. Now I use Table.Append() myGUID= Table.FieldByName("GUID")->AsString Table.FieldByName= ... Table.FieldByName= ... Table.Post() and seem ok. What is the correct way? Thanks! Mirco |
Wed, Jul 7 2021 3:16 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Mirco
You need to use SQL and check the LASTIDENTITY (Secion 9.14) in my pdf manual Example from the manual SELECT LASTIDENTITY('Customer', 'CustNo') AS LastCustNo Roy Lambert |
Wed, Jul 7 2021 4:48 AM | Permanent Link |
Mirco Malagoli | Roy Lambert wrote:
Mirco You need to use SQL and check the LASTIDENTITY (Secion 9.14) in my pdf manual Example from the manual SELECT LASTIDENTITY('Customer', 'CustNo') AS LastCustNo Roy Lambert Sorry but the field is definited as GUID, the LASTIDENTITY for me always return 0 This is the table definition "CREATE TABLE "giri" ( "idx" GUID COLLATE "UNI" DEFAULT CURRENT_GUID NOT NULL, "prog" INTEGER NOT NULL, ... ) |
Wed, Jul 7 2021 7:01 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Mirco
I apologise. I should have remembered this from a previous thread, especially since I was involved in it. I have an idea which if it works will take me a little time to work out. Roy Lambert |
Wed, Jul 7 2021 7:11 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Mirco
This query SELECT idx FROM giri ORDER BY __RowID DESC RANGE 1 to 1 will give you what you want (I hope) Roy Lambert |
Wed, Jul 7 2021 11:03 AM | Permanent Link |
Mirco Malagoli | Thanks for the reply.
This seems to work but doing a query after the insert slows down the work for me a lot (in some situations I have to insert several thousand records and the work doubles). In a short test the query takes 60mS in my table. It just seemed strange to me that there wasn't a method like the OUT parameter that can be used in scripts. Thanks! Mirco |
Thu, Jul 8 2021 4:12 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Mirco
>This seems to work but doing a query after the insert slows down the work for me a lot (in some situations I have to insert several thousand records and the work doubles). >It just seemed strange to me that there wasn't a method like the OUT parameter that can be used in scripts. Are you using SQL for the insert? If so it should be possible to use an OUT (or an inout) parameter. My aging memory tells me there's something about that on these ngs. If you're using SQL I'll see if I can track it down. Out of interest why do you want to get the GUID after insert? If its to create a linked table you might be better off using an after insert trigger. Roy |
Thu, Jul 8 2021 4:35 AM | Permanent Link |
Mirco Malagoli | No unfortunately I have to use a table with Append () to insert the new record.
I need the GUID to update 2 other linked tables |
Thu, Jul 8 2021 4:39 AM | Permanent Link |
Mirco Malagoli | In the meantime i am trying with Sysutils::CreateGUID() which seems to work for the same purpose.
Any contraindications to this method? Thanks! |
Thu, Jul 8 2021 8:07 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Mirco
>In the meantime i am trying with Sysutils::CreateGUID() which seems to work for the same purpose. >Any contraindications to this method? >Thanks! As long as you remove the default from idx you should be fine. Roy |
Page 1 of 2 | Next Page » | |
Jump to Page: 1 2 |
This web page was last updated on Saturday, May 4, 2024 at 12:54 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |