Page 1 of 1

[bug_fixed] error handling empty string values (makes NULLS)

Posted: 29.05.2007, 14:15
by zx
bug report: error handling empty string values - makes 'em NULLS
when you set field value to '' it is posted as null in ADO

I do not even want to comment this issue. In fact, it is your code and you know much more about it. The only thing I say is how does it look like now and how should it look like to work.

unit dbc\ZDbcAdoStatement.pas

original code:

Code: Select all

  S := 0;
  if SQLType = stString then
  begin
    S := Length(VarToStr(V));
    if S = 0 then
    begin
      S := 1;
      V := Null;
    end;
  end;

  if SQLType in [stUnicodeString] then
  begin
    S := Length(VarToWideStr(V));
    if S = 0 then
    begin
      S := 1;
      V := Null;
    end;
  end;
patched code:

Code: Select all

  S := 0;
  if SQLType in [stString, stUnicodeString]  then
  begin
    S := Length(VarToStr(V));
    if S = 0 then
    begin
      S := 1;
	  // no need or empty 
	  // strings become NULLS
      // V := Null;
    end;
  end;


[platform notes]
zeosdbo-6.6.1-beta
protocol: ado
delphi7
Microsoft SQL server 2000
or Microsoft Access via Jet ADO provider

Posted: 29.05.2007, 23:51
by mdaems
Hi Zx,

Are you sure there shouldn't be a difference between VarToStr ands VarToWidestr? S is reused later in the procedure as well so in case it's not an empty string it should be correct for the corresponding datatypes. Or is a string equally long as a UnicodeString? (May be a stupid question, but I don't really know the difference, sorry)

Mark

Posted: 30.05.2007, 06:06
by zx
mdaems wrote: Are you sure there shouldn't be a difference between VarToStr ands VarToWidestr?
Well, no. You are sure right. In fact, I've lost the difference, sorry. (But there is a number of applications working fine with this lame patch).

But nevertheless, changes should be done to make the code handle empty string values the right way.

Keeping your remarks in mind the code should look like:

Code: Select all

  S := 0; 
  if SQLType = stString then 
  begin 
    S := Length(VarToStr(V)); 
    if S = 0 then 
    begin 
      S := 1; 
      // V := Null; 
    end; 
  end; 

  if SQLType in [stUnicodeString] then 
  begin 
    S := Length(VarToWideStr(V)); 
    if S = 0 then 
    begin 
      S := 1; 
      // V := Null; 
    end; 
  end;
mdaems wrote: S is reused later in the procedure as well so in case it's not an empty string it should be correct for the corresponding datatypes.
Mark
Well, I think I did nothing about corrupting S value for later code.
Thanks a lot for attention, sorry for my unfortunate misprint.

Posted: 30.05.2007, 12:44
by mdaems
Committed. Rev. 254.