Browse Source

SQLite

pull/36/head
Jure Šorn 5 years ago
parent
commit
874ae3ec4d
2 changed files with 20 additions and 2 deletions
  1. 10
      README.md
  2. 12
      index.html

10
README.md

@ -1504,7 +1504,7 @@ SQLite
------
```python
import sqlite3
db = sqlite3.connect('<path>')
db = sqlite3.connect('<path>') # Also ':memory:'.
...
db.close()
```
@ -1516,6 +1516,7 @@ if cursor:
<tuple> = cursor.fetchone() # First row.
<list> = cursor.fetchall() # Remaining rows.
```
* **Returned values can be of type str, int, float or bytes.**
### Write
```python
@ -1523,6 +1524,13 @@ db.execute('<query>')
db.commit()
```
### Placeholders
```python
db.execute('<query>', <list/tuple>) # Replaces '?' in query with value.
db.execute('<query>', <dict/namedtuple>) # Replaces ':<key>' with value.
```
* **Passed values can be of type str, int, float, bytes, bool, datetime.date and datetime.datetme.**
Bytes
-----

12
index.html

@ -1324,7 +1324,7 @@ value = args.&lt;name&gt;
</code></pre>
<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
db = sqlite3.connect(<span class="hljs-string">'&lt;path&gt;'</span>)
db = sqlite3.connect(<span class="hljs-string">'&lt;path&gt;'</span>) <span class="hljs-comment"># Also ':memory:'.</span>
...
db.close()
</code></pre>
@ -1334,10 +1334,20 @@ db.close()
&lt;tuple&gt; = cursor.fetchone() <span class="hljs-comment"># First row.</span>
&lt;list&gt; = cursor.fetchall() <span class="hljs-comment"># Remaining rows.</span>
</code></pre>
<ul>
<li><strong>Returned values can be of type str, int, float or bytes.</strong></li>
</ul>
<h3 id="write">Write</h3>
<pre><code class="python language-python hljs">db.execute(<span class="hljs-string">'&lt;query&gt;'</span>)
db.commit()
</code></pre>
<h3 id="placeholders">Placeholders</h3>
<pre><code class="python language-python hljs">db.execute(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;list/tuple&gt;) <span class="hljs-comment"># Replaces '?' in query with value.</span>
db.execute(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;dict/namedtuple&gt;) <span class="hljs-comment"># Replaces ':&lt;key&gt;' 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>
<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">&lt;bytes&gt; = <span class="hljs-string">b'&lt;str&gt;'</span> <span class="hljs-comment"># Only accepts ASCII characters and \x00 - \xff.</span>

Loading…
Cancel
Save