make more tests green
This commit is contained in:
parent
18859cbaa1
commit
94684488d6
5 changed files with 8 additions and 38 deletions
|
|
@ -128,10 +128,7 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string =
|
||||||
var a = 0
|
var a = 0
|
||||||
for c in items(string(formatstr)):
|
for c in items(string(formatstr)):
|
||||||
if c == '?':
|
if c == '?':
|
||||||
if args[a].isNil:
|
add(result, dbQuote(args[a]))
|
||||||
add(result, "NULL")
|
|
||||||
else:
|
|
||||||
add(result, dbQuote(args[a]))
|
|
||||||
inc(a)
|
inc(a)
|
||||||
else:
|
else:
|
||||||
add(result, c)
|
add(result, c)
|
||||||
|
|
@ -183,24 +180,8 @@ iterator fastRows*(db: DbConn, query: SqlQuery,
|
||||||
row = mysql.fetchRow(sqlres)
|
row = mysql.fetchRow(sqlres)
|
||||||
if row == nil: break
|
if row == nil: break
|
||||||
for i in 0..L-1:
|
for i in 0..L-1:
|
||||||
if row[i] == nil:
|
setLen(result[i], 0)
|
||||||
if backup == nil:
|
result[i].add row[i]
|
||||||
newSeq(backup, L)
|
|
||||||
if backup[i] == nil and result[i] != nil:
|
|
||||||
shallowCopy(backup[i], result[i])
|
|
||||||
result[i] = nil
|
|
||||||
else:
|
|
||||||
if result[i] == nil:
|
|
||||||
if backup != nil:
|
|
||||||
if backup[i] == nil:
|
|
||||||
backup[i] = ""
|
|
||||||
shallowCopy(result[i], backup[i])
|
|
||||||
setLen(result[i], 0)
|
|
||||||
else:
|
|
||||||
result[i] = ""
|
|
||||||
else:
|
|
||||||
setLen(result[i], 0)
|
|
||||||
add(result[i], row[i])
|
|
||||||
yield result
|
yield result
|
||||||
properFreeResult(sqlres, row)
|
properFreeResult(sqlres, row)
|
||||||
|
|
||||||
|
|
@ -323,10 +304,7 @@ proc getRow*(db: DbConn, query: SqlQuery,
|
||||||
if row != nil:
|
if row != nil:
|
||||||
for i in 0..L-1:
|
for i in 0..L-1:
|
||||||
setLen(result[i], 0)
|
setLen(result[i], 0)
|
||||||
if row[i] == nil:
|
add(result[i], row[i])
|
||||||
result[i] = nil
|
|
||||||
else:
|
|
||||||
add(result[i], row[i])
|
|
||||||
properFreeResult(sqlres, row)
|
properFreeResult(sqlres, row)
|
||||||
|
|
||||||
proc getAllRows*(db: DbConn, query: SqlQuery,
|
proc getAllRows*(db: DbConn, query: SqlQuery,
|
||||||
|
|
@ -345,10 +323,7 @@ proc getAllRows*(db: DbConn, query: SqlQuery,
|
||||||
setLen(result, j+1)
|
setLen(result, j+1)
|
||||||
newSeq(result[j], L)
|
newSeq(result[j], L)
|
||||||
for i in 0..L-1:
|
for i in 0..L-1:
|
||||||
if row[i] == nil:
|
result[j][i] = $row[i]
|
||||||
result[j][i] = nil
|
|
||||||
else:
|
|
||||||
result[j][i] = $row[i]
|
|
||||||
inc(j)
|
inc(j)
|
||||||
mysql.freeResult(sqlres)
|
mysql.freeResult(sqlres)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,10 +103,7 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string =
|
||||||
else:
|
else:
|
||||||
for c in items(string(formatstr)):
|
for c in items(string(formatstr)):
|
||||||
if c == '?':
|
if c == '?':
|
||||||
if args[a] == nil:
|
add(result, dbQuote(args[a]))
|
||||||
add(result, "NULL")
|
|
||||||
else:
|
|
||||||
add(result, dbQuote(args[a]))
|
|
||||||
inc(a)
|
inc(a)
|
||||||
else:
|
else:
|
||||||
add(result, c)
|
add(result, c)
|
||||||
|
|
@ -179,7 +176,7 @@ proc setRow(res: PPGresult, r: var Row, line, cols: int32) =
|
||||||
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:
|
||||||
r[col] = nil
|
r[col] = ""
|
||||||
else:
|
else:
|
||||||
add(r[col], x)
|
add(r[col], x)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@ proc dbError*(db: DbConn) {.noreturn.} =
|
||||||
|
|
||||||
proc dbQuote*(s: string): string =
|
proc dbQuote*(s: string): string =
|
||||||
## DB quotes the string.
|
## DB quotes the string.
|
||||||
if s.isNil: return "NULL"
|
|
||||||
result = "'"
|
result = "'"
|
||||||
for c in items(s):
|
for c in items(s):
|
||||||
if c == '\'': add(result, "''")
|
if c == '\'': add(result, "''")
|
||||||
|
|
|
||||||
|
|
@ -1329,7 +1329,7 @@ when isMainModule:
|
||||||
doAssert clearTable[42] == "asd"
|
doAssert clearTable[42] == "asd"
|
||||||
clearTable.clear()
|
clearTable.clear()
|
||||||
doAssert(not clearTable.hasKey(123123))
|
doAssert(not clearTable.hasKey(123123))
|
||||||
doAssert clearTable.getOrDefault(42) == nil
|
doAssert clearTable.getOrDefault(42) == ""
|
||||||
|
|
||||||
block: #5482
|
block: #5482
|
||||||
var a = [("wrong?","foo"), ("wrong?", "foo2")].newOrderedTable()
|
var a = [("wrong?","foo"), ("wrong?", "foo2")].newOrderedTable()
|
||||||
|
|
|
||||||
|
|
@ -1869,7 +1869,6 @@ proc entityToUtf8*(entity: string): string =
|
||||||
## "" is returned if the entity name is unknown. The HTML parser
|
## "" is returned if the entity name is unknown. The HTML parser
|
||||||
## already converts entities to UTF-8.
|
## already converts entities to UTF-8.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
doAssert entityToUtf8(nil) == ""
|
|
||||||
doAssert entityToUtf8("") == ""
|
doAssert entityToUtf8("") == ""
|
||||||
doAssert entityToUtf8("a") == ""
|
doAssert entityToUtf8("a") == ""
|
||||||
doAssert entityToUtf8("gt") == ">"
|
doAssert entityToUtf8("gt") == ">"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue