六 与数据库对比

import pymssql

def compare_expected_vs_db():
       
        diff_list = []  # 存储不一致的代码

        with pymssql.connect(server='192.168.1.1', user='test', password='123456',database='db') as myconnect:
            with  myconnect.cursor(as_dict=True) as cursor:
                cursor.execute("SELECT top 10 code,content  FROM [db].[dbo].[table] where isvalid = 1 and IsDeleted =0")
                for row in cursor:
                    code, actual = row['code'], row['content']
                    expected = result_of_3api(code)  # 数据源拼接结果

                    if actual != expected:  # 预期实际对比
                        print('代码:%s\n实际结果:%s\n预期结果:%s' % (code, actual , expected))
                        diff_list.append(code)
                    else:
                        print(code, '一致')

    if diff_list:
         print('不一致的列表:', diff_list)
    else:
         print('对比结果:数据全部一致')

 

相关文章:

  • 2021-11-11
  • 2022-12-23
  • 2021-09-26
  • 2021-06-17
  • 2021-09-11
  • 2021-09-15
  • 2021-11-08
  • 2021-04-18
猜你喜欢
  • 2022-01-20
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2021-04-23
  • 2021-05-18
相关资源
相似解决方案