Skip to content

Commit

Permalink
correct spurious sqlite errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ELadner committed Feb 25, 2024
1 parent 9865013 commit c7703a2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Compatibility/inc_array.nss
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,15 @@ void Array_Erase(string tag, int index, object obj=OBJECT_INVALID)
// if not found, return INVALID_INDEX
int Array_Find_Str(string tag, string element, object obj=OBJECT_INVALID)
{
string stmt = "SELECT IFNULL(MIN(ind),@invalid_index) FROM "+GetTableName(tag, obj)+" WHERE value = @element";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
string stmt;
sqlquery sqlQuery;

// Just create it before trying to select in case it doesn't exist yet.
CreateArrayTable(tag, obj);

stmt = "SELECT IFNULL(MIN(ind),@invalid_index) FROM "+GetTableName(tag, obj)+" WHERE value = @element";
sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);

SqlBindInt(sqlQuery, "@invalid_index", INVALID_INDEX);
SqlBindString(sqlQuery, "@element", element);
if ( SqlStep(sqlQuery) ) {
Expand Down Expand Up @@ -367,6 +374,9 @@ void Array_Insert_Obj(string tag, int index, object element, object obj=OBJECT_I
// Insert a new element at the end of the array.
void Array_PushBack_Str(string tag, string element, object obj=OBJECT_INVALID)
{
// Create it before trhing to INSERT into it. If it already exists, this is a no-op.
CreateArrayTable(tag, obj);

// If rowCount = 10, indexes are from 0 to 9, so this becomes the 11th entry at index 10.
int rowCount = GetRowCount(tag, obj);

Expand Down

0 comments on commit c7703a2

Please sign in to comment.