SQLite3中文編碼 Python的實現

2022-09-21 01:12:12 字數 439 閱讀 3043

讀取十萬多條文字寫入swww.cppcns.comqlite型別資料庫,由於文字中存在中文字元,插入到資料庫沒錯,取出時一直是unicodedecodeerror,導致折騰了一天。

最後的解決方法:

python連線資料時進行如下設定:

db=sqlite3.connection("...")

db.text_factory=st

另為了python**中硬編碼的中文字串不出現問題,除了在原始碼開程式設計客棧始新增

# - coding:utf-8 -*- 

設定python原始碼的編碼為utf-8

import sys

reload(sys)

sys.setdefaultencode('uwww.cppcns.comt')

本文標題: sqlite3中文編碼 python的實現

本文位址:

SQLite 3的中文讀寫

呼叫sqlite3 open函式預設建立的資料庫encoding utf 8,執行sqlite3 exec時需要將對應的字串轉換為utf 8格式多位元組字串。比如 sqlite3 db auto retval sqlite3 open test.db db char perrmsg auto sql...

SQLite 3的中文讀寫

呼叫sqlite3 open函式預設建立的資料庫encoding utf 8,執行sqlite3 exec時需要將對應的字串轉換為utf 8格式多位元組字串。比如 sqlite3 db auto retval sqlite3 open test.db db char perrmsg auto sql...

SQLite3中TimeStamp的使用問題

color blue 在使用sqlite3時使用了timestamp,但是遇到一些問題,現總結如下 一 我的sql語句 create table logs id integer primary key,idcardno varchar 50 createdtime timestamp not nul...