make tests green again

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

View File

@@ -74,7 +74,7 @@ type
## converted to nil.
InstantRow* = object ## a handle that can be
res: PPGresult ## used to get a row's
line: int ## column text on demand
line: int ## column text on demand
SqlPrepared* = distinct string ## a identifier for the prepared queries
{.deprecated: [TRow: Row, TDbConn: DbConn, TSqlPrepared: SqlPrepared].}
@@ -175,7 +175,7 @@ proc prepare*(db: DbConn; stmtName: string, query: SqlQuery;
return SqlPrepared(stmtName)
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)
let x = pqgetvalue(res, line, col)
if x.isNil:
@@ -191,7 +191,7 @@ iterator fastRows*(db: DbConn, query: SqlQuery,
var res = setupQuery(db, query, args)
var L = pqnfields(res)
var result = newRow(L)
for i in 0..pqntuples(res)-1:
for i in 0'i32..pqntuples(res)-1:
setRow(res, result, i, L)
yield result
pqclear(res)
@@ -202,7 +202,7 @@ iterator fastRows*(db: DbConn, stmtName: SqlPrepared,
var res = setupQuery(db, stmtName, args)
var L = pqNfields(res)
var result = newRow(L)
for i in 0..pqNtuples(res)-1:
for i in 0'i32..pqNtuples(res)-1:
setRow(res, result, i, L)
yield result
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
## on demand using []. Returned handle is valid only within iterator body.
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)
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
## on demand using []. Returned handle is valid only within iterator body.
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)
pqClear(res)
@@ -240,7 +240,7 @@ proc getColumnType(res: PPGresult, col: int) : DbType =
of 21: return DbType(kind: DbTypeKind.dbInt, name: "int2", size: 2)
of 23: return DbType(kind: DbTypeKind.dbInt, name: "int4", size: 4)
of 20: return DbType(kind: DbTypeKind.dbInt, name: "int8", size: 8)
of 1560: return DbType(kind: DbTypeKind.dbBit, name: "bit")
of 1560: return DbType(kind: DbTypeKind.dbBit, name: "bit")
of 1562: return DbType(kind: DbTypeKind.dbInt, name: "varbit")
of 18: return DbType(kind: DbTypeKind.dbFixedChar, name: "char")
@@ -254,7 +254,7 @@ proc getColumnType(res: PPGresult, col: int) : DbType =
of 700: return DbType(kind: DbTypeKind.dbFloat, name: "float4")
of 701: return DbType(kind: DbTypeKind.dbFloat, name: "float8")
of 790: return DbType(kind: DbTypeKind.dbDecimal, name: "money")
of 790: return DbType(kind: DbTypeKind.dbDecimal, name: "money")
of 1700: return DbType(kind: DbTypeKind.dbDecimal, name: "numeric")
of 704: return DbType(kind: DbTypeKind.dbTimeInterval, name: "tinterval")
@@ -277,12 +277,12 @@ proc getColumnType(res: PPGresult, col: int) : DbType =
of 603: return DbType(kind: DbTypeKind.dbBox, name: "box")
of 604: return DbType(kind: DbTypeKind.dbPolygon, name: "polygon")
of 628: return DbType(kind: DbTypeKind.dbLine, name: "line")
of 718: return DbType(kind: DbTypeKind.dbCircle, name: "circle")
of 718: return DbType(kind: DbTypeKind.dbCircle, name: "circle")
of 650: return DbType(kind: DbTypeKind.dbInet, name: "cidr")
of 829: return DbType(kind: DbTypeKind.dbMacAddress, name: "macaddr")
of 869: return DbType(kind: DbTypeKind.dbInet, name: "inet")
of 2950: return DbType(kind: DbTypeKind.dbVarchar, name: "uuid")
of 3614: return DbType(kind: DbTypeKind.dbVarchar, name: "tsvector")
of 3615: return DbType(kind: DbTypeKind.dbVarchar, name: "tsquery")
@@ -364,11 +364,11 @@ proc getColumnType(res: PPGresult, col: int) : DbType =
proc setColumnInfo(columns: var DbColumns; res: PPGresult; L: int32) =
setLen(columns, L)
for i in 0..<L:
for i in 0'i32..<L:
columns[i].name = $pqfname(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.
## Query the system table pg_class to determine exactly which table is referenced.
## Query the system table pg_class to determine exactly which table is referenced.
#columns[i].primaryKey = libpq does not have a function for that
#columns[i].foreignKey = libpq does not have a function for that
@@ -377,7 +377,7 @@ iterator instantRows*(db: DbConn; columns: var DbColumns; query: SqlQuery;
{.tags: [ReadDbEffect].} =
var res = setupQuery(db, query, args)
setColumnInfo(columns, res, pqnfields(res))
for i in 0..<pqntuples(res):
for i in 0'i32..<pqntuples(res):
yield InstantRow(res: res, line: i)
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)
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], 0)
let x = column_text(stmt, col)

View File

@@ -2022,6 +2022,13 @@ when defined(nimNewRoof):
yield 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:
iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
## Counts from ordinal value `a` up to `b` (inclusive) with the given