Thema: Delphi MySQL Fehler

Einzelnen Beitrag anzeigen

Benutzerbild von Mamphil
Mamphil

Registriert seit: 17. Jul 2004
Ort: Garching b. München
149 Beiträge
 
Delphi 7 Professional
 
#7

Re: MySQL Fehler

  Alt 21. Okt 2004, 13:12
Zitat von Jelly:
Was du machen willst ist ein ganzes Skript an den Server schicken. Das klappt abe so nicht über Delphi. Stattdessen solltest du versuchen jede Anweisung einzeln an den Server zu schicken.
Das klappt übrigens auch nicht aus anderen Programmiersprachen heraus....

Ich habe eine kleine Funktion geschrieben, die z. B. einen MySQL-Dump auseinandernimmt und die einzelnen Queries in einen Array schreibt:
Delphi-Quellcode:
// im Bereich interface :
// type
// TSingleSQL = array of AnsiString;
function DumpToSingleSQL(dump: AnsiString): TSingleSQL;
var
  sql: AnsiString;
  inString, currChar: Char;
  inComment, ignore: Boolean;
  numberSingleSQL, dumpLen, i: Integer;
  ergebnis: TSingleSQL;

begin
  // init vars:
  sql := '';
  inString := #0;
  inComment := false;
  ignore := false;
  numberSingleSQL := 0;

  dump := trim(dump);
  dumpLen := Length(dump);

  for i := 1 to dumpLen do
  begin
    currChar := Copy(dump, i, 1)[1];
    // if you are inside a comment
    if inComment then
    begin
      // do nothing until end of line
      if (currChar = #10) or (currChar = #13) then
        inComment := false;
      // but continue anyway
      Continue;
    end;
    // a comment begins with # -> do nothing
    if (currChar = '#') and (inString = #0) then
    begin
      inComment := true;
      Continue;
    end;
    // handle ignore
    if ignore then
      ignore := false
    else
    // ignore character after backslash (\)
    if currChar = '\then
      ignore := true
    else
    // a string begins ...
    if ((currChar = '''') or (currChar = '"'))
       and (inString = #0) then
      inString := currChar
    else
    // a string ends ...
    if (currChar = inString) and (inString <> #0) then
      inString := #0
    else
    // a query ends with ';' (which is not inside a string)
    if (currChar = ';') and (inString = #0) then
    begin
      sql := trim(sql);
      if sql <> 'then
      begin
        SetLength(Result, numberSingleSQL + 1);
        Result[numberSingleSQL] := sql;
        Inc(numberSingleSQL);
        sql := '';
      end;
      Continue;
    end;
    sql := sql + currChar;
  end;
  // if last query does not end with ';' it should not matter:
  sql := trim(sql);
  if sql <> 'then
  begin
    SetLength(Result, numberSingleSQL + 1);
    Result[numberSingleSQL] := sql;
  end;
end;
Da ich noch ein relativer Anfänger in Delphi bin, hoffe ich, keine schweren Fehler in die Funktion eingebaut zu haben ...

Mamphil
The laws of physics are the canvas God laid down on which to paint his masterpiece. “Leonardo Vetra” in Dan Brown’s “Angels & Demons”
  Mit Zitat antworten Zitat