diff options
author | Araq <rumpf_a@web.de> | 2014-11-03 11:42:36 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-11-03 11:42:36 +0100 |
commit | adad2d5f4aa9940278e4baab25d757246c74d4a2 (patch) | |
tree | 5f677641dafd9d79daff3bd9d2ac3b63de5fa7bf /lib/impure/db_mysql.nim | |
parent | 59c0a2db8427852d919f8a65cd0158d52ade2ab7 (diff) | |
parent | 6935171b85a1b08b1cdfba2a56d5291219d89b5f (diff) | |
download | Nim-adad2d5f4aa9940278e4baab25d757246c74d4a2.tar.gz |
Merge branch 'devel' into bigbreak
Conflicts: lib/impure/db_postgres.nim lib/pure/json.nim lib/pure/math.nim lib/system/atomics.nim
Diffstat (limited to 'lib/impure/db_mysql.nim')
-rw-r--r-- | lib/impure/db_mysql.nim | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index d57e8d641..37bea45b4 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -57,7 +57,8 @@ when false: binding: seq[MYSQL_BIND] discard mysql_stmt_close(stmt) -proc dbQuote(s: string): string = +proc dbQuote*(s: string): string = + ## DB quotes the string. result = "'" for c in items(s): if c == '\'': add(result, "''") @@ -69,7 +70,10 @@ proc dbFormat(formatstr: TSqlQuery, args: varargs[string]): string = var a = 0 for c in items(string(formatstr)): if c == '?': - add(result, dbQuote(args[a])) + if args[a] == nil: + add(result, "NULL") + else: + add(result, dbQuote(args[a])) inc(a) else: add(result, c) @@ -115,7 +119,10 @@ iterator fastRows*(db: TDbConn, query: TSqlQuery, if row == nil: break for i in 0..L-1: setLen(result[i], 0) - add(result[i], row[i]) + if row[i] == nil: + result[i] = nil + else: + add(result[i], row[i]) yield result properFreeResult(sqlres, row) @@ -132,7 +139,10 @@ proc getRow*(db: TDbConn, query: TSqlQuery, if row != nil: for i in 0..L-1: setLen(result[i], 0) - add(result[i], row[i]) + if row[i] == nil: + result[i] = nil + else: + add(result[i], row[i]) properFreeResult(sqlres, row) proc getAllRows*(db: TDbConn, query: TSqlQuery, @@ -150,7 +160,11 @@ proc getAllRows*(db: TDbConn, query: TSqlQuery, if row == nil: break setLen(result, j+1) newSeq(result[j], L) - for i in 0..L-1: result[j][i] = $row[i] + for i in 0..L-1: + if row[i] == nil: + result[j][i] = nil + else: + result[j][i] = $row[i] inc(j) mysql.freeResult(sqlres) |