Einzelnen Beitrag anzeigen

DangerDistel

Registriert seit: 3. Aug 2012
16 Beiträge
 
Delphi 2010 Professional
 
#4

AW: TADOQuery und LIKE

  Alt 17. Mai 2013, 20:57
Delphi-Quellcode:
procedure TDataMod.SQL_LIKE_TBLSearch(AConnection:TADOConnection; ATblName:WideString;
                                 arr_TBLCols:array of string;
                                 arr_TBLValues:array of string;
                                 APK:string;
                                 var AResultList:TStringList);
var AQuery:TADOQuery;
    ASQLTemp:string;
    ix:integer;
    ASQL_Default:string;
begin
{SELECT STAEDTE.ID_STADT, STAEDTE.STADT_NAME
FROM STAEDTE
WHERE (([STAEDTE]![STADT_NAME] Like "*Mark"));}

  if AConnection <> nil then
  begin
    if Trim(ATblName) <> EmptyWideStr then
    begin
      if Length(arr_TBLCols) > 0 then
      begin
        if Length(arr_TBLValues) > 0 then
        begin
          if Length(arr_TBLCols) = Length(arr_TBLValues) then
          begin
            if TblExists(AConnection,ATblName) then
            begin
              AQuery:=TADOQuery.Create(Self);
              try
                ASQLTemp:='SELECT * FROM' + fConstants.BLANK1 +
                             ATblName +
                             fConstants.BLANK1 +
                             'WHERE' +
                             fConstants.BLANK1;
                ASQL_Default:=ASQLTemp;
                for ix:=Low(arr_TBLCols) to High(arr_TBLCols) do
                begin
                  if (Trim(arr_TBLCols[ix]) <> EmptyStr) and
                     (Trim(arr_TBLValues[ix]) <> EmptyStr) then
                  begin
                    if Length(arr_TBLCols) = 1 then
                    begin
                      ASQLTemp:=ASQLTemp + '[' + ATblName +']![' + arr_TBLCols[ix] + ']' + fConstants.BLANK1 +
                                'LIKE' + fConstants.BLANK1 + fConstants.AnfZeichen + arr_TBLValues[ix] + '*' + fConstants.AnfZeichen;
                    end else
                    begin
                      if ix < High(arr_TBLCols) then
                      begin
                        ASQLTemp:=ASQLTemp + '[' + ATblName +']![' + arr_TBLCols[ix] + ']' + fConstants.BLANK1 +
                                  'LIKE' + fConstants.BLANK1 + fConstants.AnfZeichen + arr_TBLValues[ix] + fConstants.AnfZeichen + fConstants.BLANK1 + 'AND' + fConstants.BLANK1;
                      end else
                      begin
                        if ix = High(arr_TBLCols) then
                        ASQLTemp:=ASQLTemp + '[' + ATblName +']![' + arr_TBLCols[ix] + ']' + fConstants.BLANK1 +
                                  'LIKE' + fConstants.BLANK1 + fConstants.AnfZeichen + arr_TBLValues[ix] + fConstants.AnfZeichen;
                      end;
                    end;
                  end;
                end;
                if ASQLTemp <> ASQL_Default then
                begin
                  AQuery.Connection:=AConnection;
                  AQuery.SQL.Add(ASQLTemp);
                  AQuery.Open;
                  AQuery.First;
                  while not(AQuery.Eof) do
                  begin
                    AResultList.Add(AQuery.FieldByName(fConstants.TBL_TOWN_ID).AsString);
                    AQuery.Next;
                  end;
                  AQuery.Close;
                end;
              finally
                AQuery.Free;
              end;
            end;
          end;
        end;
      end;
    end;
  end;
end;
so also die [-Klammern habe hinzugefügt, da Acces mir diese anbietet, die ADOQuery bingt auch keinen Fehler, der RecordCount is immernoch 0 :/
Alex

Geändert von MrSpock (17. Mai 2013 um 21:32 Uhr) Grund: Delphi Tags eingefügt.
  Mit Zitat antworten Zitat