本文整理汇总了Python中springpython.database.core.DatabaseTemplate.query_for_int方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseTemplate.query_for_int方法的具体用法?Python DatabaseTemplate.query_for_int怎么用?Python DatabaseTemplate.query_for_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类springpython.database.core.DatabaseTemplate
的用法示例。
在下文中一共展示了DatabaseTemplate.query_for_int方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AbstractDatabaseTemplateTestCase
# 需要导入模块: from springpython.database.core import DatabaseTemplate [as 别名]
# 或者: from springpython.database.core.DatabaseTemplate import query_for_int [as 别名]
#.........这里部分代码省略.........
self.assertEquals(animals[0].name, "snake")
self.assertEquals(animals[0].category, "reptile")
def testProgrammaticQueryWithBoundArgumentsWithDictionaryRowMapper(self):
animals = self.databaseTemplate.query("select name, category from animal where name = %s", ("snake",), DictionaryRowMapper())
self.assertEquals(animals[0]["name"], "snake")
self.assertEquals(animals[0]["category"], "reptile")
animals = self.databaseTemplate.query("select name, category from animal where name = ?", ("snake",), DictionaryRowMapper())
self.assertEquals(animals[0]["name"], "snake")
self.assertEquals(animals[0]["category"], "reptile")
def testProgrammaticStaticQueryForList(self):
animals = self.databaseTemplate.query_for_list("select name, category from animal")
self.assertEquals(animals[0][0], "snake")
self.assertEquals(animals[0][1], "reptile")
self.assertEquals(animals[1][0], "racoon")
self.assertEquals(animals[1][1], "mammal")
def testProgrammaticQueryForListWithBoundArguments(self):
animals = self.databaseTemplate.query_for_list("select name, category from animal where name = %s", ("snake",))
self.assertEquals(animals[0][0], "snake")
self.assertEquals(animals[0][1], "reptile")
animals = self.databaseTemplate.query_for_list("select name, category from animal where name = ?", ("snake",))
self.assertEquals(animals[0][0], "snake")
self.assertEquals(animals[0][1], "reptile")
def testProgrammaticQueryForListWithBoundArgumentsNotProperlyTuplized(self):
self.assertRaises(InvalidArgumentType, self.databaseTemplate.query_for_list, "select * from animal where name = %s", "snake")
self.assertRaises(InvalidArgumentType, self.databaseTemplate.query_for_list, "select * from animal where name = ?", "snake")
def testProgrammaticStaticQueryForInt(self):
count = self.databaseTemplate.query_for_int("select population from animal where name = 'snake'")
self.assertEquals(count, 1)
def testProgrammaticQueryForIntWithBoundArguments(self):
count = self.databaseTemplate.query_for_int("select population from animal where name = %s", ("snake",))
self.assertEquals(count, 1)
count = self.databaseTemplate.query_for_int("select population from animal where name = ?", ("snake",))
self.assertEquals(count, 1)
def testProgrammaticStaticQueryForLong(self):
count = self.databaseTemplate.query_for_object("select count(*) from animal", required_type=self.factory.count_type())
self.assertEquals(count, 4)
def testProgrammaticQueryForLongWithBoundVariables(self):
count = self.databaseTemplate.query_for_object("select count(*) from animal where name = %s", ("snake",), self.factory.count_type())
self.assertEquals(count, 1)
count = self.databaseTemplate.query_for_object("select count(*) from animal where name = ?", ("snake",), self.factory.count_type())
self.assertEquals(count, 1)
def testProgrammaticStaticQueryForObject(self):
self.assertRaises(ArgumentMustBeNamed, self.databaseTemplate.query_for_object, "select name from animal where category = 'reptile'", types.StringType)
name = self.databaseTemplate.query_for_object("select name from animal where category = 'reptile'", required_type=types.StringType)
self.assertEquals(name, "snake")
def testProgrammaticQueryForObjectWithBoundVariables(self):
name = self.databaseTemplate.query_for_object("select name from animal where category = %s", ("reptile",), types.StringType)
self.assertEquals(name, "snake")
name = self.databaseTemplate.query_for_object("select name from animal where category = ?", ("reptile",), types.StringType)
self.assertEquals(name, "snake")
示例2: DatabaseTemplateMockTestCase
# 需要导入模块: from springpython.database.core import DatabaseTemplate [as 别名]
# 或者: from springpython.database.core.DatabaseTemplate import query_for_int [as 别名]
#.........这里部分代码省略.........
def testProgrammaticStaticQueryForList(self):
self.mock.expects(once()).method("execute").id("#1")
self.mock.expects(once()).method("fetchall").will(return_value([('snake', 'reptile', 1), ('racoon', 'mammal', 1)])).id("#2").after("#1")
animals = self.databaseTemplate.query_for_list("select * from animal")
self.assertEquals(animals[0][0], "snake")
self.assertEquals(animals[0][1], "reptile")
self.assertEquals(animals[1][0], "racoon")
self.assertEquals(animals[1][1], "mammal")
def testProgrammaticQueryForListWithBoundArguments(self):
self.mock.expects(once()).method("execute").id("#1")
self.mock.expects(once()).method("fetchall").will(return_value([('snake', 'reptile', 1)])).id("#2").after("#1")
self.mock.expects(once()).method("execute").id("#3").after("#2")
self.mock.expects(once()).method("fetchall").will(return_value([('snake', 'reptile', 1)])).id("#4").after("#3")
animals = self.databaseTemplate.query_for_list("select * from animal where name = %s", ("snake",))
self.assertEquals(animals[0][0], "snake")
self.assertEquals(animals[0][1], "reptile")
animals = self.databaseTemplate.query_for_list("select * from animal where name = ?", ("snake",))
self.assertEquals(animals[0][0], "snake")
self.assertEquals(animals[0][1], "reptile")
def testProgrammaticQueryForListWithBoundArgumentsNotProperlyTuplized(self):
self.assertRaises(InvalidArgumentType, self.databaseTemplate.query_for_list, "select * from animal where name = %s", "snake")
self.assertRaises(InvalidArgumentType, self.databaseTemplate.query_for_list, "select * from animal where name = ?", "snake")
def testProgrammaticStaticQueryForInt(self):
self.mock.expects(once()).method("execute").id("#1")
self.mock.expects(once()).method("fetchall").will(return_value([(1,)])).id("#2").after("#1")
count = self.databaseTemplate.query_for_int("select population from animal where name = 'snake'")
self.assertEquals(count, 1)
def testProgrammaticQueryForIntWithBoundArguments(self):
self.mock.expects(once()).method("execute").id("#1")
self.mock.expects(once()).method("fetchall").will(return_value([(1,)])).id("#2").after("#1")
self.mock.expects(once()).method("execute").id("#3").after("#2")
self.mock.expects(once()).method("fetchall").will(return_value([(1,)])).id("#4").after("#3")
count = self.databaseTemplate.query_for_int("select population from animal where name = %s", ("snake",))
self.assertEquals(count, 1)
count = self.databaseTemplate.query_for_int("select population from animal where name = ?", ("snake",))
self.assertEquals(count, 1)
def testProgrammaticStaticQueryForLong(self):
self.mock.expects(once()).method("execute").id("#1")
self.mock.expects(once()).method("fetchall").will(return_value([(4,)])).id("#2").after("#1")
count = self.databaseTemplate.query_for_object("select count(*) from animal", required_type=types.IntType)
self.assertEquals(count, 4)
def testProgrammaticQueryForLongWithBoundVariables(self):
self.mock.expects(once()).method("execute").id("#1")
self.mock.expects(once()).method("fetchall").will(return_value([(1,)])).id("#2").after("#1")
self.mock.expects(once()).method("execute").id("#3").after("#2")
self.mock.expects(once()).method("fetchall").will(return_value([(1,)])).id("#4").after("#3")
count = self.databaseTemplate.query_for_object("select count(*) from animal where name = %s", ("snake",), types.IntType)
self.assertEquals(count, 1)
count = self.databaseTemplate.query_for_object("select count(*) from animal where name = ?", ("snake",), types.IntType)
self.assertEquals(count, 1)