I have a table component that populates with database data when a barcode is scanned; currently how it works is when you scan a barcode it queries a row of data out of a database and creates a row with the found data and the barcode inside this table component. Currently in order to not allow the same part to be scanned into this table twice I am storing previousBarcode 1, 2, & 3 (The table wont exceed 4 rows) and comparing the new barcode with each of these variables every time. This seems unsophisticated so my question is: How when a barcode is scanned can I search the barcode column within the table component to see if there is a identical barcode?
Note: This all takes place within a message handler script that gets triggered once a barcode is scanned.
If you're a database to store previous barcode scans, can you make a named query that just checks the database for the barcode ID. If it returns a value, it's a duplicate and you can make somekind of error popup.
The unsophisticaed and best way to ensure uniqueness in a database table - make the desired column(s) your primary key, or, since Ignition doesn't return non-int's nicely yet for getKey, put a UNIQUE INDEX on your column SQL CREATE UNIQUE INDEX.
Then you can follow the pythonic paradigm of try first ask for forgiveness later. Try to insert, in the event the database throws you an error that you're violating the uniqueness constraint, then handle that.