Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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
我得到一个错误,但我的代码正在工作。Python和PostgreSQL_Python_Postgresql - Fatal编程技术网

我得到一个错误,但我的代码正在工作。Python和PostgreSQL

我得到一个错误,但我的代码正在工作。Python和PostgreSQL,python,postgresql,Python,Postgresql,我并没有在字符串格式化过程中转换所有参数,但我的代码实际上正在工作。有人能告诉我我的代码有什么问题吗? 当我运行此操作时,它返回错误,但当我通过调用Query_Workers()查看工作列表时,似乎我选择的人已成功删除 def Remove_Directors(id, name): conn = None try: # read the connection parameters params = config() # conne

我并没有在字符串格式化过程中转换所有参数,但我的代码实际上正在工作。有人能告诉我我的代码有什么问题吗? 当我运行此操作时,它返回错误,但当我通过调用Query_Workers()查看工作列表时,似乎我选择的人已成功删除

def Remove_Directors(id, name):

    conn = None
    try:
        # read the connection parameters
        params = config()
        # connect to the PostgreSQL server
        conn = psycopg2.connect(**params)
        cur = conn.cursor()
        # create table one by one
        #for command in commands:
        #    cur.execute(command)
        SQL = "DELETE FROM directors WHERE id = (%s);"
        #cur.execute("DELETE FROM directors WHERE id = (%s)", (id))
        id = (id, )
        cur.execute(SQL, id)
        # close communication with the PostgreSQL database server
        cur.close()
        # commit the changes
        conn.commit()
        print ("%s has been removed from Directors.") % (name)
    except (Exception, psycopg2.DatabaseError) as error:
        print(error)
    finally:
        if conn is not None:
            conn.close()

def Modify():
打印“选择选项”
选项=原始输入(“按A键添加成员,按R键删除成员,按V键查看成员:”)
如果option.upper()=“A”:
打印“添加成员”
Director\u或\u EventManager=原始输入(“新成员是Director还是event manager?\n按D键表示Director,按E键表示event manager:”)
如果Director\u或\u EventManager.upper()=“D”:
输入的ID\u正确=错误
ID_正确输入时_==False:
id=原始输入(“输入10位id:”)
如果len(id)==10:
输入的ID\u正确=真
其他:
打印“无效ID”
名称=原始输入(“输入名称:”)
添加董事(id、姓名)
如果Director\u或\u EventManager.upper()=“E”:
输入的ID\u正确=错误
ID_正确输入时_==False:
id=原始输入(“输入10位id:”)
如果len(id)==10:
输入的ID\u正确=真
其他:
打印“无效ID”
名称=原始输入(“输入名称:”)
添加事件管理器(id、名称)
elif option.upper()=“R”:
打印“删除成员”
Director\u或\u EventManager=raw\u输入(“该成员是董事还是事件管理者?\n按D代表董事,按E代表事件管理者:”)
如果Director\u或\u EventManager.upper()=“D”:
conn=无
尝试:
params=config()
conn=psycopg2.connect(**参数)
cur=连接光标()
当前执行(“按名称从董事订单中选择id、名称”)
directors=cur.fetchall()
打印(“\tNumber\tID\t\tName”)
ids=[]
名称=[]
计数=1
对于董事中的董事:
打印(“\t%s\t%s\t%s”)%(计数,控制器[0],控制器[1])
id.append(控制器[0])
名称。追加(董事[1])
计数+=1
当前关闭()
除了(异常,psycopg2.DatabaseError)作为错误:
打印(错误)
最后:
如果conn不是无:
康涅狄格州关闭
计数-=1
num_director=int(原始输入(“输入要删除的控制器数量:”))
如果num_控制器计数:
打印“无效条目”
其他:
id=id[num_director-1]
name=名称[id.index(id)]
打印id
印刷品名称
删除董事(id、姓名)
elif option.upper()=“V”:
查询工作人员()
其他:
打印“无效选项”

该错误似乎发生在查询之后,因此它不会影响数据更改,只会影响输出调试

您只需更改这些行:

print ("%s has been removed from Directors.") % (name)

而且:

print ("\t%s\t%s\t%s") % (count, director[0], director[1])
print ("\t%s\t%s\t%s" % (count, director[0], director[1]))

print ("\t%s\t%s\t%s") % (count, director[0], director[1])
print ("\t%s\t%s\t%s" % (count, director[0], director[1]))