use single backtick (#17100)
This commit is contained in:
parent
35ded02074
commit
9450bf6c08
10 changed files with 81 additions and 81 deletions
|
|
@ -11,7 +11,7 @@
|
||||||
## (`RTTI`:idx:). See the `marshal <marshal.html>`_ module for an example of
|
## (`RTTI`:idx:). See the `marshal <marshal.html>`_ module for an example of
|
||||||
## what this module allows you to do.
|
## what this module allows you to do.
|
||||||
##
|
##
|
||||||
## Note that even though ``Any`` and its operations hide the nasty low level
|
## Note that even though `Any` and its operations hide the nasty low level
|
||||||
## details from its clients, it remains inherently unsafe! Also, Nim's
|
## details from its clients, it remains inherently unsafe! Also, Nim's
|
||||||
## runtime type information will evolve and may eventually be deprecated.
|
## runtime type information will evolve and may eventually be deprecated.
|
||||||
## As an alternative approach to programmatically understanding and
|
## As an alternative approach to programmatically understanding and
|
||||||
|
|
@ -28,10 +28,10 @@ include "system/hti.nim"
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
type
|
type
|
||||||
AnyKind* = enum ## what kind of ``any`` it is
|
AnyKind* = enum ## what kind of `any` it is
|
||||||
akNone = 0, ## invalid any
|
akNone = 0, ## invalid any
|
||||||
akBool = 1, ## any represents a ``bool``
|
akBool = 1, ## any represents a `bool`
|
||||||
akChar = 2, ## any represents a ``char``
|
akChar = 2, ## any represents a `char`
|
||||||
akEnum = 14, ## any represents an enum
|
akEnum = 14, ## any represents an enum
|
||||||
akArray = 16, ## any represents an array
|
akArray = 16, ## any represents an array
|
||||||
akObject = 17, ## any represents an object
|
akObject = 17, ## any represents an object
|
||||||
|
|
@ -63,7 +63,7 @@ type
|
||||||
|
|
||||||
Any* = object ## can represent any nim value; NOTE: the wrapped
|
Any* = object ## can represent any nim value; NOTE: the wrapped
|
||||||
## value can be modified with its wrapper! This means
|
## value can be modified with its wrapper! This means
|
||||||
## that ``Any`` keeps a non-traced pointer to its
|
## that `Any` keeps a non-traced pointer to its
|
||||||
## wrapped value and **must not** live longer than
|
## wrapped value and **must not** live longer than
|
||||||
## its wrapped value.
|
## its wrapped value.
|
||||||
value: pointer
|
value: pointer
|
||||||
|
|
@ -134,7 +134,7 @@ proc selectBranch(aa: pointer, n: ptr TNimNode): ptr TNimNode =
|
||||||
if discr <% n.len:
|
if discr <% n.len:
|
||||||
result = n.sons[discr]
|
result = n.sons[discr]
|
||||||
if result == nil: result = n.sons[n.len]
|
if result == nil: result = n.sons[n.len]
|
||||||
# n.sons[n.len] contains the ``else`` part (but may be nil)
|
# n.sons[n.len] contains the `else` part (but may be nil)
|
||||||
else:
|
else:
|
||||||
result = n.sons[n.len]
|
result = n.sons[n.len]
|
||||||
|
|
||||||
|
|
@ -144,17 +144,17 @@ proc newAny(value: pointer, rawType: PNimType): Any {.inline.} =
|
||||||
|
|
||||||
when declared(system.VarSlot):
|
when declared(system.VarSlot):
|
||||||
proc toAny*(x: VarSlot): Any {.inline.} =
|
proc toAny*(x: VarSlot): Any {.inline.} =
|
||||||
## Constructs a ``Any`` object from a variable slot ``x``.
|
## Constructs a `Any` object from a variable slot `x`.
|
||||||
## This captures `x`'s address, so `x` can be modified with its
|
## This captures `x`'s address, so `x` can be modified with its
|
||||||
## ``Any`` wrapper! The client needs to ensure that the wrapper
|
## `Any` wrapper! The client needs to ensure that the wrapper
|
||||||
## **does not** live longer than `x`!
|
## **does not** live longer than `x`!
|
||||||
## This is provided for easier reflection capabilities of a debugger.
|
## This is provided for easier reflection capabilities of a debugger.
|
||||||
result.value = x.address
|
result.value = x.address
|
||||||
result.rawType = x.typ
|
result.rawType = x.typ
|
||||||
|
|
||||||
proc toAny*[T](x: var T): Any {.inline.} =
|
proc toAny*[T](x: var T): Any {.inline.} =
|
||||||
## Constructs a ``Any`` object from `x`. This captures `x`'s address, so
|
## Constructs a `Any` object from `x`. This captures `x`'s address, so
|
||||||
## `x` can be modified with its ``Any`` wrapper! The client needs to ensure
|
## `x` can be modified with its `Any` wrapper! The client needs to ensure
|
||||||
## that the wrapper **does not** live longer than `x`!
|
## that the wrapper **does not** live longer than `x`!
|
||||||
newAny(addr(x), cast[PNimType](getTypeInfo(x)))
|
newAny(addr(x), cast[PNimType](getTypeInfo(x)))
|
||||||
|
|
||||||
|
|
@ -167,7 +167,7 @@ proc size*(x: Any): int {.inline.} =
|
||||||
result = x.rawType.size
|
result = x.rawType.size
|
||||||
|
|
||||||
proc baseTypeKind*(x: Any): AnyKind {.inline.} =
|
proc baseTypeKind*(x: Any): AnyKind {.inline.} =
|
||||||
## Gets the base type's kind; ``akNone`` is returned if `x` has no base type.
|
## Gets the base type's kind; `akNone` is returned if `x` has no base type.
|
||||||
if x.rawType.base != nil:
|
if x.rawType.base != nil:
|
||||||
result = AnyKind(ord(x.rawType.base.kind))
|
result = AnyKind(ord(x.rawType.base.kind))
|
||||||
|
|
||||||
|
|
@ -177,7 +177,7 @@ proc baseTypeSize*(x: Any): int {.inline.} =
|
||||||
result = x.rawType.base.size
|
result = x.rawType.base.size
|
||||||
|
|
||||||
proc invokeNew*(x: Any) =
|
proc invokeNew*(x: Any) =
|
||||||
## Performs ``new(x)``. `x` needs to represent a ``ref``.
|
## Performs `new(x)`. `x` needs to represent a `ref`.
|
||||||
assert x.rawType.kind == tyRef
|
assert x.rawType.kind == tyRef
|
||||||
when defined(gcDestructors):
|
when defined(gcDestructors):
|
||||||
cast[ppointer](x.value)[] = nimNewObj(x.rawType.base.size, x.rawType.base.align)
|
cast[ppointer](x.value)[] = nimNewObj(x.rawType.base.size, x.rawType.base.align)
|
||||||
|
|
@ -186,7 +186,7 @@ proc invokeNew*(x: Any) =
|
||||||
genericAssign(x.value, addr(z), x.rawType)
|
genericAssign(x.value, addr(z), x.rawType)
|
||||||
|
|
||||||
proc invokeNewSeq*(x: Any, len: int) =
|
proc invokeNewSeq*(x: Any, len: int) =
|
||||||
## Performs ``newSeq(x, len)``. `x` needs to represent a ``seq``.
|
## Performs `newSeq(x, len)`. `x` needs to represent a `seq`.
|
||||||
assert x.rawType.kind == tySequence
|
assert x.rawType.kind == tySequence
|
||||||
when defined(gcDestructors):
|
when defined(gcDestructors):
|
||||||
var s = cast[ptr NimSeqV2Reimpl](x.value)
|
var s = cast[ptr NimSeqV2Reimpl](x.value)
|
||||||
|
|
@ -198,7 +198,7 @@ proc invokeNewSeq*(x: Any, len: int) =
|
||||||
genericShallowAssign(x.value, addr(z), x.rawType)
|
genericShallowAssign(x.value, addr(z), x.rawType)
|
||||||
|
|
||||||
proc extendSeq*(x: Any) =
|
proc extendSeq*(x: Any) =
|
||||||
## Performs ``setLen(x, x.len+1)``. `x` needs to represent a ``seq``.
|
## Performs `setLen(x, x.len+1)`. `x` needs to represent a `seq`.
|
||||||
assert x.rawType.kind == tySequence
|
assert x.rawType.kind == tySequence
|
||||||
when defined(gcDestructors):
|
when defined(gcDestructors):
|
||||||
var s = cast[ptr NimSeqV2Reimpl](x.value)
|
var s = cast[ptr NimSeqV2Reimpl](x.value)
|
||||||
|
|
@ -318,16 +318,16 @@ const
|
||||||
tySequence, tyProc}
|
tySequence, tyProc}
|
||||||
|
|
||||||
proc getPointer*(x: Any): pointer =
|
proc getPointer*(x: Any): pointer =
|
||||||
## Retrieves the pointer value out of `x`. ``x`` needs to be of kind
|
## Retrieves the pointer value out of `x`. `x` needs to be of kind
|
||||||
## ``akString``, ``akCString``, ``akProc``, ``akRef``, ``akPtr``,
|
## `akString`, `akCString`, `akProc`, `akRef`, `akPtr`,
|
||||||
## ``akPointer``, ``akSequence``.
|
## `akPointer`, `akSequence`.
|
||||||
assert x.rawType.kind in pointerLike
|
assert x.rawType.kind in pointerLike
|
||||||
result = cast[ppointer](x.value)[]
|
result = cast[ppointer](x.value)[]
|
||||||
|
|
||||||
proc setPointer*(x: Any, y: pointer) =
|
proc setPointer*(x: Any, y: pointer) =
|
||||||
## Sets the pointer value of `x`. ``x`` needs to be of kind
|
## Sets the pointer value of `x`. `x` needs to be of kind
|
||||||
## ``akString``, ``akCString``, ``akProc``, ``akRef``, ``akPtr``,
|
## `akString`, `akCString`, `akProc`, `akRef`, `akPtr`,
|
||||||
## ``akPointer``, ``akSequence``.
|
## `akPointer`, `akSequence`.
|
||||||
assert x.rawType.kind in pointerLike
|
assert x.rawType.kind in pointerLike
|
||||||
if y != nil and x.rawType.kind != tyPointer:
|
if y != nil and x.rawType.kind != tyPointer:
|
||||||
genericAssign(x.value, y, x.rawType)
|
genericAssign(x.value, y, x.rawType)
|
||||||
|
|
@ -456,7 +456,7 @@ proc getInt64*(x: Any): int64 =
|
||||||
proc getBiggestInt*(x: Any): BiggestInt =
|
proc getBiggestInt*(x: Any): BiggestInt =
|
||||||
## Retrieves the integer value out of `x`. `x` needs to represent
|
## Retrieves the integer value out of `x`. `x` needs to represent
|
||||||
## some integer, a bool, a char, an enum or a small enough bit set.
|
## some integer, a bool, a char, an enum or a small enough bit set.
|
||||||
## The value might be sign-extended to ``BiggestInt``.
|
## The value might be sign-extended to `BiggestInt`.
|
||||||
var t = skipRange(x.rawType)
|
var t = skipRange(x.rawType)
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyInt: result = BiggestInt(cast[ptr int](x.value)[])
|
of tyInt: result = BiggestInt(cast[ptr int](x.value)[])
|
||||||
|
|
@ -578,7 +578,7 @@ proc skipRange*(x: Any): Any =
|
||||||
proc getEnumOrdinal*(x: Any, name: string): int =
|
proc getEnumOrdinal*(x: Any, name: string): int =
|
||||||
## Gets the enum field ordinal from `name`. `x` needs to represent an enum
|
## Gets the enum field ordinal from `name`. `x` needs to represent an enum
|
||||||
## but is only used to access the type information. In case of an error
|
## but is only used to access the type information. In case of an error
|
||||||
## ``low(int)`` is returned.
|
## `low(int)` is returned.
|
||||||
var typ = skipRange(x.rawType)
|
var typ = skipRange(x.rawType)
|
||||||
assert typ.kind == tyEnum
|
assert typ.kind == tyEnum
|
||||||
var n = typ.node
|
var n = typ.node
|
||||||
|
|
@ -630,7 +630,7 @@ proc getFloat64*(x: Any): float64 =
|
||||||
|
|
||||||
proc getBiggestFloat*(x: Any): BiggestFloat =
|
proc getBiggestFloat*(x: Any): BiggestFloat =
|
||||||
## Retrieves the float value out of `x`. `x` needs to represent
|
## Retrieves the float value out of `x`. `x` needs to represent
|
||||||
## some float. The value is extended to ``BiggestFloat``.
|
## some float. The value is extended to `BiggestFloat`.
|
||||||
case skipRange(x.rawType).kind
|
case skipRange(x.rawType).kind
|
||||||
of tyFloat: result = BiggestFloat(cast[ptr float](x.value)[])
|
of tyFloat: result = BiggestFloat(cast[ptr float](x.value)[])
|
||||||
of tyFloat32: result = BiggestFloat(cast[ptr float32](x.value)[])
|
of tyFloat32: result = BiggestFloat(cast[ptr float32](x.value)[])
|
||||||
|
|
@ -666,7 +666,7 @@ proc getCString*(x: Any): cstring =
|
||||||
result = cast[ptr cstring](x.value)[]
|
result = cast[ptr cstring](x.value)[]
|
||||||
|
|
||||||
proc assign*(x, y: Any) =
|
proc assign*(x, y: Any) =
|
||||||
## Copies the value of `y` to `x`. The assignment operator for ``Any``
|
## Copies the value of `y` to `x`. The assignment operator for `Any`
|
||||||
## does NOT do this; it performs a shallow copy instead!
|
## does NOT do this; it performs a shallow copy instead!
|
||||||
assert y.rawType == x.rawType
|
assert y.rawType == x.rawType
|
||||||
genericAssign(x.value, y.value, y.rawType)
|
genericAssign(x.value, y.value, y.rawType)
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@
|
||||||
## This module implements an algorithm to compute the
|
## This module implements an algorithm to compute the
|
||||||
## `diff`:idx: between two sequences of lines.
|
## `diff`:idx: between two sequences of lines.
|
||||||
##
|
##
|
||||||
## A basic example of ``diffInt`` on 2 arrays of integers:
|
## A basic example of `diffInt` on 2 arrays of integers:
|
||||||
##
|
##
|
||||||
## .. code::nim
|
## .. code::nim
|
||||||
##
|
##
|
||||||
## import experimental/diff
|
## import experimental/diff
|
||||||
## echo diffInt([0, 1, 2, 3, 4, 5, 6, 7, 8], [-1, 1, 2, 3, 4, 5, 666, 7, 42])
|
## echo diffInt([0, 1, 2, 3, 4, 5, 6, 7, 8], [-1, 1, 2, 3, 4, 5, 666, 7, 42])
|
||||||
##
|
##
|
||||||
## Another short example of ``diffText`` to diff strings:
|
## Another short example of `diffText` to diff strings:
|
||||||
##
|
##
|
||||||
## .. code::nim
|
## .. code::nim
|
||||||
##
|
##
|
||||||
|
|
@ -59,7 +59,7 @@ type
|
||||||
Smsrd = object
|
Smsrd = object
|
||||||
x, y: int
|
x, y: int
|
||||||
|
|
||||||
# template to avoid a seq copy. Required until ``sink`` parameters are ready.
|
# template to avoid a seq copy. Required until `sink` parameters are ready.
|
||||||
template newDiffData(initData: seq[int]; L: int): DiffData =
|
template newDiffData(initData: seq[int]; L: int): DiffData =
|
||||||
DiffData(
|
DiffData(
|
||||||
data: initData,
|
data: initData,
|
||||||
|
|
@ -71,9 +71,9 @@ proc len(d: DiffData): int {.inline.} = d.data.len
|
||||||
proc diffCodes(aText: string; h: var Table[string, int]): DiffData =
|
proc diffCodes(aText: string; h: var Table[string, int]): DiffData =
|
||||||
## This function converts all textlines of the text into unique numbers for every unique textline
|
## This function converts all textlines of the text into unique numbers for every unique textline
|
||||||
## so further work can work only with simple numbers.
|
## so further work can work only with simple numbers.
|
||||||
## ``aText`` the input text
|
## `aText` the input text
|
||||||
## ``h`` This extern initialized hashtable is used for storing all ever used textlines.
|
## `h` This extern initialized hashtable is used for storing all ever used textlines.
|
||||||
## ``trimSpace`` ignore leading and trailing space characters
|
## `trimSpace` ignore leading and trailing space characters
|
||||||
## Returns a array of integers.
|
## Returns a array of integers.
|
||||||
var lastUsedCode = h.len
|
var lastUsedCode = h.len
|
||||||
result.data = newSeq[int]()
|
result.data = newSeq[int]()
|
||||||
|
|
@ -108,14 +108,14 @@ proc optimize(data: var DiffData) =
|
||||||
proc sms(dataA: var DiffData; lowerA, upperA: int; dataB: DiffData; lowerB, upperB: int;
|
proc sms(dataA: var DiffData; lowerA, upperA: int; dataB: DiffData; lowerB, upperB: int;
|
||||||
downVector, upVector: var openArray[int]): Smsrd =
|
downVector, upVector: var openArray[int]): Smsrd =
|
||||||
## This is the algorithm to find the Shortest Middle Snake (sms).
|
## This is the algorithm to find the Shortest Middle Snake (sms).
|
||||||
## ``dataA`` sequence A
|
## `dataA` sequence A
|
||||||
## ``lowerA`` lower bound of the actual range in dataA
|
## `lowerA` lower bound of the actual range in dataA
|
||||||
## ``upperA`` upper bound of the actual range in dataA (exclusive)
|
## `upperA` upper bound of the actual range in dataA (exclusive)
|
||||||
## ``dataB`` sequence B
|
## `dataB` sequence B
|
||||||
## ``lowerB`` lower bound of the actual range in dataB
|
## `lowerB` lower bound of the actual range in dataB
|
||||||
## ``upperB`` upper bound of the actual range in dataB (exclusive)
|
## `upperB` upper bound of the actual range in dataB (exclusive)
|
||||||
## ``downVector`` a vector for the (0,0) to (x,y) search. Passed as a parameter for speed reasons.
|
## `downVector` a vector for the (0,0) to (x,y) search. Passed as a parameter for speed reasons.
|
||||||
## ``upVector`` a vector for the (u,v) to (N,M) search. Passed as a parameter for speed reasons.
|
## `upVector` a vector for the (u,v) to (N,M) search. Passed as a parameter for speed reasons.
|
||||||
## Returns a MiddleSnakeData record containing x,y and u,v.
|
## Returns a MiddleSnakeData record containing x,y and u,v.
|
||||||
|
|
||||||
let max = dataA.len + dataB.len + 1
|
let max = dataA.len + dataB.len + 1
|
||||||
|
|
@ -195,14 +195,14 @@ proc lcs(dataA: var DiffData; lowerA, upperA: int; dataB: var DiffData; lowerB,
|
||||||
## algorithm.
|
## algorithm.
|
||||||
## The published algorithm passes recursively parts of the A and B sequences.
|
## The published algorithm passes recursively parts of the A and B sequences.
|
||||||
## To avoid copying these arrays the lower and upper bounds are passed while the sequences stay constant.
|
## To avoid copying these arrays the lower and upper bounds are passed while the sequences stay constant.
|
||||||
## ``dataA`` sequence A
|
## `dataA` sequence A
|
||||||
## ``lowerA`` lower bound of the actual range in dataA
|
## `lowerA` lower bound of the actual range in dataA
|
||||||
## ``upperA`` upper bound of the actual range in dataA (exclusive)
|
## `upperA` upper bound of the actual range in dataA (exclusive)
|
||||||
## ``dataB`` sequence B
|
## `dataB` sequence B
|
||||||
## ``lowerB`` lower bound of the actual range in dataB
|
## `lowerB` lower bound of the actual range in dataB
|
||||||
## ``upperB`` upper bound of the actual range in dataB (exclusive)
|
## `upperB` upper bound of the actual range in dataB (exclusive)
|
||||||
## ``downVector`` a vector for the (0,0) to (x,y) search. Passed as a parameter for speed reasons.
|
## `downVector` a vector for the (0,0) to (x,y) search. Passed as a parameter for speed reasons.
|
||||||
## ``upVector`` a vector for the (u,v) to (N,M) search. Passed as a parameter for speed reasons.
|
## `upVector` a vector for the (u,v) to (N,M) search. Passed as a parameter for speed reasons.
|
||||||
|
|
||||||
# make mutable copy:
|
# make mutable copy:
|
||||||
var lowerA = lowerA
|
var lowerA = lowerA
|
||||||
|
|
@ -275,9 +275,9 @@ proc createDiffs(dataA, dataB: DiffData): seq[Item] =
|
||||||
proc diffInt*(arrayA, arrayB: openArray[int]): seq[Item] =
|
proc diffInt*(arrayA, arrayB: openArray[int]): seq[Item] =
|
||||||
## Find the difference in 2 arrays of integers.
|
## Find the difference in 2 arrays of integers.
|
||||||
##
|
##
|
||||||
## ``arrayA`` A-version of the numbers (usually the old one)
|
## `arrayA` A-version of the numbers (usually the old one)
|
||||||
##
|
##
|
||||||
## ``arrayB`` B-version of the numbers (usually the new one)
|
## `arrayB` B-version of the numbers (usually the new one)
|
||||||
##
|
##
|
||||||
## Returns a sequence of Items that describe the differences.
|
## Returns a sequence of Items that describe the differences.
|
||||||
|
|
||||||
|
|
@ -304,9 +304,9 @@ proc diffText*(textA, textB: string): seq[Item] =
|
||||||
## textlines into a common hashtable so i can find duplicates in there, and generating a
|
## textlines into a common hashtable so i can find duplicates in there, and generating a
|
||||||
## new number each time a new textline is inserted.
|
## new number each time a new textline is inserted.
|
||||||
##
|
##
|
||||||
## ``textA`` A-version of the text (usually the old one)
|
## `textA` A-version of the text (usually the old one)
|
||||||
##
|
##
|
||||||
## ``textB`` B-version of the text (usually the new one)
|
## `textB` B-version of the text (usually the new one)
|
||||||
##
|
##
|
||||||
## Returns a seq of Items that describe the differences.
|
## Returns a seq of Items that describe the differences.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
# This file contains the minimum required definitions
|
# This file contains the minimum required definitions
|
||||||
# for interacting with the initial Genode environment.
|
# for interacting with the initial Genode environment.
|
||||||
# It is reserved for use only within the standard
|
# It is reserved for use only within the standard
|
||||||
# library. See ``componentConstructHook`` in the system
|
# library. See `componentConstructHook` in the system
|
||||||
# module for accessing the Genode environment after the
|
# module for accessing the Genode environment after the
|
||||||
# standard library has finished initializating.
|
# standard library has finished initializating.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
## Parameter substitution
|
## Parameter substitution
|
||||||
## ======================
|
## ======================
|
||||||
##
|
##
|
||||||
## All ``db_*`` modules support the same form of parameter substitution.
|
## All `db_*` modules support the same form of parameter substitution.
|
||||||
## That is, using the ``?`` (question mark) to signify the place where a
|
## That is, using the `?` (question mark) to signify the place where a
|
||||||
## value should be placed. For example:
|
## value should be placed. For example:
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -179,7 +179,7 @@ iterator fastRows*(db: DbConn, query: SqlQuery,
|
||||||
## if you require **ALL** the rows.
|
## if you require **ALL** the rows.
|
||||||
##
|
##
|
||||||
## Breaking the fastRows() iterator during a loop will cause the next
|
## Breaking the fastRows() iterator during a loop will cause the next
|
||||||
## database query to raise an [EDb] exception ``Commands out of sync``.
|
## database query to raise an [EDb] exception `Commands out of sync`.
|
||||||
rawExec(db, query, args)
|
rawExec(db, query, args)
|
||||||
var sqlres = mysql.useResult(PMySQL db)
|
var sqlres = mysql.useResult(PMySQL db)
|
||||||
if sqlres != nil:
|
if sqlres != nil:
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
## Parameter substitution
|
## Parameter substitution
|
||||||
## ======================
|
## ======================
|
||||||
##
|
##
|
||||||
## All ``db_*`` modules support the same form of parameter substitution.
|
## All `db_*` modules support the same form of parameter substitution.
|
||||||
## That is, using the ``?`` (question mark) to signify the place where a
|
## That is, using the `?` (question mark) to signify the place where a
|
||||||
## value should be placed. For example:
|
## value should be placed. For example:
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -168,7 +168,7 @@ proc dbError*(db: var DbConn) {.
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
proc sqlCheck(db: var DbConn, resVal: TSqlSmallInt) {.raises: [DbError]} =
|
proc sqlCheck(db: var DbConn, resVal: TSqlSmallInt) {.raises: [DbError]} =
|
||||||
## Wrapper that raises [EDb] if ``resVal`` is neither SQL_SUCCESS or SQL_NO_DATA
|
## Wrapper that raises [EDb] if `resVal` is neither SQL_SUCCESS or SQL_NO_DATA
|
||||||
if resVal notIn [SQL_SUCCESS, SQL_NO_DATA]: dbError(db)
|
if resVal notIn [SQL_SUCCESS, SQL_NO_DATA]: dbError(db)
|
||||||
|
|
||||||
proc sqlGetDBMS(db: var DbConn): string {.
|
proc sqlGetDBMS(db: var DbConn): string {.
|
||||||
|
|
@ -195,7 +195,7 @@ proc dbQuote*(s: string): string {.noSideEffect.} =
|
||||||
|
|
||||||
proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string {.
|
proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string {.
|
||||||
noSideEffect.} =
|
noSideEffect.} =
|
||||||
## Replace any ``?`` placeholders with `args`,
|
## Replace any `?` placeholders with `args`,
|
||||||
## and quotes the arguments
|
## and quotes the arguments
|
||||||
result = ""
|
result = ""
|
||||||
var a = 0
|
var a = 0
|
||||||
|
|
@ -498,7 +498,7 @@ proc open*(connection, user, password, database: string): DbConn {.
|
||||||
## Raises `EDb` if the connection could not be established.
|
## Raises `EDb` if the connection could not be established.
|
||||||
##
|
##
|
||||||
## Currently the database parameter is ignored,
|
## Currently the database parameter is ignored,
|
||||||
## but included to match ``open()`` in the other db_xxxxx library modules.
|
## but included to match `open()` in the other db_xxxxx library modules.
|
||||||
var
|
var
|
||||||
val = SQL_OV_ODBC3
|
val = SQL_OV_ODBC3
|
||||||
resLen = 0
|
resLen = 0
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
## Parameter substitution
|
## Parameter substitution
|
||||||
## ======================
|
## ======================
|
||||||
##
|
##
|
||||||
## All ``db_*`` modules support the same form of parameter substitution.
|
## All `db_*` modules support the same form of parameter substitution.
|
||||||
## That is, using the ``?`` (question mark) to signify the place where a
|
## That is, using the `?` (question mark) to signify the place where a
|
||||||
## value should be placed. For example:
|
## value should be placed. For example:
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -26,9 +26,9 @@
|
||||||
## **Note**: There are two approaches to parameter substitution support by
|
## **Note**: There are two approaches to parameter substitution support by
|
||||||
## this module.
|
## this module.
|
||||||
##
|
##
|
||||||
## 1. ``SqlQuery`` using ``?, ?, ?, ...`` (same as all the ``db_*`` modules)
|
## 1. `SqlQuery` using `?, ?, ?, ...` (same as all the `db_*` modules)
|
||||||
##
|
##
|
||||||
## 2. ``SqlPrepared`` using ``$1, $2, $3, ...``
|
## 2. `SqlPrepared` using `$1, $2, $3, ...`
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## prepare(db, "myExampleInsert",
|
## prepare(db, "myExampleInsert",
|
||||||
|
|
@ -184,8 +184,8 @@ proc setupQuery(db: DbConn, stmtName: SqlPrepared,
|
||||||
|
|
||||||
proc prepare*(db: DbConn; stmtName: string, query: SqlQuery;
|
proc prepare*(db: DbConn; stmtName: string, query: SqlQuery;
|
||||||
nParams: int): SqlPrepared =
|
nParams: int): SqlPrepared =
|
||||||
## Creates a new ``SqlPrepared`` statement. Parameter substitution is done
|
## Creates a new `SqlPrepared` statement. Parameter substitution is done
|
||||||
## via ``$1``, ``$2``, ``$3``, etc.
|
## via `$1`, `$2`, `$3`, etc.
|
||||||
if nParams > 0 and not string(query).contains("$1"):
|
if nParams > 0 and not string(query).contains("$1"):
|
||||||
dbError("parameter substitution expects \"$1\"")
|
dbError("parameter substitution expects \"$1\"")
|
||||||
var res = pqprepare(db, stmtName, query.string, int32(nParams), nil)
|
var res = pqprepare(db, stmtName, query.string, int32(nParams), nil)
|
||||||
|
|
@ -488,8 +488,8 @@ proc tryInsertID*(db: DbConn, query: SqlQuery,
|
||||||
tags: [WriteDbEffect].}=
|
tags: [WriteDbEffect].}=
|
||||||
## executes the query (typically "INSERT") and returns the
|
## executes the query (typically "INSERT") and returns the
|
||||||
## generated ID for the row or -1 in case of an error. For Postgre this adds
|
## generated ID for the row or -1 in case of an error. For Postgre this adds
|
||||||
## ``RETURNING id`` to the query, so it only works if your primary key is
|
## `RETURNING id` to the query, so it only works if your primary key is
|
||||||
## named ``id``.
|
## named `id`.
|
||||||
var x = pqgetvalue(setupQuery(db, SqlQuery(string(query) & " RETURNING id"),
|
var x = pqgetvalue(setupQuery(db, SqlQuery(string(query) & " RETURNING id"),
|
||||||
args), 0, 0)
|
args), 0, 0)
|
||||||
if not isNil(x):
|
if not isNil(x):
|
||||||
|
|
@ -502,8 +502,8 @@ proc insertID*(db: DbConn, query: SqlQuery,
|
||||||
tags: [WriteDbEffect].} =
|
tags: [WriteDbEffect].} =
|
||||||
## executes the query (typically "INSERT") and returns the
|
## executes the query (typically "INSERT") and returns the
|
||||||
## generated ID for the row. For Postgre this adds
|
## generated ID for the row. For Postgre this adds
|
||||||
## ``RETURNING id`` to the query, so it only works if your primary key is
|
## `RETURNING id` to the query, so it only works if your primary key is
|
||||||
## named ``id``.
|
## named `id`.
|
||||||
result = tryInsertID(db, query, args)
|
result = tryInsertID(db, query, args)
|
||||||
if result < 0: dbError(db)
|
if result < 0: dbError(db)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
## Parameter substitution
|
## Parameter substitution
|
||||||
## ----------------------
|
## ----------------------
|
||||||
##
|
##
|
||||||
## All ``db_*`` modules support the same form of parameter substitution.
|
## All `db_*` modules support the same form of parameter substitution.
|
||||||
## That is, using the ``?`` (question mark) to signify the place where a
|
## That is, using the `?` (question mark) to signify the place where a
|
||||||
## value should be placed. For example:
|
## value should be placed. For example:
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -149,7 +149,7 @@
|
||||||
## Note
|
## Note
|
||||||
## ====
|
## ====
|
||||||
## This module does not implement any ORM features such as mapping the types from the schema.
|
## This module does not implement any ORM features such as mapping the types from the schema.
|
||||||
## Instead, a ``seq[string]`` is returned for each row.
|
## Instead, a `seq[string]` is returned for each row.
|
||||||
##
|
##
|
||||||
## The reasoning is as follows:
|
## The reasoning is as follows:
|
||||||
## 1. it's close to what many DBs offer natively (char**)
|
## 1. it's close to what many DBs offer natively (char**)
|
||||||
|
|
@ -221,7 +221,7 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string =
|
||||||
add(result, c)
|
add(result, c)
|
||||||
|
|
||||||
proc prepare*(db: DbConn; q: string): SqlPrepared {.since: (1, 3).} =
|
proc prepare*(db: DbConn; q: string): SqlPrepared {.since: (1, 3).} =
|
||||||
## Creates a new ``SqlPrepared`` statement.
|
## Creates a new `SqlPrepared` statement.
|
||||||
if prepare_v2(db, q, q.len.cint,result.PStmt, nil) != SQLITE_OK:
|
if prepare_v2(db, q, q.len.cint,result.PStmt, nil) != SQLITE_OK:
|
||||||
discard finalize(result.PStmt)
|
discard finalize(result.PStmt)
|
||||||
dbError(db)
|
dbError(db)
|
||||||
|
|
@ -310,8 +310,8 @@ iterator fastRows*(db: DbConn, query: SqlQuery,
|
||||||
## if you require **ALL** the rows.
|
## if you require **ALL** the rows.
|
||||||
##
|
##
|
||||||
## **Note:** Breaking the `fastRows()` iterator during a loop will cause the
|
## **Note:** Breaking the `fastRows()` iterator during a loop will cause the
|
||||||
## next database query to raise a `DbError` exception ``unable to close due
|
## next database query to raise a `DbError` exception `unable to close due
|
||||||
## to ...``.
|
## to ...`.
|
||||||
##
|
##
|
||||||
## **Examples:**
|
## **Examples:**
|
||||||
##
|
##
|
||||||
|
|
@ -674,8 +674,8 @@ proc insertID*(db: DbConn, query: SqlQuery,
|
||||||
## generated ID for the row.
|
## generated ID for the row.
|
||||||
##
|
##
|
||||||
## Raises a `DbError` exception when failed to insert row.
|
## Raises a `DbError` exception when failed to insert row.
|
||||||
## For Postgre this adds ``RETURNING id`` to the query, so it only works
|
## For Postgre this adds `RETURNING id` to the query, so it only works
|
||||||
## if your primary key is named ``id``.
|
## if your primary key is named `id`.
|
||||||
##
|
##
|
||||||
## **Examples:**
|
## **Examples:**
|
||||||
##
|
##
|
||||||
|
|
@ -755,7 +755,7 @@ proc open*(connection, user, password, database: string): DbConn {.
|
||||||
## Opens a database connection. Raises a `DbError` exception if the connection
|
## Opens a database connection. Raises a `DbError` exception if the connection
|
||||||
## could not be established.
|
## could not be established.
|
||||||
##
|
##
|
||||||
## **Note:** Only the ``connection`` parameter is used for ``sqlite``.
|
## **Note:** Only the `connection` parameter is used for `sqlite`.
|
||||||
##
|
##
|
||||||
## **Examples:**
|
## **Examples:**
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ batchable: false
|
||||||
# by storing them on the heap. For procs, we produce on the fly simple
|
# by storing them on the heap. For procs, we produce on the fly simple
|
||||||
# trampolines that can be dynamically overwritten to jump to a different
|
# trampolines that can be dynamically overwritten to jump to a different
|
||||||
# target. In the host program, all globals and procs are first registered
|
# target. In the host program, all globals and procs are first registered
|
||||||
# here with ``hcrRegisterGlobal`` and ``hcrRegisterProc`` and then the
|
# here with `hcrRegisterGlobal` and `hcrRegisterProc` and then the
|
||||||
# returned permanent locations are used in every reference to these symbols
|
# returned permanent locations are used in every reference to these symbols
|
||||||
# onwards.
|
# onwards.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ batchable: false
|
||||||
#
|
#
|
||||||
|
|
||||||
## Main file to generate a DLL from the standard library.
|
## Main file to generate a DLL from the standard library.
|
||||||
## The default Nimrtl does not only contain the ``system`` module, but these
|
## The default Nimrtl does not only contain the `system` module, but these
|
||||||
## too:
|
## too:
|
||||||
##
|
##
|
||||||
## * parseutils
|
## * parseutils
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ type
|
||||||
lineNumber*: int ## the current line number
|
lineNumber*: int ## the current line number
|
||||||
sentinel: int
|
sentinel: int
|
||||||
lineStart: int # index of last line start in buffer
|
lineStart: int # index of last line start in buffer
|
||||||
offsetBase*: int # use ``offsetBase + bufpos`` to get the offset
|
offsetBase*: int # use `offsetBase + bufpos` to get the offset
|
||||||
refillChars: set[char]
|
refillChars: set[char]
|
||||||
|
|
||||||
proc close*(L: var BaseLexer) =
|
proc close*(L: var BaseLexer) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue