c-core/09_core/core09Example_main.c
/*
* Raima Database Manager
*
* Copyright (c) 2019 Raima Inc., All rights reserved.
*
* Use of this software, whether in source code format, or in executable,
* binary object code form, is governed by the Raima LICENSE which
* is fully described in the LICENSE.TXT file, included within this
* distribution of files.
*/
#include <stdio.h>
#include <string.h>
#include "example_fcns.h"
#include "rdm.h"
#include "rdmstartupapi.h"
/* Generated \c struct and \c typedef definitions to be used with the RDM APIs
*/
#include "core09_structs.h"
/* Generated catalog definition to be used with the RDM rdm_dbSetCatalog() API
*/
#include "core09_cat.h"
RDM_CMDLINE cmd;
const char *const description = "Demonstrates database union read";
RDM_RETCODE display_offices (RDM_DB hDB)
{
RDM_RETCODE rc;
OFFICE office_rec;
RDM_CURSOR cursor = NULL;
print_error (rc);
{
/* The following cursor association call will allocate the cursor
* if the cursor is set to NULL. This short-cut can eliminate the
* requirement to call rdm_dbAllocCursor() before using the cursor
* in this function */
rc = rdm_dbGetRowsByKey (hDB, KEY_OFFICE_NAME, &cursor);
print_error (rc);
rc = rdm_cursorMoveToNext (cursor))
{
/* Read and display the current person record */
rc = rdm_cursorReadRow (
cursor, &office_rec, sizeof (office_rec), NULL);
print_error (rc);
printf ("%s\n", office_rec.name);
}
/* free the cursor if it was allocated */
if (cursor)
rdm_cursorFree (cursor);
/* Expect rc to be S_NOTFOUND when we exit the loop */
{
rc = sOKAY;
}
rdm_dbEnd (hDB);
}
return rc;
}
{
RDM_RETCODE rc;
OFFICE office_rec;
print_error (rc);
if (rc == sOKAY)
{
int ii;
for (ii = 0; ii < (int) listSize; ii++)
{
strncpy (office_rec.name, officeList[ii], sizeof (office_rec.name));
rc = rdm_dbInsertRow (
hDB, TABLE_OFFICE, &office_rec, sizeof (office_rec), NULL);
print_error (rc);
}
if (rc == sOKAY)
rc = rdm_dbEnd (hDB);
else
rc = rdm_dbEndRollback (hDB);
print_error (rc);
}
return rc;
}
static const char *na_office_names[] = {"Seattle", "Boise", "San Francisco",
"Dallas"};
static const char *emea_office_names[] = {"Paris", "London", "Dublin", "Zurich",
"Madrid"};
RDM_RETCODE loadDatabase (RDM_TFS hTFS)
{
RDM_RETCODE rc;
RDM_DB hDB;
rc = exampleOpenNextEmptyDatabase (hTFS, &hDB, "core09NA", core09_cat);
if (rc == sOKAY)
{
/* create records in the NA database */
rc = insertOffices (hDB, na_office_names, RLEN (na_office_names));
rdm_dbFree (hDB);
}
rc = exampleOpenNextEmptyDatabase (hTFS, &hDB, "core09EMEA", core09_cat);
if (rc == sOKAY)
{
/* create records in the NA database */
rc = insertOffices (hDB, emea_office_names, RLEN (emea_office_names));
rdm_dbFree (hDB);
}
return rc;
}
int main_core09 (int argc, const char *const *argv)
{
RDM_RETCODE rc;
RDM_TFS hTFS;
RDM_DB hDB;
rc = rdm_cmdlineInit (&cmd, argc, argv, description, opts);
print_error (rc);
if (rc == sOKAY)
{
rc = exampleAllocTFS (&hTFS);
if (rc == sOKAY)
{
rc = loadDatabase (hTFS);
}
if (rc == sOKAY)
{
rc = rdm_tfsAllocDatabase (hTFS, &hDB);
print_error (rc);
}
if (rc == sOKAY)
{
/* Read from both databases (union read) */
print_error (rc);
if (rc == sOKAY)
{
/* Display all offices */
printf ("\nAll Worldwide Offices\n");
display_offices (hDB);
}
rdm_dbFree (hDB);
}
rdm_tfsFree (hTFS);
}
return (int) rc;
}
RDM_STARTUP_EXAMPLE (core09)
Header for the native RDM Runtime API.
RDM_RETCODE rdm_dbStartRead(RDM_DB db, const RDM_TABLE_ID *tableIds, uint32_t numTableIds, RDM_TRANS *pTrans)
Get read locks.
RDM_RETCODE rdm_cursorReadRow(RDM_CURSOR cursor, void *colValues, size_t bytesIn, size_t *bytesOut)
Read all columns from a row.
The buffer used by the command line parser to hold state information.
Definition: rdmcmdlinetypes.h:85
RDM_RETCODE rdm_dbGetRowsByKey(RDM_DB db, RDM_KEY_ID keyId, RDM_CURSOR *pCursor)
Associate an RDM_CURSOR with a row set based on a key.
RDM_RETCODE rdm_dbOpen(RDM_DB db, const char *dbNameSpec, RDM_OPEN_MODE mode)
Open an existing RDM database using the specified database handle.
RDM_RETCODE rdm_tfsAllocDatabase(RDM_TFS tfs, RDM_DB *pDb)
Allocate memory for a new RDM db.
RDM_RETCODE rdm_dbEndRollback(RDM_DB db)
End and rollback a transactional operation.
RDM_RETCODE rdm_dbInsertRow(RDM_DB db, RDM_TABLE_ID tableId, const void *colValues, size_t bytesIn, RDM_CURSOR *pCursor)
Insert a new row into a table at the specified rowId.
RDM_RETCODE rdm_cmdlineInit(RDM_CMDLINE *cmd, int32_t argc, const char *const argv[], const char *description, const RDM_CMDLINE_OPT *opts)
Initialize an RDM_CMDLINE buffer and validate the command line.
RDM_RETCODE rdm_dbStartUpdate(RDM_DB db, const RDM_TABLE_ID *writeTableIds, uint32_t numWriteTableIds, const RDM_TABLE_ID *readTableIds, uint32_t numReadTableIds, RDM_TRANS *pTrans)
Get write locks.
Internal RDM Startup API used by startup macros.