欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在SQLite-Python中實(shí)現(xiàn)返回、查詢中文字段的方法

 更新時(shí)間:2019年07月17日 10:30:36   作者:Joy_917  
今天小編就為大家分享一篇在SQLite-Python中實(shí)現(xiàn)返回、查詢中文字段的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

博主在這個(gè)問(wèn)題上卡了挺久的,貼出來(lái)解決方法幫助需要的朋友,直接上代碼(測(cè)試環(huán)境:win10+Python2.7):

# coding=utf-8
 
import sqlite3
 
with sqlite3.connect(":memory:") as conn:
  try:
    init_sql = " create table test (id integer primary key ,name text(200) not null);" \
          " insert into test (name) values ('小居居');" \
          " insert into test (name) values ('大居居');"
    conn.executescript(init_sql)
  except Exception as e:
    conn.rollback()
    raise e
  else:
    conn.commit()
    conn.text_factory = str # 此處是關(guān)鍵,sqlite默認(rèn)文本存取是Unicode
    try:
      for row in conn.execute(" select * from test where name = ?",("大居居",)):
        print row[1],type(row[1])
    except Exception as e:
      raise e

結(jié)果:

大居居 <type 'str'>

以上這篇在SQLite-Python中實(shí)現(xiàn)返回、查詢中文字段的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論