I am building an App, DUNA, that references and writes data to an sqlite database. One of the functions I have is to check if the UID from a table already exists. I do this for multiple tables with the following public helper function:
methods (Access = public)
function results = checkUID(app,UID,table)
conn = sqlite(app.database);
if table == 'Deployment_Table'
elseif table == 'Logger_Table'
elseif table == 'Releaser_Table'
elseif table == 'Satellite_Table'
sqlq = ['SELECT ' cat ' FROM ' table ' WHERE ' cat ' = "' UID '"'];
results =fetch(conn, sqlq);
In general, this works, it allows me to determine if the UID already exists across multiple tables.
I have created a panel, in which I've constructed a form for users to fill out with. There is a button function ('app.SubmitDataButtonPushed') at the bottom of the form, which accesses the data manually entered into the form and organizes it. For this post, it does two things: it generates a deployment ID that needs to be unique (e.g. not in the database) and it references the database to make sure we have records of each piece of equipment (e.g. it should be in the database). This is all done with the checkUID function above.
For the Deployment_ID check the function works as expected. The code is:
function SubmitDataButtonPushed(app, event)
station = app.StationIDDropDown.Value;
depDate = app.DeploymentDateDatePicker.Value;
depDst= datetime(depDate, 'Format','yyyyMMdd');
Deployment_ID = [station '_' char(depDst)];
dbP =checkUID(app,Deployment_ID, 'Deployment_Table');
uialert(fig, ['Error: Deployment ID ' Deployment_ID ' already exists.'], 'Database Error', "Icon","error");
Great. This works both when dbP is and is not empty. If it has data, it triggers the uialert, as intended. However, when I try to modify this code to see if the releaserUID is present, I get the following errors:
releaserTypes = app.ModelDropDown_2.Value ;
if releaserTypes == 'LRT (Sonardyne)'
elseif releaserTypes == 'AR-60 (Sub Sea Sonic)'
elseif releaserTypes == 'R500 (Teledyne)'
releaserID = [prefix, char(app.ReleaseCodeEditField.Value)];
dbR =checkUID(app,releaserID, 'Releaser_Table');
uialert(fig, ['Error: releaser ID ' releaserID ' is not in database. Add information on releaser to database before adding deployment.'], 'Database Error', "Icon","error");
This does not work. It gets hung on the dbR... line. When I run this, specifically stopping on the dbR line to make sure all of the variables are as they should be, I can see nothing out of place. The 'releaserID' variable is produce as a char string, as expected, and in my test runs, it matches an UID in the database. However, this is the error I get:
Arrays have incompatible sizes for this operation.
Error in DUNA/checkUID (line 101)
if table == 'Deployment_Table'
Error in DUNA/SubmitDataButtonPushed (line 206)
dbR =checkUID(app,releaserID, 'Releaser_Table');
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
I have tried this a bunch of different ways. Feeding different variables (LRT vs AR60, etc.). When I run the code manually in Matlab it works. Any ideas what is going on here? I just don't understand why it works with one set of data, and not another.
The table names for the database are correct.
Cheers!