- 论坛徽章:
- 0
|
本帖最后由 hlsd665 于 2011-01-22 00:04 编辑
自己建个验证类继承原有验证类,解决了,可是又出现数据库提交错误。是查询和提交的时间间隔太短了,还是两次调用数据库时分别建立了两个连接造成的冲突????????
错误代码如下:- 0.0 (1): SELECT * FROM c_client WHERE years='2011' ORDER BY code
- 0.0 (2): SELECT * FROM c_client WHERE code='105'
- 0.02 (3): INSERT INTO c_client (code, name, years) VALUES ('105', '3213213', '2011')
- 0.0 (4): SELECT last_insert_rowid();
- Traceback (most recent call last):
- File "C:\Python26\lib\site-packages\web\application.py", line 242, in process
- return self.handle()
- File "C:\Python26\lib\site-packages\web\application.py", line 233, in handle
- return self._delegate(fn, self.fvars, args)
- File "C:\Python26\lib\site-packages\web\application.py", line 415, in _delegate
- return handle_class(cls)
- File "C:\Python26\lib\site-packages\web\application.py", line 390, in handle_class
- return tocall(*args)
- File "F:\workspace\dev\finance.py", line 56, in POST
- m_account.newclient(client_data.code,client_data.name,year='2011')
- File "F:\workspace\dev\model\m_account.py", line 12, in newclient
- dbh.insert('c_client',code=code,name=name,years=year)
- File "C:\Python26\lib\site-packages\web\db.py", line 744, in insert
- self.ctx.commit()
- File "C:\Python26\lib\site-packages\web\db.py", line 504, in commit
- ctx.db.commit()
- OperationalError: cannot commit transaction - SQL statements in progress
- 127.0.0.1:4275 - - [22/Jan/2011 00:04:04] "HTTP/1.1 POST /finance/clientsetup" - 500 Internal Server Error
复制代码- #coding:utf-8
- import web
- from model import m_account
- from web import form
- class revalid(form.Validator):
- def __init__(self,msg):
- self.msg = msg
-
- def valid(self, value):
- return m_account.recode(value)
-
- urls = (
- '/', 'index',
- '/system','system',
- '/clientsetup','clientsetup',
- )
- render = web.template.render('templates/finance',base='../base')
- class clientsetup:
- client_form = web.form.Form(
- web.form.Textbox("code",web.form.notnull,revalid('no requ'),description="代码"),
- web.form.Textbox("name",web.form.notnull,description="名称"),
- web.form.Button("submit",type="submit",html="添加")
- )
-
-
- def GET(self):
- clist=m_account.getclientlist('2011')
- f=self.client_form()
- return render.allsetup('客户',clist,'添加客户',f)
- def POST(self):
- f=self.client_form()
- clist=m_account.getclientlist('2011')
- if not f.validates():
- return render.allsetup('客户',clist,'添加客户',f)
- else:
- client_data = web.input()
- m_account.newclient(client_data.code,client_data.name,year='2011')
- raise web.seeother('/clientsetup')
复制代码 m_account代码如下:- #-*-coding:utf-8-*-
- import web
- import dbcon
- dbh=dbcon.dbs()
- def getclientlist(year):
- return dbh.select('c_client',where='years=$year',order = 'code',vars=locals())
- def newclient(code,name,year):
- dbh.insert('c_client',code=code,name=name,years=year)
- def recode(code):
- return not bool(dbh.select('c_client',where='code=$code',vars=locals()))
复制代码 |
|