Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 4 of 4 total |
How to iterate through field table definitions ? |
Wed, Aug 7 2013 5:03 PM | Permanent Link |
kamran | HI
Can I update a dbisam table using fieldefs and if so how ? eg an example ? I think the idea would be to have a for loop to make the code tidy instead of one line for each fieldname that needs to be updated. Something like : for i:= 1 to for i := 0 to FieldDefs.Count - 1 do begin iterate through all field names and update with a value end; Kind Regards Kamran |
Wed, Aug 7 2013 9:30 PM | Permanent Link |
Raul Team Elevate | Are you talking about updating the table definition or updating the
actual table data. Fielddefs are mainly used for table changes (like adding/removing or changing columns : http://www.elevatesoft.com/manual?action=viewtopic&id=dbisam4&product=rsdelphiwin32&version=XE4&topic=Creating_Altering_Tables) I highly doubt you can make the code "tidy" using this - you would still need to know what fields mean and what type they are. Exception is cases where you need to mass copy/update or dump table contents to some other format. Just a made up example would be something like this (i just typed it so might need cleanup to compile): //assume you have a open TDataSet called myDS while not myDS.EOF do begin myDS.Edit; for I:=0 to myDS.FieldCount-1 do begin //myDS.Fields[I].DisplayName); //fieldname if myDs.Fields[I].DataType = ftString then myDS.Fields[I].AsString := '' else if myDs.Fields[I].DataType = ftInteger then myDS.Fields[I].AsInteger := 0 end; myDS.Post; myDS.Next; end; this loops thru the table records and then for each it loops thru all fields and sets strings to '' and integer fields to 0. Raul On 8/7/2013 5:03 PM, kamran wrote: > Can I update a dbisam table using fieldefs and if so how ? > > I think the idea would be to have a for loop to make the code tidy instead of one line for each > fieldname that needs to be updated. > |
Thu, Aug 8 2013 9:16 AM | Permanent Link |
kamran | Thanks Raul - that's great - yes it was for a mass update so i did not want to keep typing every single field name (in this case 63 fields) so i guess i was looking for that 'elusive' easier method.
Kamran Raul wrote: Are you talking about updating the table definition or updating the actual table data. Fielddefs are mainly used for table changes (like adding/removing or changing columns : http://www.elevatesoft.com/manual?action=viewtopic&id=dbisam4&product=rsdelphiwin32&version=XE4&topic=Creating_Altering_Tables) I highly doubt you can make the code "tidy" using this - you would still need to know what fields mean and what type they are. Exception is cases where you need to mass copy/update or dump table contents to some other format. Just a made up example would be something like this (i just typed it so might need cleanup to compile): //assume you have a open TDataSet called myDS while not myDS.EOF do begin myDS.Edit; for I:=0 to myDS.FieldCount-1 do begin //myDS.Fields[I].DisplayName); //fieldname if myDs.Fields[I].DataType = ftString then myDS.Fields[I].AsString := '' else if myDs.Fields[I].DataType = ftInteger then myDS.Fields[I].AsInteger := 0 end; myDS.Post; myDS.Next; end; this loops thru the table records and then for each it loops thru all fields and sets strings to '' and integer fields to 0. Raul On 8/7/2013 5:03 PM, kamran wrote: > Can I update a dbisam table using fieldefs and if so how ? > > I think the idea would be to have a for loop to make the code tidy instead of one line for each > fieldname that needs to be updated. > |
Thu, Aug 8 2013 9:43 AM | Permanent Link |
Raul Team Elevate | Doing this thru a sql statement would likely be faster. Of course you'd need to include all fields - if you do this a lot then using the fielddefs you can build the sql update statement runtime in code then execute it as sql Raul On 8/8/2013 9:16 AM, kamran wrote: > Thanks Raul - that's great - yes it was for a mass update so i did not want to keep typing every single field name (in this case 63 fields) so i guess i was looking for that 'elusive' easier method. |
This web page was last updated on Thursday, March 28, 2024 at 08:36 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |