diff options
author | Huy <106477+ba0f3@users.noreply.github.com> | 2019-07-10 19:56:09 +0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-07-10 14:56:09 +0200 |
commit | e5425b5f2f9413896c87a868a84663ed5e814364 (patch) | |
tree | de3f5505b39fa4b0473b0a49c9198a5b9bcf0377 | |
parent | c94647aecad6ed7fd12152800437a6cda11e06e6 (diff) | |
download | Nim-e5425b5f2f9413896c87a868a84663ed5e814364.tar.gz |
[feature] add `unsafeColumnAt` procs, that return unsafe cstring from InstantRow (#11647)
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | lib/impure/db_mysql.nim | 4 | ||||
-rw-r--r-- | lib/impure/db_odbc.nim | 6 | ||||
-rw-r--r-- | lib/impure/db_postgres.nim | 4 | ||||
-rw-r--r-- | lib/impure/db_sqlite.nim | 8 |
5 files changed, 24 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 333f7cc02..e1294bf6e 100644 --- a/changelog.md +++ b/changelog.md @@ -19,8 +19,11 @@ - Enable Oid usage in hashtables. (#11472) +- Added `unsafeColumnAt` procs, that return unsafe cstring from InstantRow. (#11647) + - Make public `Sha1Digest` and `Sha1State` types and `newSha1State`, `update` and `finalize` procedures from `sha1` module. (#11694) + ## Language additions diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index 9c24de33a..ba560243f 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -286,6 +286,10 @@ proc `[]`*(row: InstantRow, col: int): string {.inline.} = ## Returns text for given column of the row. $row.row[col] +proc unsafeColumnAt*(row: InstantRow, index: int): cstring {.inline.} = + ## Return cstring of given column of the row + row.row[index] + proc len*(row: InstantRow): int {.inline.} = ## Returns number of columns in the row. row.len diff --git a/lib/impure/db_odbc.nim b/lib/impure/db_odbc.nim index 4c33a5a82..7b59f8313 100644 --- a/lib/impure/db_odbc.nim +++ b/lib/impure/db_odbc.nim @@ -330,7 +330,11 @@ iterator instantRows*(db: var DbConn, query: SqlQuery, proc `[]`*(row: InstantRow, col: int): string {.inline.} = ## Returns text for given column of the row - row.row[col] + $row.row[col] + +proc unsafeColumnAt*(row: InstantRow, index: int): cstring {.inline.} = + ## Return cstring of given column of the row + row.row[index] proc len*(row: InstantRow): int {.inline.} = ## Returns number of columns in the row diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index ec804072f..45cd38daa 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -381,6 +381,10 @@ proc `[]`*(row: InstantRow; col: int): string {.inline.} = ## returns text for given column of the row $pqgetvalue(row.res, int32(row.line), int32(col)) +proc unsafeColumnAt*(row: InstantRow, index: int): cstring {.inline.} = + ## Return cstring of given column of the row + pqgetvalue(row.res, int32(row.line), int32(index)) + proc len*(row: InstantRow): int {.inline.} = ## returns number of columns in the row int(pqNfields(row.res)) diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index 9b714a778..b4ac22d38 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -359,6 +359,14 @@ proc `[]`*(row: InstantRow, col: int32): string {.inline.} = ## example code $column_text(row, col) +proc unsafeColumnAt*(row: InstantRow, index: int32): cstring {.inline.} = + ## Returns cstring for given column of the row. + ## + ## See also: + ## * `instantRows iterator <#instantRows.i,DbConn,SqlQuery,varargs[string,]>`_ + ## example code + column_text(row, index) + proc len*(row: InstantRow): int32 {.inline.} = ## Returns number of columns in a row. ## |