MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Doc/includes/dbpickle.py:49–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47
48
49def main():
50 import io
51 import pprint
52
53 # Initialize and populate our database.
54 conn = sqlite3.connect(":memory:")
55 cursor = conn.cursor()
56 cursor.execute("CREATE TABLE memos(key INTEGER PRIMARY KEY, task TEXT)")
57 tasks = (
58 'give food to fish',
59 'prepare group meeting',
60 'fight with a zebra',
61 )
62 for task in tasks:
63 cursor.execute("INSERT INTO memos VALUES(NULL, ?)", (task,))
64
65 # Fetch the records to be pickled.
66 cursor.execute("SELECT * FROM memos")
67 memos = [MemoRecord(key, task) for key, task in cursor]
68 # Save the records using our custom DBPickler.
69 file = io.BytesIO()
70 DBPickler(file).dump(memos)
71
72 print("Pickled records:")
73 pprint.pprint(memos)
74
75 # Update a record, just for good measure.
76 cursor.execute("UPDATE memos SET task='learn italian' WHERE key=1")
77
78 # Load the records from the pickle data stream.
79 file.seek(0)
80 memos = DBUnpickler(file, conn).load()
81
82 print("Unpickled records:")
83 pprint.pprint(memos)
84
85
86if __name__ == '__main__':

Callers 1

dbpickle.pyFile · 0.70

Calls 8

seekMethod · 0.95
DBPicklerClass · 0.85
DBUnpicklerClass · 0.85
connectMethod · 0.45
executeMethod · 0.45
dumpMethod · 0.45
pprintMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…