mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 02:13:44 +03:00
A bunch of typos fixed in the examples by Josh Kupershmidt
This commit is contained in:
parent
c3914b8aa2
commit
b721421633
2
README
2
README
|
@ -8,7 +8,7 @@ and stable as a rock.
|
|||
psycopg2 is different from the other database adapter because it was
|
||||
designed for heavily multi-threaded applications that create and destroy
|
||||
lots of cursors and make a conspicuous number of concurrent INSERTs or
|
||||
UPDATEs. psycopg2 also provide full asycronous operations and support
|
||||
UPDATEs. psycopg2 also provides full asynchronous operations and support
|
||||
for coroutine libraries.
|
||||
|
||||
psycopg2 can compile and run on Linux, FreeBSD, Solaris, MacOS X and
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import psycopg2
|
||||
|
@ -79,7 +79,7 @@ for row in curs.fetchall():
|
|||
print "done"
|
||||
print " python type of image data is", type(row[0])
|
||||
|
||||
# this rollback is requires because we can't drop a table with a binary cusor
|
||||
# this rollback is required because we can't drop a table with a binary cusor
|
||||
# declared and still open
|
||||
conn.rollback()
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
@ -165,7 +165,7 @@ try:
|
|||
curs.copy_from(data, 'test_copy')
|
||||
except StandardError, err:
|
||||
conn.rollback()
|
||||
print " Catched error (as expected):\n", err
|
||||
print " Caught error (as expected):\n", err
|
||||
|
||||
conn.rollback()
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
|
|
@ -58,6 +58,6 @@ print "Result of fetchone():", curs.fetchone()
|
|||
try:
|
||||
curs.fetchone()
|
||||
except NoDataError, err:
|
||||
print "Exception caugth:", err
|
||||
print "Exception caught:", err
|
||||
|
||||
conn.rollback()
|
||||
|
|
|
@ -104,10 +104,10 @@ print adapt(Order()).generateInsert()
|
|||
- Discussion
|
||||
|
||||
Psycopg 2 has a great new feature: adaptation. The big thing about
|
||||
adaptation is that it enable the programmer to glue most of the
|
||||
adaptation is that it enables the programmer to glue most of the
|
||||
code out there without many difficulties.
|
||||
|
||||
This recipe tries to focus the attention on a way to generate SQL queries to
|
||||
This recipe tries to focus attention on a way to generate SQL queries to
|
||||
insert completely new objects inside a database. As you can see objects do
|
||||
not know anything about the code that is handling them. We specify all the
|
||||
fields that we need for each object through the persistent_fields dict.
|
||||
|
@ -116,7 +116,7 @@ The most important lines of this recipe are:
|
|||
register_adapter(Album, ObjectMapper)
|
||||
register_adapter(Order, ObjectMapper)
|
||||
|
||||
In these line we notify the system that when we call adapt with an Album instance
|
||||
In these lines we notify the system that when we call adapt with an Album instance
|
||||
as an argument we want it to istantiate ObjectMapper passing the Album instance
|
||||
as argument (self.orig in the ObjectMapper class).
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import psycopg2
|
||||
|
@ -73,7 +73,7 @@ print "Extracting values inserted with mx.DateTime wrappers:"
|
|||
curs.execute("SELECT d, t, dt, z FROM test_dt WHERE k = 1")
|
||||
for n, x in zip(mx1[1:], curs.fetchone()):
|
||||
try:
|
||||
# this will work only is psycopg has been compiled with datetime
|
||||
# this will work only if psycopg has been compiled with datetime
|
||||
# as the default typecaster for date/time values
|
||||
s = repr(n) + "\n -> " + str(adapt(n)) + \
|
||||
"\n -> " + repr(x) + "\n -> " + x.isoformat()
|
||||
|
@ -87,7 +87,7 @@ print "Extracting values inserted with Python datetime wrappers:"
|
|||
curs.execute("SELECT d, t, dt, z FROM test_dt WHERE k = 2")
|
||||
for n, x in zip(dt1[1:], curs.fetchone()):
|
||||
try:
|
||||
# this will work only is psycopg has been compiled with datetime
|
||||
# this will work only if psycopg has been compiled with datetime
|
||||
# as the default typecaster for date/time values
|
||||
s = repr(n) + "\n -> " + repr(x) + "\n -> " + x.isoformat()
|
||||
except:
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import psycopg2
|
||||
|
@ -52,7 +52,7 @@ conn.commit()
|
|||
# does some nice tricks with the transaction and postgres cursors
|
||||
# (remember to always commit or rollback before a DECLARE)
|
||||
#
|
||||
# we don't need to DECLARE ourselves, psycopg now support named
|
||||
# we don't need to DECLARE ourselves, psycopg now supports named
|
||||
# cursors (but we leave the code here, comments, as an example of
|
||||
# what psycopg is doing under the hood)
|
||||
#
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys, psycopg2
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import select
|
||||
|
|
|
@ -29,12 +29,12 @@ SELECT_STEP = 500
|
|||
SELECT_DIV = 250
|
||||
|
||||
# the available modes are:
|
||||
# 0 - one connection for all insert and one for all select threads
|
||||
# 0 - one connection for all inserts and one for all select threads
|
||||
# 1 - connections generated using the connection pool
|
||||
|
||||
MODE = 1
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys, psycopg2, threading
|
||||
from psycopg2.pool import ThreadedConnectionPool
|
||||
|
@ -90,7 +90,7 @@ def insert_func(conn_or_pool, rows):
|
|||
conn.commit()
|
||||
|
||||
## a nice select function that prints the current number of rows in the
|
||||
## database (and transefer them, putting some pressure on the network)
|
||||
## database (and transfer them, putting some pressure on the network)
|
||||
|
||||
def select_func(conn_or_pool, z):
|
||||
name = threading.currentThread().getName()
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
## don't modify anything below this line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import psycopg2
|
||||
|
|
Loading…
Reference in New Issue
Block a user