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 | |
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')
-rw-r--r-- | lib/impure/db_mysql.nim | 24 | ||||
-rw-r--r-- | lib/impure/db_postgres.nim | 15 | ||||
-rw-r--r-- | lib/impure/fenv.nim | 103 |
3 files changed, 133 insertions, 9 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) diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index 6ba539377..6691c5703 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -48,7 +48,8 @@ proc dbError*(msg: string) {.noreturn.} = e.msg = msg raise e -proc dbQuote(s: string): string = +proc dbQuote*(s: string): string = + ## DB quotes the string. result = "'" for c in items(s): if c == '\'': add(result, "''") @@ -60,7 +61,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) @@ -123,8 +127,11 @@ proc prepare*(db: TDbConn; stmtName: string, query: TSqlQuery; proc setRow(res: PPGresult, r: var TRow, line, cols: int32) = for col in 0..cols-1: setLen(r[col], 0) - var x = pqgetvalue(res, line, col) - add(r[col], x) + let x = pqgetvalue(res, line, col) + if x.isNil: + r[col] = nil + else: + add(r[col], x) iterator fastRows*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]): TRow {.tags: [FReadDB].} = diff --git a/lib/impure/fenv.nim b/lib/impure/fenv.nim new file mode 100644 index 000000000..1859f7be7 --- /dev/null +++ b/lib/impure/fenv.nim @@ -0,0 +1,103 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2014 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## Floating-point environment. Handling of floating-point rounding and +## exceptions (overflow, zero-devide, etc.). + +{.deadCodeElim:on.} + +when defined(Posix) and not defined(haiku): + {.passl: "-lm".} + +var + FE_DIVBYZERO* {.importc, header: "<fenv.h>".}: cint + ## division by zero + FE_INEXACT* {.importc, header: "<fenv.h>".}: cint + ## inexact result + FE_INVALID* {.importc, header: "<fenv.h>".}: cint + ## invalid operation + FE_OVERFLOW* {.importc, header: "<fenv.h>".}: cint + ## result not representable due to overflow + FE_UNDERFLOW* {.importc, header: "<fenv.h>".}: cint + ## result not representable due to underflow + FE_ALL_EXCEPT* {.importc, header: "<fenv.h>".}: cint + ## bitwise OR of all supported exceptions + FE_DOWNWARD* {.importc, header: "<fenv.h>".}: cint + ## round toward -Inf + FE_TONEAREST* {.importc, header: "<fenv.h>".}: cint + ## round to nearest + FE_TOWARDZERO* {.importc, header: "<fenv.h>".}: cint + ## round toward 0 + FE_UPWARD* {.importc, header: "<fenv.h>".}: cint + ## round toward +Inf + FE_DFL_ENV* {.importc, header: "<fenv.h>".}: cint + ## macro of type pointer to fenv_t to be used as the argument + ## to functions taking an argument of type fenv_t; in this + ## case the default environment will be used + +type + Tfenv* {.importc: "fenv_t", header: "<fenv.h>", final, pure.} = + object ## Represents the entire floating-point environment. The + ## floating-point environment refers collectively to any + ## floating-point status flags and control modes supported + ## by the implementation. + Tfexcept* {.importc: "fexcept_t", header: "<fenv.h>", final, pure.} = + object ## Represents the floating-point status flags collectively, + ## including any status the implementation associates with the + ## flags. A floating-point status flag is a system variable + ## whose value is set (but never cleared) when a floating-point + ## exception is raised, which occurs as a side effect of + ## exceptional floating-point arithmetic to provide auxiliary + ## information. A floating-point control mode is a system variable + ## whose value may be set by the user to affect the subsequent + ## behavior of floating-point arithmetic. + +proc feclearexcept*(excepts: cint): cint {.importc, header: "<fenv.h>".} + ## Clear the supported exceptions represented by `excepts`. + +proc fegetexceptflag*(flagp: ptr Tfexcept, excepts: cint): cint {. + importc, header: "<fenv.h>".} + ## Store implementation-defined representation of the exception flags + ## indicated by `excepts` in the object pointed to by `flagp`. + +proc feraiseexcept*(excepts: cint): cint {.importc, header: "<fenv.h>".} + ## Raise the supported exceptions represented by `excepts`. + +proc fesetexceptflag*(flagp: ptr Tfexcept, excepts: cint): cint {. + importc, header: "<fenv.h>".} + ## Set complete status for exceptions indicated by `excepts` according to + ## the representation in the object pointed to by `flagp`. + +proc fetestexcept*(excepts: cint): cint {.importc, header: "<fenv.h>".} + ## Determine which of subset of the exceptions specified by `excepts` are + ## currently set. + +proc fegetround*(): cint {.importc, header: "<fenv.h>".} + ## Get current rounding direction. + +proc fesetround*(roundingDirection: cint): cint {.importc, header: "<fenv.h>".} + ## Establish the rounding direction represented by `roundingDirection`. + +proc fegetenv*(envp: ptr Tfenv): cint {.importc, header: "<fenv.h>".} + ## Store the current floating-point environment in the object pointed + ## to by `envp`. + +proc feholdexcept*(envp: ptr Tfenv): cint {.importc, header: "<fenv.h>".} + ## Save the current environment in the object pointed to by `envp`, clear + ## exception flags and install a non-stop mode (if available) for all + ## exceptions. + +proc fesetenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".} + ## Establish the floating-point environment represented by the object + ## pointed to by `envp`. + +proc feupdateenv*(envp: ptr Tfenv): cint {.importc, header: "<fenv.h>".} + ## Save current exceptions in temporary storage, install environment + ## represented by object pointed to by `envp` and raise exceptions + ## according to saved exceptions. |