Some SQL queries (like “SELECT COUNT(*)…”) return a single value. The shortest way I’ve managed to come up with for obtaining the result of the query is:
using SQLite
db = SQLite.DB()
SQLite.DBInterface.execute(db, "CREATE TABLE t (field TEXT)")
count = iterate(SQLite.DBInterface.execute(db, "SELECT COUNT(*) FROM t"))[1][1]
That last line is a bit of a mouthful. Is there are better way to do this?
I wasn’t too worried about the SQLite.DBInterface... bit, it was the iterate()[1][1], and first(first()) is nicer. Good to know there’s not a DBInterface.execute_but_get_me_one_result and I’ll wrap first(first()) in something a bit prettier.