Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9ffc10

Browse files
committed
SQLite
1 parent 23b7fd7 commit c9ffc10

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,16 +1868,13 @@ SQLite
18681868
------
18691869
**A server-less database engine that stores each database into a separate file.**
18701870

1871-
### Connect
1872-
**Opens a connection to the database file. Creates a new file if path doesn't exist.**
18731871
```python
18741872
import sqlite3
1875-
<conn> = sqlite3.connect(<path>) # Also ':memory:'.
1873+
<conn> = sqlite3.connect(<path>) # Opens existing or new file. Also ':memory:'.
18761874
<conn>.close() # Closes the connection.
18771875
```
18781876

18791877
### Read
1880-
**Returned values can be of type str, int, float, bytes or None.**
18811878
```python
18821879
<cursor> = <conn>.execute('<query>') # Can raise a subclass of sqlite3.Error.
18831880
<tuple> = <cursor>.fetchone() # Returns next row. Also next(<cursor>).
@@ -1898,13 +1895,13 @@ with <conn>: # Exits the block with commit()
18981895
```
18991896

19001897
### Placeholders
1901-
* **Passed values can be of type str, int, float, bytes, None, bool, datetime.date or datetime.datetime.**
1902-
* **Bools will be stored and returned as ints and dates as [ISO formatted strings](#encode).**
19031898
```python
19041899
<conn>.execute('<query>', <list/tuple>) # Replaces '?'s in query with values.
19051900
<conn>.execute('<query>', <dict/namedtuple>) # Replaces ':<key>'s with values.
19061901
<conn>.executemany('<query>', <coll_of_above>) # Runs execute() multiple times.
19071902
```
1903+
* **Passed values can be of type str, int, float, bytes, None, bool, datetime.date or datetime.datetime.**
1904+
* **Bools will be stored and returned as ints and dates as [ISO formatted strings](#encode).**
19081905

19091906
### Example
19101907
**Values are not actually saved in this example because `'conn.commit()'` is omitted!**

index.html

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<body>
5656
<header>
57-
<aside>September 16, 2022</aside>
57+
<aside>September 19, 2022</aside>
5858
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
5959
</header>
6060

@@ -1557,20 +1557,17 @@
15571557
writer.writerows(rows)
15581558
</code></pre></div>
15591559

1560-
<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>A server-less database engine that stores each database into a separate file.</strong></p><div><h3 id="connect">Connect</h3><p><strong>Opens a connection to the database file. Creates a new file if path doesn't exist.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3
1561-
&lt;conn&gt; = sqlite3.connect(&lt;path&gt;) <span class="hljs-comment"># Also ':memory:'.</span>
1560+
<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>A server-less database engine that stores each database into a separate file.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3
1561+
&lt;conn&gt; = sqlite3.connect(&lt;path&gt;) <span class="hljs-comment"># Opens existing or new file. Also ':memory:'.</span>
15621562
&lt;conn&gt;.close() <span class="hljs-comment"># Closes the connection.</span>
1563-
</code></pre></div></div>
1564-
1565-
1563+
</code></pre></div>
15661564

15671565

1568-
<div><h3 id="read-1">Read</h3><p><strong>Returned values can be of type str, int, float, bytes or None.</strong></p><pre><code class="python language-python hljs">&lt;cursor&gt; = &lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Can raise a subclass of sqlite3.Error.</span>
1566+
<div><h3 id="read-1">Read</h3><pre><code class="python language-python hljs">&lt;cursor&gt; = &lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Can raise a subclass of sqlite3.Error.</span>
15691567
&lt;tuple&gt; = &lt;cursor&gt;.fetchone() <span class="hljs-comment"># Returns next row. Also next(&lt;cursor&gt;).</span>
15701568
&lt;list&gt; = &lt;cursor&gt;.fetchall() <span class="hljs-comment"># Returns remaining rows. Also list(&lt;cursor&gt;).</span>
15711569
</code></pre></div>
15721570

1573-
15741571
<div><h3 id="write-1">Write</h3><pre><code class="python language-python hljs">&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Can raise a subclass of sqlite3.Error.</span>
15751572
&lt;conn&gt;.commit() <span class="hljs-comment"># Saves all changes since the last commit.</span>
15761573
&lt;conn&gt;.rollback() <span class="hljs-comment"># Discards all changes since the last commit.</span>
@@ -1580,15 +1577,15 @@
15801577
&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># depending on whether any exception occurred.</span>
15811578
</code></pre></div>
15821579

1583-
<div><h3 id="placeholders">Placeholders</h3><ul>
1584-
<li><strong>Passed values can be of type str, int, float, bytes, None, bool, datetime.date or datetime.datetime.</strong></li>
1585-
<li><strong>Bools will be stored and returned as ints and dates as <a href="#encode">ISO formatted strings</a>.</strong></li>
1586-
</ul><pre><code class="python language-python hljs">&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;list/tuple&gt;) <span class="hljs-comment"># Replaces '?'s in query with values.</span>
1580+
<div><h3 id="placeholders">Placeholders</h3><pre><code class="python language-python hljs">&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;list/tuple&gt;) <span class="hljs-comment"># Replaces '?'s in query with values.</span>
15871581
&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;dict/namedtuple&gt;) <span class="hljs-comment"># Replaces ':&lt;key&gt;'s with values.</span>
15881582
&lt;conn&gt;.executemany(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;coll_of_above&gt;) <span class="hljs-comment"># Runs execute() multiple times.</span>
15891583
</code></pre></div>
15901584

1591-
1585+
<ul>
1586+
<li><strong>Passed values can be of type str, int, float, bytes, None, bool, datetime.date or datetime.datetime.</strong></li>
1587+
<li><strong>Bools will be stored and returned as ints and dates as <a href="#encode">ISO formatted strings</a>.</strong></li>
1588+
</ul>
15921589
<div><h3 id="example">Example</h3><p><strong>Values are not actually saved in this example because <code class="python hljs"><span class="hljs-string">'conn.commit()'</span></code> is omitted!</strong></p><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>conn = sqlite3.connect(<span class="hljs-string">'test.db'</span>)
15931590
<span class="hljs-meta">&gt;&gt;&gt; </span>conn.execute(<span class="hljs-string">'CREATE TABLE person (person_id INTEGER PRIMARY KEY, name, height)'</span>)
15941591
<span class="hljs-meta">&gt;&gt;&gt; </span>conn.execute(<span class="hljs-string">'INSERT INTO person VALUES (NULL, ?, ?)'</span>, (<span class="hljs-string">'Jean-Luc'</span>, <span class="hljs-number">187</span>)).lastrowid
@@ -2906,7 +2903,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29062903

29072904

29082905
<footer>
2909-
<aside>September 16, 2022</aside>
2906+
<aside>September 19, 2022</aside>
29102907
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29112908
</footer>
29122909

0 commit comments

Comments
 (0)