@@ -43,7 +43,7 @@ public IEnumerable<object> ExecuteQuery(TableMap map) {
43
43
continue ;
44
44
}
45
45
// Read value from found column
46
- object ? value = Connection . Orm . ReadColumn ( statement , i , column . ClrType ) ;
46
+ object ? value = ReadColumn ( statement , i , column . ClrType ) ;
47
47
column . SetValue ( obj , value ) ;
48
48
}
49
49
OnInstanceCreated ? . Invoke ( obj ) ;
@@ -68,7 +68,7 @@ public T ExecuteScalar<T>() {
68
68
try {
69
69
Result result = SQLiteRaw . Step ( statement ) ;
70
70
if ( result is Result . Row ) {
71
- object ? columnValue = Connection . Orm . ReadColumn ( statement , 0 , typeof ( T ) ) ;
71
+ object ? columnValue = ReadColumn ( statement , 0 , typeof ( T ) ) ;
72
72
if ( columnValue is not null ) {
73
73
Value = ( T ) columnValue ;
74
74
}
@@ -92,7 +92,7 @@ public IEnumerable<T> ExecuteQueryScalars<T>() {
92
92
throw new InvalidOperationException ( "QueryScalars should return at least one column" ) ;
93
93
}
94
94
while ( SQLiteRaw . Step ( statement ) is Result . Row ) {
95
- object ? value = Connection . Orm . ReadColumn ( statement , 0 , typeof ( T ) ) ;
95
+ object ? value = ReadColumn ( statement , 0 , typeof ( T ) ) ;
96
96
if ( value is null ) {
97
97
yield return default ! ;
98
98
}
@@ -121,9 +121,43 @@ private void BindParameters(Sqlite3Statement statement) {
121
121
int index = name is not null
122
122
? SQLiteRaw . BindParameterIndex ( statement , name )
123
123
: nextIndex ++ ;
124
- Connection . Orm . BindParameter ( statement , index , value ) ;
124
+ BindParameter ( statement , index , value ) ;
125
125
}
126
126
}
127
+ private void BindParameter ( Sqlite3Statement statement , int index , object ? value ) {
128
+ if ( value is null ) {
129
+ SQLiteRaw . BindNull ( statement , index ) ;
130
+ return ;
131
+ }
132
+
133
+ TypeSerializer typeSerializer = Connection . Orm . GetTypeSerializer ( value . GetType ( ) ) ;
134
+ SqliteValue rawValue = typeSerializer . Serialize ( value ) ;
135
+
136
+ switch ( rawValue . SqliteType ) {
137
+ case SqliteType . Null :
138
+ SQLiteRaw . BindNull ( statement , index ) ;
139
+ break ;
140
+ case SqliteType . Integer :
141
+ SQLiteRaw . BindInt64 ( statement , index , rawValue . AsInteger ) ;
142
+ break ;
143
+ case SqliteType . Float :
144
+ SQLiteRaw . BindDouble ( statement , index , rawValue . AsFloat ) ;
145
+ break ;
146
+ case SqliteType . Text :
147
+ SQLiteRaw . BindText ( statement , index , rawValue . AsText ) ;
148
+ break ;
149
+ case SqliteType . Blob :
150
+ SQLiteRaw . BindBlob ( statement , index , rawValue . AsBlob ) ;
151
+ break ;
152
+ default :
153
+ throw new NotImplementedException ( $ "Cannot bind column type '{ rawValue . SqliteType } '") ;
154
+ }
155
+ }
156
+ private object ? ReadColumn ( Sqlite3Statement statement , int index , Type type ) {
157
+ TypeSerializer typeSerializer = Connection . Orm . GetTypeSerializer ( type ) ;
158
+ SqliteValue value = SQLiteRaw . GetColumnValue ( statement , index ) ;
159
+ return typeSerializer . Deserialize ( value , type ) ;
160
+ }
127
161
128
162
private record struct Parameter ( string ? Name , object ? Value ) {
129
163
public string ? Name { get ; set ; } = Name ;
0 commit comments