123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>src/db_connector/db_mysql</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
- <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">src/db_connector/db_mysql</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li><a class="reference" id="parameter-substitution_toc" href="#parameter-substitution">Parameter substitution</a></li>
- <li><a class="reference" id="examples_toc" href="#examples">Examples</a></li>
- <ul class="simple"><li><a class="reference" id="examples-opening-a-connection-to-a-database_toc" href="#examples-opening-a-connection-to-a-database">Opening a connection to a database</a></li>
- <li><a class="reference" id="examples-creating-a-table_toc" href="#examples-creating-a-table">Creating a table</a></li>
- <li><a class="reference" id="examples-inserting-data_toc" href="#examples-inserting-data">Inserting data</a></li>
- <li><a class="reference" id="examples-larger-example_toc" href="#examples-larger-example">Larger example</a></li>
- </ul><li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#DbConn" title="DbConn = distinct PMySQL">DbConn</a></li>
- <li><a class="reference" href="#InstantRow" title="InstantRow = object">InstantRow</a></li>
- <li><a class="reference" href="#Row" title="Row = seq[string]">Row</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">[]
- <li><a class="reference" href="#%5B%5D%2CInstantRow%2Cint" title="`[]`(row: InstantRow; col: int): string">`[]`(row: InstantRow; col: int): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">close
- <li><a class="reference" href="#close%2CDbConn" title="close(db: DbConn)">close(db: DbConn)</a></li>
- </ul>
- <ul class="simple nested-toc-section">dbError
- <li><a class="reference" href="#dbError%2CDbConn" title="dbError(db: DbConn)">dbError(db: DbConn)</a></li>
- </ul>
- <ul class="simple nested-toc-section">dbQuote
- <li><a class="reference" href="#dbQuote%2Cstring" title="dbQuote(s: string): string">dbQuote(s: string): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">exec
- <li><a class="reference" href="#exec%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="exec(db: DbConn; query: SqlQuery; args: varargs[string, `$`])">exec(db: DbConn; query: SqlQuery; args: varargs[string, `$`])</a></li>
- </ul>
- <ul class="simple nested-toc-section">execAffectedRows
- <li><a class="reference" href="#execAffectedRows%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="execAffectedRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): int64">execAffectedRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): int64</a></li>
- </ul>
- <ul class="simple nested-toc-section">getAllRows
- <li><a class="reference" href="#getAllRows%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="getAllRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): seq[Row]">getAllRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): seq[Row]</a></li>
- </ul>
- <ul class="simple nested-toc-section">getRow
- <li><a class="reference" href="#getRow%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="getRow(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): Row">getRow(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): Row</a></li>
- </ul>
- <ul class="simple nested-toc-section">getValue
- <li><a class="reference" href="#getValue%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="getValue(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): string">getValue(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">insert
- <li><a class="reference" href="#insert%2CDbConn%2CSqlQuery%2Cstring%2Cvarargs%5Bstring%2C%5D" title="insert(db: DbConn; query: SqlQuery; pkName: string; args: varargs[string, `$`]): int64">insert(db: DbConn; query: SqlQuery; pkName: string; args: varargs[string, `$`]): int64</a></li>
- </ul>
- <ul class="simple nested-toc-section">insertId
- <li><a class="reference" href="#insertId%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="insertId(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): int64">insertId(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): int64</a></li>
- </ul>
- <ul class="simple nested-toc-section">len
- <li><a class="reference" href="#len%2CInstantRow" title="len(row: InstantRow): int">len(row: InstantRow): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">open
- <li><a class="reference" href="#open%2Cstring%2Cstring%2Cstring%2Cstring" title="open(connection, user, password, database: string): DbConn">open(connection, user, password, database: string): DbConn</a></li>
- </ul>
- <ul class="simple nested-toc-section">setEncoding
- <li><a class="reference" href="#setEncoding%2CDbConn%2Cstring" title="setEncoding(connection: DbConn; encoding: string): bool">setEncoding(connection: DbConn; encoding: string): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">tryExec
- <li><a class="reference" href="#tryExec%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="tryExec(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): bool">tryExec(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">tryInsert
- <li><a class="reference" href="#tryInsert%2CDbConn%2CSqlQuery%2Cstring%2Cvarargs%5Bstring%2C%5D" title="tryInsert(db: DbConn; query: SqlQuery; pkName: string;
- args: varargs[string, `$`]): int64">tryInsert(db: DbConn; query: SqlQuery; pkName: string;
- args: varargs[string, `$`]): int64</a></li>
- </ul>
- <ul class="simple nested-toc-section">tryInsertId
- <li><a class="reference" href="#tryInsertId%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="tryInsertId(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): int64">tryInsertId(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): int64</a></li>
- </ul>
- <ul class="simple nested-toc-section">unsafeColumnAt
- <li><a class="reference" href="#unsafeColumnAt%2CInstantRow%2Cint" title="unsafeColumnAt(row: InstantRow; index: int): cstring">unsafeColumnAt(row: InstantRow; index: int): cstring</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">fastRows
- <li><a class="reference" href="#fastRows.i%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="fastRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): Row">fastRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): Row</a></li>
- </ul>
- <ul class="simple nested-toc-section">instantRows
- <li><a class="reference" href="#instantRows.i%2CDbConn%2CDbColumns%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="instantRows(db: DbConn; columns: var DbColumns; query: SqlQuery;
- args: varargs[string, `$`]): InstantRow">instantRows(db: DbConn; columns: var DbColumns; query: SqlQuery;
- args: varargs[string, `$`]): InstantRow</a></li>
- <li><a class="reference" href="#instantRows.i%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="instantRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): InstantRow">instantRows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): InstantRow</a></li>
- </ul>
- <ul class="simple nested-toc-section">rows
- <li><a class="reference" href="#rows.i%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="rows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): Row">rows(db: DbConn; query: SqlQuery; args: varargs[string, `$`]): Row</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
-
- <div id="tocRoot"></div>
-
- <p class="module-desc"><div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
- In order to use this module, run <tt class="docutils literal"><span class="pre"><span class="Identifier">nimble</span> <span class="Identifier">install</span> <span class="Identifier">db_connector</span></span></tt>.</div>
- <p>A higher level <span id="mysql_1">mySQL</span> database wrapper. The same interface is implemented for other databases too.</p>
- <p>See also: <a class="reference external" href="db_odbc.html">db_odbc</a>, <a class="reference external" href="db_sqlite.html">db_sqlite</a>, <a class="reference external" href="db_postgres.html">db_postgres</a>.</p>
- <h1><a class="toc-backref" id="parameter-substitution" href="#parameter-substitution">Parameter substitution</a></h1><p>All <tt class="docutils literal"><span class="pre"><span class="Identifier">db_</span><span class="Operator">*</span></span></tt> modules support the same form of parameter substitution. That is, using the <tt class="docutils literal"><span class="pre"><span class="Operator">?</span></span></tt> (question mark) to signify the place where a value should be placed. For example:</p>
- <p><pre class="listing"><span class="RawData">sql"INSERT INTO myTable (colA, colB, colC) VALUES (?, ?, ?)"</span></pre></p>
- <h1><a class="toc-backref" id="examples" href="#examples">Examples</a></h1>
- <h2><a class="toc-backref" id="examples-opening-a-connection-to-a-database" href="#examples-opening-a-connection-to-a-database">Opening a connection to a database</a></h2><p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">db_connector</span><span class="Operator">/</span><span class="Identifier">db_mysql</span>
- <span class="Keyword">let</span> <span class="Identifier">db</span> <span class="Operator">=</span> <span class="Identifier">open</span><span class="Punctuation">(</span><span class="StringLit">"localhost"</span><span class="Punctuation">,</span> <span class="StringLit">"user"</span><span class="Punctuation">,</span> <span class="StringLit">"password"</span><span class="Punctuation">,</span> <span class="StringLit">"dbname"</span><span class="Punctuation">)</span>
- <span class="Identifier">db</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
- <h2><a class="toc-backref" id="examples-creating-a-table" href="#examples-creating-a-table">Creating a table</a></h2><p><pre class="listing"><span class="Identifier">db</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql"DROP TABLE IF EXISTS myTable"</span><span class="Punctuation">)</span>
- <span class="Identifier">db</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="Identifier">sql</span><span class="Punctuation">(</span><span class="LongStringLit">"""CREATE TABLE myTable (
- id integer,
- name varchar(50) not null)"""</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre></p>
- <h2><a class="toc-backref" id="examples-inserting-data" href="#examples-inserting-data">Inserting data</a></h2><p><pre class="listing"><span class="Identifier">db</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql"INSERT INTO myTable (id, name) VALUES (0, ?)"</span><span class="Punctuation">,</span>
- <span class="StringLit">"Dominik"</span><span class="Punctuation">)</span></pre></p>
- <h2><a class="toc-backref" id="examples-larger-example" href="#examples-larger-example">Larger example</a></h2><p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">db_connector</span><span class="Operator">/</span><span class="Identifier">db_mysql</span>
- <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">math</span>
- <span class="Keyword">let</span> <span class="Identifier">theDb</span> <span class="Operator">=</span> <span class="Identifier">open</span><span class="Punctuation">(</span><span class="StringLit">"localhost"</span><span class="Punctuation">,</span> <span class="StringLit">"nim"</span><span class="Punctuation">,</span> <span class="StringLit">"nim"</span><span class="Punctuation">,</span> <span class="StringLit">"test"</span><span class="Punctuation">)</span>
- <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql"Drop table if exists myTestTbl"</span><span class="Punctuation">)</span>
- <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="Identifier">sql</span><span class="Punctuation">(</span><span class="StringLit">"create table myTestTbl ("</span> <span class="Operator">&</span>
- <span class="StringLit">" Id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "</span> <span class="Operator">&</span>
- <span class="StringLit">" Name VARCHAR(50) NOT NULL, "</span> <span class="Operator">&</span>
- <span class="StringLit">" i INT(11), "</span> <span class="Operator">&</span>
- <span class="StringLit">" f DECIMAL(18,10))"</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
- <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql"START TRANSACTION"</span><span class="Punctuation">)</span>
- <span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="FloatNumber">1.</span><span class="Operator">.</span><span class="DecNumber">1000</span><span class="Punctuation">:</span>
- <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)"</span><span class="Punctuation">,</span>
- <span class="StringLit">"Item#"</span> <span class="Operator">&</span> <span class="Operator">$</span><span class="Identifier">i</span><span class="Punctuation">,</span> <span class="Identifier">i</span><span class="Punctuation">,</span> <span class="Identifier">sqrt</span><span class="Punctuation">(</span><span class="Identifier">i</span><span class="Operator">.</span><span class="Identifier">float</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
- <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql"COMMIT"</span><span class="Punctuation">)</span>
- <span class="Keyword">for</span> <span class="Identifier">x</span> <span class="Keyword">in</span> <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">fastRows</span><span class="Punctuation">(</span><span class="RawData">sql"select * from myTestTbl"</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
- <span class="Identifier">echo</span> <span class="Identifier">x</span>
- <span class="Keyword">let</span> <span class="Identifier">id</span> <span class="Operator">=</span> <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">tryInsertId</span><span class="Punctuation">(</span><span class="RawData">sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)"</span><span class="Punctuation">,</span>
- <span class="StringLit">"Item#1001"</span><span class="Punctuation">,</span> <span class="DecNumber">1001</span><span class="Punctuation">,</span> <span class="Identifier">sqrt</span><span class="Punctuation">(</span><span class="FloatNumber">1001.0</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
- <span class="Identifier">echo</span> <span class="StringLit">"Inserted item: "</span><span class="Punctuation">,</span> <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">getValue</span><span class="Punctuation">(</span><span class="RawData">sql"SELECT name FROM myTestTbl WHERE id=?"</span><span class="Punctuation">,</span> <span class="Identifier">id</span><span class="Punctuation">)</span>
- <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
- </p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="mysql.html">mysql</a>, <a class="reference external" href="db_common.html">db_common</a>, <a class="reference external" href="dbutils.html">dbutils</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="DbConn">
- <dt><pre><a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="mysql.html#PMySQL"><span class="Identifier">PMySQL</span></a></pre></dt>
- <dd>
-
- encapsulates a database connection
-
- </dd>
- </div>
- <div id="InstantRow">
- <dt><pre><a href="db_mysql.html#InstantRow"><span class="Identifier">InstantRow</span></a> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
- <dd>
-
- a handle that can be used to get a row's column text on demand
-
- </dd>
- </div>
- <div id="Row">
- <dt><pre><a href="db_mysql.html#Row"><span class="Identifier">Row</span></a> <span class="Other">=</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span></pre></dt>
- <dd>
-
- a row of a dataset. NULL database values will be converted to nil.
-
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="[]-procs-all">
- <div id="[],InstantRow,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CInstantRow%2Cint"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">row</span><span class="Other">:</span> <a href="db_mysql.html#InstantRow"><span class="Identifier">InstantRow</span></a><span class="Other">;</span> <span class="Identifier">col</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns text for given column of the row.
-
- </dd>
- </div>
- </div>
- <div id="close-procs-all">
- <div id="close,DbConn">
- <dt><pre><span class="Keyword">proc</span> <a href="#close%2CDbConn"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#DbEffect"><span class="Identifier">DbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- closes the database connection.
-
- </dd>
- </div>
- </div>
- <div id="dbError-procs-all">
- <div id="dbError,DbConn">
- <dt><pre><span class="Keyword">proc</span> <a href="#dbError%2CDbConn"><span class="Identifier">dbError</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">)</span> {.<span class="Identifier">noreturn</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- raises a DbError exception.
-
- </dd>
- </div>
- </div>
- <div id="dbQuote-procs-all">
- <div id="dbQuote,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#dbQuote%2Cstring"><span class="Identifier">dbQuote</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- DB quotes the string. Note that this doesn't escape <tt class="docutils literal"><span class="pre"><span class="Operator">%</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">_</span></span></tt>.
-
- </dd>
- </div>
- </div>
- <div id="exec-procs-all">
- <div id="exec,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#exec%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">exec</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">,</span> <a href="db_common.html#WriteDbEffect"><span class="Identifier">WriteDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- executes the query and raises EDB if not successful.
-
- </dd>
- </div>
- </div>
- <div id="execAffectedRows-procs-all">
- <div id="execAffectedRows,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#execAffectedRows%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">execAffectedRows</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int64</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">,</span> <a href="db_common.html#WriteDbEffect"><span class="Identifier">WriteDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- runs the query (typically "UPDATE") and returns the number of affected rows
-
- </dd>
- </div>
- </div>
- <div id="getAllRows-procs-all">
- <div id="getAllRows,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#getAllRows%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">getAllRows</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span>
- <a href="db_mysql.html#Row"><span class="Identifier">Row</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- executes the query and returns the whole result dataset.
-
- </dd>
- </div>
- </div>
- <div id="getRow-procs-all">
- <div id="getRow,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#getRow%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">getRow</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="db_mysql.html#Row"><span class="Identifier">Row</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Retrieves a single row. If the query doesn't return any rows, this proc will return a Row with empty strings for each column.
-
- </dd>
- </div>
- </div>
- <div id="getValue-procs-all">
- <div id="getValue,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#getValue%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">getValue</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- 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.
-
- </dd>
- </div>
- </div>
- <div id="insert-procs-all">
- <div id="insert,DbConn,SqlQuery,string,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#insert%2CDbConn%2CSqlQuery%2Cstring%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">insert</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">pkName</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span>
- <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int64</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#WriteDbEffect"><span class="Identifier">WriteDbEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- same as insertId
-
- </dd>
- </div>
- </div>
- <div id="insertId-procs-all">
- <div id="insertId,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#insertId%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">insertId</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int64</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#WriteDbEffect"><span class="Identifier">WriteDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- executes the query (typically "INSERT") and returns the generated ID for the row.
-
- </dd>
- </div>
- </div>
- <div id="len-procs-all">
- <div id="len,InstantRow">
- <dt><pre><span class="Keyword">proc</span> <a href="#len%2CInstantRow"><span class="Identifier">len</span></a><span class="Other">(</span><span class="Identifier">row</span><span class="Other">:</span> <a href="db_mysql.html#InstantRow"><span class="Identifier">InstantRow</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns number of columns in the row.
-
- </dd>
- </div>
- </div>
- <div id="open-procs-all">
- <div id="open,string,string,string,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#open%2Cstring%2Cstring%2Cstring%2Cstring"><span class="Identifier">open</span></a><span class="Other">(</span><span class="Identifier">connection</span><span class="Other">,</span> <span class="Identifier">user</span><span class="Other">,</span> <span class="Identifier">password</span><span class="Other">,</span> <span class="Identifier">database</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#DbEffect"><span class="Identifier">DbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- opens a database connection. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">EDb</span></span></tt> if the connection could not be established.
-
- </dd>
- </div>
- </div>
- <div id="setEncoding-procs-all">
- <div id="setEncoding,DbConn,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#setEncoding%2CDbConn%2Cstring"><span class="Identifier">setEncoding</span></a><span class="Other">(</span><span class="Identifier">connection</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">encoding</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#DbEffect"><span class="Identifier">DbEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- sets the encoding of a database connection, returns true for success, false for failure.
-
- </dd>
- </div>
- </div>
- <div id="tryExec-procs-all">
- <div id="tryExec,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#tryExec%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">tryExec</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">bool</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">,</span> <a href="db_common.html#WriteDbEffect"><span class="Identifier">WriteDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- tries to execute the query and returns true if successful, false otherwise.
-
- </dd>
- </div>
- </div>
- <div id="tryInsert-procs-all">
- <div id="tryInsert,DbConn,SqlQuery,string,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#tryInsert%2CDbConn%2CSqlQuery%2Cstring%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">tryInsert</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">pkName</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span>
- <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int64</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#WriteDbEffect"><span class="Identifier">WriteDbEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#DbError"><span class="Identifier">DbError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- same as tryInsertID
-
- </dd>
- </div>
- </div>
- <div id="tryInsertId-procs-all">
- <div id="tryInsertId,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">proc</span> <a href="#tryInsertId%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">tryInsertId</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int64</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#WriteDbEffect"><span class="Identifier">WriteDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#DbError"><span class="Identifier">DbError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- executes the query (typically "INSERT") and returns the generated ID for the row or -1 in case of an error.
-
- </dd>
- </div>
- </div>
- <div id="unsafeColumnAt-procs-all">
- <div id="unsafeColumnAt,InstantRow,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#unsafeColumnAt%2CInstantRow%2Cint"><span class="Identifier">unsafeColumnAt</span></a><span class="Other">(</span><span class="Identifier">row</span><span class="Other">:</span> <a href="db_mysql.html#InstantRow"><span class="Identifier">InstantRow</span></a><span class="Other">;</span> <span class="Identifier">index</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">cstring</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Return cstring of given column of the row
-
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="15">
- <h1><a class="toc-backref" href="#15">Iterators</a></h1>
- <dl class="item">
- <div id="fastRows-iterators-all">
- <div id="fastRows.i,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#fastRows.i%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">fastRows</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="db_mysql.html#Row"><span class="Identifier">Row</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>executes the query and iterates over the result dataset.</p>
- <p>This is very fast, but potentially dangerous. Use this iterator only if you require <strong>ALL</strong> the rows.</p>
- <p>Breaking the fastRows() iterator during a loop will cause the next database query to raise an <tt class="docutils literal"><span class="pre"><span class="Identifier">EDb</span></span></tt> exception <tt class="docutils literal"><span class="pre"><span class="Identifier">Commands</span> <span class="Keyword">out</span> <span class="Keyword">of</span> <span class="Identifier">sync</span></span></tt>.</p>
-
- </dd>
- </div>
- </div>
- <div id="instantRows-iterators-all">
- <div id="instantRows.i,DbConn,DbColumns,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#instantRows.i%2CDbConn%2CDbColumns%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">instantRows</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">columns</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="db_common.html#DbColumns"><span class="Identifier">DbColumns</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span>
- <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="db_mysql.html#InstantRow"><span class="Identifier">InstantRow</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Same as fastRows but returns a handle that can be used to get column text on demand using <tt class="docutils literal"><span class="pre"><span class="Punctuation">[</span><span class="Punctuation">]</span></span></tt>. Returned handle is valid only within the iterator body.
-
- </dd>
- </div>
- <div id="instantRows.i,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#instantRows.i%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">instantRows</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="db_mysql.html#InstantRow"><span class="Identifier">InstantRow</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Same as fastRows but returns a handle that can be used to get column text on demand using <tt class="docutils literal"><span class="pre"><span class="Punctuation">[</span><span class="Punctuation">]</span></span></tt>. Returned handle is valid only within the iterator body.
-
- </dd>
- </div>
- </div>
- <div id="rows-iterators-all">
- <div id="rows.i,DbConn,SqlQuery,varargs[string,]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#rows.i%2CDbConn%2CSqlQuery%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">rows</span></a><span class="Other">(</span><span class="Identifier">db</span><span class="Other">:</span> <a href="db_mysql.html#DbConn"><span class="Identifier">DbConn</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="db_common.html#SqlQuery"><span class="Identifier">SqlQuery</span></a><span class="Other">;</span> <span class="Identifier">args</span><span class="Other">:</span> <span class="Identifier">varargs</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="db_mysql.html#Row"><span class="Identifier">Row</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="db_common.html#ReadDbEffect"><span class="Identifier">ReadDbEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">DbError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- same as <tt class="docutils literal"><span class="pre"><span class="Identifier">fastRows</span></span></tt>, but slower and safe.
-
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2024-12-25 13:28:33 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|