[nim-dev] for x in dbx.exec(sql_query): gives compiler error with Sqlite database module

  • From: bobg <bobgus@xxxxxxx>
  • To: nim-dev@xxxxxxxxxxxxx
  • Date: Sun, 23 Oct 2016 20:07:23 +0000

I'm having a problem with getting data out of a sqlite database. If I comment 
the offending statements, it compiles and 'strings SqliteDB' shows the 
character data just fine, so I think most of the program is correct. If I use 
postgresql (with slightly different syntax), getting data out with a 'for x in 
db.fastdata(sqlQuery):` works. 

I get the same error using either the 14.2 or 15.2 compilers. CXX or Clang 
doesn't seem to make a difference.

```
# sqlite.nim
import db_sqlite
# import db_postgres
import strutils, strfmt, sequtils
import tables, hashes, math

let dbx = open("SqliteDB", nil, nil, nil)
dbx.exec(sql"Drop table if exists myTestTbl")
dbx.exec(sql("""create table myTestTbl (
     Id    INTEGER PRIMARY KEY,
     Name  VARCHAR(50) NOT NULL,
     i     INT(11),
     f     DECIMAL(18,10))"""))

dbx.exec(sql"INSERT INTO myTestTbl (id, Name, i, f) VALUES (1, ?, ?, ?)",
           "Alex", 200, 40.11)

for x in exec(dbx,sql"SELECT * FROM myTestTbl"):
  echo x.repr

dbx.close()
```

Below shows the compiler diagnostic
```
air:dataquery bobgus$ nim c -r sqlite.nim

sqlite.nim(17, 14) Error: expression 'exec(dbx,
  SqlQuery(r"SELECT * FROM myTestTbl"),
     [])' has no type (or is ambiguous)
```

Below shows the nim version
```
$ nim -V
Nim Compiler Version 0.15.2 (2016-10-22) [MacOSX: amd64]
Copyright (c) 2006-2016 by Andreas Rumpf

git hash: 9f895c6f5a4133f6c06324be3f4032b273a48971
active boot switches: -d:release
```

Other related posts: