Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用占位符在OrientDB中参数化查询_Orientdb_Pyorient - Fatal编程技术网

使用占位符在OrientDB中参数化查询

使用占位符在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

我正在使用pyorient并希望参数化查询——我假设command()允许占位符,但找不到任何文档。我特别希望按照postgres“%”(name)的构造使用dict()args,但也可以使元组/列表工作

我用我的
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)可能允许重复使用查询计划。我不想把事情搞得乱七八糟。这并不是在回答最初的问题。