<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    海上月明

    editer by sun
    posts - 162, comments - 51, trackbacks - 0, articles - 8
       :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

    python操作sqlite3 碰到中文問題

    Posted on 2013-06-07 19:01 pts 閱讀(5836) 評論(0)  編輯  收藏 所屬分類: Python

    錯問癥狀:

    OperationalError: Could not decode to UTF-8 column 'shouji_lanshouyuan' with text '國際2部 鄔長春'

    解決方案:

    conn = sqlite3.connection(" ... ")
    conn.text_factory = str

    解決問題方案來源:http://bbs.csdn.net/topics/250055755

    設置python使用什么類型來處理sqlite3的text類型,默認是unicode,所以才會產(chǎn)生
    OperationalError: Could not decode to UTF-8 column 'name' with text '國內其他' 
    這個錯誤

    因為從數(shù)據(jù)庫中取出數(shù)據(jù)時,是gbk編碼(因為你上次存進去的是gbk)
    conn.text_factory的默認值是unicode,python會嘗試將text類型的字段轉換成unicode,就產(chǎn)生了錯誤

     

    附:sqlite3的row操作:

    Row對象的詳細介紹

    class sqlite3.Row

    Row instance serves as a highly optimized row_factory for Connection objects. It tries to mimic a tuple in most of its features.

    It supports mapping access by column name and index, iteration, representation, equality testing and len().

    If two Row objects have exactly the same columns and their members are equal, they compare equal.

    Changed in version 2.6: Added iteration and equality (hashability).

    keys()

    This method returns a tuple of column names. Immediately after a query, it is the first member of each tuple in Cursor.description.

    New in version 2.6.

        下面舉例說明

    復制代碼
    cx.row_factory = sqlite3.Row

    = cx.cursor()

    c.execute('select * from catalog')
     <sqlite3.Cursor object at 0x05666680>

    = c.fetchone()

    type(r)
    <type 'sqlite3.Row'>

    r
    <sqlite3.Row object at 0x05348980>

    print r
    (0, 
    10, u'\u9c7c', u'Yu')

    len(r)
    4

    r[2]            #使用索引查詢
    u'\u9c7c'

    r.keys()
    ['id''pid''name''nickname']

     使用列的關鍵詞查詢
    In [43]: r['id']
    Out[43]: 0
    In [44]: r['name']
    Out[44]: u'\u9c7c'

     

    主站蜘蛛池模板: 国产亚洲精品欧洲在线观看| 亚洲中文字幕伊人久久无码| 亚洲精品在线免费看| 中文字幕无码一区二区免费| 久久久久亚洲AV成人网人人软件| 一级毛片视频免费| 亚洲综合国产精品第一页| 国产黄在线观看免费观看不卡| 免费国产小视频在线观看| 美女视频黄频a免费| 亚洲国模精品一区| 99精品视频免费| 久久久久亚洲AV无码专区首| 久久久久久一品道精品免费看| 久久夜色精品国产亚洲AV动态图| 91精品国产免费| 亚洲人成人77777网站不卡| 青青草免费在线视频| 国产亚洲精品美女2020久久| 中文字幕亚洲乱码熟女一区二区| 免费观看91视频| 亚洲人成图片网站| 天堂亚洲免费视频| 久久免费精彩视频| 精品亚洲成A人无码成A在线观看 | 成人黄网站片免费视频| 亚洲一区二区三区首页| 无码人妻一区二区三区免费手机| 亚洲国产精品无码观看久久| 亚洲人午夜射精精品日韩| 人妻无码一区二区三区免费| 亚洲一久久久久久久久| 亚洲午夜无码片在线观看影院猛| 日本免费高清视频| 国产精品亚洲精品久久精品| 亚洲日韩aⅴ在线视频| 免费三级毛片电影片| 九九综合VA免费看| 亚洲日本在线观看网址| 亚洲精品无码久久毛片| 免费看又黄又无码的网站|