Recent

Author Topic: Fields being truncated.  (Read 523 times)

Prime

  • Jr. Member
  • **
  • Posts: 63
Fields being truncated.
« on: April 08, 2023, 09:10:35 am »
Hi all,

I'm using the Zeos components to access a sqllite database and am having the following problem in modifying fields in my program.
Code: Pascal  [Select][+][-]
  1. PROCEDURE TDoomDataModule.FixIWADPaths;
  2.  
  3. VAR     IWADNo  : INTEGER;
  4.     OldPath : STRING;
  5.     NewPath : STRING;
  6.     WADFile : TWadBin;
  7.  
  8. BEGIN;
  9.   FErrors.Clear;
  10.   WADFile:=TWadBin.Create;
  11.   TRY
  12.     WITH ZIWADQuery DO
  13.     BEGIN;
  14.       First;
  15.       FOR IWADNo:=0 TO (RecordCount-1) DO
  16.       BEGIN;
  17.         OldPath:=FieldByName(DBFIWadsFilename).AsString;
  18.         NewPath:=FindGameFile(OldPath,FFTryAll);
  19.         Debug.Log('OldPath: %s, Length=%d',[OldPath,Length(OldPath)]);
  20.         Debug.Log('NewPath: %s,Length=%d',[NewPath,Length(NewPath)]);
  21.  
  22.         IF (NewPath <> OldPath) THEN
  23.         BEGIN;
  24.           WADFile.LoadFromFile(NewPath);
  25.           IF (WADFile.IsIWAD) THEN
  26.           BEGIN;
  27.             Edit;
  28.             FieldByName(DBFIWadsFilename).AsString:=NewPath;
  29.             Post;
  30.             Debug.Log('Replaced: %s, Length=%d',[FieldByName(DBFIWadsFilename).AsString,Length(FieldByName(DBFIWadsFilename).AsString)]);
  31.           END;
  32.         END;
  33.         Next;
  34.       END;
  35.     END;
  36.   FINALLY
  37.     WADFile.Free;
  38.   END;
  39. END;
  40.  

The output I get on the debug log is :

Code: Pascal  [Select][+][-]
  1. [127.0.0.1] OldPath: G:\games\doomsday\Run\jHeretic\blasphem.wad, Length=43
  2. [127.0.0.1] NewPath: /usr/local/share/doom/wads/blasphem.wad,Length=39
  3. [127.0.0.1] Replaced: /usr/local/share/doom/wads/blasphem.wa, Length=38
  4.  

As you can see the posted string is truncated by one character, when read back. I don't have this problem if I edit the field with one of the visual components, or if I execute a query which replaces the values.

The field I'm replacing is defined as blob, so it shouldn't be an issue of overflowing the database field. Also if I edit that field in another part of the code and add the missing last character that replacement works.

Anyone have any idea what is going on here.

Cheers.

Phill.

balazsszekely

  • Guest
Re: Fields being truncated.
« Reply #1 on: April 08, 2023, 11:59:32 am »
1. Try this:
Code: Pascal  [Select][+][-]
  1.  IF (NewPath <> OldPath) THEN
  2.  BEGIN;
  3.    WADFile.LoadFromFile(NewPath);
  4.    IF (WADFile.IsIWAD) THEN
  5.    BEGIN;
  6.      Edit;
  7.      FieldByName(DBFIWadsFilename).AsString:=NewPath + #0; //<-add #0
  8.      Post;
  9.      Debug.Log('Replaced: %s, Length=%d',[FieldByName(DBFIWadsFilename).AsString,Length(FieldByName(DBFIWadsFilename).AsString)]);
  10.    END;
  11.  END;

2. If 1 is not working, then:
Code: Pascal  [Select][+][-]
  1.   IF (NewPath <> OldPath) THEN
  2.   BEGIN;
  3.     WADFile.LoadFromFile(NewPath);
  4.     IF (WADFile.IsIWAD) THEN
  5.     BEGIN;
  6.       Edit;
  7.       ST := CreateBlobStream(FieldByName('DBFIWadsFilename'), bmWrite);
  8.       try
  9.         ST.WriteBuffer(Pointer(NewPath)^, Length(NewPath));
  10.         ST.Position := 0;
  11.         Post;
  12.       finally
  13.         ST.Free;
  14.       end;
  15.       Debug.Log('Replaced: %s, Length=%d',[FieldByName(DBFIWadsFilename).AsString,Length(FieldByName(DBFIWadsFilename).AsString)]);
  16.     END;
  17.   END;

 

TinyPortal © 2005-2018