本文整理汇总了Python中model.Session.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Session.execute方法的具体用法?Python Session.execute怎么用?Python Session.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Session
的用法示例。
在下文中一共展示了Session.execute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_provider
# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import execute [as 别名]
def add_provider(db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude):
# if db is enabled, then open a session with the database
if db_enabled:
session = Session()
# create an instance of the Provider type
provider = Provider(lastname=lastname, firstname=firstname,
credentials=credentials, addr1=addr1, addr2=addr2,
city=city, zipcode=zipcode,state=state,
latitude=latitude, longitude=longitude)
#To check if the record already exists in database
p = select([Provider.firstname]).where(Provider.firstname+Provider.lastname+Provider.credentials
+Provider.addr1+Provider.addr2 == firstname+lastname+credentials+addr1+addr2)
res = session.execute(p)
prov_data = res.fetchone()
session.close()
#To check if record exists, then this step will be skipped
if not(prov_data):
session = Session()
# To fetch the Geographical coordinates from Zip_geotable
z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode)
result = session.execute(z)
geo_data = result.fetchone()
if geo_data:
latitude = geo_data.latitude
longitude= geo_data.longitude
#print db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude
# create an instance of the Provider type
provider = Provider(lastname=lastname, firstname=firstname,
credentials=credentials, addr1=addr1, addr2=addr2,
city=city, zipcode=zipcode,state=state,
latitude=latitude, longitude=longitude)
# if db is enabled, then add to the recordset and commit the txn
session.add(provider)
session.commit()
session.close()
return provider
示例2: get_coordinates
# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import execute [as 别名]
def get_coordinates(zipcode , miles):
session = Session()
# To fetch the Geographical coordinates from Zip_geotable
z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode)
result = session.execute(z)
#print result
geo_data = result.fetchone()
#If zipcode exists in database
if geo_data:
latitude = geo_data.latitude
longitude= geo_data.longitude
patient_loc = geopy.Point(latitude,longitude )
#print latitude,longitude
find_distance(patient_loc, miles)
else:
print 'Zipcode not found. Please enter a valid zipcode'
session.close()
示例3: find_distance
# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import execute [as 别名]
def find_distance(patient_location, miles):
session = Session()
p = select([Provider.latitude, Provider.longitude])
result = session.execute(p)
doc_data = result.fetchall()
doc_count = 0
# Checks for each doctor's location in the database
for coordinates in doc_data:
doc_location = geopy.Point(coordinates.latitude,coordinates.longitude )
dist = geopy.distance.distance(patient_location, doc_location).miles
if dist < float(miles):
doc_count = doc_count + 1
if doc_count == 0:
print 'No doctors found near you in ' + str(miles)+ ' miles'
else:
print str(doc_count) + ' doctors found near you in ' + str(miles)+ ' miles'
示例4: deleteTable
# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import execute [as 别名]
def deleteTable():
session = Session()
session.execute("DELETE FROM zones_competent_authorities;")
session.execute("DELETE FROM zones_lau_codes;")
session.execute("DELETE FROM zone_predecessors;")
session.execute("DELETE FROM zone_pollutants;")
session.execute("DELETE FROM zone_legal_acts;")
session.execute("DELETE FROM zone_time_extension_types;")
session.execute("DELETE FROM authorities;")
session.execute("DELETE FROM legal_acts;")
session.execute("DELETE FROM zones;")
session.execute("DELETE FROM authorities;")
session.commit()