Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   select mit ' läuft nicht (https://www.delphipraxis.net/208980-select-mit-laeuft-nicht.html)

himitsu 9. Okt 2021 23:39

AW: select mit ' läuft nicht
 
Es ist genau andersrum.
Pascal hat mit Escapezeichen nix am Hut, aber SQL schon. (so wie praktisch jede andere C-artige Syntax)

OK, ein Doppelquote ala '' wird im SQL zwar oft auch als ' interpretiert, aber eigentlich quotet man dort mit \.

Und nun noch viel Spaß mit
Delphi-Quellcode:
QuoteStr('das ist ein Test mit \')
.
Bei
Delphi-Quellcode:
QuoteStr('ein \n ist nett')
knallt es zwar nicht, aber das N wird womöglich nicht mehr das sein, was es war,
und bei
Delphi-Quellcode:
QuoteStr('... \\ ...')
verschwindet einfach so das erste \.


Echt mal, was ist daran so schwer, die "richtige" Escape-Funktion zu verwenden, welche es irgendwo in deiner DB-Komponente geben sollte
anstatt irgendwelchem Schrott, der herfür nicht gedacht ist und auch niemals dafür gedacht war, weil er für was Anderes vorgesehen ist?

irgendwas wie EscapeLiteral (mit ' für Strings) und EscapeName (mit " für Bezeichner) oder irgendwie so


Klar, man kann auch mit dem Trabbi Ford Tourer-Nachbau von Sudhakar Yadav auf den Nürburgring .. es funktioniert, aber man nimmt etwas, was eher dafür gedacht ist.

BigAl 10. Okt 2021 07:39

AW: select mit ' läuft nicht
 
Nochmal: MS SQL kann von Haus aus mit Escape-Zeichen nichts anfangen. Zeichen wie \n oder \\ werden als genau diese ausgegeben. Ein String wie 'That\'s it' geht in MS SQL nicht.

Es gibt zwar eine Funktion zur Interpretation solcher Ausdrücke (STRING_ESCAPE) aber diese wurde aus anderen Gründen eingeführt.

z.B.

SELECT 'Das ist ein Test\'

ergibt

Das ist ein Test\

als Resultat. Entweder sprechen wir von verschiedenen Dingen oder bei manchen Datenbanken ist das halt problematisch. Bei Oracle ist es genau so. Kann man z.B. hier testen. Einfach mal "SELECT 'Hello\nWorld' eingeben...

Delphi.Narium 10. Okt 2021 09:04

AW: select mit ' läuft nicht
 
MS SQL kann damit problemlos umgehen. Das trifft aber nicht auf alle Datenbanksysteme zu.

Wenn man mit Delphi Datenbankprogramme schreibt, ohne sich auf die dahinterliegende Datenbank festzulegen, sollte man halt immer im Auge behalten, dass QuotedStr funktionieren kann, aber nicht muss.

Zitat:

Zitat von Access
In Access, you use the double-quote character around literal text, such as the Control Source of a text box: ="This text is in quotes." Often, you need quote marks inside quotes, e.g. when working with DLookup (). This article explains how.

Zitat:

Zitat von MySQL
MySQL QUOTE () produces a string which is a properly escaped data value in an SQL statement, out of a user supplied by the string as an argument. The function achieves this by enclosing the string with single quotes, and by preceding each single quote, backslash, ASCII NUL and control-Z with a backslash.

Zitat:

Zitat von PostGres
Basically, a single quote is used to define a token as a string; this is the context used in PostgreSQL for different purposes. When we write any text in a single quote it is treated as a reference object and the identifier is represented by using double-quoted text. For example, suppose our statement is like select ‘Welcome in PostgreSQL’;

Zitat:

Zitat von SQLite
The SQLite quote () function allows you to escape a string so that it’s suitable for inclusion in an SQL statement. Strings are surrounded by single-quotes with escapes on interior quotes. BLOBs are encoded as hexadecimal literals. Note that strings with embedded NUL characters cannot be represented as string literals in SQL.

Zitat:

Zitat von Ingres
Use single quotes to delimit embedded SQL string literals. To embed a single quote in a string literal, you must double it. Example: Quote usage in string literals. exec sql insert into comments (anecdotes) values ('single'' quote followed by double " quote'); This insert example writes the following string into the anecdotes column of the comments table: single' quote followed by double ...

Zitat:

Zitat von Oracle
Oracle Database offers the ability, in both SQL and PL/SQL, to specify our own user-defined delimiters for string literals. Here's how it works: you prefix your literal with the letter "q". Then you type a single quote, followeed by your starting delimiter for the literal. Then you type your literal string without having to double up on your single quote characters. When you have ...

Sie machen es alle ähnlich und doch alle ein bisserl anders, soviel zum Thema "Standardisierung" ;-)

Das Schöne an Parametern ist, dass man sich im Delphi-Quelltext nicht um diese Feinheiten kümmern muss. Da nimmt einem das die Datenbankschnittstelle ab.

himitsu 10. Okt 2021 09:44

AW: select mit ' läuft nicht
 
Ohhhh, OK, war davon ausgegangen Microsoft macht es da grundelegend so ähnlich wie auch fast alle Anderen, :oops:
wenn selbst so abgespecktes Zeugs ala SQLite es auch so macht.

Hab selbst bisher nur mit MySQL, Postgres, SQLite und irgendwas, wo ich mich nicht mehr dran erinnern kann (Access?) gearbeitet.


Aber mein Vorredner hat es ja schon nochmals gesagt.
Parameter sind eine feine Sache.

Und wenn man die Quote/Escape-Funktion der DB-Komponente nimmt, dann ist es auch egal, mit welchem DBMS man verbunden ist, weil sich dann der Richtige um das richtige Format kümmert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:37 Uhr.
Seite 3 von 3     123   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz