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:

  * Sources could be more cross linked, i.e. types between pages, sources to 
each other etc. Quite a lot of flipping between db_sqlite, sqlite3, and 
db_common. Took a google to find db_common because for some reason it doesn't 
show up on modules page. db_common seems maybe mis-named as it appears to have 
some SQL-specific stuff, though maybe its more generally useful I don't know.
  * Reinvented dbError due to stupidity, which was a bit painful because I 
couldn't figure out how to make a string from a cstring. After some stack 
exchange I ended up with toString like so:


    
    
    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.

Reply via email to