SIL LSDev Linux Development

Language software for Linux and Mac OS X

.NET LINQ to Firebird

Since we’re porting from SQL Server to Firebird, code that works on both RDBMSs is highly valuable. We want to connect to either using C#.

Microsoft’s ADO.NET Entity Framework does just that. One of the components is LINQ. Here is a beginner’s application to show how to do it with Firebird.

Download and run the latest Firebird Data Provider for .NET and Mono.

Open Visual Studio 2008 (VS). You can try using 2005, but I couldn’t get it to work. Create a new project. (File/New/Project…) Under “Project types” select Windows. Under Templates select Console Application. Give it a name. (I used LinqToFirebird.) Give the project a location. I prefer to leave the checkbox “Create directory for solution” unchecked, to avoid a deeper directory tree than I want.

In VS, go to the Solution Explorer. We’re going to add a reference to the Firebird .NET Data Provider. Right-click on References. A dialog will appear. Select the Browse tab. Go to the directory where you installed the provider and select FirebirdSqlData.FirebirdClient.dll

Now we get to code. In Program.cs, add the following above namespace at the top:

using System.Data;
using FirebirdSql.Data.FirebirdClient;

In the Main method, use the following code. You will have to change the connection string to your own, of course. (The best site for database connection strings is ConnectionStrings.com.) Microsoft has a number of examples for LINQ.

FbConnection con = new FbConnection(
“ServerType=0;User=SYSDBA;Password=masterkey;Dialect=3;” +
“Database=C:\\Firebird\\Data\\FieldWorks\\FW01.FDB;”);

FbDataAdapter fbadapt = new FbDataAdapter(
“SELECT * FROM RDB$CHARACTER_SETS;”, con);

// Table mappings
fbadapt.TableMappings.Add(”Table0″, “CharSets”);
DataSet dataset = new DataSet();

// Fill the dataset with a call to the database
fbadapt.Fill(dataset);

// Query
DataTable CharSets = dataset.Tables[0];
var queryCharSets =
from rCharSets in CharSets.AsEnumerable()
select rCharSets;

Console.WriteLine(”RDB$CHARACTER_SETS:”);
foreach (DataRow rCharSets in queryCharSets)
{
Console.WriteLine(rCharSets.Field(”RDB$CHARACTER_SET_NAME”));
}

// pause
Console.ReadLine();

CloseConnection(con);

Introducing Steve Miller

I’m a Michigander working in Texas. I’ve been working on databases for FieldWorks since 2001. Currently FieldWorks uses SQL Server. My role in the Linux team is to help port from SQL Server to Firebird.

A significant milestone

As a result of the breakthrough described in the last post, Brent was able to get a sample application running (HelloView.Net). It’s written in C#, runs on Mono, and uses the FieldWorks infrastructure packaged as COM objects. In particular, it uses the Views component of FieldWorks, one of the key pieces of the infrastructure, and this is the first time that Views has ever run on a non-Windows platform.

Read the rest of this post…

A long-awaited breakthrough

Our porting work depends on having a link from C# to C++ using COM. This is a fundamental requirement, and without it we cannot proceed. Although we’ve had this working in small test programs for a long time, it would crash badly when we tried it with our application (WorldPad, part of FieldWorks). We were fairly sure it was something we were doing wrong, but could never pin it down. Well, now Tom and Brent have found the solution!

Read the rest of this post…

libcom 0.4.0 released

The libcom COM Support Library version 0.4.0 has been released. This is the first release of libcom. libcom is licensed under the LGPL.

libcom implements a subset of Microsoft COM (Component Object Model) and supports both C++ and C# (via Mono) COM clients and servers on Linux. libcom is similar to ole32.dll in Windows.

libcom can be downloaded from http://linux.lsdev.sil.org/wiki/index.php/Downloads.

Update: libcom now has its own web page at http://linux.lsdev.sil.org/wiki/index.php/Libcom.

Bibledit in OLPC emulation

At the Bibledit web site here go to Download, Installation procedure and find instructions for installing Bibledit on the OLPC. This was tested in the VMPlayer OLPC emulation (running OLPC build 625) and it was successful. We used the XO activity button at the Bibledit web site per the instructions. We did however do our own build of Bibledit so as to have the current version. The Bibledit build was done on a separate computer and then transfered to the OLPC emulation.

OLPC in an emulator

The B2 development machine we currently have will not run the latest OLPC builds so I have been attempting to get them running in an emulator. I decided to try all 3 emulators to see what issues there were with each one, the 3 being Qemu, VMPlayer and VirtualBox.

After doing the installs the launchers are put in various places. Qemu puts the launcher under Accessories, VMPlayer puts the launcher under Other and VirtualBox winds up in System Tools as Innotek VirtualBox. More detailed instructions are available for the emulations here http://wiki.laptop.org/go/Emulating_the_XO. The following is not meant to be instructions but is a short collection of tips for each emulator that were either hard to find at the above website or were not at this website. Read the rest of this post…

C++ accessing C# COM objects through CCW in Mono on Linux

Recently we had a couple developers from other offices join us for LSDev Linux Brainstorming Week to learn from one another, talk about technology choices, and do some pair programming.

Recognizing that parts of our C++ code need to be able to access and work with C# objects through COM (Component Object Model), Eberhard and I set out to test this in Mono on Linux.

We were successful in making a C# application create a regular C# object and a C++ object (via libcom and RCW), pass the C# object to the C++ object, have the C++ object modify the C# object from native code, and then back in C# code observe that our C# object was indeed manipulated successfully from C++.

This capability to call back and forth between C# and C++ using COM is very important for porting several SIL programs to Linux, and we were concerned about whether it would even be possible with Mono. We found out several months ago that C# calling into C++ using libcom and Mono RCWs worked, and I was pleased to find that going the other direction, C++ calling C#, elegantly Just Works.

This new test works thanks to Jonathan Chambers’s implementation of COM Callable Wrappers (CCWs) in Mono, which was announced here.

Eberhard and I largely reused existing libcom test code and just made some additions. The steps to perform this test and an explanation of what is happening can be found on our wiki here.

Graphite and OLPC

It may not have been obvious from the last two posts, but we are taking steps towards getting Graphite working on the OLPC. Read the rest of this post…

Packaging for multiple platforms on Hydra vserver

HydraThere are a number of SIL projects which would benefit from an organized way of being packaged for multiple Linux distributions. In addition to supporting several distributions, we would like to support the current and previous distribution releases as well as both 32- and 64-bit architectures.

The way we have chosen to do this is to host each kind of system as a vserver guest all on one physical machine. VServer is more like an advanced chroot than a virtual machine, and is faster and closer to the hardware than other kinds of virtualization. A script could build packages for each platform by invoking each guest’s package-building process.
Developers could also log in to experience and test their software on any of the supported platforms without having to set up such a machine themselves.

Hydra, our multi-headed monster, named for its many guests on one base machine, is being set up to host these guests.

For more information, see the wiki page for Packaging and testing.

« Previous Entries