Strange database toolbox behavior
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a simple SQL Server query--SELECT [field list] FROM [in-database view]--that, with a where clause, returns the correct results--a 252 x 17 mixed-type cellarray--without generating a java heap outofmemory error, but without a where clause, generates a java heap outof emory error. If I add code similar to that provided by "Example 3 — Import Rows Iteratively Until You Retrieve All Data" in the help doc for cursor.fetch:
function data = grabInPieces(~, curs)
% Initialize result holder and fetch size
data = {};
rowLimit = 20;
% Check for and retrieve more data
while ~strcmp(curs.Data, 'No Data')
curs = fetch(curs, rowLimit);
data(end+1:end+size(curs.Data,1),:) = curs.Data;
end
end
and have a call to this inside a catch block following the first attempt to fetch, the outofmem error is dealt with, but the result set is drastically abbreviated--down to 8 rows from an expected 320 (which is the number of rows the same query returns in SQL Server Management Studio).
Any ideas?
Thanks, OlyDLG
댓글 수: 2
Oleg Komarov
2012년 8월 29일
Is the code you posted, exactly what you're using? If not, post the code you're using.
Which MATLAB version do you have?
답변 (3개)
Oleg Komarov
2012년 8월 29일
The code looks correct, unless you're doing something that fetches most of the data (without storing it) before calling grabInPieces().
댓글 수: 2
Oleg Komarov
2012년 8월 29일
편집: Oleg Komarov
2012년 8월 29일
The cursor usually works like a file pointer. However, I am unsure what should happen in case of a Java out of memory error.
I would try to avoid the out of memory by estimating the memory use per row.
You can try to query the meta info of the table with:
Curs = exec(Connection, Statement);
attributes = get(rsmd(resultset(Curs)));
and establish the amount of rows to import (keeping it prudent).
Then, what you just need is to do a first pre-fetch and keep fetching iteratively but inverting the order of the commands in the while loop:
while ~strcmp(curs.Data, 'No Data')
data(end+1:end+size(curs.Data,1),:) = curs.Data;
curs = fetch(curs, rowLimit);
end
Otherwise, you can use a try catch block (but keep the commands in the loop inverted, i.e. first store the results from the previous fetch). However, I am unsure whether the state of the cursor is preserved in the catch part.
David Goldsmith
2012년 8월 30일
댓글 수: 2
Sean de Wolski
2012년 8월 30일
What else do you have open in ML? Do you have a large *.m files open in the editor, GUIs, etc? How about the current folder, are there many files in there?
I would recommend to try closing the various desktop components you are not using in an effort to minimize your Java heap footprint to see if that helps.
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!