Switch to: V10V9V8V7V6V5

Lesson 1 - Local Database

We assume here, that you have download and install C++ SDK to your computer.

Step 1: Prepare Project

1.1 Create a New Console Project

Start your C++ IDE (netbeans, visual, xcode, …) and create standard “Console App” project. Now we need make this project aware about VSDK location, so C++ will be able to find headers and libs.

1.2 Specify VSDK Include Path

VSDK is installed into HOME → Documentations → Paradigma Software folder. On any OS (mac, win, lin)

Open settings of your project and find a place to specify the path to includes. Add the path to VSDK:

HOME/Documents/Paradigma Software/sources

1.3 Specify Linker VSDK Libraries

VSDK also installs to your computer a special vcomponents folder with few Valentina DLLs.

On Mac and Linux it is located as:

  • /usr/local/lib/vcomponents.

On Windows it is located as:

  • 32: '\Program Files(x86)\Paradigma Software\vcomponents_win_vc'
  • 64: '\Program Files\Paradigma Software\vcomponents_win_vc'

Open this folder on your computer, to see exact names of Valentina DLLs.

Open settings of Linker, and specify for now only 2 Valentina libs: vshared and vkernel with the exact name as they are in your vcomponents folder.

If your IDE requires it, then add path of this vcomponents folder into “Additional Lib Paths” settings.

At this point your project should compile and link fine without errors.

Step 2: Initializing Valentina

#include <iostream>
#include <VSDK/VSDK2.h>
 
using namespace std;
using namespace FBL;
 
int main()
{
    ValentinaInit();
 
    // ...
 
    ValentinaShutDown();
}
  • To start work with Valentina, you should first of all to initialize it. So we adding the call to Valentina_Init(). If you have serials purchased from Paradigma Software, then you must specify them in this call.
  • Also we call Valentina_ShutDown() at the end when we going to close Valentina libs.
  • You need to specify Valentina header on the top. Please note that this is the single Valentina SDK header, which you must specify in your code. It includes all other required headers.

Step 3: Create Database

#include <iostream>
#include <VSDK/VSDK2.h>
 
using namespace std;
using namespace FBL;
 
int main()
{
    ValentinaInit();
 
    // Make CPP object:
    I_SqlDatabase_Ptr pSqlDb = CreateSqlDatabase();
    I_Database_Ptr pDb = pSqlDb->get_BaseDatabase();
 
 
    // Create DB on disk at specified location:
    I_Location_Ptr pDbLocation = CreateDiskLocation( "db1.vdb" );
    pDb->put_Location( pDbLocation );
    pDb->Create();
 
 
    // WORK WITH DB:
    CreateSchema( pSqlDb );
    InsertRecords( pSqlDb );
    SelectRecords( pSqlDb );
 
 
    // Close all:
    pDb->Close(); 
    ValentinaShutDown();
}

Step 4: Create Schema

void CreateSchema( I_SqlDatabase_Ptr inSqlDb )
{
    String cmd( "CREATE TABLE T1(f1 LONG)" );
 
    inSqlDb->SqlExecute( cmd );
}

Step 5: Insert Records

void InsertRecords( I_SqlDatabase_Ptr inSqlDb )
{
    String cmd( "INSERT INTO T1(f1) VALUES(33)" );
 
    inSqlDb->SqlExecute( cmd );
}

Step 6: Select Records

void SelectRecords( I_SqlDatabase_Ptr inSqlDb )
{
    String cmd( "SELECT * FROM T1" );
 
    I_Cursor_Ptr pCursor = inSqlDb->SqlSelect( cmd );
 
    std::cout << "T1.f1 = " << pCursor->get_Field("f1")->get_Value()->get_String().getBufferA();
}