Programmer Guide : solidDB® SA : Reading data by using solidDB® SA without SQL
  
Reading data by using solidDB® SA without SQL
solidDB® SA functions required for query operations are listed in this topic.
With solidDB® SA, data is queried using cursors. The query data is found in a way similar to update and delete operations. A cursor is created to a specific table, variables are bound to columns of the table, and the cursor is then opened. The constraints for finding the rows for the query are set before starting the actual search. If more than one row is found, each row must be fetched separately. After all the rows are fetched, the cursor needs to be freed.
Basically, all solidDB® SA queries use the solidDB® optimizer in a way similar to SQL-based queries. The index selection strategy is the same as in SQL. The only exception is that the solidDB® SA search uses ORDER BY for selecting an index. This means that an index that best fits ORDER BY is the one selected. If two indices are equally good, then the one with a smaller cost is selected. The query is optimized each time SaCursorSearch is called.
There is no way to use optimizer hints functionality when solidDB® SA is used.
Query operation steps
Steps
SA function(s)
Comment
1 Create a cursor
SaCursorCreate
 
2 Bind variables to cursor
SaCursorColInt, SACursorColStr and others for other data types
 
3 Open the cursor
SaCursorOpen
 
4 Set the search constraint for the row to be queried
SaCursorEqual, SaCursorAtleast, SaCursorAtmost
 
5 Start a search for the row to be queried
SaCursorSearch
 
6 Fetch the row(s) that match the given criteria
SaCursorNext
Perform this in a loop if necessary
7 Free the cursor
SaCursorFree
 
Example
/* Create cursor to a database table. */
scur = SaCursorCreate(scon, "SAEXAMPLE");
/* Bind variables to columns of test table. */
rc = SaCursorColInt(scur, "INTC", &intc);
rc = SaCursorColStr(scur, "CHARC", &str);
/* Open the cursor. */
rc = SaCursorOpen(scur);
assert(rc == SA_RC_SUCC);
/* Set search constraints. */
str = "A";
rc = SaCursorAtleast(scur, "CHARC");
str = "C";
rc = SaCursorAtmost(scur, "CHARC");
/* Set ordering criteria. */
rc = SaCursorAscending(scur, "CHARC");
/* Start a search. */
rc = SaCursorSearch(scur);
/* Fetch the rows. */
for (i = 1; i <= 3; i++) {
  rc = SaCursorNext(scur);
  switch (intc) {
  case 1:
    assert(strcmp(str, "A"), == 0);
    break;
  case 2:
    assert(strcmp(str, "B”), == 0);
    break;
  case 3:
    assert(strcmp(str, "C"), == 0);
    break; }
  }
  /* Close the cursor. */
  SaCursorFree(scur);
}
See also
solidDB® SA