Skip to content

Commit 874ae3e

Browse files
committed
SQLite
1 parent 53012f9 commit 874ae3e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ SQLite
15041504
------
15051505
```python
15061506
import sqlite3
1507-
db = sqlite3.connect('<path>')
1507+
db = sqlite3.connect('<path>') # Also ':memory:'.
15081508
...
15091509
db.close()
15101510
```
@@ -1516,13 +1516,21 @@ if cursor:
15161516
<tuple> = cursor.fetchone() # First row.
15171517
<list> = cursor.fetchall() # Remaining rows.
15181518
```
1519+
* **Returned values can be of type str, int, float or bytes.**
15191520

15201521
### Write
15211522
```python
15221523
db.execute('<query>')
15231524
db.commit()
15241525
```
15251526

1527+
### Placeholders
1528+
```python
1529+
db.execute('<query>', <list/tuple>) # Replaces '?' in query with value.
1530+
db.execute('<query>', <dict/namedtuple>) # Replaces ':<key>' with value.
1531+
```
1532+
* **Passed values can be of type str, int, float, bytes, bool, datetime.date and datetime.datetme.**
1533+
15261534

15271535
Bytes
15281536
-----

index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ <h3 id="writeobjecttofile">Write Object to File</h3>
13241324
</code></pre>
13251325
<h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2>
13261326
<pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3
1327-
db = sqlite3.connect(<span class="hljs-string">'&lt;path&gt;'</span>)
1327+
db = sqlite3.connect(<span class="hljs-string">'&lt;path&gt;'</span>) <span class="hljs-comment"># Also ':memory:'.</span>
13281328
...
13291329
db.close()
13301330
</code></pre>
@@ -1334,10 +1334,20 @@ <h3 id="read">Read</h3>
13341334
&lt;tuple&gt; = cursor.fetchone() <span class="hljs-comment"># First row.</span>
13351335
&lt;list&gt; = cursor.fetchall() <span class="hljs-comment"># Remaining rows.</span>
13361336
</code></pre>
1337+
<ul>
1338+
<li><strong>Returned values can be of type str, int, float or bytes.</strong></li>
1339+
</ul>
13371340
<h3 id="write">Write</h3>
13381341
<pre><code class="python language-python hljs">db.execute(<span class="hljs-string">'&lt;query&gt;'</span>)
13391342
db.commit()
13401343
</code></pre>
1344+
<h3 id="placeholders">Placeholders</h3>
1345+
<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>
1346+
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>
1347+
</code></pre>
1348+
<ul>
1349+
<li><strong>Passed values can be of type str, int, float, bytes, bool, datetime.date and datetime.datetme.</strong></li>
1350+
</ul>
13411351
<h2 id="bytes"><a href="#bytes" name="bytes">#</a>Bytes</h2>
13421352
<p><strong>Bytes object is an immutable sequence of single bytes. Mutable version is called 'bytearray'.</strong></p>
13431353
<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>

0 commit comments

Comments
 (0)