Database Reference
In-Depth Information
"""
curws = conn.cursor()
curws.execute('SELECT * FROM
chp08.wstations WHERE id=%s',
(station_id,))
count = curws.rowcount
if count==0: # we need to add the
weather station
curws.execute(
"""INSERT INTO
chp08.wstations (id, the_geom, name,
temperature)
VALUES (%s,
ST_GeomFromText('POINT(%s %s)', 4326),
%s, %s)""",
(station_id, lon, lat, name,
temperature)
)
curws.close()
print 'Added the %s weather
station to the database.' % name
return True
else: # weather station already in
database
print 'The %s weather station is
already in the database.' % name
return False
# program starts here
# get a connection to the database
conn =
psycopg2.connect('dbname=postgis_cookbook
user=me password=mypassword')
# we do not need transaction here, so set
the connection to autocommit mode
conn.set_isolation_level(0)
# open a cursor to update the table with
Search WWH ::




Custom Search