如果选项卡中已有两个条件,则更新

2024-09-30 01:23:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个python脚本和一些SQL代码,我正在努力制作if语句。我有两个ID,如果它们已经存在,那么Logtext应该被更新,如果它们不存在,那么它应该用所有信息创建一个新的

TextJobName = str(JenkinsJobName)
TextBuildNr = str(JenkinsBuild)
TextJobId   = str(TestJobId)
# Security since Jenkin requires a username and code
urllib3.disable_warnings()
req = requests.get(JenkinsLog_URL, auth=(user, pw), verify=False)
# Puts the console text output in logText
logText = pymysql.escape_string(req.text)
sqlConnection = connectionObject.cursor()
SendingLogFile = f"INSERT INTO testreportingdebug.logtexts(LogTextData, LogID, BuildID, JenkinsJobName) VALUES('{logText}', '{TextJobId}', '{TextBuildNr}', '{TextJobName}');"
sqlConnection.execute(SendingLogFile)

我怎么做这样的东西

SendingLogFile = f"IF testreportingdebug.logtexts(LogID, BuildID) IS SAME AS VALUES('{TextJobId}', '{TextBuildNr}') THEN UPDATE testreportingdebug.logtexts(LogTextData) VALUES('{logText}')
ELSE 
INSERT INTO testreportingdebug.logtexts(LogTextData, LogID, BuildID, JenkinsJobName) 
VALUES('{logText}', '{TextJobId}', '{TextBuildNr}', '{TextJobName}');"

Tags: textreqvaluesstrlogidbuildidlogtextlogtextdata

热门问题