db_mysql.html 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>src/db_connector/db_mysql</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <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=="/>
  14. <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=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">src/db_connector/db_mysql</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li><a class="reference" id="parameter-substitution_toc" href="#parameter-substitution">Parameter substitution</a></li>
  50. <li><a class="reference" id="examples_toc" href="#examples">Examples</a></li>
  51. <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>
  52. <li><a class="reference" id="examples-creating-a-table_toc" href="#examples-creating-a-table">Creating a table</a></li>
  53. <li><a class="reference" id="examples-inserting-data_toc" href="#examples-inserting-data">Inserting data</a></li>
  54. <li><a class="reference" id="examples-larger-example_toc" href="#examples-larger-example">Larger example</a></li>
  55. </ul><li>
  56. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  57. </li>
  58. <li>
  59. <details open>
  60. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  61. <ul class="simple simple-toc-section">
  62. <li><a class="reference" href="#DbConn" title="DbConn = distinct PMySQL">DbConn</a></li>
  63. <li><a class="reference" href="#InstantRow" title="InstantRow = object">InstantRow</a></li>
  64. <li><a class="reference" href="#Row" title="Row = seq[string]">Row</a></li>
  65. </ul>
  66. </details>
  67. </li>
  68. <li>
  69. <details open>
  70. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  71. <ul class="simple simple-toc-section">
  72. <ul class="simple nested-toc-section">[]
  73. <li><a class="reference" href="#%5B%5D%2CInstantRow%2Cint" title="`[]`(row: InstantRow; col: int): string">`[]`(row: InstantRow; col: int): string</a></li>
  74. </ul>
  75. <ul class="simple nested-toc-section">close
  76. <li><a class="reference" href="#close%2CDbConn" title="close(db: DbConn)">close(db: DbConn)</a></li>
  77. </ul>
  78. <ul class="simple nested-toc-section">dbError
  79. <li><a class="reference" href="#dbError%2CDbConn" title="dbError(db: DbConn)">dbError(db: DbConn)</a></li>
  80. </ul>
  81. <ul class="simple nested-toc-section">dbQuote
  82. <li><a class="reference" href="#dbQuote%2Cstring" title="dbQuote(s: string): string">dbQuote(s: string): string</a></li>
  83. </ul>
  84. <ul class="simple nested-toc-section">exec
  85. <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>
  86. </ul>
  87. <ul class="simple nested-toc-section">execAffectedRows
  88. <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>
  89. </ul>
  90. <ul class="simple nested-toc-section">getAllRows
  91. <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>
  92. </ul>
  93. <ul class="simple nested-toc-section">getRow
  94. <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>
  95. </ul>
  96. <ul class="simple nested-toc-section">getValue
  97. <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>
  98. </ul>
  99. <ul class="simple nested-toc-section">insert
  100. <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>
  101. </ul>
  102. <ul class="simple nested-toc-section">insertId
  103. <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>
  104. </ul>
  105. <ul class="simple nested-toc-section">len
  106. <li><a class="reference" href="#len%2CInstantRow" title="len(row: InstantRow): int">len(row: InstantRow): int</a></li>
  107. </ul>
  108. <ul class="simple nested-toc-section">open
  109. <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>
  110. </ul>
  111. <ul class="simple nested-toc-section">setEncoding
  112. <li><a class="reference" href="#setEncoding%2CDbConn%2Cstring" title="setEncoding(connection: DbConn; encoding: string): bool">setEncoding(connection: DbConn; encoding: string): bool</a></li>
  113. </ul>
  114. <ul class="simple nested-toc-section">tryExec
  115. <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>
  116. </ul>
  117. <ul class="simple nested-toc-section">tryInsert
  118. <li><a class="reference" href="#tryInsert%2CDbConn%2CSqlQuery%2Cstring%2Cvarargs%5Bstring%2C%5D" title="tryInsert(db: DbConn; query: SqlQuery; pkName: string;
  119. args: varargs[string, `$`]): int64">tryInsert(db: DbConn; query: SqlQuery; pkName: string;
  120. args: varargs[string, `$`]): int64</a></li>
  121. </ul>
  122. <ul class="simple nested-toc-section">tryInsertId
  123. <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>
  124. </ul>
  125. <ul class="simple nested-toc-section">unsafeColumnAt
  126. <li><a class="reference" href="#unsafeColumnAt%2CInstantRow%2Cint" title="unsafeColumnAt(row: InstantRow; index: int): cstring">unsafeColumnAt(row: InstantRow; index: int): cstring</a></li>
  127. </ul>
  128. </ul>
  129. </details>
  130. </li>
  131. <li>
  132. <details open>
  133. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  134. <ul class="simple simple-toc-section">
  135. <ul class="simple nested-toc-section">fastRows
  136. <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>
  137. </ul>
  138. <ul class="simple nested-toc-section">instantRows
  139. <li><a class="reference" href="#instantRows.i%2CDbConn%2CDbColumns%2CSqlQuery%2Cvarargs%5Bstring%2C%5D" title="instantRows(db: DbConn; columns: var DbColumns; query: SqlQuery;
  140. args: varargs[string, `$`]): InstantRow">instantRows(db: DbConn; columns: var DbColumns; query: SqlQuery;
  141. args: varargs[string, `$`]): InstantRow</a></li>
  142. <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>
  143. </ul>
  144. <ul class="simple nested-toc-section">rows
  145. <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>
  146. </ul>
  147. </ul>
  148. </details>
  149. </li>
  150. </ul>
  151. </div>
  152. <div class="nine columns" id="content">
  153. <div id="tocRoot"></div>
  154. <p class="module-desc"><div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  155. 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>
  156. <p>A higher level <span id="mysql_1">mySQL</span> database wrapper. The same interface is implemented for other databases too.</p>
  157. <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>
  158. <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>
  159. <p><pre class="listing"><span class="RawData">sql&quot;INSERT INTO myTable (colA, colB, colC) VALUES (?, ?, ?)&quot;</span></pre></p>
  160. <h1><a class="toc-backref" id="examples" href="#examples">Examples</a></h1>
  161. <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>
  162. <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">&quot;localhost&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;user&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;password&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;dbname&quot;</span><span class="Punctuation">)</span>
  163. <span class="Identifier">db</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  164. <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&quot;DROP TABLE IF EXISTS myTable&quot;</span><span class="Punctuation">)</span>
  165. <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">&quot;&quot;&quot;CREATE TABLE myTable (
  166. id integer,
  167. name varchar(50) not null)&quot;&quot;&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre></p>
  168. <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&quot;INSERT INTO myTable (id, name) VALUES (0, ?)&quot;</span><span class="Punctuation">,</span>
  169. <span class="StringLit">&quot;Dominik&quot;</span><span class="Punctuation">)</span></pre></p>
  170. <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>
  171. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">math</span>
  172. <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">&quot;localhost&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;nim&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;nim&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;test&quot;</span><span class="Punctuation">)</span>
  173. <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql&quot;Drop table if exists myTestTbl&quot;</span><span class="Punctuation">)</span>
  174. <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">&quot;create table myTestTbl (&quot;</span> <span class="Operator">&amp;</span>
  175. <span class="StringLit">&quot; Id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, &quot;</span> <span class="Operator">&amp;</span>
  176. <span class="StringLit">&quot; Name VARCHAR(50) NOT NULL, &quot;</span> <span class="Operator">&amp;</span>
  177. <span class="StringLit">&quot; i INT(11), &quot;</span> <span class="Operator">&amp;</span>
  178. <span class="StringLit">&quot; f DECIMAL(18,10))&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  179. <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql&quot;START TRANSACTION&quot;</span><span class="Punctuation">)</span>
  180. <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>
  181. <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql&quot;INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)&quot;</span><span class="Punctuation">,</span>
  182. <span class="StringLit">&quot;Item#&quot;</span> <span class="Operator">&amp;</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>
  183. <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">exec</span><span class="Punctuation">(</span><span class="RawData">sql&quot;COMMIT&quot;</span><span class="Punctuation">)</span>
  184. <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&quot;select * from myTestTbl&quot;</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  185. <span class="Identifier">echo</span> <span class="Identifier">x</span>
  186. <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&quot;INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)&quot;</span><span class="Punctuation">,</span>
  187. <span class="StringLit">&quot;Item#1001&quot;</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>
  188. <span class="Identifier">echo</span> <span class="StringLit">&quot;Inserted item: &quot;</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&quot;SELECT name FROM myTestTbl WHERE id=?&quot;</span><span class="Punctuation">,</span> <span class="Identifier">id</span><span class="Punctuation">)</span>
  189. <span class="Identifier">theDb</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  190. </p>
  191. <div class="section" id="6">
  192. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  193. <dl class="item">
  194. <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>
  195. </dl>
  196. </div>
  197. <div class="section" id="7">
  198. <h1><a class="toc-backref" href="#7">Types</a></h1>
  199. <dl class="item">
  200. <div id="DbConn">
  201. <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>
  202. <dd>
  203. encapsulates a database connection
  204. </dd>
  205. </div>
  206. <div id="InstantRow">
  207. <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>
  208. <dd>
  209. a handle that can be used to get a row's column text on demand
  210. </dd>
  211. </div>
  212. <div id="Row">
  213. <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>
  214. <dd>
  215. a row of a dataset. NULL database values will be converted to nil.
  216. </dd>
  217. </div>
  218. </dl>
  219. </div>
  220. <div class="section" id="12">
  221. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  222. <dl class="item">
  223. <div id="[]-procs-all">
  224. <div id="[],InstantRow,int">
  225. <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>
  226. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  227. <dd>
  228. Returns text for given column of the row.
  229. </dd>
  230. </div>
  231. </div>
  232. <div id="close-procs-all">
  233. <div id="close,DbConn">
  234. <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>
  235. <dd>
  236. closes the database connection.
  237. </dd>
  238. </div>
  239. </div>
  240. <div id="dbError-procs-all">
  241. <div id="dbError,DbConn">
  242. <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>
  243. <dd>
  244. raises a DbError exception.
  245. </dd>
  246. </div>
  247. </div>
  248. <div id="dbQuote-procs-all">
  249. <div id="dbQuote,string">
  250. <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>
  251. <dd>
  252. 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>.
  253. </dd>
  254. </div>
  255. </div>
  256. <div id="exec-procs-all">
  257. <div id="exec,DbConn,SqlQuery,varargs[string,]">
  258. <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> {.
  259. <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>
  260. <dd>
  261. executes the query and raises EDB if not successful.
  262. </dd>
  263. </div>
  264. </div>
  265. <div id="execAffectedRows-procs-all">
  266. <div id="execAffectedRows,DbConn,SqlQuery,varargs[string,]">
  267. <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> {.
  268. <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>
  269. <dd>
  270. runs the query (typically &quot;UPDATE&quot;) and returns the number of affected rows
  271. </dd>
  272. </div>
  273. </div>
  274. <div id="getAllRows-procs-all">
  275. <div id="getAllRows,DbConn,SqlQuery,varargs[string,]">
  276. <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>
  277. <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>
  278. <dd>
  279. executes the query and returns the whole result dataset.
  280. </dd>
  281. </div>
  282. </div>
  283. <div id="getRow-procs-all">
  284. <div id="getRow,DbConn,SqlQuery,varargs[string,]">
  285. <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> {.
  286. <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>
  287. <dd>
  288. Retrieves a single row. If the query doesn't return any rows, this proc will return a Row with empty strings for each column.
  289. </dd>
  290. </div>
  291. </div>
  292. <div id="getValue-procs-all">
  293. <div id="getValue,DbConn,SqlQuery,varargs[string,]">
  294. <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> {.
  295. <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>
  296. <dd>
  297. executes the query and returns the first column of the first row of the result dataset. Returns &quot;&quot; if the dataset contains no rows or the database value is NULL.
  298. </dd>
  299. </div>
  300. </div>
  301. <div id="insert-procs-all">
  302. <div id="insert,DbConn,SqlQuery,string,varargs[string,]">
  303. <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>
  304. <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>
  305. <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>
  306. <dd>
  307. same as insertId
  308. </dd>
  309. </div>
  310. </div>
  311. <div id="insertId-procs-all">
  312. <div id="insertId,DbConn,SqlQuery,varargs[string,]">
  313. <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> {.
  314. <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>
  315. <dd>
  316. executes the query (typically &quot;INSERT&quot;) and returns the generated ID for the row.
  317. </dd>
  318. </div>
  319. </div>
  320. <div id="len-procs-all">
  321. <div id="len,InstantRow">
  322. <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>
  323. <dd>
  324. Returns number of columns in the row.
  325. </dd>
  326. </div>
  327. </div>
  328. <div id="open-procs-all">
  329. <div id="open,string,string,string,string">
  330. <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> {.
  331. <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>
  332. <dd>
  333. 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.
  334. </dd>
  335. </div>
  336. </div>
  337. <div id="setEncoding-procs-all">
  338. <div id="setEncoding,DbConn,string">
  339. <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>
  340. <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>
  341. <dd>
  342. sets the encoding of a database connection, returns true for success, false for failure.
  343. </dd>
  344. </div>
  345. </div>
  346. <div id="tryExec-procs-all">
  347. <div id="tryExec,DbConn,SqlQuery,varargs[string,]">
  348. <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> {.
  349. <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>
  350. <dd>
  351. tries to execute the query and returns true if successful, false otherwise.
  352. </dd>
  353. </div>
  354. </div>
  355. <div id="tryInsert-procs-all">
  356. <div id="tryInsert,DbConn,SqlQuery,string,varargs[string,]">
  357. <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>
  358. <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>
  359. <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>
  360. <dd>
  361. same as tryInsertID
  362. </dd>
  363. </div>
  364. </div>
  365. <div id="tryInsertId-procs-all">
  366. <div id="tryInsertId,DbConn,SqlQuery,varargs[string,]">
  367. <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> {.
  368. <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>
  369. <dd>
  370. executes the query (typically &quot;INSERT&quot;) and returns the generated ID for the row or -1 in case of an error.
  371. </dd>
  372. </div>
  373. </div>
  374. <div id="unsafeColumnAt-procs-all">
  375. <div id="unsafeColumnAt,InstantRow,int">
  376. <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>
  377. <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>
  378. <dd>
  379. Return cstring of given column of the row
  380. </dd>
  381. </div>
  382. </div>
  383. </dl>
  384. </div>
  385. <div class="section" id="15">
  386. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  387. <dl class="item">
  388. <div id="fastRows-iterators-all">
  389. <div id="fastRows.i,DbConn,SqlQuery,varargs[string,]">
  390. <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> {.
  391. <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>
  392. <dd>
  393. <p>executes the query and iterates over the result dataset.</p>
  394. <p>This is very fast, but potentially dangerous. Use this iterator only if you require <strong>ALL</strong> the rows.</p>
  395. <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>
  396. </dd>
  397. </div>
  398. </div>
  399. <div id="instantRows-iterators-all">
  400. <div id="instantRows.i,DbConn,DbColumns,SqlQuery,varargs[string,]">
  401. <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>
  402. <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> {.
  403. <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>
  404. <dd>
  405. 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.
  406. </dd>
  407. </div>
  408. <div id="instantRows.i,DbConn,SqlQuery,varargs[string,]">
  409. <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> {.
  410. <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>
  411. <dd>
  412. 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.
  413. </dd>
  414. </div>
  415. </div>
  416. <div id="rows-iterators-all">
  417. <div id="rows.i,DbConn,SqlQuery,varargs[string,]">
  418. <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> {.
  419. <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>
  420. <dd>
  421. same as <tt class="docutils literal"><span class="pre"><span class="Identifier">fastRows</span></span></tt>, but slower and safe.
  422. </dd>
  423. </div>
  424. </div>
  425. </dl>
  426. </div>
  427. </div>
  428. </div>
  429. <div class="twelve-columns footer">
  430. <span class="nim-sprite"></span>
  431. <br>
  432. <small style="color: var(--hint);">Made with Nim. Generated: 2024-12-25 08:36:43 UTC</small>
  433. </div>
  434. </div>
  435. </div>
  436. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  437. </body>
  438. </html>