Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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
can';t更新日期值MySQL python_Python_Mysql - Fatal编程技术网

can';t更新日期值MySQL python

can';t更新日期值MySQL python,python,mysql,Python,Mysql,我试着研究了几个与这个问题类似的问题,但出于某种原因,它们似乎仍然不适合我 我收到错误信息: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET stockPriceRef.ticker='NGVT' SET stockPriceRef.updateDa

我试着研究了几个与这个问题类似的问题,但出于某种原因,它们似乎仍然不适合我

我收到错误信息

(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET stockPriceRef.ticker='NGVT' SET stockPriceRef.updateDate='2020-05-25 01:22:1' at line 1")
'UPDATE stockPriceRef SET stockPriceRef.id=%s SET stockPriceRef.ticker=%s SET stockPriceRef.updateDate=%s SET stockPriceRef.open=%s SET stockPriceRef.high=%s SET stockPriceRef.low=%s SET stockPriceRef.close=%s SET stockPriceRef.volume=%s WHERE id=%s;'
我在没有时间的情况下尝试了这个方法,它很有效,但是我仍然想更新时间戳

我尝试使用的查询

(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET stockPriceRef.ticker='NGVT' SET stockPriceRef.updateDate='2020-05-25 01:22:1' at line 1")
'UPDATE stockPriceRef SET stockPriceRef.id=%s SET stockPriceRef.ticker=%s SET stockPriceRef.updateDate=%s SET stockPriceRef.open=%s SET stockPriceRef.high=%s SET stockPriceRef.low=%s SET stockPriceRef.close=%s SET stockPriceRef.volume=%s WHERE id=%s;'
我这样称呼它:

#上面提到的更新语句
update\u stock\u price\u ref=create\u update\u prepared\u语句('stockPriceRef',self.sql)
#获取当前时间并格式化它
time=datetime.datetime.now().strftime(“%Y-%m-%d%H:%m:%S”)
#调用execute语句并传递值
self.sql.execute_query(update_stock_price_ref,values=(ticker_id,ticker,time,price_summ['open'],price_summ['high']),
价格总和['low',价格总和['previousClose',价格总和['volume',股票代码))
def执行_查询(self,query,value=None):
“”“执行查询”“”
#如果您想使用ssh密码,请使用-ssh\u password='your ssh password',如下
数据=无
#打印('执行查询:{}'。格式(查询))
cursor=self.sql\u conn.cursor()
尝试:
如果(值为无):
data=cursor.execute(查询)
data=cursor.fetchall()
其他:
如果(类型(值)不是元组):
raise TypeError(f'值应为tuple类型,{type(Values)}'类型)
data=cursor.execute(查询、值)
data=cursor.fetchall()
如果查询中的('INSERT'或查询中的'UPDATE'):
self.sql\u conn.commit()
例外情况除外,例如:
印刷品(ex)
打印('查询:{}'。格式(查询))
打印(f'values:{values}')
一无所获
#
返回数据
我也尝试过从mySQL控制台执行该语句,但由于某些原因,它仍然可以工作,但当我从python调用它时,它就不能工作了。在这一点上,任何事情都会很有帮助

编辑: 以下是我已经研究过的一些其他问题。

编辑2 多亏了,他们指出我在查询中有不止一个集合。查看了mySQL文档,发现我的查询还存在一些其他问题

UPDATE stockPriceRef SET id=%s,ticker=%s,updateDate=%s,open=%s,high=%s,low=%s,close=%s,volume=%s WHERE id=%s;
使用此查询

UPDATE
   stockPriceRef 
SET
   stockPriceRef.id =% s, stockPriceRef.ticker =% s, stockPriceRef.updateDate =% s, stockPriceRef.open =% s, stockPriceRef.high =% s, stockPriceRef.low =% s, stockPriceRef.close =% s, stockPriceRef.volume =% s 
WHERE
   id =% s;
有关准备好的报表,请参阅: 使用此查询

UPDATE
   stockPriceRef 
SET
   stockPriceRef.id =% s, stockPriceRef.ticker =% s, stockPriceRef.updateDate =% s, stockPriceRef.open =% s, stockPriceRef.high =% s, stockPriceRef.low =% s, stockPriceRef.close =% s, stockPriceRef.volume =% s 
WHERE
   id =% s;
有关准备好的报表,请参阅:

查询中只允许一个
集合
。是的,这给了我正确的方向!谢谢。我也看到了一些其他错误。在查询中只允许一个
SET
。是的,这让我找到了正确的方向!谢谢。我也看到了一些其他的错误。