Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 7 of 7 total |
Best Practice -> Copying a full record in same table... |
Mon, Jun 25 2007 11:02 AM | Permanent Link |
Bryan | Hello group.
What is the best way to copy a record in a table? Basically what I want to do is copy a single record and paste it back into the same table and then change only a couple items (field values). I was planning on reading each field, into a record structure, then insert the data back into the table with slight modifications. Is there an easier way with SQL maybe? Thanks for any suggestions. Regards, Bryan |
Mon, Jun 25 2007 11:20 AM | Permanent Link |
"Terry Swiers" | Bryan,
> Basically what I want to do is copy a single record and paste it back into > the same table and then change only a couple items (field values). Look at the CopyOnAppend property for the DBISAM table or query components. With this property, you can easily copy the current row, make your changes, and then save it down into the same table using the following code: Table.CopyOnAppend := True; Table.Insert; //Make your data changes here Table.Post; Table.CopyOnAppend := False; Hope this helps. -- --------------------------------------- Terry Swiers Millennium Software, LLC http://www.1000years.com http://www.atrex.com Atrex Inventory Control/POS - Big business features without spending big business bucks! Atrex Electronic Support Options: Atrex Knowledgebase: http://www.atrex.com/atrexkb.asp Email: mailto:support@atrex.com Newsgroup: news://news.1000years.com/millennium.atrex Fax: 1-925-829-1851 Phone: 1-925-828-5892 (M-F, 9a-5p Pacific) --------------------------------------- |
Mon, Jun 25 2007 11:52 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Bryan
You could use something like INSERT INTO Companies SELECT '000000000000000' AS _Company, CAST('FRED BLOGGS' AS VARCHAR(60)) AS "_Name" , "_Parent", "_Fax", "_Phone" , "_STDCode" , "_Website" , "_Area1" , "_OrgType", FALSE AS "_CTPS" , "_SICGroup" , "_MainSIC" , "_MainMarket" , "_Turnover" , "_Staffing", "_YearEnd" , "_Status" , "_Control" , "_Consultant", "_AlteredBy" , CURRENT_DATE AS "_ModDate" , "_Source" , CAST (NULL AS DATE) AS "_LastCall", "_Created" , "_Notes" , "_Address" , CAST(NULL AS MEMO) AS "_Links" , CAST(NULL AS MEMO) AS "_mpGrp" , CAST(NULL AS MEMO) AS "_mpSup", CAST(NULL AS MEMO) AS "_mpCust" , CAST(NULL AS MEMO) AS "_mpRivals" , CAST(NULL AS MEMO) AS "_Profile" , CAST(NULL AS MEMO) AS "_Products" FROM Companies WHERE _Company = '2SISTERSPREM' But I personally I just have two instances of the table and do a loop round the fields. Roy Lambert |
Mon, Jun 25 2007 2:43 PM | Permanent Link |
Dave Harrison | Terry Swiers wrote:
> Bryan, > > >>Basically what I want to do is copy a single record and paste it back into >>the same table and then change only a couple items (field values). > > > Look at the CopyOnAppend property for the DBISAM table or query components. > With this property, you can easily copy the current row, make your changes, > and then save it down into the same table using the following code: > > Table.CopyOnAppend := True; > Table.Insert; > //Make your data changes here > Table.Post; > Table.CopyOnAppend := False; > > Hope this helps. > Terry, That's clever. I suppose the autoinc fields will have to be set to NULL prior to the post to avoid duplicate index entries (or does DBISAM override the duplicate autoinc field by generating a new one?). Dave |
Mon, Jun 25 2007 3:35 PM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Dave
> That's clever. I suppose the autoinc fields will have to be set to >NULL prior to the post to avoid duplicate index entries (or does DBISAM >override the duplicate autoinc field by generating a new one?). I'd forgotten that way You will need to set the autoincs back to null so that DBISAM will create a new one for you, also alter any fields that are part of a unique index. Roy Lambert |
Mon, Jun 25 2007 4:27 PM | Permanent Link |
Bryan | Terry,
It works like a charm. Thanks! Roy, thanks for your suggestion also. Cheers, Bryan "Terry Swiers" <millennium@1000years.com> wrote: Bryan, > Basically what I want to do is copy a single record and paste it back into > the same table and then change only a couple items (field values). Look at the CopyOnAppend property for the DBISAM table or query components. With this property, you can easily copy the current row, make your changes, and then save it down into the same table using the following code: Table.CopyOnAppend := True; Table.Insert; //Make your data changes here Table.Post; Table.CopyOnAppend := False; Hope this helps. -- --------------------------------------- Terry Swiers Millennium Software, LLC http://www.1000years.com http://www.atrex.com Atrex Inventory Control/POS - Big business features without spending big business bucks! Atrex Electronic Support Options: Atrex Knowledgebase: http://www.atrex.com/atrexkb.asp Email: mailto:support@atrex.com Newsgroup: news://news.1000years.com/millennium.atrex Fax: 1-925-829-1851 Phone: 1-925-828-5892 (M-F, 9a-5p Pacific) --------------------------------------- |
Sun, Jul 15 2007 2:21 PM | Permanent Link |
"Ralf Mimoun" | Bryan wrote:
> It works like a charm. Thanks! Don't forget to use a bunch of try/finally blocks to make absolutely sure to switch of CopyOnAppend. Ralf |
This web page was last updated on Sunday, May 19, 2024 at 08:46 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |