From 874ae3ec4dc9f0c6a482b1e6245dec48ff529c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 2 Jul 2019 17:36:44 +0200 Subject: [PATCH] SQLite --- README.md | 10 +++++++++- index.html | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d1befb1..25e5d52 100644 --- a/README.md +++ b/README.md @@ -1504,7 +1504,7 @@ SQLite ------ ```python import sqlite3 -db = sqlite3.connect('') +db = sqlite3.connect('') # Also ':memory:'. ... db.close() ``` @@ -1516,6 +1516,7 @@ if cursor: = cursor.fetchone() # First row. = cursor.fetchall() # Remaining rows. ``` +* **Returned values can be of type str, int, float or bytes.** ### Write ```python @@ -1523,6 +1524,13 @@ db.execute('') db.commit() ``` +### Placeholders +```python +db.execute('', ) # Replaces '?' in query with value. +db.execute('', ) # Replaces ':' with value. +``` +* **Passed values can be of type str, int, float, bytes, bool, datetime.date and datetime.datetme.** + Bytes ----- diff --git a/index.html b/index.html index d793f81..5fa14ef 100644 --- a/index.html +++ b/index.html @@ -1324,7 +1324,7 @@ value = args.<name>

#SQLite

import sqlite3
-db = sqlite3.connect('<path>')
+db = sqlite3.connect('<path>')   # Also ':memory:'.
 ...
 db.close()
 
@@ -1334,10 +1334,20 @@ db.close() <tuple> = cursor.fetchone() # First row. <list> = cursor.fetchall() # Remaining rows. +
    +
  • Returned values can be of type str, int, float or bytes.
  • +

Write

db.execute('<query>')
 db.commit()
 
+

Placeholders

+
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

Bytes object is an immutable sequence of single bytes. Mutable version is called 'bytearray'.

<bytes> = b'<str>'                       # Only accepts ASCII characters and \x00 - \xff.