calling sql database from GUI

4 vues (au cours des 30 derniers jours)
Christof
Christof le 24 Juin 2011
[EDIT: 20110625 11:12 CDT - reformat - WDR]
Hi, I tried using the following script in a GUI
global sql_call;
global global_flags;
global global_data;
global global_bdate;
global global_edate;
conn=database('fixedincome', '', '');
ping(conn)
flags=global_flags;
bdate=global_bdate;
edate=global_edate;
flags=find(flags==1);
n=length(flags);
sql_call = strcat('SELECT * FROM fixedincome.instrument', num2str(flags(1)));
for i = 2 : n
c=flags(i);
add_txt = strcat(' INNER JOIN fixedincome.instrument', num2str(c));
add_cond = strcat(' ON instrument', num2str(flags(1)),'.time = instrument', num2str(c),'.time');
sql_call=strcat(sql_call,add_txt,add_cond);
end
if ~isempty(global_bdate) | ~isempty(global_edate);
add_where = strcat(' where ');
if ~isempty(global_bdate);
add_where=strcat(add_where, ' TIME > ', ''', global_bdate,''');
if ~isempty(global_edate);
add_where=strcat(add_where, 'AND');
end;end;
if ~isempty(global_edate);
add_where=strcat(add_where, 'TIME < ',''', global_edate,''');
end;
sql_call= strcat(sql_call, add_where);
end;
curs = exec(conn, sql_call);
data_item = fetch(curs);
data = data_item.data;
global_data = data;
However, it does not load the data. If I execute the script as a separate script manually, it works. If I call the script from the GUI function assigned to a button, it does not load the data. Any ideas how I can work around that?
  1 commentaire
Kaustubha Govind
Kaustubha Govind le 24 Juin 2011
What happens when you set a breakpoint in your GUI code in the button callback and step through the code? It is likely that the data in getting creating in the workspace local to the GUI callback function. Use the function ASSIGNIN to send the data to the base workspace.

Connectez-vous pour commenter.

Réponse acceptée

Anathea Pepperl
Anathea Pepperl le 24 Juin 2011
You need to pass the data. You can use ASSIGNIN as the comment above suggested, or save the data in the handles structure and use the GUIDATA function to update the data.

Plus de réponses (1)

Christof
Christof le 29 Juin 2011
thanks for your help

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by