solidDB Help : Programming : solidDB SA : Writing data by using solidDB SA without SQL
  
Writing data by using solidDB SA without SQL
With solidDB SA, data is written by using cursors.
For update and delete operations, after the cursor is created, a search is performed so that the cursor points to the row that is to be updated or deleted. For insert operations, after the cursor is created, the insertion row(s) are immediately written to the cursor. solidDB SA also enables several rows to be passed for insertion inside a single network message.
Performing insert operations
The solidDB SA functions that are required for insert operations are listed in the following table.
After solidDB creates a cursor to a certain table, variables are bound to columns, rows are written to the cursor, and then the cursor is closed.
If you use SaArrayInsert to insert more than one row in a single message, then you must perform an explicit flush to send the rows to the database.
 
Step
Action
SA function
1
Create a cursor.
SaCursorCreate
2
Bind variables to the cursor.
SaCursorColData, SaCursorColDate, SaCursorColDateFormat, SaCursorColDFloat, SaCursorColDouble, SaCursorColDynData, SaCursorColDynstr, SaCursorColFloat, SaCursorColInt, SaCursorColLong, SaCursorColStr, SaCursorColTime, SaCursorColTimestamp
3
Open the cursor.
SaCursorOpen
4
Write one or more rows to the cursor.
SaCursorInsert (for a single row)
SaArrayInsert (for more than one row)
Perform this in a loop if necessary.
5
Free the cursor.
SaCursorFree
6
Flush the network message to the server.
SaArrayFlush
Necessary only if using SaArrayInsert
The following code sample excerpt demonstrates how to write four rows of data in a single network message using the SaArrayInsert function. In the code, a call to SaArrayFlush flushes all rows to the server so they are passed in the same network message.
scur = SaCursorCreate(scon, "SAEXAMPLE");
/* Bind variables to columns. */
SaCursorColInt(scur, "INTC", &intc);
SaCursorColStr(scur, "CHARC", &str);
/* Open the cursor. */
SaCursorOpen(scur);
/* Insert values to the table. The column values are taken
* from the user variables that are bound to columns.
*/
for (intc = 2; intc <= 5; intc++) {
 switch (intc) {
    case 2:
      str = "B";
      break;
    case 3:
      str = "C";
      break;
    case 4:
      str = "D";
      break;
    case 5:
      str = "E";
      break;
    }
    SaArrayInsert(scur);
  }
/* Close the cursor. */
SaCursorFree(scur);
/* Flush the inserts to the server. */
SaArrayFlush(scon, NULL);
Performing update and delete operations
solidDB SA functions that are required for basic update and delete operations are listed in the following table.
After solidDB creates a cursor to a specific table, variables are bound to columns of the table, and the cursor is opened. Before the actual search begins, the constraints for finding the row for deletion are set. If there are more rows to be updated, each of the rows requires a separate fetch before they are updated or deleted. After the operation, the cursor is freed.
 
Step
Action
SA function(s)
1
Create a cursor.
SaCursorCreate
2
Bind variables to cursor.
SaCursorColData, SaCursorColDate, SaCursorColDateFormat, SaCursorColDFloat, SaCursorColDouble, SaCursorColDynData, SaCursorColDynstr, SaCursorColFloat, SaCursorColInt, SaCursorColLong, SaCursorColStr, SaCursorColTime, SaCursorColTimestamp
3
Open the cursor.
SaCursorOpen
4
Set the search constraint for the row to be updated or deleted.
SaCursorEqual, SaCursorAtleast, SaCursorAtmost
5
Start a search for the row to be updated or deleted.
SaCursorSearch
6
Fetch the row to be updated or deleted.
SaCursorNext
7
Perform actual update or delete.
SaCursorUpdate or SaCursorDelete
For updates, the new values must be in variables bound in step 2.
8
Free the cursor.
SaCursorFree
The following code sample demonstrates how to update a row in a table by using SaCursorUpdate. Note that in the code, the new values for the update are in variables that are bound to the columns of the table by using SaCursorColInt and SaCursorColStr after the cursor is created.
scur = SaCursorCreate(scon, "SAEXAMPLE");
/* Bind variables to columns INTC and CHARC of test table. */
SaCursorColInt(scur, "INTC", &intc);
SaCursorColStr(scur, "CHARC", &str);
/* Open the cursor. */
SaCursorOpen(scur);
/* Set search constraint. */
str = "D"; SaCursorEqual(scur, "CHARC");
/* Start a search. */
SaCursorSearch(scur);
/* Fetch the column. */
SaCursorNext(scur);
/* Update the current row in the cursor. */
intc = 1000;
str = "D Updated";
SaCursorUpdate(scur);
/* Close the cursor. */
SaCursorFree(scur);
Go up to
solidDB SA