|
|
@ -1567,6 +1567,12 @@ db.close() |
|
|
|
<ul> |
|
|
|
<li><strong>New database will be created if path doesn't exist.</strong></li> |
|
|
|
</ul> |
|
|
|
<div><h3 id="create">Create</h3><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span>db.execute(<span class="hljs-string">'create table t (a, b, c)'</span>) |
|
|
|
<span class="hljs-meta">>>> </span>db.execute(<span class="hljs-string">'insert into t values (1, 2, 3)'</span>) |
|
|
|
<span class="hljs-meta">>>> </span>db.execute(<span class="hljs-string">'select * from t'</span>).fetchall() |
|
|
|
[(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)] |
|
|
|
</code></pre></div> |
|
|
|
|
|
|
|
<div><h3 id="read">Read</h3><pre><code class="python language-python hljs">cursor = db.execute(<span class="hljs-string">'<query>'</span>) |
|
|
|
<span class="hljs-keyword">if</span> cursor: |
|
|
|
<tuple> = cursor.fetchone() <span class="hljs-comment"># First row.</span> |
|
|
|