[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
objects effectively serve the roles of both database records and database-processing programs. We can also use the underlying pi ...
Notice that calling Bob’s tax method works even though we didn’t import the Person class in this last session. Python is smart e ...
self.job = job self.pay = pay # real instance data def getattr(self, attr): # on person.attr if attr == 'tax': return self.pay * ...
keys must further be str strings in Python 3.X, not bytes, because the shelve will at- tempt to encode them in all cases. Object ...
Underlying DBM format portability With shelves, the files created by an underlying DBM system used to store your per- sistent ob ...
from that module using the original class name. If the module or class has been moved or renamed, it might not be found. In appl ...
persistence support, but it offers additional features for advanced data stores. For more on ZODB, let’s move on to the next sec ...
Transaction commit and rollback If your program crashes, your changes are not retained unless you explicitly commit them to the ...
To give you a brief sample of ZODB’s flavor, though, here’s a quick spin through its operation in Python 2.X. Once we’ve install ...
none of the partially complete work it has done is retained. In fact, ZODB supports general database undo operations. Pulling pe ...
to force the change to be written to disk (built-in list and dictionary objects do not know that they are persistent). Because Z ...
For some applications, the end result can be a potent combination. Moreover, some SQL-based database systems provide industrial- ...
Cursor objects Represent an SQL statement submitted as a string and can be used to access and step through SQL statement results ...
After running an SQL statement, the cursor’s rowcount attribute gives the number of rows changed (for DML changes) or fetched (f ...
Thanks to Python’s portable database API, though, other popular database packages such as PostgreSQL, MySQL, and Oracle are used ...
As long as a script sticks to using standard SQL code, the connect call’s arguments are usually the only thing that can vary acr ...
provided in SQLite; in other words, don’t depend on it if you want your database scripts to work on other database systems. Para ...
Running queries OK, we’ve now added six records to our database table. Let’s run an SQL query to see how we did: >>> cu ...
>>> curs.execute('select * from people') >>> names = [rec[0] for rec in curs.fetchall()] >>> names [' ...
>>> curs.fetchall() [] Naturally, we can do more than fetch an entire table; the full power of the SQL language is at y ...
«
64
65
66
67
68
69
70
71
72
73
»
Free download pdf