1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Data ;
3
4
using System . Data . Common ;
4
5
using System . Text ;
@@ -18,6 +19,13 @@ namespace NHibernate.Dialect
18
19
/// </remarks>
19
20
public class SQLiteDialect : Dialect
20
21
{
22
+ /// <summary>
23
+ /// The effective value of the BinaryGuid connection string parameter.
24
+ /// The default value in SQLite is true.
25
+ /// </summary>
26
+ private bool _binaryGuid = true ;
27
+
28
+
21
29
/// <summary>
22
30
///
23
31
/// </summary>
@@ -94,8 +102,34 @@ protected virtual void RegisterFunctions()
94
102
95
103
// NH-3787: SQLite requires the cast in SQL too for not defaulting to string.
96
104
RegisterFunction ( "transparentcast" , new CastFunction ( ) ) ;
97
-
98
- RegisterFunction ( "strguid" , new SQLFunctionTemplate ( NHibernateUtil . String , "substr(hex(?1), 7, 2) || substr(hex(?1), 5, 2) || substr(hex(?1), 3, 2) || substr(hex(?1), 1, 2) || '-' || substr(hex(?1), 11, 2) || substr(hex(?1), 9, 2) || '-' || substr(hex(?1), 15, 2) || substr(hex(?1), 13, 2) || '-' || substr(hex(?1), 17, 4) || '-' || substr(hex(?1), 21) " ) ) ;
105
+
106
+ if ( _binaryGuid )
107
+ RegisterFunction ( "strguid" , new SQLFunctionTemplate ( NHibernateUtil . String , "substr(hex(?1), 7, 2) || substr(hex(?1), 5, 2) || substr(hex(?1), 3, 2) || substr(hex(?1), 1, 2) || '-' || substr(hex(?1), 11, 2) || substr(hex(?1), 9, 2) || '-' || substr(hex(?1), 15, 2) || substr(hex(?1), 13, 2) || '-' || substr(hex(?1), 17, 4) || '-' || substr(hex(?1), 21) " ) ) ;
108
+ else
109
+ RegisterFunction ( "strguid" , new SQLFunctionTemplate ( NHibernateUtil . String , "cast(?1 as char)" ) ) ;
110
+ }
111
+
112
+
113
+ public override void Configure ( IDictionary < string , string > settings )
114
+ {
115
+ base . Configure ( settings ) ;
116
+
117
+ if ( settings . TryGetValue ( Cfg . Environment . ConnectionString , out string connectionString ) )
118
+ {
119
+ var builder = new DbConnectionStringBuilder { ConnectionString = connectionString } ;
120
+
121
+ string strBinaryGuid = GetConnectionStringProperty ( builder , "BinaryGuid" ) ;
122
+ _binaryGuid = strBinaryGuid == null || bool . Parse ( strBinaryGuid ) ;
123
+ }
124
+
125
+ // Re-register functions depending on settings.
126
+ RegisterFunctions ( ) ;
127
+ }
128
+
129
+ private string GetConnectionStringProperty ( DbConnectionStringBuilder builder , string propertyName )
130
+ {
131
+ builder . TryGetValue ( propertyName , out object propertyValue ) ;
132
+ return ( string ) propertyValue ;
99
133
}
100
134
101
135
#region private static readonly string[] DialectKeywords = { ... }
0 commit comments