Markdown code blocks migration part 7 (#20547)

This commit is contained in:
Andrey Makarov
2022-10-12 17:13:43 +03:00
committed by ringabout
parent 769869c699
commit d0cc21e322

View File

@@ -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