Embedded C/C++ Application (Raspberry PI)

Introduction

Now that you've gotten comfortable with creating a database in the How to Create a Schema section, lets build an application that will allow you to read and write to a database.

We recommend getting familiar with some of the concepts and tools that you will be using in this tutorial. We will be covering: interacting with the Transaction File Server (TFS), inserting a row with the function call rdm_dbInsertRow(), and reading rows with the function call rdm_cursorReadRow(). You may also find it useful to read about the DOCROOT as well.

  • The TFS is responsible for safely storing and retrieving objects. It is like a key/value store, but very fast and transactionally safe. The TFS owns and is co-located with the database files.
  • In this example rdm_dbInsertRow() will be used to insert a new row into two of our tables: AUTHOR and BOOK.
  • rdm_cursorReadRow() reads all columns from a row specified by the RDM_CURSOR and places the contents inside of the designated buffer.
  • The DOCROOT is a directory which is designated for holding databases available to a Transaction File Server (TFS). The concept is similar to a web server document root for storing web pages

Prerequisites:

Steps:

The following steps will be identical to the Embedded C/C++ Application (Linux/gcc) steps used to build the bookStore example on a host machine. The following steps will target the 32bit version of the Raspberry PI using the arm-linux-gnueabihf-gcc cross compile on a Linux x86_64 host.

For a 64bit version running on the Raspberry PI, use the aarch64-linux-gnu-gcc cross compile tool chain and target directory in the RDM installer package.

Follow the steps on the Embedded C/C++ Application (Linux/gcc) section using the following configure.ac file.

configure.ac

The RDM_INSTALL_DIR variable in the following may need to be changed to the directory where RDM is installed on your computer.

# initialize the process
AC_INIT([bookStore], [0.01])
# make config headers
AC_CONFIG_HEADERS([config.h])
# init automake
AM_INIT_AUTOMAKE([1.11])
#configure and create "Makefile"
AC_CONFIG_FILES([Makefile])
#find and probe C compiler
CC=arm-linux-gnueabihf-gcc

AC_PROG_CC RDM_INSTALL_DIR=/opt/Raima/rdm_enterprise-15.2 RDM_INCDIR="${RDM_INSTALL_DIR}/include" RDM_LIBDIR="${RDM_INSTALL_DIR}/target/lnx-arm-gnueabihf/lib" # # RDM Flags # AC_SUBST([RDM_CFLAGS]) AC_SUBST([RDM_LDFLAGS]) AC_SUBST([RDM_INCDIR]) AC_SUBST([RDM_LIBDIR]) #End AC_OUTPUT
  1. In your project directory, run the following command which will create the Makefile for building a cross target:
$> ./configure --host=arm-unknown-linux-gnueabihf
  1. Now you can run the command make from the command line to build your executable: make
  2. A bookStore executable should have been created. This file can be copied to the target environment and executed there.

Since this bookStore example requires that the database already exist, a prebuilt database needs to be copied to the target device as well.

Conclusion

Your program should be fully functional at this point. You set up an Embedded TFS which is used when you are interacting with a database that is not shared with other processes, and you wrote and read rows from the database by interacting with the TFS.

Next, you might want to add some more functionality by deleting a row with rdm_cursorDeleteRow() or update a row with rdm_cursorUpdateRow(). Some other concepts to look over might be:

The full source file can be found here: learn/bookStore_embed.c