gpt4 book ai didi

MySQL 键有点奇怪

转载 作者:行者123 更新时间:2023-11-29 07:07:38 25 4
gpt4 key购买 nike

我在使用 MySQL 时遇到了一些以前从未见过的奇怪问题。基本上,我需要在表中输入相同的条目 x 次。主键是自动递增的,所以不应该有重复值的问题。但是,它采用了最后几列并且似乎将它们全部聚集成一个值并将其用作键。我得到的错误是:

    Duplicate entry '80-0--2011-06-16-0-1' for key 'idx_mt'

请注意,没有名为 idx_mt 的字段。主键字段称为 ID。 80-0--2011-06-16-0-1 是最后 8 列左右(您可以在 cols 变量中看到它们的名称)连接在一起,他们显然不应该这样做。还有,循环第一次跑完,entry通过了,后面的又和它冲突了。我通过将最后 8 列之一更改为基于循环的值来确认这是问题所在,并且没有出现任何问题。有什么见解吗?

    Dim cols As String = ""
Dim msi As System.Globalization.DateTimeFormatInfo = New System.Globalization.DateTimeFormatInfo()

cols = "TEMPLATE_NAME," & _
"DESCRIPTION," & _
"FORMAT," & _
"SENDER," & _
"`REPLY-TO`," & _
"SUBJECT," & _
"BODYHTML," & _
"BODYTEXT," & _
"CAMPAIGN_ID," & _
"SPLIT_GROUP_ID," & _
"TEMPLATE_IDENTIFIER," & _
"MESSAGE_SEND_DATE," & _
"DAYS_TO_DELAY_SEND," & _
"ACTIVE"

Try
Dim test As Integer = CInt(cmbEffort.Text)
Catch ex As Exception
MsgBox("Please use numerical values from 1 - 6 for the effort #.")
Return
End Try

If (cmbEffort.Text < 1 Or cmbEffort.Text > 6) Then
MsgBox("Please use numerical values from 1 - 6 for the effort #.")
Return
End If

Dim query As String = ""
Dim _date As Date = DateTimePicker1.Value
Dim dateSent As String = ""
Dim html As String = ""
Dim temp As message

If (_date.DayOfWeek <> DayOfWeek.Thursday) Then
MsgBox("Selected date must be a Thursday.")
Return
End If

dateSent = formatDate(_date)

Try
fileStreamIn = New IO.FileStream(txtHTML.Text, IO.FileMode.Open)
streamReader = New IO.StreamReader(fileStreamIn)
Catch ex As Exception
MsgBox("HTML File not found.")
Return
End Try

html = streamReader.ReadToEnd()
html = html.Replace("'", "&apos")

streamReader.Close()

server.query("SELECT * FROM TEMPLATES_TO_COPY WHERE CAMPAIGN_ID = " & cmpgnID)
server.read()

temp = getMessage(cmpgnID.ToString())
temp.bodyText = txtMessage.Text
temp.HTML = html
temp.sendDate = dateSent
temp.description = txtDescription.Text & "_" & cmbEffort.Text
temp.campaignID = cmpgnID
temp.name = temp.name.Replace("MMM", msi.GetMonthName(_date.Month).Substring(0, 3).ToUpper())
temp.name = temp.name.Replace("YY", _date.Year.ToString().Substring(2, 2))

For i As Integer = 1 To cmbEffort.Text
temp.name = temp.name.Replace("X", (i + 1).ToString())
query = "INSERT INTO MESSAGE_TEMPLATES (" & _
cols & ")" & _
"VALUES ('" & temp.name & "','" & temp.description & "','" & temp.format & "','" & temp.sender & "','" & temp.replyTo & "','" & temp.subject & "','" & temp.HTML & "','" & temp.bodyText & "'," & temp.campaignID & "," & 0 & ",'','" & temp.sendDate & "'," & temp.daysToDelay & "," & temp.active & ");"

If (Not server.query(query)) Then
Return
End If
temp.name = temp.name.Replace((i + 1).ToString(), "X")
Next

最佳答案

错误正是它所说的:

 Duplicate entry '80-0--2011-06-16-0-1' for key 'idx_mt'

有一个您定义的名为 idx_mt 的键/索引。此键设置在少数几列之间。正如其他人在评论中指出的那样,所有这些列的值加在一起与表中已有的一行相同,因此导致了这种冲突。

将字段连接在一起的重复条目是 MySQL 显示该键的值(甚至可能存储,我不确定)的方式。它基本上像另一列一样跟踪它。放在那里的值由表中的其他列组成。

当您看到 80-0--2011-06-16-0-1 时,表示此索引中此特定行的字段的值为 80、0、null、2011-06-16、0 和 1。您插入的内容与此冲突。

关于MySQL 键有点奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6363642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com