|
29 | 29 | cur.execute(statement) |
30 | 30 |
|
31 | 31 | # Insert default rows |
32 | | -rows = [(1, 'Bob', 35, 'I like dogs'), |
33 | | - (2, 'Kim', 27, 'I like birds'), |
34 | | - (3, 'Cheryl', 23, 'I like horses'), |
35 | | - (4, 'Bob', 27, 'I like rabbits'), |
36 | | - (5, 'Stacey', 45, 'I like snakes'), |
37 | | - (6, 'Pete', 23, 'I like cats'), |
38 | | - (7, 'Pat', 36, 'I like dogs')] |
| 32 | +rows = [{'id':1, 'name':'Bob', 'age':35, 'notes':'I like dogs'}, |
| 33 | + {'id':2, 'name':'Kim', 'age':27, 'notes':'I like birds'}, |
| 34 | + {'id':3, 'name':'Cheryl', 'age':23, 'notes':'I like horses'}, |
| 35 | + {'id':4, 'name':'Bob', 'age':27, 'notes':'I like rabbits'}, |
| 36 | + {'id':5, 'name':'Stacey', 'age':45, 'notes':'I like snakes'}, |
| 37 | + {'id':6, 'name':'Pete', 'age':23, 'notes':'I like cats'}, |
| 38 | + {'id':7, 'name':'Pat', 'age':36, 'notes':'I like dogs'}] |
39 | 39 | cur.bindarraysize = 2 |
40 | | -cur.setinputsizes(int, 20, int, 100) |
41 | | -cur.executemany("insert into lcs_people(id, name, age, notes) values (:1, :2, :3, :4)", rows) |
| 40 | +cur.executemany("insert into lcs_people(id, name, age, notes) values (:id, :name, :age, :notes)", rows) |
42 | 41 | con.commit() |
43 | 42 |
|
44 | 43 | # Insert default rows |
45 | | -rows = [(1, 'Duke', 1, 'dog'), |
46 | | - (2, 'Dragon', 2, 'bird'), |
47 | | - (3, 'Sneaky', 5, 'snake'), |
48 | | - (4, 'Red', 2, 'bird'), |
49 | | - (5, 'Red', 3, 'horse'), |
50 | | - (6, 'Buster', 1, 'dog'), |
51 | | - (7, 'Fido', 7, 'cat')] |
| 44 | +rows = [{'id':1, 'name':'Duke', 'owner':1, 'type':'dog'}, |
| 45 | + {'id':2, 'name':'Dragon', 'owner':2, 'type':'bird'}, |
| 46 | + {'id':3, 'name':'Sneaky', 'owner':5, 'type':'snake'}, |
| 47 | + {'id':4, 'name':'Red', 'owner':2, 'type':'bird'}, |
| 48 | + {'id':5, 'name':'Red', 'owner':3, 'type':'horse'}, |
| 49 | + {'id':6, 'name':'Buster', 'owner':1, 'type':'dog'}, |
| 50 | + {'id':7, 'name':'Fido', 'owner':7, 'type':'cat'}] |
52 | 51 | cur.bindarraysize = 2 |
53 | | -cur.setinputsizes(int, 20, int, 100) |
54 | | -cur.executemany("insert into lcs_pets (id, name, owner, type) values (:1, :2, :3, :4)", rows) |
| 52 | +cur.executemany("insert into lcs_pets (id, name, owner, type) values (:id, :name, :owner, :type)", rows) |
55 | 53 | con.commit() |
56 | 54 |
|
57 | 55 | cur.close() |
0 commit comments