In my Powerbuilder 19 project, it's about article management. So when I insert a new article, it works fine, and when I update an article, it works fine also, but when I insert another article (after the update), I get an error
sqlstate 23000 - duplicated primary key
with a reference to the article that I inserted first, even though that the reference does not exist.
Note: reference column is primary key; not auto increment and is not null
Here is the script of "new" button
char reference
dwc_article.scrolltorow(dwc_article.insertrow(0))
// Scroll to the newly inserted row
long ll_new_row
ll_new_row = dwc_article.InsertRow(0)
dwc_article.ScrollToRow(ll_new_row)
// Get the current date
date ld_date_creation
ld_date_creation = today()
string ls_formatted_date
ls_formatted_date = String(ld_date_creation, "yyyy-mm-dd")
// Set the current date to the "date_de_creation" column
dwc_article.SetItem(ll_new_row, "date_de_creation", ls_formatted_date)
dwc_article.modify("reference.Protect='0'") // This removes input capability from all columns
dwc_article.modify("name.Protect='0'")
dwc_article.modify("prix.Protect='0'")
dwc_article.modify("date_de_creation.Protect='1'")
and here is the script of "save new article" button
dwc_article.accepttext()
dwc_article.update()
int li_sqlcode
commit using sqlca;
// Check for SQL errors
li_sqlcode = sqlca.sqlcode
if li_sqlcode = 0 then
MessageBox("Success", "The article was successfully added.")
else
MessageBox("Error", "Failed to add the article. SQLCode: ")
end if
// Refresh the report
dwc_report.Retrieve()
So you say the table is not set up to autoincrement the primary key. It does not look like you are providing the key value in your second entry (insert). How then is the system supposed to determine what the key value is for the new row?