cpp01Example_main.cpp
                                            
                                            Basic tutorial in C++ where a database is created, a row is inserted and then a row is retrieved and displayed. This example needs a compiled schema, hello_world.sdl.
/*
                                                    
                                                     * HELLO WORLD CPP
                                                    
                                                     * ---------------
                                                    
                                                     *
                                                    
                                                     * This document describes the process to create a simple database,
                                                    
                                                     * insert a record containing a text field, read the text field from
                                                    
                                                     * database and print it out.
                                                    
                                                     */
                                                    
                                                    #include <iostream>
                                                    
                                                    #include <string.h>
                                                    
                                                    #include <stdlib.h>
                                                    
                                                    #include "cpp-tfs.h"// The RDM TFS class
                                                    
                                                    #include "cpp-exception.h"// The RDM exception class
                                                    
                                                    #include "cpp-transaction.h"// The RDM transaction class
                                                    
                                                    #include "hello_world_gen_api.h"// The hello_world database API.
                                                    
                                                    #include "rdmstartupapi.h"
                                                    
                                                    using namespace RDM_CPP::HELLO_WORLD;  // RDM hello_world Db Class
                                                    static void hello_worldCPP (void)
                                                    {
                                                    TFS tfs;
                                                        Db_hello_world db;
                                                    RDM_TABLE_ID tables[] = {TABLE_INFO};
                                                    try
                                                    
                                                        {
                                                    // Allocate RDM_TFS handle
                                                    
                                                    
                                                    // Allocate RDM_DB handle
                                                    
                                                            db = tfs.AllocDatabase ();
                                                    // Open database
                                                    
                                                    
                                                    
                                                        {
                                                            std::cerr << "I can't open the hello_world database." << std::endl;
                                                    throw;
                                                        }
                                                    /* Start an update transaction and lock the table */
                                                    
                                                    
                                                    try
                                                    
                                                        {
                                                    /* Remove all of the rows from the database */
                                                    
                                                            db.DeleteAllRows ();
                                                    /* Commit the transaction */
                                                    
                                                            db.End ();
                                                        } catch (rdm_exception)
                                                        {
                                                    /* Rollback the transaction */
                                                    
                                                            db.EndRollback ();
                                                    throw;
                                                        }
                                                    /* Start an update transaction and lock the table */
                                                    
                                                        db.StartUpdate (tables, RDM_LEN (tables));
                                                    try
                                                    
                                                        {
                                                            INFO infoInserted;
                                                    /* Insert a row into the table */
                                                    
                                                            strcpy (
                                                                infoInserted.MYCHAR, "Hello World CPP! - using the embedded TFS");
                                                            db.Insert_INFO_Row (infoInserted);
                                                    /* Commit a transaction */
                                                    
                                                            db.End ();
                                                        } catch (rdm_exception)
                                                        {
                                                    /* Rollback the transaction */
                                                    
                                                            db.EndRollback ();
                                                    throw;
                                                        }
                                                    /* Start a read transaction and lock the table */
                                                    
                                                        db.StartRead (tables, RDM_LEN (tables));
                                                    try
                                                    
                                                        {
                                                            Cursor_INFO cursor;
                                                            INFO infoRead;
                                                    /* Fill a cursor with all the rows in a table */
                                                    
                                                            cursor = db.Get_INFO_Rows ();
                                                    /* Move to the first row in the info table */
                                                    
                                                            cursor.MoveToFirst ();
                                                    /* Read the full content of the current record */
                                                    
                                                            cursor.ReadRow (infoRead);
                                                            std::cout << infoRead.MYCHAR << std::endl;
                                                    /* Free the read lock on the table */
                                                    
                                                            db.End ();
                                                        } catch (rdm_exception)
                                                        {
                                                    /* Rollback the transaction */
                                                    
                                                            db.EndRollback ();
                                                    throw;
                                                        }
                                                    }
                                                    int32_t main_hello_worldCPPTutorial (int32_t argc, const char *const *argv)
                                                    {
                                                    RDM_UNREF (argc);
                                                    RDM_UNREF (argv);
                                                    try
                                                    
                                                        {
                                                            hello_worldCPP ();
                                                    
                                                        {
                                                    
                                                    
                                                    return EXIT_FAILURE;
                                                        }
                                                    return EXIT_SUCCESS;
                                                    }
                                                    RDM_STARTUP_EXAMPLE (hello_worldCPPTutorial)
                                                Header for C++ exceptions.
                                        Header for the C++ Transaction File Server (TFS) API.
                                        Transaction StartUpdate(const RDM_TABLE_ID writeTableIds[], uint32_t numWriteTableIds, const RDM_TABLE_ID readTableIds[]=NULL, uint32_t numReadTableIds=0) const
                                            Begin updating a database.
                                        Db Open(const char *name, RDM_OPEN_MODE mode, const char *const catalog) const
                                            Open the database.
                                        virtual const char * GetEnum() const
                                        Header for the C++ transaction API.
                                        the rdm_exception class This class implements the exception thrown by the RDM CPP API
                                            Definition: cpp-exception.h:46
                                        virtual const char * GetDescription() const
                                            method to get a text description of the error causing the exception to be thrown
                                        Internal RDM Startup API used by startup macros.