AArhin / jazz-sdk

Automatically exported from code.google.com/p/jazz-sdk
2 stars 0 forks source link

Problema com OID composto #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Para reproduzir
1. Crie um objeto BO e mapeie mais de um campo como OID
2. Grave algum objeto deste no banco, depois tente excluí-lo(Não tive
problemas com inserção e seleção, apenas com exclusão. Atualização não 
testei)

O comando SQL gerado para esta operação só considera o último campo da OID
para gerar a clausula where

Sugestão:
Alterar TSQLSelectObjectStatement.GetSQLWhere para:
function TSQLSelectObjectStatement.GetSQLWhere: string;
var
 I: Integer;
 LColName: string;
 LParamIndex: Integer;
 LParamName: string;
 LItem: IMemberMeta;
begin
 LParamIndex:= 0;

 for I:= 0 to Meta.OID.Count -1 do
 begin
   LItem:= Meta.OID[I];
   LColName:= Driver.GetColumnName(Meta, LItem.MemberName, False);
   LParamName:= Format('P%d_%s', [LParamIndex, LItem.ColumnName]);
   if I = 0 then
     Result := 'WHERE'
   else
     Result := Result + ' AND';

   Result:= Result + ' (' + LColName + ' = :' + LParamName + ')';
   Inc(LParamIndex);
 end;
end;

Original issue reported on code.google.com by magn...@gmail.com on 12 Dec 2006 at 1:02

GoogleCodeExporter commented 8 years ago
Fixed:

function TSQLSelectObjectStatement.GetSQLWhere: string;
const
  LSQL = '%s (%s = :%s)';
var
  I: Integer;
  LColName: string;
  LParamIndex: Integer;
  LParamName: string;
  LItem: IMemberMeta;
begin
  Result:= '';
  LParamIndex:= 0;

  for I:= 0 to Meta.OID.Count -1 do
  begin
    LItem:= Meta.OID[I];
    LColName:= Driver.GetColumnName(Meta, LItem.MemberName, False);
    LParamName:= Format('P%d_%s', [LParamIndex, LItem.ColumnName]);
    if Result = '' then
      Result:= Format(LSQL, ['WHERE' LColName, LParamName])
    else
      Result:= Format(LSQL, [' AND' LColName, LParamName]);
    Inc(LParamIndex);
  end;
end;

Original comment by cesarliws on 12 Dec 2006 at 4:45