From 72dfe176f5211f561263984a2df653f16dcf5466 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 23 Apr 2018 17:02:38 +0800 Subject: remove dead code elimination option (#7669) --- lib/impure/db_sqlite.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/impure/db_sqlite.nim') diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index 21049571f..f88037e2f 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -81,7 +81,7 @@ ## ## theDb.close() -{.deadCodeElim:on.} +{.deadCodeElim: on.} # dce option deprecated import strutils, sqlite3 -- cgit 1.4.1-2-gfad0 From af593c2ef3abb323a60ae49e5f1bbb08ffb6262e Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 9 May 2018 19:33:58 +0100 Subject: Better db_sqlite errors when db_sqlite not connected. --- lib/impure/db_sqlite.nim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/impure/db_sqlite.nim') diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index f88037e2f..b1541c1ba 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -126,6 +126,7 @@ proc tryExec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]): bool {. tags: [ReadDbEffect, WriteDbEffect].} = ## tries to execute the query and returns true if successful, false otherwise. + assert(not db.isNil, "Database not connected.") var q = dbFormat(query, args) var stmt: sqlite3.Pstmt if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK: @@ -144,6 +145,7 @@ proc newRow(L: int): Row = proc setupQuery(db: DbConn, query: SqlQuery, args: varargs[string]): Pstmt = + assert(not db.isNil, "Database not connected.") var q = dbFormat(query, args) if prepare_v2(db, q, q.len.cint, result, nil) != SQLITE_OK: dbError(db) @@ -267,6 +269,7 @@ proc tryInsertID*(db: DbConn, query: SqlQuery, {.tags: [WriteDbEffect], raises: [].} = ## executes the query (typically "INSERT") and returns the ## generated ID for the row or -1 in case of an error. + assert(not db.isNil, "Database not connected.") var q = dbFormat(query, args) var stmt: sqlite3.Pstmt result = -1 -- cgit 1.4.1-2-gfad0 From cb87bba82fa81240ea449e13a99280ce134096db Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Fri, 1 Jun 2018 16:28:20 +0100 Subject: Update example (#7788) --- lib/impure/db_sqlite.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/impure/db_sqlite.nim') diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index b1541c1ba..6b8ca4881 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -31,7 +31,7 @@ ## ## .. code-block:: Nim ## import db_sqlite -## let db = open("localhost", "user", "password", "dbname") +## let db = open("mytest.db", nil, nil, nil) # user, password, database name can be nil ## db.close() ## ## Creating a table -- cgit 1.4.1-2-gfad0 From 381acc09e9a5c2d61a67f0f1f6b60d2efb577657 Mon Sep 17 00:00:00 2001 From: Varriount Date: Sun, 3 Jun 2018 14:37:41 -0400 Subject: Update sqlite example to use empty strings. Update sqlite example to use empty strings to use empty strings instead of nil. --- lib/impure/db_sqlite.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/impure/db_sqlite.nim') diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index 6b8ca4881..fd25b2b94 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -57,7 +57,7 @@ ## ## import db_sqlite, math ## -## let theDb = open("mytest.db", nil, nil, nil) +## let theDb = open("mytest.db", "", "", "") ## ## theDb.exec(sql"Drop table if exists myTestTbl") ## theDb.exec(sql("""create table myTestTbl ( -- cgit 1.4.1-2-gfad0 From 94684488d61143b8012b8b97e9f48777985aad42 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 14 Aug 2018 21:15:03 +0200 Subject: make more tests green --- lib/impure/db_mysql.nim | 35 +++++------------------------------ lib/impure/db_postgres.nim | 7 ++----- lib/impure/db_sqlite.nim | 1 - lib/pure/collections/tables.nim | 2 +- lib/pure/htmlparser.nim | 1 - 5 files changed, 8 insertions(+), 38 deletions(-) (limited to 'lib/impure/db_sqlite.nim') diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index ca0e29d11..26bc7d0ad 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -128,10 +128,7 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string = var a = 0 for c in items(string(formatstr)): if c == '?': - if args[a].isNil: - add(result, "NULL") - else: - add(result, dbQuote(args[a])) + add(result, dbQuote(args[a])) inc(a) else: add(result, c) @@ -183,24 +180,8 @@ iterator fastRows*(db: DbConn, query: SqlQuery, row = mysql.fetchRow(sqlres) if row == nil: break for i in 0..L-1: - if row[i] == nil: - if backup == nil: - newSeq(backup, L) - if backup[i] == nil and result[i] != nil: - shallowCopy(backup[i], result[i]) - result[i] = nil - else: - if result[i] == nil: - if backup != nil: - if backup[i] == nil: - backup[i] = "" - shallowCopy(result[i], backup[i]) - setLen(result[i], 0) - else: - result[i] = "" - else: - setLen(result[i], 0) - add(result[i], row[i]) + setLen(result[i], 0) + result[i].add row[i] yield result properFreeResult(sqlres, row) @@ -323,10 +304,7 @@ proc getRow*(db: DbConn, query: SqlQuery, if row != nil: for i in 0..L-1: setLen(result[i], 0) - if row[i] == nil: - result[i] = nil - else: - add(result[i], row[i]) + add(result[i], row[i]) properFreeResult(sqlres, row) proc getAllRows*(db: DbConn, query: SqlQuery, @@ -345,10 +323,7 @@ proc getAllRows*(db: DbConn, query: SqlQuery, setLen(result, j+1) newSeq(result[j], L) for i in 0..L-1: - if row[i] == nil: - result[j][i] = nil - else: - result[j][i] = $row[i] + 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 1459f0d7e..e765cc197 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -103,10 +103,7 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string = else: for c in items(string(formatstr)): if c == '?': - if args[a] == nil: - add(result, "NULL") - else: - add(result, dbQuote(args[a])) + add(result, dbQuote(args[a])) inc(a) else: add(result, c) @@ -179,7 +176,7 @@ proc setRow(res: PPGresult, r: var Row, line, cols: int32) = setLen(r[col], 0) let x = pqgetvalue(res, line, col) if x.isNil: - r[col] = nil + r[col] = "" else: add(r[col], x) diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index fd25b2b94..a40c88a11 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -105,7 +105,6 @@ proc dbError*(db: DbConn) {.noreturn.} = proc dbQuote*(s: string): string = ## DB quotes the string. - if s.isNil: return "NULL" result = "'" for c in items(s): if c == '\'': add(result, "''") diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 308f31eae..f85de7546 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -1329,7 +1329,7 @@ when isMainModule: doAssert clearTable[42] == "asd" clearTable.clear() doAssert(not clearTable.hasKey(123123)) - doAssert clearTable.getOrDefault(42) == nil + doAssert clearTable.getOrDefault(42) == "" block: #5482 var a = [("wrong?","foo"), ("wrong?", "foo2")].newOrderedTable() diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index c38c36874..f54fe87f7 100644 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -1869,7 +1869,6 @@ proc entityToUtf8*(entity: string): string = ## "" is returned if the entity name is unknown. The HTML parser ## already converts entities to UTF-8. runnableExamples: - doAssert entityToUtf8(nil) == "" doAssert entityToUtf8("") == "" doAssert entityToUtf8("a") == "" doAssert entityToUtf8("gt") == ">" -- cgit 1.4.1-2-gfad0