Hello,

I have data `seq[float64]` that I wish to write in a SQLite database in a 
binary format.

So I tried to do it this way :
    
    
    let db = open(dbName, "", "", "")
      db.exec(sql"DROP TABLE IF EXISTS test")
      
      let createTableStr = sql"""CREATE TABLE test(
        id INTEGER,
        data BLOB
      )
      """
      
      db.exec(createTableStr)
      
      
      var data : seq[float64]
      var bufSize = int(sizeof(float64)/sizeof(byte))*(data.len)
      var strm = newStringStream("")
      strm.writeData(unsafeAddr(data[0]), bufSize)
      strm.flush()
      strm.setPosition(0)
      
      db.exec(sql"INSERT INTO test (id, data) VALUES (?, ?)", $0, strm.data)
      strm.close()
      db.close()
    
    
    Run

The problem with this approach is that the data gets converted to cstring which 
means that if I have the equivalent of `00`, my datas gets truncated.

I arrived at this conclusion when I echo'd this : 
    
    
    echo "string  ", len(strm.data)
      echo "cstring ", len(strm.data.cstring)
    
    
    Run

and obtained different results.

How could I solve this issue and insert my data directly in a sqlite database 
without having to convert the binary data to an intermediate string 
representation ? Or is that the wrong approach (I didn't find any `ByteStream` 
in `streams` so I used `StringStream`) ?

Reply via email to