本文整理汇总了Python中model.database.Database.execUpdateQuery方法的典型用法代码示例。如果您正苦于以下问题:Python Database.execUpdateQuery方法的具体用法?Python Database.execUpdateQuery怎么用?Python Database.execUpdateQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.database.Database
的用法示例。
在下文中一共展示了Database.execUpdateQuery方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
class GlobalHouseholdCharacteristicsManager:
def __init__(self):
self.database = Database()
def getGlobalHouseholdCharacteristic(self, charid=0, charname=""):
char = GlobalHouseholdCharacteristic(charid, charname)
return char
def addGlobalHouseholdCharacteristic(self, charname, datatype):
char = GlobalHouseholdCharacteristic(0, charname, datatype)
return char
def editGlobalHouseholdCharacteristic(self, charid, charname, datatype):
char = GlobalHouseholdCharacteristic(charid)
char.setData(charname, datatype)
def delGlobalHouseholdCharacteristic(self, charid="", charname=""):
query = "DELETE FROM globalhouseholdcharacteristics WHERE id=%i OR characteristic='%s' " % (charid, charname)
self.database.open()
self.database.execUpdateQuery(query)
self.database.close()
def getGlobalHouseholdCharacteristics(self):
query = "SELECT id FROM globalhouseholdcharacteristics"
self.database.open()
rows = self.database.execSelectQuery(query)
self.database.close()
chars = []
for row in rows:
charid = row[0]
char = GlobalHouseholdCharacteristic(charid)
chars.append(char)
return chars
示例2: logIhmTransfer
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def logIhmTransfer(self, pid, pid_access, projectname, startdate, currency ):
query = '''INSERT INTO transferlog(pid,pid_access,projectname,datecollected,currency)
VALUES(%s,%s,'%s','%s','%s')''' % (pid, pid_access, projectname, startdate, currency)
database = Database()
database.open()
database.execUpdateQuery( query )
database.close()
示例3: test_execDefinitionQuery
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def test_execDefinitionQuery(self):
self.helper.setup_clean_db()
database = Database()
database.open()
database.execDefinitionQuery('create table simples (test int)')
database.close()
# and just to prove it's there to put something into.
database.open()
database.execUpdateQuery('insert into simples values (3)')
database.close()
示例4: test_execUpdateQuery
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def test_execUpdateQuery(self):
self.helper.setup_clean_db()
database = Database()
database.open()
database.execUpdateQuery("""
insert into projects
(projectname, startdate, enddate, description, currency)
values
('test', '2012-06-04', '2013-07-03', 'a simple test', 'GBP')""")
query = 'select * from projects'
self.assertEqual([(2, u'test', datetime.date(2012, 6, 4),
datetime.date(2013, 7, 3), u'a simple test', u'GBP')],
database.execSelectQuery(query))
database.close()
示例5: delCorrespondingIhmProject
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def delCorrespondingIhmProject(self, projectname, startdate, currency):
''' Delete if the project was transfered before '''
query = '''SELECT projects.pid FROM projects, transferlog WHERE projects.pid=transferlog.pid
AND transferlog.projectname='%s' AND transferlog.datecollected='%s'
AND transferlog.currency='%s' ''' % (projectname, startdate, currency)
db = Database()
db.open()
records = db.execSelectQuery( query )
for record in records:
pid = record[0]
query = '''DELETE FROM projects WHERE pid=%s''' % pid
db.execUpdateQuery( query )
db.close()
示例6: importIhmProjectData
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def importIhmProjectData(self, project, filename):
dbfile = file(filename, 'r')
contents = dbfile.read()
dbfile.close()
queries = contents.split('<endl>\n')
database = Database()
database.open()
for index in range(len(queries)):
if index != 0: # ignore the first row containing project (already created above)
query = queries[index].strip()
if ( query.startswith("INSERT") ):
query = query.replace("{pid}", str(project.pid) )
print str(index) + " " + query
database.execUpdateQuery( query )
database.close()
示例7: deleteProject
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def deleteProject(self, pid):
query = "DELETE FROM projects WHERE pid=%s" % pid
database = Database()
database.open()
database.execUpdateQuery( query )
database.close()
示例8: CurrencyManager
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
class CurrencyManager( object ):
"""Manages currencies.
Allows adding, editing, deleting and retrieval of currencies.
"""
def __init__( self ) :
self.database = Database()
self.currencies = None
self.currency_names = None
self.getCurrencies()
def existsCurrency(self, name):
"""Check if currency 'name' exists
"""
currency = Currency(currencyname=name)
if not currency.name :
return False
else:
return True
def getCurrencyByID(self, currencyid):
"""return currency currencyid from the database
(returns by currency id)
"""
currency = Currency(currencyid)
if not currency.name :
raise CurrencyError(
"Can't get Currency id %r which does not exist" % currencyid )
return currency
def getCurrencyByName(self, name):
"""return currency currencyname from the database
(returns by currency name)
"""
currency = Currency(currencyname=name)
if not currency.name :
raise CurrencyError(
"Can't get Currency '%r' which does not exist" % name )
return currency
def addCurrency(self, currencyname, abbreviation, symbol ):
"""Adds currency 'currencyname' to the currencies database.
"""
currency = Currency( 0 , currencyname, abbreviation, symbol )
self.getCurrencies() # update currency list
return currency
def editCurrency(self, currencyid, currencyname, abbreviation, symbol ):
"""Edit currency 'currencyid' providing new name, abbreviation, symbol.
"""
currency = Currency(currencyid)
if not currency.name :
raise CurrencyError(
"Can't find Currency id %r which does not exist" % currencyid )
currency.editData( currencyname, abbreviation, symbol )
self.getCurrencies() # update currency list
return
def delCurrency(self, currencyid):
"""Delete currency 'currencyid' from the database.
"""
currency = Currency(currencyid)
if not currency.name :
raise CurrencyError(
"Can't delete Currency id %r which does not exist" %currencyid )
query = "DELETE FROM currencies WHERE id=%i " % ( currencyid )
self.database.open()
self.database.execUpdateQuery( query )
self.database.close()
self.getCurrencies() # update currency list
return
def getCurrencies(self):
"""Return a list of currencies stored in the database
At same time set self.currencies to this list.
"""
query = "SELECT id FROM currencies"
self.database.open()
rows = self.database.execSelectQuery( query )
self.database.close()
self.currencies = list()
for row in rows:
curr_id = row[0]
currency = Currency(curr_id)
self.currencies.append( currency )
self.currency_names = [ x.name for x in self.currencies ]
return self.currencies
示例9: delGlobalPersonCharacteristic
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def delGlobalPersonCharacteristic(self, charid="", charname=""):
query = "DELETE FROM globalpersonalcharacteristics WHERE id=%i OR characteristic='%s' " % ( charid, charname )
database = Database()
database.open()
database.execUpdateQuery( query )
database.close()
示例10: delGlobalCharacteristic
# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import execUpdateQuery [as 别名]
def delGlobalCharacteristic(self, charname=""):
database = Database()
query = "DELETE FROM globalcharacteristics WHERE characteristic='%s' " % ( charname )
database.open()
database.execUpdateQuery( query )
database.close()