|
@ -1324,7 +1324,7 @@ value = args.<name> |
|
|
</code></pre> |
|
|
</code></pre> |
|
|
<h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2> |
|
|
<h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2> |
|
|
<pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3 |
|
|
<pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3 |
|
|
db = sqlite3.connect(<span class="hljs-string">'<path>'</span>) |
|
|
|
|
|
|
|
|
db = sqlite3.connect(<span class="hljs-string">'<path>'</span>) <span class="hljs-comment"># Also ':memory:'.</span> |
|
|
... |
|
|
... |
|
|
db.close() |
|
|
db.close() |
|
|
</code></pre> |
|
|
</code></pre> |
|
@ -1334,10 +1334,20 @@ db.close() |
|
|
<tuple> = cursor.fetchone() <span class="hljs-comment"># First row.</span> |
|
|
<tuple> = cursor.fetchone() <span class="hljs-comment"># First row.</span> |
|
|
<list> = cursor.fetchall() <span class="hljs-comment"># Remaining rows.</span> |
|
|
<list> = cursor.fetchall() <span class="hljs-comment"># Remaining rows.</span> |
|
|
</code></pre> |
|
|
</code></pre> |
|
|
|
|
|
<ul> |
|
|
|
|
|
<li><strong>Returned values can be of type str, int, float or bytes.</strong></li> |
|
|
|
|
|
</ul> |
|
|
<h3 id="write">Write</h3> |
|
|
<h3 id="write">Write</h3> |
|
|
<pre><code class="python language-python hljs">db.execute(<span class="hljs-string">'<query>'</span>) |
|
|
<pre><code class="python language-python hljs">db.execute(<span class="hljs-string">'<query>'</span>) |
|
|
db.commit() |
|
|
db.commit() |
|
|
</code></pre> |
|
|
</code></pre> |
|
|
|
|
|
<h3 id="placeholders">Placeholders</h3> |
|
|
|
|
|
<pre><code class="python language-python hljs">db.execute(<span class="hljs-string">'<query>'</span>, <list/tuple>) <span class="hljs-comment"># Replaces '?' in query with value.</span> |
|
|
|
|
|
db.execute(<span class="hljs-string">'<query>'</span>, <dict/namedtuple>) <span class="hljs-comment"># Replaces ':<key>' with value.</span> |
|
|
|
|
|
</code></pre> |
|
|
|
|
|
<ul> |
|
|
|
|
|
<li><strong>Passed values can be of type str, int, float, bytes, bool, datetime.date and datetime.datetme.</strong></li> |
|
|
|
|
|
</ul> |
|
|
<h2 id="bytes"><a href="#bytes" name="bytes">#</a>Bytes</h2> |
|
|
<h2 id="bytes"><a href="#bytes" name="bytes">#</a>Bytes</h2> |
|
|
<p><strong>Bytes object is an immutable sequence of single bytes. Mutable version is called 'bytearray'.</strong></p> |
|
|
<p><strong>Bytes object is an immutable sequence of single bytes. Mutable version is called 'bytearray'.</strong></p> |
|
|
<pre><code class="python language-python hljs"><bytes> = <span class="hljs-string">b'<str>'</span> <span class="hljs-comment"># Only accepts ASCII characters and \x00 - \xff.</span> |
|
|
<pre><code class="python language-python hljs"><bytes> = <span class="hljs-string">b'<str>'</span> <span class="hljs-comment"># Only accepts ASCII characters and \x00 - \xff.</span> |
|
|