From d0cc21e3229a5bd4efb698cc719c316aad703d12 Mon Sep 17 00:00:00 2001 From: Andrey Makarov Date: Wed, 12 Oct 2022 17:13:43 +0300 Subject: [PATCH] Markdown code blocks migration part 7 (#20547) --- src/db_odbc.nim | 74 ++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/db_odbc.nim b/src/db_odbc.nim index 756957acb4..2427f64fa5 100644 --- a/src/db_odbc.nim +++ b/src/db_odbc.nim @@ -26,8 +26,9 @@ ## 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 (?, ?, ?)" +## ```Nim +## sql"INSERT INTO myTable (colA, colB, colC) VALUES (?, ?, ?)" +## ``` ## ## ## Examples @@ -36,57 +37,60 @@ ## Opening a connection to a database ## ---------------------------------- ## -## .. code-block:: Nim -## import std/db_odbc -## var db = open("localhost", "user", "password", "dbname") -## db.close() +## ```Nim +## import std/db_odbc +## var 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)""")) +## ```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") +## ```Nim +## db.exec(sql"INSERT INTO myTable (id, name) VALUES (0, ?)", +## "Andreas") +## ``` ## ## Large example ## ------------- ## -## .. code-block:: Nim +## ```Nim +## import std/[db_odbc, math] ## -## import std/[db_odbc, math] +## var theDb = open("localhost", "nim", "nim", "test") ## -## var theDb = open("localhost", "nim", "nim", "test") +## theDb.exec(sql"Drop table if exists myTestTbl") +## theDb.exec(sql("create table myTestTbl (" & +## " Id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, " & +## " Name VARCHAR(50) NOT NULL, " & +## " i INT(11), " & +## " f DECIMAL(18,10))")) ## -## theDb.exec(sql"Drop table if exists myTestTbl") -## theDb.exec(sql("create table myTestTbl (" & -## " Id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, " & -## " Name VARCHAR(50) NOT NULL, " & -## " i INT(11), " & -## " f DECIMAL(18,10))")) +## theDb.exec(sql"START TRANSACTION") +## for i in 1..1000: +## theDb.exec(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)", +## "Item#" & $i, i, sqrt(i.float)) +## theDb.exec(sql"COMMIT") ## -## theDb.exec(sql"START TRANSACTION") -## for i in 1..1000: -## theDb.exec(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)", -## "Item#" & $i, i, sqrt(i.float)) -## theDb.exec(sql"COMMIT") +## for x in theDb.fastRows(sql"select * from myTestTbl"): +## echo x ## -## for x in theDb.fastRows(sql"select * from myTestTbl"): -## echo x +## let id = theDb.tryInsertId(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)", +## "Item#1001", 1001, sqrt(1001.0)) +## echo "Inserted item: ", theDb.getValue(sql"SELECT name FROM myTestTbl WHERE id=?", id) ## -## let id = theDb.tryInsertId(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)", -## "Item#1001", 1001, sqrt(1001.0)) -## echo "Inserted item: ", theDb.getValue(sql"SELECT name FROM myTestTbl WHERE id=?", id) -## -## theDb.close() +## theDb.close() +## ``` import strutils, odbcsql import db_common