Skip to content

TBufDataset does not support ftVarBytes or ftVariant

Original Reporter info from Mantis: BigChimp
  • Reporter name: Reinier Olislagers

Description:

Assigning/retrieving values to ftVarBytes and ftVariant data types in TBufDataset doesn't seem to work. See attached test code.

Either:

  1. I'm doing something wrong
  2. TBufDataset should not support those field types and explicitly error out when trying to create them
  3. Support for those types needs to be added.

In case 1, I can update at least the wiki:
- http://wiki.lazarus.freepascal.org/Database_field_type
- http://wiki.lazarus.freepascal.org/How_to_write_in-memory_database_applications_in_Lazarus/FPC
... but I'd appreciate a mention in the FPC documentation (e.g. in the info on ftVarBytes, ftVariant) on how to set the value for these datatypes.

Steps to reproduce:

Compile and run attached test project.
My output on Windows Vista x64 with a recent Lazarus/FPC snapshot:
bufvarerror --format=plain -a
 Time:00.001 N:2 E:1 F:1 I:0
  TtestBufVar Time:00.001 N:2 E:1 F:1 I:0
    00.000  TestBufVar_VarBytes  Failed: ftVarBytes returns correct data expecte
d: <Hello 42 this is longer than 10 characters> but was: <Hello 42 t  >
    00.001  TestBufVar_Variant  Error: EAccessViolation
      Exception:   Access violation
      Source unit:
      Method name:
      Line number: 96

Number of run tests: 2
Number of errors: 1
Number of failures: 1

List of errors:

  Error:
    Message:           TtestBufVar.TestBufVar_Variant: Access violation
    Exception class:   EAccessViolation
    Exception message: Access violation
    Source unitname:
    Line number:       96
    Failed methodname:

List of failures:

  Failure:
    Message:           TtestBufVar.TestBufVar_VarBytes: ftVarBytes returns corre

ct data expected: &LtPos;Hello 42 this is longer than 10 characters> but was: &LtPos;Hello 4
2 t >

    Exception class:   EAssertionFailedError
    Exception message: ftVarBytes returns correct data expected: <Hello 42 this

is longer than 10 characters> but was: &LtPos;Hello 42 t >

D:\Reinier\Documents\SourceCode\fpc_laz_patch_playground\bufdataset>bufvarerror
--format=plain -a
 Time:00.001 N:4 E:2 F:1 I:0
  TtestBufVar Time:00.001 N:4 E:2 F:1 I:0
    00.000  TestBufVar_VarBytesLong  Failed: ftVarBytes returns correct data exp
ected: <Hello 42 this is longer than 10 characters> but was: <Hello 42 t  >
    00.000  TestBufVar_VariantLong  Error: EAccessViolation
      Exception:   Access violation
      Source unit:
      Method name:
      Line number: 145
    00.000  TestBufVar_VarBytesShort
    00.001  TestBufVar_VariantShort  Error: EAccessViolation
      Exception:   Access violation
      Source unit:
      Method name:
      Line number: 145

Number of run tests: 4
Number of errors: 2
Number of failures: 1

List of errors:

  Error:
    Message:           TtestBufVar.TestBufVar_VariantLong: Access violation
    Exception class:   EAccessViolation
    Exception message: Access violation
    Source unitname:
    Line number:       145
    Failed methodname:

  Error:
    Message:           TtestBufVar.TestBufVar_VariantShort: Access violation
    Exception class:   EAccessViolation
    Exception message: Access violation
    Source unitname:
    Line number:       145
    Failed methodname:

List of failures:

  Failure:
    Message:           TtestBufVar.TestBufVar_VarBytesLong: ftVarBytes returns c

orrect data expected: &LtPos;Hello 42 this is longer than 10 characters> but was: &LtPos;Hel
lo 42 t >

    Exception class:   EAssertionFailedError
    Exception message: ftVarBytes returns correct data expected: <Hello 42 this

is longer than 10 characters> but was: &LtPos;Hello 42 t >

Additional information:

I've marked this major because people who don't know these types don't work will get unexpected crashes.

See mailing list discussion, with thanks to Ludo Brands:
http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg25061.html

How can I properly assign values to ftVarBytes and ftVariant
and retrieve them? I know I asked before for ftVarBytes; I
just use .AsString:='bla', but obviously it doesn't work.

Same problem as before: TBufDataset doesn't support correctly ftVarBytes and
ftVariant and doesn't raise an SErrFieldTypeNotSupported like TMemDataset is
doing.
Look at TCustomBufDataset.GetFieldSize and you'll see that data length for
ftVarBytes and ftVariant is arbitrarely set at 10. Compare this with
TMemDataset.MDSGetBufferSize.

Mantis conversion info:

  • Mantis ID: 19930
  • OS: Windows
  • OS Build: Vista
  • Build: 2.5.1, SVN 31861
  • Platform: x64
  • Fixed in version: 3.0.0
  • Monitored by: » @lacak.sk (LacaK)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information