• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python database.Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中model.database.Database的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    db = Database(mode='PROD', echo=True)
    if not db.has_tables():
        db.make_tables()
    with open('.smurfs.txt') as f:
        for line in f:
            fetch_and_store_summoner(line.strip(), db)

    session = db.SessionMaker()
    print(session.query(GameStats, GameStats.champion).all())
开发者ID:Zacharoo,项目名称:riot-api,代码行数:10,代码来源:main.py


示例2: getGlobalPersonCharacteristics

 def getGlobalPersonCharacteristics(self):        
    query = "SELECT id FROM globalpersonalcharacteristics"
    database = Database()
    atabase.open()
    rows = database.execSelectQuery( query )
    database.close()
    chars = []
    
    for row in rows:
        charid = row[0]
        char = GlobalPersonCharacteristic(charid)
        chars.append( char )
        
    return chars
开发者ID:r4vi,项目名称:open-ihm,代码行数:14,代码来源:globalpersoncharacteristicsmanager.py


示例3: public

    def public(self, **kwargs):

        self.__assert_argument("callback", kwargs)
        self.__assert_argument("maxCount", kwargs)

        entries = Database.get_messages(kwargs["maxCount"])
        return self.__get_jsonp_response(kwargs["callback"], entries)
开发者ID:kestava,项目名称:timeline-server,代码行数:7,代码来源:root.py


示例4: new_database

 def new_database(self):
     ret = self.mainAppWindow.gamestateController.unsaved_changes()
     if(not ret == QMessageBox.Cancel):
         file_dialog = QFileDialog()
         filename = file_dialog.getSaveFileName(self.mainAppWindow, self.mainAppWindow.trUtf8('Create New PGN'), \
                                                None, 'PGN (*.pgn)', QFileDialog.DontUseNativeDialog)
         if(filename):
             if(not filename.endswith(".pgn")):
                 filename = filename + ".pgn"
             self.model.gamestate.last_save_dir = QFileInfo(filename).dir().absolutePath()
             db = Database(filename)
             db.create_new_pgn()
             self.mainAppWindow.save.setEnabled(False)
             self.model.database = db
             self.model.user_settings.active_database = db.filename
     self.mainAppWindow.moves_edit_view.setFocus()
开发者ID:liggettla,项目名称:jerry,代码行数:16,代码来源:file_mnu_ctr.py


示例5: logIhmTransfer

 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()
开发者ID:r4vi,项目名称:open-ihm,代码行数:8,代码来源:openihmimportmanager1.py


示例6: __init__

   def __init__(self):
       db = Database({
           "type": 'postgresql',
           "host": 'fg-cn-decaf-head1.cs.upb.de',
           "port": '5432',
           "database": 'decaf_storage',
           "user": 'pgdecaf',
           "password": 'pgdecafpw'
       })
       #db.drop_all()
       db.init_db()
       # Configure logging
       log_file = LOGFILE
       logger = logging.getLogger(__name__)
       logger.setLevel(logging.DEBUG)
       fh = logging.FileHandler(log_file)
       logger.addHandler(fh)

       self.storage = Storage(db, logger=logger)
开发者ID:aw32,项目名称:OpenBarista,代码行数:19,代码来源:load_data.py


示例7: exportHouseholds

 def exportHouseholds(self, project,  filename):
     database = Database()
     database.open()
     
     query = '''SELECT hhid, householdname, dateofcollection FROM households
                   WHERE pid=%s''' % project.pid
                   
     households = database.execSelectQuery( query )
     
     database.close()
     
     ihmFile = open(filename, 'a')
     for household in households:
         householdline = '''INSERT INTO households(pid,hhid,householdname,dateofcollection) 
                 VALUES({pid},%s, '%s', '%s')<endl>\n''' % (household[0], household[1], household[2])
         ihmFile.write(householdline)
     ihmFile.close()
     
     self.exportHouseholdCharacteristics(project, filename)
     self.exportHouseholdAssets(project, filename)
     self.exportHouseholdExpenditure(project, filename)
     self.exportHouseholdCropIncome(project, filename)
     self.exportHouseholdLivestockIncome(project, filename)
     self.exportHouseholdWildfoodsIncome(project, filename)
     self.exportHouseholdEmploymentIncome(project, filename)
     self.exportHouseholdTransfersIncome(project, filename)
     self.exportHouseholdMembers(project, filename)
开发者ID:r4vi,项目名称:open-ihm,代码行数:27,代码来源:openihmexportmanager1.py


示例8: test_execUpdateQuery

 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()
开发者ID:snim2mirror,项目名称:openihm,代码行数:14,代码来源:test_model_database.py


示例9: getProjectsMatching

 def getProjectsMatching(self,  pid="",  ptitle=""):
     SQLcondition 	= ""
     if ( pid != "" ):
         SQLcondition = " WHERE pid=%s" % pid
     
     if ( ptitle != "" ):
         if ( SQLcondition == "" ):
             SQLcondition = " WHERE projectname LIKE '%" + "%s" % ( ptitle ) + "%'" 
         else:
             SQLcondition = SQLcondition + " OR projectname LIKE '%" + "%s" % ( ptitle ) + "%'" 
             
     query = ''' SELECT pid FROM projects%s''' % ( SQLcondition )
     
     database = Database()
     database.open()
     rows = database.execSelectQuery(  query )
     database.close()
     
     projects = []
     for row in rows:
         pid = row[0]
         project = Project(pid)
         projects.append( project )
     
     return projects
开发者ID:r4vi,项目名称:open-ihm,代码行数:25,代码来源:controller.py


示例10: TestTableExistence

class TestTableExistence(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.db = Database('TEST')
        self.db.make_tables()

    @classmethod
    def tearDownClass(self):
        self.db.destroy_tables()

    def tearDown(self):
        self.db.truncate_tables()

    def test_when_all_tables_exist(self):
        assert 'game_stats' in self.db.Meta.tables.keys()
        assert 'game' in self.db.Meta.tables.keys()
        assert 'summoner' in self.db.Meta.tables.keys()
        assert 'summoner_name' in self.db.Meta.tables.keys()

    def test_all_tables_have_rigth_columns(self):
        t = TableTester(self.db)
        test = t.has_next_table()
        while test:
            test()
            test = t.has_next_table()
开发者ID:Zacharoo,项目名称:riot-api,代码行数:26,代码来源:test_table_existence.py


示例11: open_database

 def open_database(self):
     dialog = QFileDialog()
     if self.model.gamestate.last_open_dir != None:
         dialog.setDirectory(self.model.gamestate.last_open_dir)
     filename = dialog.getOpenFileName(
         self.mainAppWindow.chessboard_view,
         self.mainAppWindow.trUtf8("Open PGN"),
         None,
         "PGN (*.pgn)",
         QFileDialog.DontUseNativeDialog,
     )
     if filename:
         db = Database(filename)
         db.init_from_pgn(self.mainAppWindow, self.mainAppWindow.trUtf8("Scanning PGN File..."))
         self.model.database = db
         self.model.user_settings.active_database = db.filename
         selectedGame = 0
         if db.no_of_games() > 1:
             dlg = DialogBrowsePgn(db)
             if dlg.exec_() == QDialog.Accepted:
                 items = dlg.table.selectedItems()
                 selectedGame = int(items[0].text()) - 1
             else:
                 selectedGame = None
         if not selectedGame == None and db.no_of_games() > 0:
             loaded_game = db.load_game(selectedGame)
             self.model.gamestate.current = loaded_game
             self.mainAppWindow.chessboard_view.update()
             self.mainAppWindow.chessboard_view.emit(SIGNAL("statechanged()"))
             self.mainAppWindow.save.setEnabled(False)
             self.mainAppWindow.setLabels()
             self.mainAppWindow.moves_edit_view.setFocus()
             self.model.gamestate.last_open_dir = QFileInfo(filename).dir().absolutePath()
             self.model.gamestate.init_game_tree(self.mainAppWindow)
     self.mainAppWindow.moves_edit_view.setFocus()
开发者ID:jasiegel4,项目名称:jerry,代码行数:35,代码来源:file_mnu_ctr.py


示例12: delCorrespondingIhmProject

 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()
开发者ID:r4vi,项目名称:open-ihm,代码行数:16,代码来源:openihmimportmanager1.py


示例13: getProjects

 def getProjects(self):       
     query = "SELECT pid FROM projects"
     database = Database()
     database.open()
     rows = database.execSelectQuery( query )
     database.close()
     projects = []
     
     for row in rows:
         pid = row[0]
         project = Project(pid)
         projects.append( project )
         
     return projects
开发者ID:r4vi,项目名称:open-ihm,代码行数:14,代码来源:controller.py


示例14: importIhmProjectData

 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()
开发者ID:r4vi,项目名称:open-ihm,代码行数:19,代码来源:openihmimportmanager1.py


示例15: exportProjectIncomeSources

 def exportProjectIncomeSources(self, project, filename):
     database = Database()
     database.open()
     
     query = '''SELECT incomesource, incometype FROM projectincomesources
                   WHERE pid=%s''' % project.pid
                   
     incomes = database.execSelectQuery( query )
     
     database.close()
     ihmFile = open(filename, 'a')
     for inc in incomes:
         incomeline = '''INSERT INTO projectincomesources(pid,incomesource,incometype) 
         VALUES({pid},'%s','%s')<endl>\n''' % (inc[0], inc[1])
         ihmFile.write(incomeline)
     ihmFile.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:16,代码来源:openihmexportmanager1.py


示例16: exportHouseholdCharacteristics

 def exportHouseholdCharacteristics(self, project, filename):
     database = Database()
     database.open()
     
     query = '''SELECT hhid, characteristic, charvalue FROM householdcharacteristics
                   WHERE pid=%s''' % project.pid
                   
     chars = database.execSelectQuery( query )
     
     database.close()
     
     ihmFile = open(filename, 'a')
     for char in chars:
         charline = '''INSERT INTO householdcharacteristics (pid,hhid, characteristic, charvalue )
             VALUES({pid},%s,'%s','%s')<endl>\n'''  % (char[0], char[1], char[2])
         ihmFile.write(charline)
     ihmFile.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:17,代码来源:openihmexportmanager1.py


示例17: exportHouseholdAssets

 def exportHouseholdAssets(self, project, filename):
     database = Database()
     database.open()
     
     query = '''SELECT hhid, assetcategory, assettype, unitofmeasure, unitcost, totalunits FROM assets
                   WHERE pid=%s''' % project.pid
                   
     assets = database.execSelectQuery( query )
     
     database.close()
     
     ihmFile = open(filename, 'a')
     for asset in assets:
         assetline = '''INSERT INTO assets (pid, hhid, assetcategory, assettype, unitofmeasure, unitcost, totalunits )
             VALUES({pid},%s,'%s','%s','%s',%s,%s)<endl>\n''' % (asset[0], asset[1], asset[2], asset[3], asset[4], asset[5])
         ihmFile.write(assetline)
     ihmFile.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:17,代码来源:openihmexportmanager1.py


示例18: exportProjectDiet

 def exportProjectDiet(self, project, filename):
     database = Database()
     database.open()
     
     query = '''SELECT fooditem, unitofmeasure, percentage, priceperunit FROM diet
                   WHERE pid=%s''' % project.pid
                   
     diets = database.execSelectQuery( query )
     
     database.close()
     
     ihmFile = open(filename, 'a')
     for diet in diets:
         dietline = '''INSERT INTO diet (pid, fooditem,unitofmeasure,percentage, priceperunit )
                     VALUES({pid},'%s','%s',%s,%s)<endl>\n''' % (diet[0], diet[1], diet[2], diet[3])
         ihmFile.write(dietline)
     ihmFile.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:17,代码来源:openihmexportmanager1.py


示例19: exportProjectAssets

 def exportProjectAssets(self, project, filename):
     database = Database()
     database.open()
     
     query = '''SELECT assetname, assettype FROM projectassets
                   WHERE pid=%s''' % project.pid
                   
     assets = database.execSelectQuery( query )
     
     database.close()
     
     ihmFile = open(filename, 'a')
     for asset in assets:
         assetline = '''INSERT INTO projectassets(pid,assetname,assettype) 
         VALUES({pid},'%s','%s')<endl>\n''' % (asset[0], asset[1])
         ihmFile.write(assetline)
     ihmFile.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:17,代码来源:openihmexportmanager1.py


示例20: exportHouseholdCropIncome

 def exportHouseholdCropIncome(self, project, filename):
     database = Database()
     database.open()
     
     query = '''SELECT hhid, incomesource, unitofmeasure, unitsproduced, unitssold, unitprice, otheruses, unitsconsumed FROM cropincome
                   WHERE pid=%s''' % project.pid
                   
     crops = database.execSelectQuery( query )
     
     database.close()
     
     ihmFile = open(filename, 'a')
     for crop in crops:
         cropline = '''INSERT INTO cropincome(pid, hhid, incomesource, unitofmeasure, unitsproduced, unitssold, unitprice, otheruses, unitsconsumed)
             VALUES({pid},%s,'%s','%s',%s,%s,%s,%s,%s)<endl>\n''' % (crop[0],  crop[1], crop[2], crop[3], crop[4], crop[5], crop[6], crop[7])
         ihmFile.write(cropline)
     ihmFile.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:17,代码来源:openihmexportmanager1.py



注:本文中的model.database.Database类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python db.create_all函数代码示例发布时间:2022-05-27
下一篇:
Python factory.generateID函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap