diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/impure/db_mysql.nim | 44 | ||||
-rw-r--r-- | lib/impure/db_odbc.nim | 48 | ||||
-rw-r--r-- | lib/impure/db_postgres.nim | 18 | ||||
-rw-r--r-- | lib/impure/db_sqlite.nim | 43 | ||||
-rw-r--r-- | lib/impure/rdstdin.nim | 2 | ||||
-rw-r--r-- | lib/pure/collections/tables.nim | 14 | ||||
-rw-r--r-- | lib/pure/fsmonitor.nim | 3 | ||||
-rw-r--r-- | lib/pure/gentabs.nim | 2 | ||||
-rw-r--r-- | lib/pure/httpserver.nim | 3 | ||||
-rw-r--r-- | lib/pure/nativesockets.nim | 2 | ||||
-rw-r--r-- | lib/pure/net.nim | 2 | ||||
-rw-r--r-- | lib/pure/numeric.nim | 3 | ||||
-rw-r--r-- | lib/pure/poly.nim | 3 | ||||
-rw-r--r-- | lib/pure/romans.nim | 3 | ||||
-rw-r--r-- | lib/pure/securehash.nim | 3 | ||||
-rw-r--r-- | lib/stdlib.nimble | 2 | ||||
-rw-r--r-- | lib/system.nim | 4 |
17 files changed, 183 insertions, 16 deletions
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index 170fee8b8..1b7f1de61 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -10,7 +10,49 @@ ## A higher level `mySQL`:idx: database wrapper. The same interface is ## implemented for other databases too. ## -## Example: +## See also: `db_odbc <db_odbc.html>`_, `db_sqlite <db_sqlite.html>`_, +## `db_postgres <db_postgres.html>`_. +## +## Parameter substitution +## ---------------------- +## +## All ``db_*`` modules support the same form of parameter substitution. +## That is, using the ``?`` (question mark) to signify the place where a +## value should be placed. For example: +## +## .. code-block:: Nim +## sql"INSERT INTO myTable (colA, colB, colC) VALUES (?, ?, ?)" +## +## +## Examples +## -------- +## +## Opening a connection to a database +## ================================== +## +## .. code-block:: Nim +## import db_mysql +## let db = open("localhost", "user", "password", "dbname") +## db.close() +## +## Creating a table +## ================ +## +## .. code-block:: Nim +## db.exec(sql"DROP TABLE IF EXISTS myTable") +## db.exec(sql("""CREATE TABLE myTable ( +## id integer, +## name varchar(50) not null)""")) +## +## Inserting data +## ============== +## +## .. code-block:: Nim +## db.exec(sql"INSERT INTO myTable (id, name) VALUES (0, ?)", +## "Dominik") +## +## Larger example +## ============== ## ## .. code-block:: Nim ## diff --git a/lib/impure/db_odbc.nim b/lib/impure/db_odbc.nim index 6af69d842..4f0b0469d 100644 --- a/lib/impure/db_odbc.nim +++ b/lib/impure/db_odbc.nim @@ -11,12 +11,54 @@ ## ## This is the same interface that is implemented for other databases. ## -## This has NOT yet been (extensively) tested agains ODBC drivers for -## Teradata, Oracle, Sybase, MSSqlvSvr, et. al. databases +## This has NOT yet been (extensively) tested against ODBC drivers for +## Teradata, Oracle, Sybase, MSSqlvSvr, et. al. databases. ## ## Currently all queries are ANSI calls, not Unicode. ## -## Example: +## See also: `db_postgres <db_postgres.html>`_, `db_sqlite <db_sqlite.html>`_, +## `db_mysql <db_mysql.html>`_. +## +## Parameter substitution +## ---------------------- +## +## All ``db_*`` modules support the same form of parameter substitution. +## That is, using the ``?`` (question mark) to signify the place where a +## value should be placed. For example: +## +## .. code-block:: Nim +## sql"INSERT INTO myTable (colA, colB, colC) VALUES (?, ?, ?)" +## +## +## Examples +## -------- +## +## Opening a connection to a database +## ================================== +## +## .. code-block:: Nim +## import db_odbc +## let db = open("localhost", "user", "password", "dbname") +## db.close() +## +## Creating a table +## ================ +## +## .. code-block:: Nim +## db.exec(sql"DROP TABLE IF EXISTS myTable") +## db.exec(sql("""CREATE TABLE myTable ( +## id integer, +## name varchar(50) not null)""")) +## +## Inserting data +## ============== +## +## .. code-block:: Nim +## db.exec(sql"INSERT INTO myTable (id, name) VALUES (0, ?)", +## "Andreas") +## +## Large example +## ============= ## ## .. code-block:: Nim ## diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index 9bdbae4c2..60bd1f081 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -10,6 +10,9 @@ ## A higher level `PostgreSQL`:idx: database wrapper. This interface ## is implemented for other databases also. ## +## See also: `db_odbc <db_odbc.html>`_, `db_sqlite <db_sqlite.html>`_, +## `db_mysql <db_mysql.html>`_. +## ## Parameter substitution ## ---------------------- ## @@ -27,7 +30,7 @@ ## ## 2. ``SqlPrepared`` using ``$1, $2, $3, ...`` ## -## .. code-block:: Nim +## .. code-block:: Nim ## prepare(db, "myExampleInsert", ## sql"""INSERT INTO myTable ## (colA, colB, colC) @@ -162,8 +165,10 @@ proc setupQuery(db: DbConn, stmtName: SqlPrepared, proc prepare*(db: DbConn; stmtName: string, query: SqlQuery; nParams: int): SqlPrepared = + ## Creates a new ``SqlPrepared`` statement. Parameter substitution is done + ## via ``$1``, ``$2``, ``$3``, etc. 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) if pqResultStatus(res) != PGRES_COMMAND_OK: dbError(db) return SqlPrepared(stmtName) @@ -282,6 +287,15 @@ proc getValue*(db: DbConn, query: SqlQuery, var x = pqgetvalue(setupQuery(db, query, args), 0, 0) result = if isNil(x): "" else: $x +proc getValue*(db: DbConn, stmtName: SqlPrepared, + args: varargs[string, `$`]): string {. + tags: [ReadDbEffect].} = + ## executes the query and returns the first column of the first row of the + ## result dataset. Returns "" if the dataset contains no rows or the database + ## value is NULL. + var x = pqgetvalue(setupQuery(db, stmtName, args), 0, 0) + result = if isNil(x): "" else: $x + proc tryInsertID*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]): int64 {. tags: [WriteDbEffect].}= diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index c0d221a0d..1633d48f7 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -10,7 +10,48 @@ ## A higher level `SQLite`:idx: database wrapper. This interface ## is implemented for other databases too. ## -## Example: +## See also: `db_odbc <db_odbc.html>`_, `db_postgres <db_postgres.html>`_, +## `db_mysql <db_mysql.html>`_. +## +## Parameter substitution +## ---------------------- +## +## All ``db_*`` modules support the same form of parameter substitution. +## That is, using the ``?`` (question mark) to signify the place where a +## value should be placed. For example: +## +## .. code-block:: Nim +## sql"INSERT INTO myTable (colA, colB, colC) VALUES (?, ?, ?)" +## +## Examples +## -------- +## +## Opening a connection to a database +## ================================== +## +## .. code-block:: Nim +## import db_sqlite +## let db = open("localhost", "user", "password", "dbname") +## db.close() +## +## Creating a table +## ================ +## +## .. code-block:: Nim +## db.exec(sql"DROP TABLE IF EXISTS myTable") +## db.exec(sql("""CREATE TABLE myTable ( +## id integer, +## name varchar(50) not null)""")) +## +## Inserting data +## ============== +## +## .. code-block:: Nim +## db.exec(sql"INSERT INTO myTable (id, name) VALUES (0, ?)", +## "Jack") +## +## Larger example +## ============== ## ## .. code-block:: nim ## diff --git a/lib/impure/rdstdin.nim b/lib/impure/rdstdin.nim index b373859f4..15137b436 100644 --- a/lib/impure/rdstdin.nim +++ b/lib/impure/rdstdin.nim @@ -100,7 +100,7 @@ when defined(Windows): stdout.write "\n" else: - import linenoise, termios, unsigned + import linenoise, termios proc readLineFromStdin*(prompt: string): TaintedString {. tags: [ReadIOEffect, WriteIOEffect].} = diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 329b2a1cb..2ed0d2034 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -887,7 +887,7 @@ proc mget*[A](t: CountTableRef[A], key: A): var int {.deprecated.} = result = t[][key] proc getOrDefault*[A](t: CountTableRef[A], key: A): int = - getOrDefaultImpl(t, key) + result = t[].getOrDefault(key) proc hasKey*[A](t: CountTableRef[A], key: A): bool = ## returns true iff `key` is in the table `t`. @@ -1028,3 +1028,15 @@ when isMainModule: assert(merged["foo"] == 5) assert(merged["bar"] == 3) assert(merged["baz"] == 14) + + block: + const testKey = "TESTKEY" + let t: CountTableRef[string] = newCountTable[string]() + + # Before, does not compile with error message: + #test_counttable.nim(7, 43) template/generic instantiation from here + #lib/pure/collections/tables.nim(117, 21) template/generic instantiation from here + #lib/pure/collections/tableimpl.nim(32, 27) Error: undeclared field: 'hcode + doAssert 0 == t.getOrDefault(testKey) + t.inc(testKey,3) + doAssert 3 == t.getOrDefault(testKey) diff --git a/lib/pure/fsmonitor.nim b/lib/pure/fsmonitor.nim index 115c4739e..b22e84f44 100644 --- a/lib/pure/fsmonitor.nim +++ b/lib/pure/fsmonitor.nim @@ -10,6 +10,9 @@ ## This module allows you to monitor files or directories for changes using ## asyncio. ## +## **Warning**: This module will likely disappear soon and be moved into a +## new Nimble package. +## ## Windows support is not yet implemented. ## ## **Note:** This module uses ``inotify`` on Linux (Other Unixes are not yet diff --git a/lib/pure/gentabs.nim b/lib/pure/gentabs.nim index e6a05ec63..928ff8fe0 100644 --- a/lib/pure/gentabs.nim +++ b/lib/pure/gentabs.nim @@ -11,6 +11,8 @@ ## key-value mapping. The keys are required to be strings, but the values ## may be any Nim or user defined type. This module supports matching ## of keys in case-sensitive, case-insensitive and style-insensitive modes. +## +## **Warning:** This module is deprecated, new code shouldn't use it! {.deprecated.} diff --git a/lib/pure/httpserver.nim b/lib/pure/httpserver.nim index 71ba04991..632eb198a 100644 --- a/lib/pure/httpserver.nim +++ b/lib/pure/httpserver.nim @@ -9,6 +9,9 @@ ## This module implements a simple HTTP-Server. ## +## **Warning**: This module will soon be deprecated in favour of +## the ``asyncdispatch`` module, you should use it instead. +## ## Example: ## ## .. code-block:: nim diff --git a/lib/pure/nativesockets.nim b/lib/pure/nativesockets.nim index b5a8d5777..3951b46a3 100644 --- a/lib/pure/nativesockets.nim +++ b/lib/pure/nativesockets.nim @@ -12,7 +12,7 @@ # TODO: Clean up the exports a bit and everything else in general. -import unsigned, os +import os when hostOS == "solaris": {.passl: "-lsocket -lnsl".} diff --git a/lib/pure/net.nim b/lib/pure/net.nim index d1016011e..1cfaf029f 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -10,7 +10,7 @@ ## This module implements a high-level cross-platform sockets interface. {.deadCodeElim: on.} -import nativesockets, os, strutils, unsigned, parseutils, times +import nativesockets, os, strutils, parseutils, times export Port, `$`, `==` const useWinVersion = defined(Windows) or defined(nimdoc) diff --git a/lib/pure/numeric.nim b/lib/pure/numeric.nim index 71adf19b3..ccda3a146 100644 --- a/lib/pure/numeric.nim +++ b/lib/pure/numeric.nim @@ -7,6 +7,9 @@ # distribution, for details about the copyright. # +## **Warning:** This module will be moved out of the stdlib and into a +## Nimble package, don't use it. + type OneVarFunction* = proc (x: float): float {.deprecated: [TOneVarFunction: OneVarFunction].} diff --git a/lib/pure/poly.nim b/lib/pure/poly.nim index c52300400..b20e9f9d0 100644 --- a/lib/pure/poly.nim +++ b/lib/pure/poly.nim @@ -7,6 +7,9 @@ # distribution, for details about the copyright. # +## **Warning:** This module will be moved out of the stdlib and into a +## Nimble package, don't use it. + import math import strutils import numeric diff --git a/lib/pure/romans.nim b/lib/pure/romans.nim index 18c04ef58..aa047d1cc 100644 --- a/lib/pure/romans.nim +++ b/lib/pure/romans.nim @@ -9,6 +9,9 @@ ## Module for converting an integer to a Roman numeral. ## See http://en.wikipedia.org/wiki/Roman_numerals for reference. +## +## **Warning:** This module will be moved out of the stdlib and into a +## Nimble package, don't use it. const RomanNumeralDigits* = {'I', 'i', 'V', 'v', 'X', 'x', 'L', 'l', 'C', 'c', diff --git a/lib/pure/securehash.nim b/lib/pure/securehash.nim index 8ac6acb0e..657782889 100644 --- a/lib/pure/securehash.nim +++ b/lib/pure/securehash.nim @@ -7,8 +7,7 @@ # distribution, for details about the copyright. # -import - strutils, unsigned +import strutils const Sha1DigestSize = 20 diff --git a/lib/stdlib.nimble b/lib/stdlib.nimble index 0805ead54..e8bb364f1 100644 --- a/lib/stdlib.nimble +++ b/lib/stdlib.nimble @@ -1,6 +1,6 @@ [Package] name = "stdlib" -version = "0.9.0" +version = "0.13.0" author = "Dominik Picheta" description = "Nim's standard library." license = "MIT" diff --git a/lib/system.nim b/lib/system.nim index bb8254364..e884e784c 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1808,10 +1808,10 @@ const NimMajor*: int = 0 ## is the major number of Nim's version. - NimMinor*: int = 12 + NimMinor*: int = 13 ## is the minor number of Nim's version. - NimPatch*: int = 1 + NimPatch*: int = 0 ## is the patch number of Nim's version. NimVersion*: string = $NimMajor & "." & $NimMinor & "." & $NimPatch |