Autor Beitrag
AndreM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Win2k, WinXP, Suse 10
D7 Ent
BeitragVerfasst: Sa 24.01.04 10:28 
Hallo,

ich füge über ein IBQuery einen neuen Datensatz in eine IB-DB ein. Die Daten hierzu werden aus mehreren Edit-Feld gelesen.
Das ganze klappt auch schon ganz wunderbar. Nur leider gibt es ein kleines Problem, wenn in den Edit-Feld ein " eingefügt wird. Denn das Zeichen wird ja in einem SQL-String dazu benutzt Strings zu markieren.

Nur kann ich ja schlecht dem Anwender verbieten ein " in seinen Daten zu verwenden. Gibt es irgendein Möglichkeit das ganze zu umgehen, oder muß ich wirklich überprüfen ob ein " in irgendeinem der Felder eingefügt wurde und dann ne Fehlermeldung aufen Bildschirm schmeißen?
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 24.01.04 10:35 
Du könntest im OnKey.... Event des Editfeldes das ' Zeichen ausblenden, indem Du auf dieses Zeichen prüfst und dann #0 zürückgibst. Damit kann der Nutzer das Zeichen nicht eingeben.

Wie baust Du denn die Query zusammen ?. Nutzt Du bereits QuotedStr ?

Geht es um das ' Zeichen oder das " Zeichen ?. Das zweite darf keine Probleme machen...
AndreM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Win2k, WinXP, Suse 10
D7 Ent
BeitragVerfasst: Sa 24.01.04 11:01 
Moin tomtom62,

also mit bereitet das 2te Zeichen also das " nicht das ' die Probleme. Das ' kann ich ohne weiteres in den Edit-Feldern verwenden. Sobald ich ein " im Edit-Feld verwende kommt diese Fehlermeldung.

user defined image

Die SQL String setze ich so zusammen. (ist jetzt nen Update, aber dürfte ja egal sein!).

ausblenden Delphi-Quelltext
1:
Form_Kunden.Query_Kunden.SQL.Add('update D20_KUNDEN set D20_NAME1= "' + Form_Kunden.Edit_Name1.Text +  '" where D20_KDNR = "' + Form_Kunden.Edit_KdNr.Text + '"');					


Was genau du mit QuotedStr meinst müßtst du mir nochmal erklären! :D
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 24.01.04 11:13 
Versuchs mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
tt: string;

tt:='UPDATE D20_KUNDEN set D20_NAME1= '+ Quotedstr(Form_Kunden.Edit_Name1.Text) +' WHERE D20_KDNR = ' + QuotedStr(Form_Kunden.Edit_KdNr.Text)+')';

Form_Kunden.Query_Kunden.SQL.Add(tt);


Wichtig ist, dass Du ' anstelle von " verwendest..
AndreM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Win2k, WinXP, Suse 10
D7 Ent
BeitragVerfasst: Sa 24.01.04 11:34 
Hab den kompletten String jetzt mal auf QuotedStr umgemützt. Jetzt wird beim Einfügen auch nirgend mehr ein " genutzt. Nur sobald ich bei nem Edit-Feld wieder nen " benutze kommt wieder obige Fehlermeldung. :(
AndreM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Win2k, WinXP, Suse 10
D7 Ent
BeitragVerfasst: Sa 24.01.04 11:45 
Hab nochmal nen wenig rumprobiert, dass Problem tritt auf wenn entweder nur ein " im text vorhanden ist (Beispiel: test"), oder zwischen zwei "" noch Text steht (Beispiel: test"Hallo"). Wenn ich das ganze z.B. so mache (test""), dann fügt er den Namen Test"" in die Datenbank ein.
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 24.01.04 14:32 
Welche Komponenten benutzt Du ?. IBX oder ibobjects ?

Ich habe es eben mal in einem Programm getestet, welches mit IBObjects gemacht wurde, da kann ich sowohl " als auch "" eingeben..
AndreM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Win2k, WinXP, Suse 10
D7 Ent
BeitragVerfasst: Sa 24.01.04 15:45 
Ich nutze derzeit die Komponenten die bei D5 gleich dabei sind. Müßten also die IBX sein. Ich hab mir gerade mal die IBObjects von der Entwicklerseite gesaugt! Mal schauen ob es damit besser funktioniert.! :)
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 24.01.04 15:56 
Also ich habe gleich zu IBO gewechselt. IBX hat zwar IBServices, welches nicht uninteressant ist, wenn man Nutzer bearbeiten löschen etc. will.

Aber ansonsten kann ich IBO nur empfehlen. Allein der Support ist den Wechsel wert..