nakagami / firebirdsql

Firebird RDBMS sql driver for Go (golang)
MIT License
220 stars 60 forks source link

Auto trim varchar vs trim char in 0.9.8 #167

Open McFris opened 3 months ago

McFris commented 3 months ago
create procedure TEST_TRIM
returns (
    CH char(4),
    VARCH varchar(4))
as
begin
   CH = 'F   ';
   VARCH = 'F   ';
   suspend;
end

require github.com/nakagami/firebirdsql v0.9.8

conn.QueryRow(`select ch, trim(ch) trimch, varch, trim(varch) trimvarch from test_trim`).Scan(&a.Ch, &a.TrimCh, &a.VarCh, &a.TrimVarCh)

fmt.Printf("Char is: '%s', hex: %v\n", a.Ch, []byte(a.Ch))
fmt.Printf("Trim char is: '%s', hex: %v\n", a.TrimCh, []byte(a.TrimCh))

fmt.Printf("Varchar is: '%s', hex: %v\n", a.VarCh, []byte(a.VarCh))
fmt.Printf("Trim varchar is: '%s', hex: %v\n", a.TrimVarCh, []byte(a.TrimVarCh))

Result: Char is: 'F', hex: [70] Trim char is: 'F', hex: [70] Varchar is: 'F ', hex: [70 32 32 32] <<<<<<<<<<<<< Trim varchar is: 'F', hex: [70]

nakagami commented 3 months ago

CHAR is trimmed VARCHAR is not trimmed These behaviors are as expected.

McFris commented 3 months ago

Is there possibility to make forced trimming similar for all text fields, at least as an option? Similar to FIBPlus for Delphi? изображение

palevi67 commented 1 month ago

I don't know if there is any agreement on whether char fields should be trimmed or not, but I can say that the postgresql drivers don't do it.

McFris commented 1 month ago

I don't know if there is any agreement on whether char fields should be trimmed or not, but I can say that the postgresql drivers don't do it.

And that's why we always have to write such a SQL query: select trim(DATWEB) datweb, trim(CLIENT) client, trim(TIP) tip, trim(PROJECT) project from select_procedure