@@ -208,6 +208,7 @@ public virtual void Configure(IDictionary<string, string> settings)
208
208
DefaultCastLength = PropertiesHelper . GetInt32 ( Environment . QueryDefaultCastLength , settings , 4000 ) ;
209
209
DefaultCastPrecision = PropertiesHelper . GetByte ( Environment . QueryDefaultCastPrecision , settings , null ) ?? 29 ;
210
210
DefaultCastScale = PropertiesHelper . GetByte ( Environment . QueryDefaultCastScale , settings , null ) ?? 10 ;
211
+ EscapeBackslashInStrings = PropertiesHelper . GetBoolean ( Environment . EscapeBackslashInStrings , settings , EscapeBackslashInStrings ) ;
211
212
}
212
213
213
214
#endregion
@@ -1354,14 +1355,6 @@ public virtual CaseFragment CreateCaseFragment()
1354
1355
return new ANSICaseFragment ( this ) ;
1355
1356
}
1356
1357
1357
- /// <summary> The SQL literal value to which this database maps boolean values. </summary>
1358
- /// <param name="value">The boolean value </param>
1359
- /// <returns> The appropriate SQL literal. </returns>
1360
- public virtual string ToBooleanValueString ( bool value )
1361
- {
1362
- return value ? "1" : "0" ;
1363
- }
1364
-
1365
1358
internal static void ExtractColumnOrAliasNames ( SqlString select , out List < SqlString > columnsOrAliases , out Dictionary < SqlString , SqlString > aliasToColumn , out Dictionary < SqlString , SqlString > columnToAlias )
1366
1359
{
1367
1360
columnsOrAliases = new List < SqlString > ( ) ;
@@ -2076,6 +2069,55 @@ public virtual string ConvertQuotesForCatalogName(string catalogName)
2076
2069
2077
2070
#endregion
2078
2071
2072
+ #region Literals support
2073
+
2074
+ /// <summary>The SQL literal value to which this database maps boolean values.</summary>
2075
+ /// <param name="value">The boolean value.</param>
2076
+ /// <returns>The appropriate SQL literal.</returns>
2077
+ public virtual string ToBooleanValueString ( bool value )
2078
+ => value ? "1" : "0" ;
2079
+
2080
+ /// <summary>
2081
+ /// <see langword="true" /> if the database needs to have backslash escaped in string literals.
2082
+ /// </summary>
2083
+ /// <remarks><see langword="false" /> by default in the base dialect, to conform to SQL standard.</remarks>
2084
+ protected virtual bool EscapeBackslashInStrings { get ; set ; }
2085
+
2086
+ /// <summary>
2087
+ /// <see langword="true" /> if the database needs to have Unicode literals prefixed by <c>N</c>.
2088
+ /// </summary>
2089
+ /// <remarks><see langword="false" /> by default in the base dialect.</remarks>
2090
+ protected virtual bool UseNPrefixForUnicodeStrings { get ; set ; }
2091
+
2092
+ /// <summary>The SQL string literal value to which this database maps string values.</summary>
2093
+ /// <param name="value">The string value.</param>
2094
+ /// <param name="type">The SQL type of the string value.</param>
2095
+ /// <returns>The appropriate SQL string literal.</returns>
2096
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> or
2097
+ /// <paramref name="type"/> is <see langword="null" />.</exception>
2098
+ public virtual string ToStringLiteral ( string value , SqlType type )
2099
+ {
2100
+ if ( value == null )
2101
+ throw new ArgumentNullException ( nameof ( value ) ) ;
2102
+ if ( type == null )
2103
+ throw new ArgumentNullException ( nameof ( value ) ) ;
2104
+
2105
+ var literal = new StringBuilder ( value ) ;
2106
+ if ( EscapeBackslashInStrings )
2107
+ literal . Replace ( @"\" , @"\\" ) ;
2108
+
2109
+ literal
2110
+ . Replace ( "'" , "''" )
2111
+ . Insert ( 0 , '\' ' )
2112
+ . Append ( '\' ' ) ;
2113
+
2114
+ if ( UseNPrefixForUnicodeStrings && type . DbType == DbType . String || type . DbType == DbType . StringFixedLength )
2115
+ literal . Insert ( 0 , 'N' ) ;
2116
+ return literal . ToString ( ) ;
2117
+ }
2118
+
2119
+ #endregion
2120
+
2079
2121
#region Union subclass support
2080
2122
2081
2123
/// <summary>
0 commit comments