Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update inc_array.nss to remove PRIMARY KEY status of index #1687

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

Tildryn
Copy link
Contributor

@Tildryn Tildryn commented Jul 24, 2023

PRIMARY KEY status of index prevents INSERT operations from working correctly, as when shifting the entries' positions the operation fails due to the constraint.

PRIMARY KEY status of index prevents INSERT operations from working correctly, as when shifting the entries' positions the operation fails due to the constraint.
@Daztek Daztek merged commit 92e3b7a into nwnxee:master Jul 25, 2023
5 checks passed
@ELadner
Copy link
Collaborator

ELadner commented Jul 25, 2023 via email

@Tildryn
Copy link
Contributor Author

Tildryn commented Jul 25, 2023

It shouldn't be an issue since the 'ind' field for the index is an internal implementation detail. The user never manipulates the 'ind' field in the table directly. Inserting multiple instances of the same key will result in two records with different indices.

The issue is here, in Array_Insert_Str:

if (index >= 0 && index <= rows) {
    // index is passed as an integer, so immune (as far as I know) to SQL injection for a one shot query.
    ExecuteStatement("UPDATE "+GetTableName(tag, obj)+" SET ind = ind + 1 WHERE ind >= "+IntToString(index), obj);
    // Element, however, is not.
    string stmt = "INSERT INTO "+GetTableName(tag, obj)+" VALUES ( @ind, @element )";
    sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
    SqlBindInt(sqlQuery, "@ind", index);
    SqlBindString(sqlQuery, "@element", element);
    SqlStep(sqlQuery);
}

Since this attempts to update with 'ind = ind + 1', it attempts to change 'ind' to one that already exists (the index above it), and this fails due to the PRIMARY KEY constraint on 'ind'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants