1.14.3 Accessing SQLite Database


SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine, and it has become the most widely deployed SQL database in the world. Due to the excellent features, SQLite is now widely used in different applications and systems.

SQLite3 is the latest version released. Origin provides DLLs for accessing 32-bit and 64-bit SQLite database from Origin C. It is necessary to include a header file that contains the prototypes of SQLite3 APIs:

#include <oc_Sqlite.h>

A simple example of how to use these functions is available at the end of the header file.

Origin C also provides a wrapped class, OSQLite, that makes accessing SQLite much easier. To use this Origin C class, the header file containing this class must be included, like:

//DataSet1.1.db is a database file, which contains a table named Originlab
//The table is created with the following statement
//CREATE TABLE OriginLab(ID INTEGER NOT NULL, NUMBER INTEGER NOT NULL, SALARY INTE
//GER NOT NULL, Data BLOB NOT NULL);
#include <..\Originlab\oSQLite.h> //required header file
#define	STR_DATABASE_FILE	"E:\\DataSet1.1.db"
#define	STR_QUERY_STRING	"select * from Originlab limit 80"
void test_OSQLite()
{
	OSQLite sqlObj(STR_DATABASE_FILE);	
	LPCSTR lpSQL = STR_QUERY_STRING;
	sqlObj.Select(lpSQL);
	Worksheet wks;
	wks.Create("Origin");
	sqlObj.Import(wks);
	//after modify the data, may use the following code to export data
	//sqlObj.Export("OriginLab", wks);
}