我正在使用 pyorient 并且想要参数化查询——我假设 command() 允许使用占位符,但找不到任何文档。特别是,我想根据 postgres 的 %(name)s 构造使用 dict() args,但也可以使元组/列表也能正常工作。
问问题
263 次
1 回答
1
我用我的python_test
数据库试过你的情况:
数据集:
我使用了两个参数:
name
--->string
;surname
--->string
;
我将它们传递给command()
函数。
PyOrient 代码:
import pyorient
db_name = 'python_test'
user = 'root'
pwd = 'root'
print("Connecting...")
client = pyorient.OrientDB("localhost",2424)
session_id = client.connect(user, pwd)
print("OK - sessionID: ",session_id,"\n")
if client.db_exists( db_name, pyorient.STORAGE_TYPE_PLOCAL ):
print("DB "+db_name+" already exists\n")
client.db_open(db_name, user, pwd, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_PLOCAL)
name = 'test name'
surname = 'test surname'
vertexes = client.command("SELECT FROM TestClass WHERE name = '" + name + "' AND surname = '" + surname + "'")
for vertex in vertexes:
print(vertex)
else:
print("Creating DB "+ db_name + "...")
client.db_create( db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_PLOCAL )
print("DB " + db_name + " created\n")
client.db_close()
输出:
Connecting...
OK - sessionID: 40
DB python_test already exists
{'@TestClass':{'surname': 'test surname', 'name': 'test name'},'version':1,'rid':'#12:0'}
希望能帮助到你
于 2016-06-16T08:04:26.037 回答