Skip to content

Commit c01a439

Browse files
committed
Issue #2250: use N(ational) prefix in MS SQL for any text value going through the second version of EscapeString(), supporting Unicode now when importing a file into a table.
Issue #41: use N(ational) prefix on MS SQL strings on all quoted strings, regardless of their exact data type, to support Unicode in meta queries as well
1 parent d9d870f commit c01a439

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

source/dbconnection.pas

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,6 +5141,11 @@ function TDBConnection.EscapeString(Text: String; ProcessJokerChars: Boolean=fal
51415141
if DoQuote then begin
51425142
// Add surrounding single quotes
51435143
Result := FStringQuoteChar + Result + FStringQuoteChar;
5144+
5145+
// Support international characters with National prefix on MSSQL, see #1115, #2250, #41.
5146+
// Previously only done in some callers of EscapeString(), and only for column types dbdtNchar, dbdtNvarchar, dbdtNtext.
5147+
if FParameters.IsAnyMSSQL and (ServerVersionInt >= 1100) then
5148+
Result := 'N' + Result;
51445149
end;
51455150
end;
51465151

@@ -9773,14 +9778,10 @@ function TDBQuery.SaveModifications: Boolean;
97739778
end;
97749779
dtcBinary, dtcSpatial:
97759780
Val := FConnection.EscapeBin(Cell.NewText);
9776-
else begin
9777-
if Datatype(i).Index in [dbdtNchar, dbdtNvarchar, dbdtNtext] then
9778-
Val := 'N' + Connection.EscapeString(Cell.NewText)
9779-
else if Datatype(i).Category = dtcTemporal then
9780-
Val := Connection.EscapeString(Connection.GetDateTimeValue(Cell.NewText, Datatype(i).Index))
9781-
else
9782-
Val := Connection.EscapeString(Cell.NewText);
9783-
end;
9781+
dtcTemporal:
9782+
Val := Connection.EscapeString(Connection.GetDateTimeValue(Cell.NewText, Datatype(i).Index))
9783+
else
9784+
Val := Connection.EscapeString(Cell.NewText, Datatype(i));
97849785
end;
97859786
sqlUpdate := sqlUpdate + Connection.QuoteIdent(FColumnOrgNames[i]) + '=' + Val;
97869787
sqlInsertColumns := sqlInsertColumns + Connection.QuoteIdent(FColumnOrgNames[i]);
@@ -10166,13 +10167,7 @@ function TDBQuery.GetWhereClause: String;
1016610167
Result := Result + '=' + FConnection.EscapeBin(ColVal);
1016710168
else begin
1016810169
// Any other data type goes here, including text:
10169-
case DataType(j).Index of
10170-
// Support international characters with N-prefix on MSSQL, see #1115:
10171-
dbdtNchar, dbdtNvarchar, dbdtNtext:
10172-
Result := Result + '=N' + Connection.EscapeString(ColVal);
10173-
else
10174-
Result := Result + '=' + Connection.EscapeString(ColVal);
10175-
end;
10170+
Result := Result + '=' + Connection.EscapeString(ColVal, DataType(j));
1017610171
end;
1017710172
end;
1017810173
end;

0 commit comments

Comments
 (0)