10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

How You Can Access a Database with Standard SQL Statements• Providing better performance than a select loop when the application plansto limit the number of rows selectedSelect loops cache every row that qualifies for the select. SettingDBSessionObject's PreFetchRow attribute when using a read-only cursorlets you limit the number of qualifying rows actually fetched.For example, suppose you want to fill a tablefield with the top 10 salespeople(by sales) from a particular region. Using a select loop, you would code:i = 1;select :tf[i].name = name, :tf[i].quota = quota,:tf[i].sales = salesfrom salespeople where region = :regionorder by sales desc{i = i + 1;if i > 10 thenendloop;endif;}This technique is inefficient because all salespeople rows for the specifiedregion are returned to OpenROAD from the database when only 10 aredesired. The following example is a more efficient way to code this situation:CurFrame.DBsession.PrefetchRows = 10;open cursor1 for select name as name,quota as quota,sales as salesfrom salespeople where region = :regionorder by sales desc for readonly;i = 0;curs_state = CS_CURRENT;while (curs_state = CS_CURRENT) doi = i + 1;fetch cursor1 into :tf[i].name = name,:tf[i].quota = quota, :tf[i].sales =sales;curs_state = cursor1.state;if i > 10 thenendloop;endif;endwhile;/* number of rows fetched = i-1 */close cursor1;The PreFetchRows attribute enables you to tune the performance of cursorswhen you have an approximate idea of the number of rows the cursor willreturn.158 <strong>Programming</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!