![]() |
Datenbank: MySQL • Version: 5 • Zugriff über: Ka
Syntax SQL Update
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
ich habe aktuell ein SQL Query Update Syntax problem... ich habe bereits schon viele Schreibweisen ausprobiert und jedesmal kommt eine Fehlermeldung an unterschiedlicher stelle, wie angehängt. Ich hatte schon alle Edits in QuotedStr() gepackt, schon "" weggelassen und [""] ausprobiert, aber nichts hilft... Habt Ihr eine schnelle abhilfe für mich? Aktuell:
Code:
MainModule.UniMainModule.mySQLQuery1.SQL.Text := 'update `' + UniMainModule.SQLTabelle + '`' + #10 +
'set' + #10 + ' Vorname = "'+UniEdit8.Text+'",'+ #10 + ' Name = "'+UniEdit12.Text+'",'+ #10 + ' user = "'+lowercase(UniEdit13.Text)+'",'+ #10 + ' Firma = "'+UniEdit1.Text+'",'+ #10 + ' Adress1 = "'+UniEdit2.Text+'",'+ #10 + ' Adress2 = "'+UniEdit3.Text+'",'+ #10 + ' Straße = "'+UniEdit4.Text+'",'+ #10 + ' PLZ = "'+ UniEdit5.Text+'",'+ #10 + ' Ort = "'+ UniEdit6.Text+'",'+ #10 + ' Land = "'+ UniEdit7.Text+'",'+ #10 + ' Telefonnummer = '+ UniEdit14.Text + '' + #10 + 'where'+ #10 + ' Vorname = '+UniMainModule.Vorname+' and'+ #10 + ' Name = '+UniMainModule.Name+' and'+ #10 + ' user = '+UniMainModule.user+' and'+ #10 + ' Firma = '+UniMainModule.Firma+' and'+ #10 + ' Adress1 = '+UniMainModule.Adress1+' and'+ #10 + ' Adress2 = '+UniMainModule.Adress2+' and'+ #10 + ' Straße = '+UniMainModule.Straße+' and'+ #10 + ' PLZ = '+UniMainModule.PLZ+' and'+ #10 + ' Ort = '+UniMainModule.Ort+' and'+ #10 + ' Land = '+UniMainModule.Land+' and'+ #10 + ' Telefonnummer = ' + UniMainModule.Telefon + ';'; MainModule.UniMainModule.mySQLQuery1.ExecSQL; |
AW: Syntax SQL Update
Benutze Parameter ... aus mehreren Gründen
Wie und wo findest du über die Forensuche |
AW: Syntax SQL Update
Hallo,
das Schlimme an dem Code ist, dass er überhaupt nicht debuggbar ist. Warum schreibst du den SQL-Befehl nicht vorher in eine Stringvariable. Dann könntest du uns den Inhalt der Variable hier posten. In deinem Where fehlen übrigens die Klammern um die einzelnen Abschnitte und das QuotedStr oder halt besser Parameter. Heiko |
AW: Syntax SQL Update
Such mal nach sog. 'Surrogate Keys'. Die sind besser geeignet, einen Datensatz eindeutig zu identifizieren.
Die einzelnen Strings in der Where-Klausel müssen mit Gänsefüßchen umschlossen werden. Das übernehmen die Parameter für Dich. |
AW: Syntax SQL Update
Zitat:
Und wie Dejan Vu erwähnte, in der where-Klausel müssen die Strings ebenfalls in " oder ' eingefasst werden. Gruß K-H |
AW: Syntax SQL Update
Hallo,
er gibt mir zwar keine Fehlermeldung aus, aber es passiert auch kein Update in der Datenbank... ?! Woran könnte es liegen?
Code:
MainModule.UniMainModule.mySQLQuery1.SQL.Clear;
MainModule.UniMainModule.mySQLQuery1.SQL.Add('update `' + UniMainModule.SQLTabelle + '`'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('set'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Vorname = :Vorname,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Name = :Name,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('user = :user,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Firma = :Firma,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Adress1 = :Adress1,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Adress2 = :Adress2,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Straße = :Straße,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('PLZ = :PLZ,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Ort = :Ort,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Land = :Land,'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Telefonnummer = :Telefonnummer'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('where'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Vorname = :OLD_Vorname and'); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Name = :OLD_Name'); MainModule.UniMainModule.mySQLQuery1.ParamByName('Vorname').AsString := UniEdit8.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Name').AsString := UniEdit12.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('user').AsString := lowercase(UniEdit13.Text); MainModule.UniMainModule.mySQLQuery1.ParamByName('Firma').AsString := UniEdit1.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Adress1').AsString := UniEdit2.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Adress2').AsString := UniEdit3.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Straße').AsString := UniEdit4.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('PLZ').AsString := UniEdit5.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Ort').AsString := UniEdit6.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Land').AsString := UniEdit7.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Telefonnummer').AsString := UniEdit14.Text; MainModule.UniMainModule.mySQLQuery1.ExecSQL; |
AW: Syntax SQL Update
Hier fehlte schon mal das Leerzeichen am Ende:
Delphi-Quellcode:
Und hier der Strichpunkt (wenn dies meist tleriert wird):
MainModule.UniMainModule.mySQLQuery1.SQL.Add('Vorname = :OLD_Vorname and ');
Delphi-Quellcode:
MainModule.UniMainModule.mySQLQuery1.SQL.Add('Name = :OLD_Name;');
|
AW: Syntax SQL Update
Hey,
leider wird immernoch nichts in der DB akualisiert:/
Code:
MainModule.UniMainModule.mySQLQuery1.SQL.Clear;
MainModule.UniMainModule.mySQLQuery1.SQL.Add('update ' + UniMainModule.SQLTabelle); MainModule.UniMainModule.mySQLQuery1.SQL.Add('set '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Vorname = :Vorname, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Name = :Name, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('user = :user, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Firma = :Firma, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Adress1 = :Adress1, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Adress2 = :Adress2, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Straße = :Straße, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('PLZ = :PLZ, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Ort = :Ort, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Land = :Land, '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Telefonnummer = :Telefonnummer '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('where '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Vorname = :OLD_Vorname and '); MainModule.UniMainModule.mySQLQuery1.SQL.Add('Name = :OLD_Name;'); MainModule.UniMainModule.mySQLQuery1.ParamByName('Vorname').AsString := UniEdit8.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Name').AsString := UniEdit12.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('user').AsString := lowercase(UniEdit13.Text); MainModule.UniMainModule.mySQLQuery1.ParamByName('Firma').AsString := UniEdit1.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Adress1').AsString := UniEdit2.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Adress2').AsString := UniEdit3.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Straße').AsString := UniEdit4.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('PLZ').AsString := UniEdit5.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Ort').AsString := UniEdit6.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Land').AsString := UniEdit7.Text; MainModule.UniMainModule.mySQLQuery1.ParamByName('Telefonnummer').AsString := UniEdit14.Text; MainModule.UniMainModule.mySQLQuery1.ExecSQL; |
AW: Syntax SQL Update
Zitat:
Nicht, dass das nicht funktionieren würde, aber für so was nimmt man eine ID mit autoincrement, oder macht sich notfalls eine eigene. Hauptsache sie ist eindeutig. Ich hatte bei meinem früheren Arbeitgeber tatsächlich mal 2 Kollegen mit gleichem Vor- und Nachnamen. Kommt öfter vor, als man denkt. |
AW: Syntax SQL Update
Logisch. Du läßt ja Old_Vorname und Old_Name leer. Somit wird auch kein Datensatz gefunden, auf den die Where-Bedingung zutrifft. Aber nochmal siehe meinen Post vorher.
Füg man diese Zeilen hinzu:
Code:
MainModule.UniMainModule.mySQLQuery1.ParamByName('Old_Vorname).AsString := ichmussmirdenvornamenirgendwiemerken;
MainModule.UniMainModule.mySQLQuery1.ParamByName('Old_Name).AsString := jetztmussichmirdennachnamenauchnochirgendwiemerken; |
AW: Syntax SQL Update
Zitat:
|
AW: Syntax SQL Update
@Captnemo
nun geht es! Vielen Dank. Das mit der ID in der Tabelle, um eine eindeutige Zuordnung des Datensatzes zubekommen, ist bei mir auf der Uhr, dazu muss ich später dann die Tabellen alle anpassen und brauche dann nur WHERE ID=XX eintragen im Code (is natürlich einfacher^^), dann sollte das erledigt sein... Erst einmal vielen Dank! Gerne Abschluss. |
AW: Syntax SQL Update
Zitat:
|
AW: Syntax SQL Update
Hallo,
zumindestens der SQL-Server hatte mal Probleme mit fehlendem Semikolon, also mkinzler immer mit anführen. Heiko |
AW: Syntax SQL Update
Zitat:
|
AW: Syntax SQL Update
Zitat:
Zitat:
Jedes .Add schreibt gleichzeitig auch einen Zeilentrenner in den .Text, von daher kann man sich die "TrennerBlanks" am Zeilenende sparen. Gruß K-H |
AW: Syntax SQL Update
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:09 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz