This is the first of the Getting Started samples, and probably where you should start when exploring EDMsdk. In this sample, we will show you haw to create your first EDMdatabase, create a user and a repository for containing your data. You will learn how to compile an EXPRESS schema into the EDMdatabase and to import a data set in an EDMmodel. Then you will learn how you can export the data set to a Part28 XML file. This sample also shows how you may do conditional selection of subsets of the data and print it out on the screen as well as to Part28 XML.
The complete package with resource files and source code is available from Getting Started, but you may also download the source code of the sample below.
In the following, we will walk you through all the statements and explain them.
Creating the EDMdatabase
When your application is a EDMstandaloneClient, you will create and operate on the EDMdatabase locally. The first you need to do is to create this database (unless you already have one on your file system). This sample assumes that there is already an EDMdatabase on your file system, created by your previous run, and that you will delete it first.
if (rstat = edmiDeleteDatabase (dbPath, dbName, dbPwd)) { if (rstat != edmiENOSUCHDATABASE) { printf("\nERROR: Failed to delete database with error '%s'", edmiGetErrorText(rstat)); goto err; } }
The EDMdatabase will consist of a great number of files, so make sure you create a separate folder for it.
if (rstat = edmiCreateDatabase (dbPath, dbName, dbPwd)) { printf("\nERROR: Failed to create database with error '%s'", edmiGetErrorText(rstat)); goto err; }
After creating the EDMdatabase, you will have typically 50 files in your database folder. Any standalone process can open and connect to this EDMdatabase once it is created, but only one process can open it at the time. If you need multiple client applications connect to the EDMdatabase simultaneously, you need an EDMserver and write your application as an EDMthinClient.
if (rstat = edmiOpenDatabase(dbPath, dbName, dbPwd)) { printf("\nERROR: Failed to open database with error '%s'", edmiGetErrorText(rstat)); goto err; }
The EDMdatabase is now open and therefore uavailable to other EDMclient applications. At this stage, you would be connected to the database with a session for the default EDMuser named sdai-user. If we were to continue with API calls from here, it would be as the sdai-user. But in this sample, we will start by creating a new EDMuser and an EDMgroup. Only the superuser has permission to create new EDMusers and EDMgroups, so we now now need to connect as the superuser.
if (rstat = edmiConnect("superuser", NULL, dbPwd, &unavailMess)) { printf("\nERROR: Failed to connect as superuser with error '%s'", edmiGetErrorText(rstat)); goto err; }
The password of the superuser is by default set to the password you specified when you created the EDMdatabase. If, from some reason, the EDMdatabase should be set temporarily unavailable by the susperuser, an attempt to connect would fail with the error code edmiEUNAVAILABLE. The message provided by the superuser will be returned in the unavailMess string. Next step will be to open a session for the superuser.
if ((suSessId = sdaiOpenSession()) == 0) { printf("\nERROR: Failed to open session for superuser with error '%s'", edmiGetErrorText(rstat)); goto err; }