@@ -22,6 +22,7 @@ import (
2222 "fmt"
2323 "io"
2424 "net"
25+ "reflect"
2526 "strconv"
2627 "strings"
2728 "time"
@@ -221,20 +222,49 @@ func (this *Value) readBufferAt(chunk *Chunk, offset uint64) (uint64, error) {
221222 return 0 , errors .New ("Unsuported type" )
222223}
223224
224- func protocolBufferFromValue (v interface {}) [][]byte {
225+ func protocolBufferFromValue (v interface {}) ( [][]byte , error ) {
225226 switch v := v .(type ) {
226227 case nil :
227- return protocolBufferFromNull ()
228- case int , int8 , int16 , int32 , int64 :
229- return protocolBufferFromInt (v )
230- case float32 , float64 :
231- return protocolBufferFromFloat (v )
228+ return protocolBufferFromNull (), nil
229+ case int , int8 , int16 , int32 , int64 , uint , uint8 , uint16 , uint32 , uint64 :
230+ return protocolBufferFromInt (v ), nil
231+ case float32 :
232+ return protocolBufferFromFloat (float64 (v )), nil
233+ case float64 :
234+ return protocolBufferFromFloat (v ), nil
232235 case string :
233- return protocolBufferFromString (v , true )
236+ return protocolBufferFromString (v , true ), nil
234237 case []byte :
235- return protocolBufferFromBytes (v )
238+ return protocolBufferFromBytes (v ), nil
236239 default :
237- return make ([][]byte , 0 )
240+ rv := reflect .ValueOf (v )
241+ if ! rv .IsValid () {
242+ return protocolBufferFromNull (), nil
243+ }
244+ if rv .Kind () == reflect .Pointer {
245+ if rv .IsNil () {
246+ return protocolBufferFromNull (), nil
247+ }
248+ return protocolBufferFromValue (rv .Elem ().Interface ())
249+ }
250+
251+ switch rv .Kind () {
252+ case reflect .String :
253+ return protocolBufferFromString (rv .String (), true ), nil
254+ case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
255+ return protocolBufferFromInt (rv .Int ()), nil
256+ case reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 :
257+ return protocolBufferFromInt (rv .Uint ()), nil
258+ case reflect .Float32 , reflect .Float64 :
259+ return protocolBufferFromFloat (rv .Convert (reflect .TypeOf (float64 (0 ))).Float ()), nil
260+ case reflect .Bool :
261+ if rv .Bool () {
262+ return protocolBufferFromInt (1 ), nil
263+ }
264+ return protocolBufferFromInt (0 ), nil
265+ default :
266+ return nil , fmt .Errorf ("unsupported parameter type %T" , v )
267+ }
238268 }
239269}
240270
@@ -371,7 +401,11 @@ func (this *SQCloud) sendArray(command string, values []interface{}) (int, error
371401 // convert values to buffers encoded with whe sqlitecloud protocol
372402 buffers := [][]byte {protocolBufferFromString (command , true )[0 ]}
373403 for _ , v := range values {
374- buffers = append (buffers , protocolBufferFromValue (v )... )
404+ valueBuffers , err := protocolBufferFromValue (v )
405+ if err != nil {
406+ return 0 , err
407+ }
408+ buffers = append (buffers , valueBuffers ... )
375409 }
376410
377411 // calculate the array header
0 commit comments