Enjoying the heck out of nim so far.
In case it's useful for documentation or anything...
So I want to use db, but it seems db_sqlite doesn't really offer prepared statements (though it uses them internally), so I dip down into sqlite3. A few hours for total noob to have prepared statement working, not bad. Here's what caused bother/confusion along the way:
import sequtils
proc toString(str: seq[char]): string =
result = newStringOfCap(len(str))
for ch in str:
add(result, ch)
proc dbErrExcept(): ref Exception =
var escs: cstring = db.errmsg
var es = toString(toSeq(escs.items))
result = newException(Exception, es)
It seemed like there must be an easier way to go cstring -> string but it took a long time to realize it was $ operator. Not sure what might be done to make realizing this more likely, maybe it's all me.
SqLite is written in C
SqLite therefore uses cstring
Don't bother with seq[char], just use cstring which Nim easily converts to string
Why not copy what db_sqlite has done, and have your own setupQuery() which calls SqLite's prepare_v2()
then you can
var stmt = setupQuery(db, query, args)
# now step thru the stmt to iterate thru rows of data
but don't let me stop you doing things the hard way ;-)