示例#1
0
    def test_execute_sql_string(self):
        job_rows = JobModel.execute_sql_string('select id, title from job where id = :id', {'id': 4789})
        self.assertEqual(len(job_rows), 1)
        self.assertEqual(job_rows[0][0], 4789)
        self.assertEqual(job_rows[0][1], u'Android开发工程师')

        job_rows = JobModel.execute_sql_string('select id, title from job')
        self.assertEqual(len(job_rows), 2)
        self.assertEqual(job_rows[0][0], 4789)
        self.assertEqual(job_rows[0][1], u'Android开发工程师')

        affect_rows = JobModel.execute_sql_string("update job set title = '测试' where id = :id", {'id': 4789})
        self.assertEqual(affect_rows, 1)
        job = JobModel.get_by_pk(pk=4789)
        self.assertEqual(job.title, u'测试')
示例#2
0
    def test_execute_sql_string(self):
        job_rows = JobModel.execute_sql_string(
            'SELECT id, title FROM job WHERE id = :id', {'id': 1})
        self.assertEqual(len(job_rows), 1)
        self.assertEqual(job_rows[0][0], 1)
        self.assertEqual(job_rows[0][1], u'高级前端开发工程师')

        job_rows = JobModel.execute_sql_string('SELECT id, title FROM job')
        self.assertEqual(len(job_rows), 3)
        self.assertEqual(job_rows[0][0], 1)
        self.assertEqual(job_rows[0][1], u'高级前端开发工程师')

        affect_rows = JobModel.execute_sql_string(
            "UPDATE job SET title = '测试' WHERE id = :id", {'id': 1})
        self.assertEqual(affect_rows, 1)
        job = JobModel.get_by_pk(pk=1)
        self.assertEqual(job.title, u'测试')