当前位置:网站首页>Solve the problem of reading Chinese garbled code in sqlserver connection database

Solve the problem of reading Chinese garbled code in sqlserver connection database

2022-07-06 00:12:00 Addiction 񘱴 ۣۖ ิ ۣۖ ิ ۣۖ ิꦿ

         In a sophomore's database class , On a dark and windy night , I suddenly realized that , stay pycharm Characters that I have never seen appear on the terminal , It turned out that the Chinese display read was garbled , And then the operation is as fierce as a tiger , Start crazy Baidu , In two hours , I got the reason for the problem .

         because SQLServer I won't support it UTF-8, When using varchar When saving Chinese characters , There will be garbled code , Need to transform .

        cast function

         We will need to select the columns to display , utilize cast function , use nvarchar Save Chinese characters , It can solve the problem of Chinese garbled code

        select cast(xx as nvarchar(20)) xxxx …

    def showall(self):
        self.model.removeRows(0, self.model.rowCount())
        sql = "SELECT OwnerId,cast(OwnerName as nvarchar(20)),cast(OwnerSex as nvarchar(20)),OwnerBir,OwnerPhone,OwnerIdent,BuildId,RoomId FROM Owner"
        self.cur.execute(sql)
        rows = self.cur.fetchall()
        print(rows)
        self.addItem(rows)

原网站

版权声明
本文为[Addiction 񘱴 ۣۖ ิ ۣۖ ิ ۣۖ ิꦿ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060006405210.html