简体   繁体   中英

How to use the Input Dialog to execute SQL queries

Is it possible to use the inputdlg function 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:

搜索栏从数据库表中搜索n列

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM