@@ -61,31 +61,12 @@ public virtual SqlString Render(IList args, ISessionFactoryImplementor factory)
61
61
throw new QueryException ( "cast() requires two arguments" ) ;
62
62
}
63
63
string typeName = args [ 1 ] . ToString ( ) ;
64
- string sqlType ;
65
- IType hqlType = TypeFactory . HeuristicType ( typeName ) ;
66
64
67
- if ( hqlType != null )
68
- {
69
- SqlType [ ] sqlTypeCodes = hqlType . SqlTypes ( factory ) ;
70
- if ( sqlTypeCodes . Length != 1 )
71
- {
72
- throw new QueryException ( "invalid NHibernate type for cast(), was:" + typeName ) ;
73
- }
74
-
75
- sqlType = factory . Dialect . GetCastTypeName ( sqlTypeCodes [ 0 ] ) ;
76
- //{
77
- // //trim off the length/precision/scale
78
- // int loc = sqlType.IndexOf('(');
79
- // if (loc>-1)
80
- // {
81
- // sqlType = sqlType.Substring(0, loc);
82
- // }
83
- //}
84
- }
85
- else
86
- {
87
- throw new QueryException ( string . Format ( "invalid Hibernate type for cast(): type {0} not found" , typeName ) ) ;
88
- }
65
+ IType hqlType =
66
+ TypeFactory . HeuristicType ( typeName )
67
+ ?? throw new QueryException ( string . Format ( "invalid Hibernate type for cast(): type {0} not found" , typeName ) ) ;
68
+
69
+ string sqlType = GetCastTypeName ( factory , hqlType , typeName ) ;
89
70
90
71
// TODO 6.0: Remove pragma block with its content
91
72
#pragma warning disable 618
@@ -117,6 +98,20 @@ protected virtual SqlString Render(object expression, string sqlType, ISessionFa
117
98
return new SqlString ( "cast(" , expression , " as " , sqlType , ")" ) ;
118
99
}
119
100
101
+ internal SqlString Render ( IList args , IType expectedType , ISessionFactoryImplementor factory )
102
+ {
103
+ return Render ( args [ 0 ] , GetCastTypeName ( factory , expectedType , expectedType . Name ) , factory ) ;
104
+ }
105
+
106
+ private static string GetCastTypeName ( ISessionFactoryImplementor factory , IType hqlType , string typeName )
107
+ {
108
+ SqlType [ ] sqlTypeCodes = hqlType . SqlTypes ( factory ) ;
109
+ if ( sqlTypeCodes . Length != 1 )
110
+ throw new QueryException ( "invalid NHibernate type for cast(), was:" + typeName ) ;
111
+
112
+ return factory . Dialect . GetCastTypeName ( sqlTypeCodes [ 0 ] ) ;
113
+ }
114
+
120
115
#region IFunctionGrammar Members
121
116
122
117
bool IFunctionGrammar . IsSeparator ( string token )
0 commit comments