c-core/14_core/core14Example_main.c
#include "rdm.h"
#include "rdmapi.h"
#include "rdmtfsapi.h"
#include "bulkInsert_Tutorial_structs.h"
#include "bulkInsert_Tutorial_cat.h"
#include "rdmdatetimeapi.h"
#include "rdmstartupapi.h"
#include <stdio.h>
#include <stdlib.h>
int32_t main_bulkInsertTutorial (int32_t argc, const char *const *argv)
{
RDM_TFS tfs;
RDM_UNREF (argc);
RDM_UNREF (argv);
/* Allocate a TFS Handle */
rc = rdm_rdmAllocTFS (&tfs);
if (rc == sOKAY)
{
rc = rdm_tfsInitialize (tfs);
/* Allocate a database hande */
if (rc == sOKAY)
{
RDM_DB db;
rc = rdm_tfsAllocDatabase (tfs, &db);
if (rc == sOKAY)
{
/* Override default DURABLE setting to CONSISTENT */
rc = rdm_dbSetOptions (db, "durability=consistent");
}
if (rc == sOKAY)
{
RDM_TABLE_ID tables[] = {TABLE_BULKINSERT};
rc = rdm_dbSetCatalog (db, bulkInsert_Tutorial_cat);
if (rc == sOKAY)
{
/* Open the database. */
rc =
rdm_dbOpen (db, "bulkInsert_Tutorial", RDM_OPEN_SHARED);
}
if (rc == sOKAY)
{
/* Start an update transaction and lock the table */
db, tables, RDM_LEN (tables), NULL, 0, NULL);
}
if (rc == sOKAY)
{
/* Remove all of the rows from the database */
if (rc == sOKAY)
{
/* Commit a transaction */
rc = rdm_dbEnd (db);
}
else
{
/* Abort the transaction */
}
}
if (rc == sOKAY)
{
/* Start an update transaction and lock the table */
db, tables, RDM_LEN (tables), NULL, 0, NULL);
}
if (rc == sOKAY)
{
BULKINSERT insertions[3];
int16_t tzPST = -420;
uint32_t counter;
"11-11-2011", RDM_MMDDYYYY, &rdmDate);
insertions[0].id = rdmDate;
insertions[0]._id_has_value = RDM_COL_HAS_VALUE;
(void) rdm_dateToday (tzPST, &rdmDate);
insertions[1].id = rdmDate;
insertions[1]._id_has_value = RDM_COL_HAS_VALUE;
"09-17-2013", RDM_MMDDYYYY, &rdmDate);
insertions[2].id = rdmDate;
insertions[2]._id_has_value = RDM_COL_HAS_VALUE;
/* Insert multiple rows into the table */
db, TABLE_BULKINSERT, insertions, sizeof (insertions),
RDM_LEN (insertions), NULL, NULL);
for (counter = 0;
rc == sOKAY && counter < RDM_LEN (insertions);
counter++)
{
char outBuffer[100];
insertions[counter].id, RDM_MMDDYYYY,
RDM_DEF_DATE_SEP, outBuffer, sizeof (outBuffer),
NULL);
printf ("Date Inserted: %s\n", outBuffer);
}
if (rc == sOKAY)
{
/* Commit a transaction */
rc = rdm_dbEnd (db);
}
else
{
/* Abort the transaction */
}
}
if (rc == sOKAY)
{
/* Start a read transaction and lock the table */
rc = rdm_dbStartRead (db, tables, RDM_LEN (tables), NULL);
}
if (rc == sOKAY)
{
RDM_CURSOR cursor = NULL;
rc = rdm_dbGetRows (db, TABLE_BULKINSERT, &cursor);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToFirst (cursor);
while (rc == sOKAY)
{
BULKINSERT recS;
cursor, &recS, sizeof (recS), NULL);
if (rc == sOKAY)
{
char outBuffer[100];
RDM_DEF_DATE_SEP, outBuffer,
sizeof (outBuffer), NULL);
printf ("Date Retrieved: %s\n", outBuffer);
rc = rdm_cursorMoveToNext (cursor);
}
}
/* We will break out of the loop with a sENDOFCURSOR
* return code */
if (rc == sENDOFCURSOR)
{
rc = sOKAY;
}
/* Free the cursor allocated in the rdm_dbGetRows call
*/
rdm_cursorFree (cursor);
}
/* Free the read locks */
rdm_dbEnd (db);
}
/* Free the databse handle */
rdm_dbFree (db);
}
}
/* Free the TFS handle */
rdm_tfsFree (tfs);
}
if (rc != sOKAY)
{
printf (
"There was an error in this Tutorial (%s - %s)\n",
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
RDM_STARTUP_EXAMPLE (bulkInsertTutorial)