266 |
|
function QuoteIdentifierIfNeeded(Dialect: Integer; Value: AnsiString): AnsiString; |
267 |
|
function Space2Underscore(s: AnsiString): AnsiString; |
268 |
|
function SQLSafeString(const s: AnsiString): AnsiString; |
269 |
+ |
function IsSQLIdentifier(Value: AnsiString): boolean; |
270 |
|
|
271 |
|
implementation |
272 |
|
|
400 |
|
Result := Value; |
401 |
|
end; |
402 |
|
|
403 |
+ |
const |
404 |
+ |
ValidSQLIdentifierChars = ['A'..'Z','a'..'z','0'..'9','_','$']; |
405 |
+ |
|
406 |
+ |
function IsSQLIdentifier(Value: AnsiString): boolean; |
407 |
+ |
var i: integer; |
408 |
+ |
begin |
409 |
+ |
Result := false; |
410 |
+ |
for i := 1 to Length(Value) do |
411 |
+ |
if not (Value[i] in ValidSQLIdentifierChars) then Exit; |
412 |
+ |
Result := true; |
413 |
+ |
end; |
414 |
+ |
|
415 |
|
function QuoteIdentifierIfNeeded(Dialect: Integer; Value: AnsiString): AnsiString; |
416 |
|
begin |
417 |
|
if (Dialect = 3) and |
418 |
< |
((AnsiUpperCase(Value) <> Value) or IsReservedWord(Value)) then |
418 |
> |
(IsReservedWord(Value) or not IsSQLIdentifier(Value) or (AnsiUpperCase(Value) <> Value)) then |
419 |
|
Result := '"' + Value + '"' |
420 |
|
else |
421 |
|
Result := Value |