??xml version="1.0" encoding="utf-8" standalone="yes"?>JoinoseDemo_EVT_MOTION
]]>
CZ代码?
1)x可被cparent内部使用,但不能被子类调用
2)y的作用域只是在parent.__init__Ҏ(gu)?br />3)z可被cparent内部使用也可被子c调?br />CZ代码如下:testGlobal.py
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3# Filename: testGlobal.py
4# Author : 水晶?/span>
5# Date : 2006-06-08
6class parent:
7 global x #q就是只能供cd部用的变量,子类不能讉K
8 x='xxxx' #注意:赋g定义要分开?/span>
9 def __init__(self):
10 y='yyyy'
11 self.z='zzzz'
12 def test(self):
13 print "test.x="+x
14
15class child(parent):
16 def __init__(self):
17 parent.__init__(self)
18
19if __name__=='__main__':
20 #试图讉K实例中的x
21 p=parent()
22 try:
23 print p.x
24 except:
25 print "1.不能直接讉K实例中的global变量"
26
27 #可以供类中其它方法访?
28 print '2.通过testҎ(gu)才可以访问x:',
29 p.test()
30
31 c=child()
32 #试图讉K父类中的变量----x,l果?p|
33 try:
34 print c.x
35 except:
36 print "3.不能讉K父类中的global变量"
37
38 print "4.但可以通过父类中的testҎ(gu)得到:",
39 c.test()
40
41 print "5.可以讉K父类中的self变量",c.z
CZ代码输出l果?
C:\Documents and Settings\Administrator\桌面>testGlobal.py
1.不能直接讉K实例中的global变量
2.通过testҎ(gu)才可以访问x: test.x=xxxx
3.不能讉K父类中的global变量
4.但可以通过父类中的testҎ(gu)得到: test.x=xxxx
5.可以讉K父类中的self变量 zzzz
]]>
Eyes 19:58:18
怎样探测一个变量是否存?
水晶?20:17:03
Q?
Eyes 20:17:30
我想知道一个变量是否存?
水晶?20:17:53
有办法的
Eyes 20:18:02
说啊
水晶?20:18:29
local字典
水晶?20:18:50
locals()
Eyes 20:19:04
谢谢
水晶?20:19:51
例子Q?br />怎样探测一个变量是否存?
1>>> a='f'
2>>> locals()
3{'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', 'pywin': <module 'pywin' from 'C:\ActivePython24\Lib\site-packages\pythonwin\pywin\__init__.pyc'>, '__doc__': None, 'a': 'f'}
4>>> locals().has_key('a')
5True
6>>>
]]>
病历l合查询q个模块没有遇到什么大的困难,主要是考虑的是怎么实现l合查询q个功能Q这里我是用动态sql的方式,查询写成一个视图,然后Ҏ(gu)l合查询界面输入的条Ӟ生成sqlQ然后执行查询,q回l果的显C同“当天登C览表”模块一栗?br />l合查询业务实现Ҏ(gu)代码Q?br />病历l合查询
1 def listPatientInfo(self,conditions={'idtype':'',
2 'identityid':'',
3 'patientid':'',
4 'name':'',
5 'sex':'',
6 'birthday':'',
7 'address':'',
8 'age':'',
9 'registrationid':'',
10 'diseases':'',
11 'description':'',
12 'suggestion':'',
13 'start':(),
14 'operator':'',
15 'regtime':(),
16 'meds':''}):
17 """
18 病历l合查询
19 """
20
21 sql="""
22 select distinct p.registrationid,p.patientid,p.idtype,p.identityid,p.patientname,
23 p.birthday,p.sex,p.address,p.description,
24 p.start,p.suggestion,p.operatorname,p.time
25 from v_patientinfo p
26 where 1=1
27 """
28 if conditions.has_key('idtype'):
29 if conditions.get('idtype')<>'':
30 sql+=" and p.idtype='%s'" % conditions.get('idtype')
31
32 if conditions.has_key('identityid'):
33 if conditions.get('identityid')<>'':
34 sql+=" and p.identityid='%s'" % conditions.get('identityid')
35
36 if conditions.has_key('patientid'):
37 if conditions.get('patientid')<>'':
38 sql+=" and p.patientid='%s'" % conditions.get('patientid')
39
40 if conditions.has_key('name'):
41 if conditions.get('name')<>'':
42 sql+=" and p.patientname='%s'" % conditions.get('name')
43
44 if conditions.has_key('sex'):
45 if conditions.get('sex')<>'':
46 sql+=" and p.sex=%s" % conditions.get('sex')
47
48 if conditions.has_key('birthday'):
49 if conditions.get('birthday')<>'':
50 sql+=" and p.birthday='%s'" % conditions.get('birthday')
51
52 if conditions.has_key('address'):
53 if conditions.get('address')<>'':
54 sql+=" and p.address like '%%%s%%'" % conditions.get('address')
55##TODO:按年龄查?/span>
56## if conditions.has_key('age'):
57## if conditions.get('age')<>'':
58## sql+=" and p.age='"+conditions.get('age')+"'"
59 if conditions.has_key('registrationid'):
60 if conditions.get('registrationid')<>'':
61 sql+=" and p.registrationid='%s'" % conditions.get('registrationid')
62
63 if conditions.has_key('diseases'):
64 if conditions.get('diseases')<>'':
65 sql+=" and p.diseasetype='%s'" % conditions.get('diseases')
66
67 if conditions.has_key('description'):
68 if conditions.get('description')<>'':
69 sql+=" and p.description like '%%%s%%'" % conditions.get('description')
70
71 if conditions.has_key('suggestion'):
72 if conditions.get('suggestion')<>'':
73 sql+=" and p.suggestion like '%%%s%%'" % conditions.get('suggestion')
74
75 if conditions.has_key('start'):
76 if conditions.get('start')<>():
77 sql+=" and p.start between '%s' and '%s'" % (conditions.get('start')[0],conditions.get('start')[1])
78
79 if conditions.has_key('meds'):
80 if conditions.get('meds')<>'':
81 sql+=" and p.medname='%s'" % conditions.get('meds')
82
83 if conditions.has_key('operator'):
84 if conditions.get('operator')<>'':
85 sql+=" and p.operatorname='%s'" % conditions.get('operator')
86
87 if conditions.has_key('regtime'):
88 if conditions.get('regtime')<>():
89 sql+=" and p.time between '%s' and '%s'" % (conditions.get('regtime')[0],conditions.get('regtime')[1])
90
91 sql+=" order by p.registrationid,p.patientid"
92 result=self.execute(sql)
93
94 colname=('挂号','病h~号','证gcd','证gL(fng)','姓名',
95 '出生日期','性别','居住地址','病症描述',
96 '生病旉','ȝ','操作?/span>','登记旉')
97 total=('记录敎ͼ(x)',str(len(result))+"?/span>",'','','','','','','','','','','')
98 result.insert(0,colname)
99 result.append(total)
100 return result
xQ病历管理模块基本功能完?br />【下期提C?/font>完成字典l护
]]>
在做【当天登C息一览】这个模块时Q结合^时的试l验Q设计表现Ş式,军_用wx.Notebook来做数据昄Q第一|C列表,W二|C列表中选中记录的详l信息?br />列表用wx.ListCtrl来显C数据,q里为求快速简单,写了一个DataListCtrlcȝ单地l承了wx.ListCtrlq个c,主要扩充了数据填充方法,能将一个字典数据填入列表。主要的代码片断Q?br />
1class PatientManageTodayListPanel(wx.Notebook):
2 """
3 当天登记一?br /> 4
"""
5 def __init__(self, parent):
6 wx.Notebook.__init__(self, parent, wx.ID_ANY,style=wx.NB_NOPAGETHEME|wx.NB_BOTTOM)
7 self.listPanel=PatientManageListPanel(self)
8 self.detailPanel=PatientManageDetailPanel(self)
9 self.AddPage(self.listPanel, "当天登记信息列表",select=True)
10 self.AddPage(self.detailPanel, "当天登记信息详细信息",select=False)
11 self.currentItem=0
12
13 self.listPanel.list.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
14 self.listPanel.list.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
15
16 def OnItemSelected(self, event):
17 self.currentItem = event.m_itemIndex
18
19 def OnDoubleClick(self, event):
20 self.detailPanel.ShowPatientInfo(self.listPanel.list.GetItemText(self.currentItem))
21 self.SetSelection(1)
22
23class PatientManageListPanel(wx.Panel,PatientManageBase):
24 """
25 当天登记一览列?br /> 26
"""
27 def __init__(self, parent):
28 wx.Panel.__init__(self, parent, wx.ID_ANY, style=wx.WANTS_CHARS)
29 PatientManageBase.__init__(self)
30 data=utils.list2dic(self.pm.listTodayRegInfo())
31 self.list=DataListCtrl.DataListCtrl(self,data)
32 self.Bind(wx.EVT_SIZE, self.OnSize)
33 self.list.Select(0)
34
35 def OnSize(self, event):
36 w,h = self.GetClientSizeTuple()
37 self.list.SetDimensions(0, 0, w, h)
38
39class PatientManageDetailPanel(PatientManagePanelBase):
40 """
41 当天登记详细信息
42 """
43 def __init__(self, parent):
44 PatientManagePanelBase.__init__(self,parent,False)
45 self.btnAdd.Show(False)
46 self.btnCancel.Show(False)
47 self.lblNew.Show(False)
48
49 def InitBasicInfo(self):
50 self.idType=self.pm.listAllIdTypes()
51 self.sex=['?/span>','?/span>']
52
53 def InitDiseaseHistory(self):
54 self.diseaseList=self.dic.listAllAvailableDiseaseTypeName()
55
56 def InitPrescription(self):
57 self.medsList = self.dic.listAllAvailableGoodsName()
58
59 def InitControlPanel(self):
60 self.operator=self.pm.listAllOperatorNames()
61
62 def SetEditable(self,editable=True):
63 controls=[self.cbIdType,self.txtPatientId,self.txtId,self.txtName,self.cbSex,self.dpcBirthday,self.txtAge,self.txtAddress,
64 self.txtRegId,self.diseaseType,self.txtDisease,self.dpcStart,self.txtSuggestion,
65 self.meds,
66 self.cbOperator
67 ]
68 for control in controls:
69 control.Enable(editable)
70
71 def ShowPatientInfo(self,registrationId):
72 vals=self.pm.getPatientInfo(registrationId)
73 self.FillData(vals)
74
75 def FillData(self,dic):
76 """
77 填充控g
78 """
79 d=wx.DateTime()
80
81 self.cbIdType.SetValue(dic.get('idtype'))
82 self.txtId.SetValue(dic.get('identityid'))
83 self.txtPatientId.SetValue(dic.get('patientid'))
84 self.txtName.SetValue(dic.get('name'))
85 self.cbSex.SetValue(dic.get('sex'))
86
87 list=dic.get('birthday').split('-')
88 d.Set(int(list[2]),int(list[1])-1,int(list[0]))
89 self.dpcBirthday.SetValue(d)
90
91 self.txtRegId.SetValue(dic.get('registrationid'))
92 self.txtAddress.SetValue(dic.get('address'))
93 self.txtDisease.SetValue(dic.get('description'))
94
95 list=dic.get('start').split('-')
96 d.Set(int(list[2]),int(list[1])-1,int(list[0]))
97 self.dpcStart.SetValue(d)
98
99 self.txtSuggestion.SetValue(dic.get('suggestion'))
100 self.cbOperator.SetValue(dic.get('operator'))
101
102 self.diseaseType.Set(self.diseaseList)
103 for item in dic.get('diseases'):
104## print item
105 for i in self.diseaseList:
106## print i
107 if item==i:
108 self.diseaseType.Check(self.diseaseList.index(i),True)
109
110 self.meds.Set(self.medsList)
111 for item in dic.get('meds'):
112 for i in self.medsList:
113 if item==i:
114 self.meds.Check(self.medsList.index(i),True)
刚开始我把选中单条记录(OnItemSelected)和双d条记?OnDoubleClick)q两个方法也写在DataListCtrlcMQ但后来发现q样写不太通用Q于是把它们提出来写在PatientManageTodayListPanelq个cMQ然后在q里l定DataListCtrl的单选和双击事g?br />之前遇到一个问题:(x)如何在单击菜单后打开一个wx.Notbook的PageQ再ơ单击这个菜单时能自动蟩到这个打开的Page上?查过wx.Notebook的API文Q没有发现现存的查找Page的方法,于是p己想办法解决Q后来我是这栯决的Q?br />用一个字典来记录Page是否打开Q以?qing)它的index
然后在显C个Page的时候更新这个字典:(x)如何跛_打开的Page?/span>
1 ##用于记录菜单界面是否已经打开
2 self.dicMenu={'病h资料录入':(False,-1),
3 '病h资料修改':(False,-1),
4 '当天登记信息一?/span>':(False,-1)
5 }
6
7 def ShowPatientInfoReg(self):
8 """
9 昄病历登记界面
10 """
11 if self.dicMenu.get('病h资料录入')[0]==True:
12 self.win.SetSelection(self.dicMenu.get('病h资料录入')[1])
13 else:
14 pm =PM.PatientManageRegPanel(self.win)
15 exists=self.win.AddPage(pm, "病h资料录入",select=True)
16 index=self.win.GetPageCount()-1
17 text=unicode(self.win.GetPageText(index)).encode('cp936')
18 self.dicMenu.__setitem__('病h资料录入',(exists,index))
19 self.Refresh()
截图Q?br />
【下期提C?/font>完成病历l合查询
]]>
]]>
五一前真是太忙了,没空研究q个pȝ,不过雉碎地有做一?但上节计划要做的字典l护模块遇到一些技术问?暂且攑处理,q周主要?/font>病h资料登记模块的核心业务做好了,截图如下:
字典l护模块遇到的问题有:
1.怎么用grid完成增加,更新?qing)删除记?br />2.如何做成一个通用的模板应用在所有字典的l护?br />【下期提C?font color="#000000">完成病h资料修改模块
]]>
沉寂一整周了,今天l于把主界面做好了?br />最q?天特别忙Q赶上公叔R目发布最新版本,一大堆的测试Q务不敢懈怠,当学?fn)与工作冲突时还是应当以工作为重Q学?fn)暂放一边,所以这ơ学?fn)比计划多花了几天,不过虽然内容很少Q但也遇C几个NQ?br />1.如何l窗体加上一个背景图片?
2.如何使HtmlWindow内的链接正常打开Q?br />我想在窗体上昄一张背景图片,于是ȝwxPthon 的API文Q想找找有没有像VB里的frame的picture属性,但出乎意料的Ӟwx.Window中ƈ没有q种属性,虽然可以在此之上再放一个图片控Ӟ来达到同L(fng)效果Q正在发愁,于是拿v?strong>wxPython in Action ?下文UCؓ(f)PA)q本书快速探索一遍,l于扑ֈ办法了,原来要实现这L(fng)效果Q需要徏立定Ӟ参照里面的办法写了一个可以配|背景图片的windowc?import wx
2
3class ImageBackGroundWindow(wx.Window):
4 def __init__(self, parent, image):
5 wx.Window.__init__(self, parent)
6 self.photo = image.ConvertToBitmap()
7 self.positions = [(0,0)]
8 self.Bind(wx.EVT_PAINT, self.OnPaint)
9 def OnPaint(self, evt):
10 dc = wx.PaintDC(self)
11 brush = wx.Brush("sky blue")
12 dc.SetBackground(brush)
13 dc.Clear()
14 for x,y in self.positions:
15 dc.DrawBitmap(self.photo, x, y, True)
def OnLinkClicked(self, linkinfo):
2 import webbrowser
3 webbrowser.open(linkinfo.GetHref(), 1)
ȝ面和关于H体截图如下Q?br />
【下期提C?/font>
完成字典理模块
]]>
wxPthon是一个非常强大的界面制作模块Q下载地址?a >http://www.wxpython.org/。wxPython安装包中附送了大量实例代码Q每个界面控件的使用Ҏ(gu)都有介绍Q同时还可以L看在Uapi文http://www.wxpython.org/docs/api/wx-module.htmlQ这个文档的风格很像javadocQ习(fn)惯了java api 文的h一看就清楚Q如果想pȝC解一下wyPython则可以下载官Ҏ(gu)荐的?strong>wxPython in Action 》一书?br />_略览一下wyPtyhon DemoQ便立即开始尝试编写C(j)linicOS的登录模块,首先认一下界面表现力和功能:(x)
界面元素Q?br />1.一个登录窗?br />2.帐号标签?qing)文本框Q密码标{֏(qing)文本?br />3.定和取消按?br />功能Q?br />1.单击『确定』按钮时能验证输入的帐号和密码是否正,如果正确则显CClinicȝ?TODOQ暂时让它显CZ个成功消息框)Q否则提C“帐h密码错误”?br />2.单击『取消』按钮退出登录模?br />l过一番努力,l于把界面画好了Q暂时丑了点Q待以后l它容?br />
不过画这点界面很不方便,得有点耐心Q特别是控g的位|要全手工地调坐标,q对于缺乏方向和位置感的我来说更是痛?img height="19" src="http://m.tkk7.com/Emoticons/red_smile.gif" width="19" border="0" />Q想找一个可以做界面用的IDE for pythonQ却始终没找刎ͼ没办法,只好痛苦忍受到底?br />以下是完整的代码Q?br />
1#!/usr/bin/python
2# -*- coding: UTF-8 -*-
3# $Id: login.py 12 2006-04-11 03:20:48Z Administrator $
4"""
5d模块
6"""
7import wx
8import dbconnect,utils
9
10class LoginFrame(wx.Frame):
11 """
12 d界面
13 """
14 def __init__(self):
15 """
16 创徏一个自定义的窗?br />17
"""
18 loginstyle=wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER|
19 wx.MINIMIZE_BOX|
20 wx.MAXIMIZE_BOX|
21 wx.CLOSE_BOX)
22 wx.Frame.__init__(self,None,id=-1,title="d",style=loginstyle,size=(400,300))
23
24 panel=wx.Panel(self)
25
26 lblAccount=wx.StaticText(panel,label="帐 号Q?/span>",pos=(100,100))
27 self.txtAccount=wx.TextCtrl(panel,size=(125,-1),pos=(160,100))
28
29 lblPwd=wx.StaticText(panel,label="密 码Q?/span>",pos=(100,150))
30 self.txtPwd=wx.TextCtrl(panel,size=(125,-1),pos=(160,150),style=wx.TE_PASSWORD)
31
32 btnOK=wx.Button(panel,label="定(&O)",pos=(150,200))
33 self.Bind(wx.EVT_BUTTON,self.OnClickOK,btnOK)
34
35 btnQuit=wx.Button(panel,label="取消(&C)",pos=(240,200))
36 self.Bind(wx.EVT_BUTTON,self.OnClickQuit,btnQuit)
37 self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
38 def MessageBox(self,description,title):
39 dlg = wx.MessageDialog(self,description,
40 title,
41 wx.OK | wx.ICON_INFORMATION
42 #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
43 )
44 dlg.ShowModal()
45 dlg.Destroy()
46 def OnClickOK(self,event):
47 """
48 单击定按钮响应事g
49 """
50 sql="""
51 select count(id) as count from d_operator
52 """
53 sql=sql+" where account='"+self.txtAccount.GetValue()+"'"+" and password='"+utils.encrypt(self.txtPwd.GetValue())+"'"
54
55 conn=dbconnect.SqliteConnection()
56 list=conn.execute(sql)
57 if int(list[0][0])==1:
58 self.MessageBox("d成功","成功")
59 else:
60 self.MessageBox("帐号或密码错误,请重新输?","d")
61 def OnClickQuit(self,event):
62 """
63 单击取消按钮响应事g
64 """
65 self.Close(True)
66 def OnCloseWindow(self,event):
67 self.Destroy()
68class LoginApp(wx.App):
69 """
70 d模块
71 """
72 def OnInit(self):
73 frame=LoginFrame()
74 frame.Show()
75 return True
76
77if __name__=='__main__':
78 app=LoginApp()
79 app.MainLoop()
1.导入md5和base64Qimport md5,base64
2.创徏一个md5对象实例Q?md5.new("字符?).digest()
3.生成的md5串做个base64转换Qbase64.b64encode(md5.new("字符?).digest()q个q回的就是加密字W串?br />
【下期提C?/font>逐步深入学习(fn)wxPythonQ?/font> 制作ClinicOSȝ?img src ="http://m.tkk7.com/joinose/aggbug/40459.html" width = "1" height = "1" />
]]>
Python要操作SQLite可以使用Pyslqite模块Q最新的模块可以?a >www.pysqlite.org下蝲Q当初下载的时候顺便简单看了看usage-guide(http://initd.org/pub/software/pysqlite/doc/usage-guide.html)Q觉得挺单的Q没有仔l研I便开始考虑~写Q我考虑把sqlite的访问写成一个类Q在cȝ初始化和销毁时候分别徏立连接和关闭q接Q然后再d一个执行sql语句的方法,׃传入的sql可能没有q回g可能有返回|而返回的值可能是单列g可能是多条记录,Zq种复杂情况Q就让这个方法返回一个列表,它q回什么,通通加到列表中然后q回Q我觉得在这一点上Qpython比其它语a方便多了。下面是q个c:(x)#!/usr/bin/python
# -*- coding: UTF-8 -*-
# $Id: dbconnect.py 8 2006-04-08 14:21:32Z Administrator $
import ConfigParser
import locale
from pysqlite2 import dbapi2 as sqlite
class SqliteConnection:
def __init__(self,dbname):
"""
初始化数据库q接
"""
self.conn = sqlite.connect(dbname)
def execute(self,sql):
"""
执行传入的sql语句,q回一个元l或者None
"""
self.cu=self.conn.cursor()
self.cu.execute(sql)
self.conn.commit()
self.rows=[]
for self.row in self.cu:
self.rows.append(self.row)
return self.rows
def __del__(self):
"""关闭数据库连?/span>"""
self.conn.close()
def test():
"""试Ҏ(gu)"""
config=ConfigParser.ConfigParser()
config.read('config')
dbname=config.get('SQLiteDB','filename')
test= SqliteConnection(":memory:")
test.execute("create table person(lastname, firstname)")
test.execute("insert into person(lastname,firstname) values('?,'?)")
test.execute("insert into person(lastname,firstname) values('?,'?)")
if __name__=='__main__':
test()
Traceback (most recent call last):
File "D:\source\dbconnect.py", line 49, in
?
test()
File "D:\source\dbconnect.py", line 42, in
test
temp=test.execute("select * from person")
File "D:\source\dbconnect.py", line 22, in
execute
self.cu.execute(sql)
pysqlite2.dbapi2.OperationalError: Could not decode to UTF-8 column firstname wi
th text ?br />既然出错了,那么大概是这几种情况Q?br />1.pysqlite不支持中?br />2.sqlite不支持中?br />3.代码Z问题
出错之后Q经q测试,排除W??两种可能Q?br />于是我仔l简单代码,可还是没有找到出错原因,于是x看pysqlite源代码,可是他的代码是封闭在一个pyd的二q制文g中的Q没办法查看Q于是去下蝲pysqlite的源代码Q拿到源代码后在pysqlite-2.2.0\src\cursor.cq个代码中找COperationalError错误cdQ知道原来是字符转换时出q个错。于是我p试将q回D{为可是我弄了很久都没有弄好,在网上google一下也没有扑ֈq方面的资料Q找了一天了也没有找到解决的办法Q无奈之下险些泄气。虽然之前看qpysqlite文Q但看得不仔l,只是单浏览,当时只是惌东西应该挺简单的Q例子也够详l就没有花太多时间去看文,为得也是节省旉。现在遇到问题了Q还是老老实实仔l看看pysqlite文吧。果然不枉我滴着D水把它看完,l于扑ֈ原因了,原来pysqlite中有?span class="p_identifier">con.text_factory可以解决q个问题Q这个参数默认值是unicode Q现在只需要把它设|成str可以了Q?br />
1#!/usr/bin/python
2# -*- coding: UTF-8 -*-
3# $Id: dbconnect.py 8 2006-04-08 14:21:32Z Administrator $
4import ConfigParser
5import locale
6from pysqlite2 import dbapi2 as sqlite
7
8class SqliteConnection:
9
10 def __init__(self,dbname):
11 """
12 初始化数据库q接
13 """
14 self.conn = sqlite.connect(dbname)
15 self.conn.row_factory = sqlite.Row #加上q句才能使用列名来返回?/span>
16 self.conn.text_factory=str #加上q一?否则出现"Could not decode to UTF-8 column"错误
17 def execute(self,sql):
18 """
19 执行传入的sql语句,q回一个元l或者None
20 """
21 self.cu=self.conn.cursor()
22 self.cu.execute(sql)
23 self.conn.commit()
24
25 self.rows=[]
26 for self.row in self.cu:
27 self.rows.append(self.row)
28 return self.rows
29 def __del__(self):
30 """关闭数据库连?/span>"""
31 self.conn.close()
32def test():
33 """试Ҏ(gu)"""
34 config=ConfigParser.ConfigParser()
35 config.read('config')
36 dbname=config.get('SQLiteDB','filename')
37
38 test= SqliteConnection(":memory:")
39 test.execute("create table person(lastname, firstname)")
40 test.execute("insert into person(lastname,firstname) values('?,'?)")
41 test.execute("insert into person(lastname,firstname) values('?,'?)")
42 temp=test.execute("select * from person")
43 print temp
44 encoding = locale.getdefaultlocale()[1]
45 print str('W一条记?').decode(encoding)+str(temp[0][1]).decode(encoding)+str(temp[0][0]).decode(encoding)
46 print str('W二条记?').decode(encoding)+str(temp[1][1]).decode(encoding)+str(temp[1][0]).decode(encoding)
47 assert str(temp[0][1]).decode(encoding)+str(temp[0][0]).decode(encoding)==str("张三").decode(encoding)
48if __name__=='__main__':
49 test()
]]>
1.能否保存复杂数据Q支持Blob?br />2.支持自动~号。但前提是将主键一定要是Integercd。能自动Ҏ(gu)当前记录最大值向下l编受?br />3.支持标准SQL语句。对数据cd(g)查不严格Q能自动数据类型{成SQLite标准数据cdQ这一点在脚本UL很管用,能将其它数据库管理系l的脚本直接导入Q但要注意避免用SQLite暂不支持的命令?br />4.支持触发器。这个功能不错。什么时候支持存储过E就更好了,^_^
对SQLite了解q不是很深入Q边用边学吧?br />开始着手徏数据库,搜烦(ch)了一下数据库模型工具Q以前没有用q什么这斚w的工P随便搜到一个CASEStudio。用了一下,感觉功能q不错,支持很多数据库,能自动生成数据库脚本Q可惜不支持SQLite数据库引擎。胡q了一通,l于把ClinicOS数据库E-R囄好了Q?br />
也顺便生成了数据库脚本,l过雉散散的近5个小时的努力Q数据库l构ȝ搭徏好了?br />【下期提C?/font>准备学习(fn)Python了,先学?fn)PySQLiteQ解决编写数据库d问题
]]>
工作d很重Q没什么时间学?fn),很不?gu)挤出一Ҏ(gu)间来研究我的学习(fn)d?br />q一节我把题目叫作《需求分析》实?img height="19" src="http://m.tkk7.com/Emoticons/red_smile.gif" width="19" border="0" />......惭愧。没有学qY件工E,更没有做q需求分析,只是在凭借自q惛_然来|列功能Q打有I的时候去找本好书好好学学软g工程。接下来q是|列一下我的想法吧Q我觉得q样的一个小pȝ应该包括以下功能Q?br />一.病h病史案理
1.登记病h基本信息
2.登记病h本次病历
3.登记本次病h症状、医生处斏V所用治疗药?br /> 4.打印病历?br /> 5.查询病史案
?药品理
1.药品入库登记
2.入库审核
3.药品出库登记Q包括报废出库及(qing)领药出库
4.出库审核
5.物品状态提醒:(x)q期药品警戒,库存数量警戒
6.入库查询?qing)统?br /> 7.库存查询?qing)统?br /> 8.出库查询?qing)统?br /> 9.报废药品?qing)统?br />?财务l算
1.病h收费登记Q诊断费+药品?br /> 2.药品采购支出登记
3.每日收支报表
4.每月收支情况报表
5.q度收支l计分析?/font>
【下期提C?/font>要学?fn)的东西很多Q下来我惌是从单入手,先学SqliteQ不知道有没有什么好用的用来写Sqlite脚本的客L(fng)工具?