当前位置: 首页>>代码示例>>Python>>正文


Python database.Database类代码示例

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


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

示例1: load_scores

def load_scores(scoring_method, unweighted, unstressed):
    method_mean, method_addition = SCORING_METHODS[scoring_method]

    sql = "select word, score from scores where \
        unweighted = {} and unstressed = {} \
        and method_mean = {} and method_addition = {};".format(
            unweighted, unstressed, method_mean, method_addition
        )

    return Database.fetch(sql)
开发者ID:gkufera,项目名称:phonetic_markov,代码行数:10,代码来源:load_data.py

示例2: load_phonemes

def load_phonemes(unweighted, unstressed):
    next_phonemes = 'next_phonemes_unweighted' if unweighted else 'next_phonemes'
    sql = "select phoneme, {} from phonemes where unstressed = {};".format(
        next_phonemes, unstressed
    )
    results = Database.fetch(sql)

    output = {}
    for phoneme, next_phonemes in results:
        output[phoneme] = json.loads(next_phonemes)

    return output
开发者ID:gkufera,项目名称:phonetic_markov,代码行数:12,代码来源:load_data.py

示例3: 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'
     # FIXME: the None's look hinky.
     self.assertEqual([(2, u'test', None, None, u'a simple test', u'GBP')],
                     database.execSelectQuery(query))
     database.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:14,代码来源:test_openihm_data_database.py

示例4: executeQuery

 def executeQuery(self,query):
     '''Execute queries under adult equivalent calculations '''
     databaseConnector = Database()
     databaseConnector.open()
     result = databaseConnector.execSelectQuery( query )
     databaseConnector.close()
     return result
开发者ID:r4vi,项目名称:open-ihm,代码行数:7,代码来源:report_adultequivalent.py

示例5: executeSelectQuery

 def executeSelectQuery(self,query):
     '''Run Select Query'''
     dbconnector = Database()
     dbconnector.open()
     recset = dbconnector.execSelectQuery(query)
     dbconnector.close()
     return recset
开发者ID:r4vi,项目名称:open-ihm,代码行数:7,代码来源:report_livingthreshold.py

示例6: 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_openihm_data_database.py

示例7: executeQuery

 def executeQuery(self,query):
     '''run various select queries'''
     
     dbconnector = Database()
     dbconnector.open()
     recordset = dbconnector.execSelectQuery(query)
     dbconnector.close()
     return recordset
开发者ID:r4vi,项目名称:open-ihm,代码行数:8,代码来源:report_disposable_income_simulation.py

示例8: getincomeSources

 def getincomeSources(self,query):
     '''run various select queries'''
     dbconnector = Database()
     dbconnector.open()
     print query
     recordset = dbconnector.execSelectQuery(query)
     dbconnector.close()
     return recordset
开发者ID:r4vi,项目名称:open-ihm,代码行数:8,代码来源:generate_data_entry_sheet.py

示例9: getReportHouseholdIDs

 def getReportHouseholdIDs(self,query):
     
     reporthouseholdIDs=[]
     databaseConnector = Database()
     if query !='':
         databaseConnector.open()
         reporthouseholdIDs = databaseConnector.execSelectQuery( query )
         databaseConnector.close()
     return reporthouseholdIDs
开发者ID:r4vi,项目名称:open-ihm,代码行数:9,代码来源:report_disposable_income_simulation.py

示例10: readBasicMemberDetails

        def readBasicMemberDetails(self, householdsheet, row_index):
            # print book.nsheets
            start_row_index = row_index + 1
            empty_cell_count = 0
            hhid = householdsheet.name
            print hhid
            database = Database()
            database.open()

            for current_row_index in range(start_row_index, householdsheet.nrows):
                values = []
                for col_index in range(0, 4):
                    cellvalue = householdsheet.cell(current_row_index, col_index).value
                    print cellvalue
                    if cellvalue == "":
                        empty_cell_count = empty_cell_count + 1
                        cellvalue = None
                    if col_index > 0 and valueisdigit() == False:
                        cellvalue = None
                    if col_index == 3 and (cellvalue == 1 or cellvalue == "yes"):
                        cellvalue = "Yes"
                    else:
                        cellvalue = "No"

                    values.append(cellvalue)

                if empty_cell_count == 4 or value == "PersonalCharacteristics":  # check if entire row is empty
                    break
                else:

                    sex = values[0]
                    age = values[1]
                    yearofbirth = values[2]
                    hhead = values[3]
                    personid = str(sex) + str(age)

                query = """REPLACE INTO householdmembers (personid,hhid,headofhousehold,yearofbirth,sex,pid)
                            VALUES ('%s',%s,'%s',%s,'%s','%s',%s)""" % (
                    personid,
                    hhid,
                    hhead,
                    yearofbirth,
                    self.pid,
                )

                print query
                database.execUpdateQuery(query)

                empty_cell_count = 0

            database.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:51,代码来源:read_data_entry_sheets.py

示例11: readProjectHouseholdsData

    def readProjectHouseholdsData(self,book):
        '''Import Project Households'''
        sheet1 = book.sheet_by_index(0)

        # Start Block of code for importing a project's households
        database = Database()
        database.open()

        for row in range(2,sheet1.nrows):
            values = []
            for col in range(sheet1.ncols):
                skiprow =False
                cell = sheet1.cell(row,col)
                cellvalue = cell.value
                #cellvalue = sheet1.cell(row,col).value
                
                if cellvalue =='':
                    #if cellvalue =='' or (col ==3 and cell.ctype!=3):
                    skiprow =True
                    break

                else:
                    if col == 2:
                        if cell.ctype == 3: #date
                            date_value = xldate_as_tuple(cell.value,book.datemode)
                            cellvalue = date(*date_value[:3])
                        else:
                            cellvalue = datetime.strptime(cellvalue, "%d-%m-%Y").strftime('%Y-%m-%d')

                values.append(cellvalue)

            if skiprow ==True:
                continue
            else:
                hhid = values[0]
                hholdname = values[1]
                datevisited = values[2]
                pid= sheet1.name

                testquery ='''SELECT hhid,pid FROM households WHERE hhid='%s' AND pid =%s ''' % (hhid,self.pid)
                numrows =self.checkRecordExistence(testquery)
		if numrows ==0:
                    query ='''INSERT INTO households (hhid,householdname,dateofcollection,pid) VALUES ('%s','%s','%s',%s)''' % (hhid,hholdname,datevisited,pid)
                        
                else:
                    query ='''UPDATE households SET hhid='%s',householdname='%s',dateofcollection='%s',pid=%s
                                WHERE hhid='%s' AND pid =%s ''' % (hhid,hholdname,datevisited,pid,hhid,pid)
                database.execUpdateQuery(query)
                

        database.close()
开发者ID:snim2mirror,项目名称:openihm,代码行数:51,代码来源:read_data_entry_sheets.py

示例12: checkRecordExistence

    def checkRecordExistence(self,testquery):
        '''Test if a record with some given primary key already exists'''
        database = Database()
        database.open()
        testrecset = database.execSelectQuery(testquery)
        numrows =0
        for row in testrecset:
	    numrows = numrows + 1
        database.open()
	return numrows
开发者ID:snim2mirror,项目名称:openihm,代码行数:10,代码来源:read_data_entry_sheets.py

示例13: test_databaseServerRunning

 def test_databaseServerRunning(self):
     database = Database()
     assert database.databaseServerRunning()
开发者ID:r4vi,项目名称:open-ihm,代码行数:3,代码来源:test_openihm_data_database.py

示例14: test_execDefinitionQuery

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

示例15: insertSartUpValues

    def insertSartUpValues(self):
        '''Insert food energy requirements by age and sex into table lookup_energy_needs'''
        
        database = Database()
        database.open()
        deleteQuery = '''DELETE FROM lookup_energy_needs'''
        database.execUpdateQuery(deleteQuery)
        
        insertQuery = '''INSERT INTO lookup_energy_needs (age,kCalNeedM,kCalNeedF) VALUES
                            (0,820,820),
                            (1,820,820),
                            (2,1150,1150),
                            (3,1350,1350),
                            (4,1550,1550),
                            (5,1550,1550),
                            (6,1850,1750),
                            (7,1850,1750),
                            (8,1850,1750),
                            (9,1850,1750),
                            (10,2100,1800),
                            (11,2100,1800),
                            (12,2200,1950),
                            (13,2200,1950),
                            (14,2400,2100),
                            (15,2400,2100),
                            (16,2650,2150),
                            (17,2650,2150)'''
                            
        database.execUpdateQuery(insertQuery)
        
        insertQuery = "INSERT INTO lookup_energy_needs (age,kCalNeedM,kCalNeedF) VALUES (18,2600,2600)"
        
        for i in range(19,30):
            insertQuery = insertQuery + ",(%s,2600,2600) " % i 
        database.execUpdateQuery(insertQuery)

        insertQuery = "INSERT INTO lookup_energy_needs (age,kCalNeedM,kCalNeedF) VALUES (30,2500,2050)"
        
        for i in range(31,60):
            insertQuery = insertQuery + ",(%s,2500,2050) " % i 
        database.execUpdateQuery(insertQuery)

        insertQuery = "INSERT INTO lookup_energy_needs (age,kCalNeedM,kCalNeedF) VALUES (60,2100,1850)"
        
        for i in range(61,100):
            insertQuery = insertQuery + ",(%s,2100,1850) " % i 
        database.execUpdateQuery(insertQuery)

        database.close()
开发者ID:r4vi,项目名称:open-ihm,代码行数:49,代码来源:setup_foodrequirement_startupvalues.py


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