0

Is it possible to use the inputdlgfunction to execute an SQL query such as below :

    pdbSearchQuery = input('Enter your PDB Code: ', 's');
    curs = fetch(exec(conn, ['SELECT * FROM cath_2_wo_dup WHERE pdbcode = ' '''' pdbSearchQuery '''']));
    pdbSearchResults = curs.Data

I manage to do this by default, using the Command Window to search for columns in a database, but i would like to create a dialog box where users can type in a value to search the database, using the variables i have stated above.

It would look like this at the end:

Search bar to search for n column from the database table

When they click 'OK', it would lead that button to execute another script where it will create the tables and figures for them.

Is this possible to do in inputdlg or is there another function that does this similar method?

1 Answer 1

1

This is absolutely possible and will give you a lot of freedom in your code. For example, modified from the inputdlg help:

prompt = {'Enter table name:','Enter query field:'};
dlg_title = 'Input for query';
num_lines = 1;
def = {'mytable','thatProperty'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
curs = fetch(exec(conn, ['SELECT * FROM ' char(answer{1}) ' WHERE ' char(answer{1}) '= ' '''' pdbSearchQuery '''']));

Should work well. Hope this helps!

Sign up to request clarification or add additional context in comments.

3 Comments

I changed a few names and variables around and i manage to retrieve columns from the database. However, when i ran this code as a script and type in a value in the input field and hit 'OK', MATLAB crashes. Could it be that it can't handle the number of scripts i am executing after the dialog window? I tried not executing anything, it still crashes. Please advise.
@Jeiman, I think it's likely the exec or fetch crashing, do you have multiple database connections at once? Also, when you say "not executing anything", you mean not executing any m-script after the call to the dialog box?
My apologies, i called out my other scripts too early before another script could take place. It's fixed now and working properly. Thank you very much for the explanation and solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.