#1 2012-04-16 22:46:49

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Copy information between 2 databases

I need of a tool to convert a small version of my database to a new version. My old databse is similat to new database but on new database I have remove some record and remane some of them.

On my tool I use this code to set new record value from old record value:

    while TableOld.FillOne do
      begin
        TableNew := TableNameNew.Create;

        for i := 0 to Length(TableOld.RecordProps.FieldsName) - 1 do
          begin
            Excluded := False;

            for a := 0 to Length(ExcludedFields) - 1 do
              begin
                if LowerCase(TableOld.RecordProps.FieldsName[i]) = LowerCase(StringToUTF8(ExcludedFields[a])) then
                  begin
                    Excluded := True;
                    Break;
                  end;
              end;

            Modified := -1;

            for a := 0 to Length(ModifiedFieldsOld) - 1 do
              begin
                if LowerCase(TableOld.RecordProps.FieldsName[i]) = LowerCase(StringToUTF8(ModifiedFieldsOld[a])) then
                  begin
                    Modified := a;
                    Break;
                  end;
              end;

            if not Excluded then
              begin
                if Modified > -1 then
                  begin
                    TableNew.SetFieldVariant(ModifiedFieldsNew[Modified], TableOld.GetFieldVariant(TableOld.RecordProps.FieldsName[i]));
                  end
                else
                  begin
                    TableNew.SetFieldVariant(TableOld.RecordProps.FieldsName[i], TableOld.GetFieldVariant(TableOld.RecordProps.FieldsName[i]));
                  end;
              end;
          end;

        TableNew.ID := TableOld.ID;
        DatabaseDummy2.Add(TableNew, True, True);
        TableNew.Free;
      end;

This code works, but I have some problem with DATE fields. All DATE fields of my new database are "30/12/1899".

Do you have any advice to copy all formats without problems?

Thanks

Offline

#2 2012-04-17 05:43:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Copy information between 2 databases

SetFieldVariant / GetFieldVariant is perhaps not the best way to process it.

You may simply use GetValue / SetValue, and a temp RawUTF8.

Note also that you have some dedicated methods to locate a field, without coding a loop, named FieldIndex() or FieldIndexFromRawUTF8().

Offline

#3 2012-04-17 12:14:07

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Copy information between 2 databases

I think you mean GetFieldValue/SetFieldValue. There are not GetValue/SetValue.

Do you think GetFieldValue/SetFieldValue work also with TSQLRawBlob record?

Last edited by array81 (2012-04-17 12:26:05)

Offline

#4 2012-04-17 12:35:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Copy information between 2 databases

I meant TPropInfo.GetValue() and TPropInfo.SetValue(), since you are working on the field level.
GetFieldValue/SetFieldValue are wrapper around those methods.

It will handle TSQLRawBlob directly.

Offline

Board footer

Powered by FluxBB