使用占位符在OrientDB中参数化查询
我正在使用pyorient并希望参数化查询——我假设command()允许占位符,但找不到任何文档。我特别希望按照postgres“%”(name)的构造使用dict()args,但也可以使元组/列表工作 我用我的使用占位符在OrientDB中参数化查询,orientdb,pyorient,Orientdb,Pyorient,我正在使用pyorient并希望参数化查询——我假设command()允许占位符,但找不到任何文档。我特别希望按照postgres“%”(name)的构造使用dict()args,但也可以使元组/列表工作 我用我的python\u测试数据库尝试了您的案例: 数据集: import pyorient db_name = 'python_test' user = 'root' pwd = 'root' print("Connecting...") client = pyorient.Orien
python\u测试
数据库尝试了您的案例:
数据集:
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'}
我使用了两个参数:
-->名称
李>字符串
-->姓氏
李>字符串
命令()
函数中
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'}
输出:
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'}
希望它能有所帮助谢谢数据集,我更喜欢使用驱动程序替换,而不是使用我自己的,因为它将(a)防止注入,(b)可能允许重复使用查询计划。我不想把事情搞得乱七八糟。这并不是在回答最初的问题。