make tests green again

This commit is contained in:
Andreas Rumpf 2017-11-07 12:57:32 +01:00
commit bb5bab1b74
3 changed files with 21 additions and 14 deletions

View file

@ -175,7 +175,7 @@ proc prepare*(db: DbConn; stmtName: string, query: SqlQuery;
return SqlPrepared(stmtName) return SqlPrepared(stmtName)
proc setRow(res: PPGresult, r: var Row, line, cols: int32) = proc setRow(res: PPGresult, r: var Row, line, cols: int32) =
for col in 0..cols-1: for col in 0'i32..cols-1:
setLen(r[col], 0) setLen(r[col], 0)
let x = pqgetvalue(res, line, col) let x = pqgetvalue(res, line, col)
if x.isNil: if x.isNil:
@ -191,7 +191,7 @@ iterator fastRows*(db: DbConn, query: SqlQuery,
var res = setupQuery(db, query, args) var res = setupQuery(db, query, args)
var L = pqnfields(res) var L = pqnfields(res)
var result = newRow(L) var result = newRow(L)
for i in 0..pqntuples(res)-1: for i in 0'i32..pqntuples(res)-1:
setRow(res, result, i, L) setRow(res, result, i, L)
yield result yield result
pqclear(res) pqclear(res)
@ -202,7 +202,7 @@ iterator fastRows*(db: DbConn, stmtName: SqlPrepared,
var res = setupQuery(db, stmtName, args) var res = setupQuery(db, stmtName, args)
var L = pqNfields(res) var L = pqNfields(res)
var result = newRow(L) var result = newRow(L)
for i in 0..pqNtuples(res)-1: for i in 0'i32..pqNtuples(res)-1:
setRow(res, result, i, L) setRow(res, result, i, L)
yield result yield result
pqClear(res) pqClear(res)
@ -213,7 +213,7 @@ iterator instantRows*(db: DbConn, query: SqlQuery,
## same as fastRows but returns a handle that can be used to get column text ## same as fastRows but returns a handle that can be used to get column text
## on demand using []. Returned handle is valid only within iterator body. ## on demand using []. Returned handle is valid only within iterator body.
var res = setupQuery(db, query, args) var res = setupQuery(db, query, args)
for i in 0..pqNtuples(res)-1: for i in 0'i32..pqNtuples(res)-1:
yield InstantRow(res: res, line: i) yield InstantRow(res: res, line: i)
pqClear(res) pqClear(res)
@ -223,7 +223,7 @@ iterator instantRows*(db: DbConn, stmtName: SqlPrepared,
## same as fastRows but returns a handle that can be used to get column text ## same as fastRows but returns a handle that can be used to get column text
## on demand using []. Returned handle is valid only within iterator body. ## on demand using []. Returned handle is valid only within iterator body.
var res = setupQuery(db, stmtName, args) var res = setupQuery(db, stmtName, args)
for i in 0..pqNtuples(res)-1: for i in 0'i32..pqNtuples(res)-1:
yield InstantRow(res: res, line: i) yield InstantRow(res: res, line: i)
pqClear(res) pqClear(res)
@ -364,7 +364,7 @@ proc getColumnType(res: PPGresult, col: int) : DbType =
proc setColumnInfo(columns: var DbColumns; res: PPGresult; L: int32) = proc setColumnInfo(columns: var DbColumns; res: PPGresult; L: int32) =
setLen(columns, L) setLen(columns, L)
for i in 0..<L: for i in 0'i32..<L:
columns[i].name = $pqfname(res, i) columns[i].name = $pqfname(res, i)
columns[i].typ = getColumnType(res, i) columns[i].typ = getColumnType(res, i)
columns[i].tableName = $(pqftable(res, i)) ## Returns the OID of the table from which the given column was fetched. columns[i].tableName = $(pqftable(res, i)) ## Returns the OID of the table from which the given column was fetched.
@ -377,7 +377,7 @@ iterator instantRows*(db: DbConn; columns: var DbColumns; query: SqlQuery;
{.tags: [ReadDbEffect].} = {.tags: [ReadDbEffect].} =
var res = setupQuery(db, query, args) var res = setupQuery(db, query, args)
setColumnInfo(columns, res, pqnfields(res)) setColumnInfo(columns, res, pqnfields(res))
for i in 0..<pqntuples(res): for i in 0'i32..<pqntuples(res):
yield InstantRow(res: res, line: i) yield InstantRow(res: res, line: i)
pqClear(res) pqClear(res)

View file

@ -148,7 +148,7 @@ proc setupQuery(db: DbConn, query: SqlQuery,
if prepare_v2(db, q, q.len.cint, result, nil) != SQLITE_OK: dbError(db) if prepare_v2(db, q, q.len.cint, result, nil) != SQLITE_OK: dbError(db)
proc setRow(stmt: Pstmt, r: var Row, cols: cint) = proc setRow(stmt: Pstmt, r: var Row, cols: cint) =
for col in 0..cols-1: for col in 0'i32..cols-1:
setLen(r[col], column_bytes(stmt, col)) # set capacity setLen(r[col], column_bytes(stmt, col)) # set capacity
setLen(r[col], 0) setLen(r[col], 0)
let x = column_text(stmt, col) let x = column_text(stmt, col)

View file

@ -2022,6 +2022,13 @@ when defined(nimNewRoof):
yield res yield res
inc(res) inc(res)
iterator `..`*(a, b: int32): int32 {.inline.} =
## A special version of `..`` for ``int32`` only.
var res = a
while res <= b:
yield res
inc(res)
else: else:
iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} = iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
## Counts from ordinal value `a` up to `b` (inclusive) with the given ## Counts from ordinal value `a` up to `b` (inclusive) with the given