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

Code patches written by our users to solve certain "problems" that were not solved, yet.

Moderators: gto, cipto_kh, EgonHugeist, mdaems

Post Reply
zx
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 13.10.2005, 14:05

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

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
zx
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 13.10.2005, 14:05

Post 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.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Committed. Rev. 254.
Post Reply