solidDB Help : Programming : solidDB SA : Reading data by using solidDB SA without SQL
  
Reading data by using solidDB SA without SQL
With solidDB SA, data is queried by using cursors. 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 must be freed.
All solidDB SA queries use the solidDB optimizer in a similar way 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 the index that best fits ORDER BY is the one selected. If two indexes 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.
solidDB SA functions that are required for search operations are listed in the following table.
 
Step
Action
SA function(s)
 
Create a cursor.
SaCursorCreate
 
Bind variables to cursor.
SaCursorColInt, SACursorColStr (and others for other data types)
 
Open the cursor.
SaCursorOpen
 
Set the search constraint for the row to be queried.
SaCursorEqual, SaCursorAtleast, SaCursorAtmost
 
Start a search for the row to be queried.
SaCursorSearch
 
Fetch the row or rows that match the given criteria.
SaCursorNext
Perform this step in a loop if necessary
 
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);
}
Go up to
solidDB SA