The principle classes for most eXtremeSQL C# applications are Database, SqlLocalConnection and SqlResultSet. The SqlLocalConnection is normally instantiated by calling the Database
ConnectSql()
method. Then SqlLocalConnection methodExecuteStatement()
is called to execute SQLinsert
,update
anddelete
statements. Alternatively SqlLocalConnection methodInsert()
can be called to insert objects of database classes andCurrentCursor.Update()
andCurrentCursor.Remove()
can be called to update or delete objects. MethodExecuteQuery()
is called to execute aselect
statement returning a SqlResultSet. Then various SqlResultSet methods can be used to process result sets. The following sections will walk through the steps for building a simple C# eXtremeSQL application. In addition, note that there are C# SDK samples that demonstrate specific eXtremeSQL features.Database definition
For C# applications the database is defined using native C# class syntax applying special attributes (See here for a detailed explanation). For this example application we will use a schema defined as follows:
[Persistent(AutoID = true)] class Person { [Indexable(Type = Database.IndexType.BTree, Unique = true)] public String name; public unsigned int ordinal; }Open the database
To open the database we first instantiate a Database object
db
in order to call itsOpen()
method. There are a number of constructors for the Database class. For this sample we use the default constructor. The Database classOpen()
method has three overloads; we will call the version which allows us to specify the following properties for an in-memory database:
- name - a string identifying the database
- parameters - a DatabaseParameters object (see explanation below)
- size - the total amount of memory available for the database
The DatabaseParameters class has a number of properties. The property
Classes
must be initialized with an array of classes to be stored in the database. For this example there is simply the class Person. In the following code snippet we instantiate the Database object, define the DatabaseParametersClasses
and the memory page size (the basic unit of memory access) properties, then call theOpen()
method.To complete this step we will call the
db.Close()
method to terminate the database instance. The sample code forProgram.cs
so far looks like this:public static void Main(String[] args) { const int PAGE_SIZE = 128; const int DATABASE_SIZE = 16*1024*1024; Database db = new Database(); Database.Parameters parameters = new Database.Parameters(); parameters.MemPageSize = PAGE_SIZE; parameters.Classes = new Type[]{typeof(Person)}; db.Open("PersonDb", parameters, DATABASE_SIZE); // Do database processing db.Close(); }Populate and query the database using SQL
To populate the database using SQL instantiate a SqlLocalConnection object and call its
ExecuteStatement()
method as follows:SqlLocalConnection con = db.ConnectSql(); con.ExecuteStatement("insert into Person values('Luke Skywalker', 0)"); con.ExecuteStatement("insert into Person values('Han Solo', 1)");Then to query the database we call the SqlLocalConnection
ExecuteQuery()
method to instantiate a SqlResultSet objectresult
:SqlResultSet result = con.ExecuteQuery("select * from Person") );Processing query results
The SqlResultSet object returned from
ExecuteQuery()
is a dataset that has numerous methods for extracting the result rows and information about the columns, etc. But presenting these details is beyond the scope of this quick start demonstration. Please see QueryResult processing for details and the C# SDK samples for several examples.