Top

Name

import_clr — This function automatically creates the SQL Type wrappers based on the CLR Reflection API.

Synopsis

any import_clr ( in assemblies_vector any ,
  in classes_vector any ,
  in security_mode integer );
 

Description

This function automatically creates the SQL Type wrappers based on the CLR Reflection API.

Parameters

assemblies_vector

a vector of assembly names (as VARCHAR) to look into (or null).

classes_vector

a vector of type names to create SQL type wrappers for (or null to mark all the types in the assemblies specified by assemblies_vector. In that case the assemblies_vector cannot be NULL).

security_mode

This optional parameter defines the access mode as follows:

0 - restricted (default if unspecified)
1 - unrestricted

Examples

Example 24.186. Importing a Class

Here is a simple C# program that we can import and use with Virtuoso. This example requires that you are running Virtuoso with CLR support.

Using a text editor create a C# source file in the server root directory called sanity.cs, with the following contents:

using System;

public class sanity
{
    public static string test(string  name) {
       return "Hello "+ name + ", from Virtuoso";
    }
}

This sample needs to be compiled into bytecode assembly before it can be used. Use a command prompt that is suitably set up to find .NET utilities in its path, the .NET Framework SDK installation provides a shortcut in the Start menu to a command prompt that is preconfigured. From the command prompt change directory to the Virtuoso server root containing the C# source file. Execute:

C:\Program Files\OpenLink\Virtuoso 3.0\bin>csc /target:library sanity.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

Now this library must be introduce to the Virtuoso Server. Using ISQL use the following commands to test the CLR:

C:\Program Files\OpenLink\Virtuoso 3.0\bin>isql 1112
Connected to OpenLink Virtuoso
Driver: 03.00.2315 OpenLink Virtuoso ODBC Driver
OpenLink Interactive SQL (Virtuoso), version 0.9849b.
Type HELP; for help and EXIT; to exit.
SQL> DB..import_clr (vector ('sanity'), vector ('sanity'));

Done. -- 300 msec.
SQL> select sanity::test('Rob');
callret
VARCHAR
______________________________________________

Hello Rob, from Virtuoso

1 Rows. -- 60 msec.

Congratulations, you have proven that your Virtuoso server can run .NET classes.