@@ -43,7 +43,7 @@ public IEnumerable<object> ExecuteQuery(TableMap map) {
4343 continue ;
4444 }
4545 // Read value from found column
46- object ? value = Connection . Orm . ReadColumn ( statement , i , column . ClrType ) ;
46+ object ? value = ReadColumn ( statement , i , column . ClrType ) ;
4747 column . SetValue ( obj , value ) ;
4848 }
4949 OnInstanceCreated ? . Invoke ( obj ) ;
@@ -68,7 +68,7 @@ public T ExecuteScalar<T>() {
6868 try {
6969 Result result = SQLiteRaw . Step ( statement ) ;
7070 if ( result is Result . Row ) {
71- object ? columnValue = Connection . Orm . ReadColumn ( statement , 0 , typeof ( T ) ) ;
71+ object ? columnValue = ReadColumn ( statement , 0 , typeof ( T ) ) ;
7272 if ( columnValue is not null ) {
7373 Value = ( T ) columnValue ;
7474 }
@@ -92,7 +92,7 @@ public IEnumerable<T> ExecuteQueryScalars<T>() {
9292 throw new InvalidOperationException ( "QueryScalars should return at least one column" ) ;
9393 }
9494 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 ) ) ;
9696 if ( value is null ) {
9797 yield return default ! ;
9898 }
@@ -121,9 +121,43 @@ private void BindParameters(Sqlite3Statement statement) {
121121 int index = name is not null
122122 ? SQLiteRaw . BindParameterIndex ( statement , name )
123123 : nextIndex ++ ;
124- Connection . Orm . BindParameter ( statement , index , value ) ;
124+ BindParameter ( statement , index , value ) ;
125125 }
126126 }
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+ }
127161
128162 private record struct Parameter ( string ? Name , object ? Value ) {
129163 public string ? Name { get ; set ; } = Name ;
0 commit comments