Passing variables in query retrieves no data ...

1 view (last 30 days)
Why it is not displaying any data?.... When I pass number in protmass like protmass=30000 it shows output but not in this case. Thanks in advance.
Code is:
for i=1:fullindex
str = mw(i);
if isempty(str)==1
continue;
end
spot_name=spots(i);
spot_name=char(spot_name);
parts = regexp(str,'D','split');
per=parts{1}(2);
protmass=parts{1}(1); % class of protmass is cell
if strcmp(per,' Approx')
display('IN Approx')
protmass=str2double(protmass);
Upmax= num2str(protmass+900);
Upmin= num2str(protmass-900);
query=['select Sequences from Pro where MW between (',Upmin,') AND (',Upmax,')'];
curss=exec(con,query);
curss=fetch(curss);
seq=get(curss,'Data');
display(seq);
end
Output
seq =
'No Data'
  5 Comments
Geoff Hayes
Geoff Hayes on 13 Sep 2015
Rafia - can you show us what value is assigned to query so that we can see how your SQL command has been constructed?
Rafia Raja
Rafia Raja on 13 Sep 2015
sqlquery = 'select MW from Table1';
curs = exec(conn,sqlquery);
curs = fetch(curs);
mw=curs.data
Below are the few values from data base
'300000 D Approx'
'300000 D Approx'
'300000 D Approx'
'500000 D Approx'
'700000 D Approx'
'300000 D Approx'
'300000 D Approx'
'300000 D Approx'
'500000 D Approx'
'100000 D Approx'
'700000 D Approx'
After splitting only numerical value is passed in protmass

Sign in to comment.

Answers (2)

the cyclist
the cyclist on 12 Sep 2015
The fact that this is returning the string 'No Data' indicates that the query is syntactically valid, but is returning zero rows. [I haven't seen people use parentheses around the min/max values typically, but I verified that that works in my Postgres database.]
My best guess is that you accidentally calculated your window such that it is not capturing any values. Just as a debugging test, you could make it extremely wide. Also, might want to take the semicolon after the
query = ...
statement out, so it prints the query to the screen, to make sure it is giving what you expect.
  3 Comments
the cyclist
the cyclist on 13 Sep 2015
What does
query=['select Sequences from Pro where MW between (',Upmin,') AND (',Upmax,')']
output?
Have you looked at your database with some other tool to be absolutely certain there is a value in the range you are trying to extract?
All I can tell you at this stage is that I have successfully done this sort of query many times.
Rafia Raja
Rafia Raja on 14 Sep 2015
yup values are there in database ... it gives no data for every range

Sign in to comment.


Geoff Hayes
Geoff Hayes on 13 Sep 2015
Rafia - I'm trying to understand your query:
select MW from Table1
You are selecting something called MW from Table1 which, according to your output, returns three fields for each record: the protmass (?), a single character, and then a string (APPROX). Is this correct, or does the query return a single string built from a number, a character, and another string?
You mention how When I pass number in protmass like protmass=30000 it shows output. Does this mean your query is something like
select MW from Table1 where protmass=30000
or is it something different? And if this query does work, then why not do something like
select MW from Table1 where protmass between (29100) and (30900)
to get the records that you desire?
  1 Comment
Rafia Raja
Rafia Raja on 14 Sep 2015
In every condition it will add 900 to upmax and subtract 900 in upmin... the code above shows the value of protmass comes from database... For checking If I will pass value to protmass myself it will give output but when it comes to database it gives no data for any range whether it is present in database or not..

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!