您的位置:首页 > 编程语言 > Python开发

python 以nosql方式连接mysql handlersocket插入操作获得变量值方法

2012-05-04 20:51 921 查看
ubuntu11.10安装mysql+handlersocket

/article/7079515.html

何为pyhs?简单来说,就是封装了接口,实现python以nosql方式连接mysql数据库,对数据库进行一些操作。

pyhs is a pure Python client (with optional C speedups) for HandlerSocket plugin to MySQL database. In short, it provides access to the data omitting the SQL engine in a NoSQL-like interface. It allows all simple operations (get, insert, update, delete) over indexed data to perform considerably faster than by usual means.

安装方法:

http://packages.python.org/python-handler-socket/installation.html

简明教程:

http://packages.python.org/python-handler-socket/usage.html

进入主题,在update操作时,使用变量是没错的:

from pyhs import Manager

attendant_id = '222'
newname = 'wxb'
newpwd = '123456'

hs = Manager()
name = '2a'

data=hs.update('final','kf_attendant','=',['AD_ID','AD_Name','AD_Password'],[attendant_id],[attendant_id,newname,newpwd],None,1,0,True)


但是进行insert操作时,直接使用变量名就一直出错“SystemError: NULL result without error in PyObject_Call”,结果使用str()函数解决了~

from pyhs import Manager
import uuid

hs = Manager()

newid = uuid.uuid1()
newname = 'aaa'
newpwd = '123'

hs.insert('final','kf_attendant',[('AD_ID',str(newid)),('AD_Name',str(newname)),('AD_Password',str(newpwd))])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: