Page 1 of 1

TZTable establish a dbText type field with empty and non-NUL

Posted: 08.05.2013, 09:36
by MiguelAngel
Hi,

took several days to a problem that has naked eye should not be hard to fix, but here I am not knowing what else to turn. Such a problem has arisen with the I component ZEOS TZTable package.

I'm programming with Delphi 2010 and using version 7.0.3 stable ZEOS

It is assigned an empty value, not NULL, a specific type field DBMemo. But to assign the empty string, the component sets this field to the value NULL in the database (MySQL). It is not a problem of the structure of the table, as if the insertion is done by SQL code works perfectly.

Here I leave the function I use to assign this field


This is the function in DELPHI:

[php]

procedure SetValues(tipo:integer; valor:String='');
begin
With zTable1 do
try
if not (State in [DsEdit, DsInsert]) then
edit;
case tipo of
//Set value to NULL
0:fieldByname(fieldName).Clear;
//Set value to EMPTY
1:fieldByname(fieldName).AsString:='';
else
//Set value to TEXT
fieldByname(fieldName).AsString:=Valor;
end;
finally
try
post;
except
On e:Exception do begin
MessageDlg(E.Message, mtError, [mbOK], 0);
cancel;
end;
end;
end;
end;

[/php]


the function fails when type = 1, I tried putting the character 0 (# 0) instead of double quotes, and in that case no longer returns a NULL value, but that option does not help, because the length of the field and not is 0, otherwise 1.

As a last alternative I upgraded to the latest version of ZEOS and continuous components with the same problem.

Indicate that this same process is working without any problem with ADO components into a MSSQL database

Thanks for your help and greet all

Posted: 09.05.2013, 18:50
by crono81
I found a workaround in the file ZDbcCache.pas
in this function:

Code: Select all

function TZRowAccessor.GetAsciiStream(ColumnIndex: Integer;
  var IsNull: Boolean): TStream;
var
  TempBlob: IZBlob;
begin
{$IFNDEF DISABLE_CHECKING}
  CheckColumnConvertion(ColumnIndex, stAsciiStream);
{$ENDIF}
  TempBlob := GetBlobObject(FBuffer, ColumnIndex);
  if (TempBlob <> nil) and not TempBlob.IsEmpty then
    Result := TempBlob.GetStream
  else Result := nil;
  IsNull := Result = nil;
end;
in the line:

Code: Select all

if (TempBlob <> nil) and not TempBlob.IsEmpty then
the "not TempBlob.IsEmpty" causes the "issue", I tried already, and i can insert empty string in text data type fields with the TZTable

Posted: 15.05.2013, 16:26
by MiguelAngel
Thanks for your answer crono81

I tried removing that condition and return to recompile and install the package, but not eliminate this bug

Since this bug fix needed as quickly as possible, I have chosen not to distinguish between NULL values ​​and EMPTY

A greeting