This section is designed to offer just a taste of the Function Level API. If you have never developed with this API, it will be beneficial to take a moment to learn some of the basics. This will come in handy when we start building our first c-treeDB .NET application.
Below we will list the API function calls necessary to connect to a database, open a table, and add a record. This exercise is meant to expose the most commonly used parts of the API and goes through the sequence of calls to be performed for most database tasks.
The nomenclature for the Function Level API is to prefix "ctdb." to all function names. For example, AllocSession() is ctdbAllocSession() in c-treeDB and ctdb.AllocSession() in .NET.
In the .NET IDE, once the "." (period) after "ctdb" is typed, then IntelliSense® will take over and present a drop-down of properties and methods.
Examples:
Connect to a Database
pSession = cdtb.AllocSession(ctdb.SESSION_TYPE.SESSION_CTDB);
ctdb.CreateSession(pSession, uid,upw,svn);
ctdb.Logon(pSession, uid,upw,svn);
pDatabase = ctdb.AllocDatabase(pSession);
ctdb.CreateDatabase(pDatabase, "dbName");
ctdb.Connect(pDatabase, "dbName");
Open a Table
hTable = ctdb.AllocTable(pDatabase);
ctdb.AddField(hTable, ...);
ctdb.AddIndex(hTable, ...);
ctdb.AddSegment(hTable, ...);
ctdb.CreateTable(hTable,"tblName",ctdb.CREATE_MODE.CREATE_NORMAL);
ctdb.OpenTable(hTable, "tblName", ctdb.OPEN_MODE.OPEN_NORMAL);
Add a Record
hRecord = ctdb.AllocRecord(hTable);
ctdb.ClearRecord(hRecord);
ctdb.SetFieldasUnsigned(hRecord,0,1000);
ctdb.SetFieldAsString(hRecord,1,"John Smith");
ctdb.WriteRecord(hRecord);