adjustments

main
Matthew Huntington 2 years ago
parent 9e3e587a02
commit 521b57147d

@ -113,13 +113,13 @@ Create a table (this could also be done in `psycopg2-binary` as well). Note the
```python ```python
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("CREATE TABLE people (name, age)") cursor.execute("CREATE TABLE people (id, name, age)")
``` ```
`INSERT` is very similar to `psycopg2-binary`, but you use `?` instead of `%s` `INSERT` is very similar to `psycopg2-binary`, but you use `?` instead of `%s`
```python ```python
cursor.execute("INSERT INTO people (name, age) VALUES (?, ?)", ['Zagthorp', 543]) cursor.execute("INSERT INTO people (id, name, age) VALUES (?, ?, ?)", [1, 'Zagthorp', 543])
connection.commit() connection.commit()
``` ```
@ -133,21 +133,21 @@ print(result.fetchall())
Selecting a single row works as expected Selecting a single row works as expected
```python ```python
result = cursor.execute("SELECT * FROM people WHERE name = ?", ['Matt']) result = cursor.execute("SELECT * FROM people WHERE id = ?", [1])
print(result.fetchone()) print(result.fetchone())
``` ```
So does `DELETE` So does `DELETE`
```python ```python
cursor.execute("DELETE FROM people WHERE name = ?", ['Bilbo']) cursor.execute("DELETE FROM people WHERE name = ?", [1])
connection.commit() connection.commit()
``` ```
and `UPDATE` and `UPDATE`
```python ```python
cursor.execute("UPDATE people SET name = ? WHERE name = ?", ['Bilbo', 'Matthew']) cursor.execute("UPDATE people SET name = ? WHERE id = ?", ['Bilbo', 2])
connection.commit() connection.commit()
``` ```

Loading…
Cancel
Save