Openservers

What is an Openserver?

In order to understand an openserver it is necessary to understand the Sybase architecture in a little more detail.

Every client calls a subroutine library named Open Client Lib to talk to a Sybase server. The Open Client library uses a Tabular Data Stream (TDS) protocol to talk to the Sybase server.

TDS is a delivers the ASCII buffer representing the query to the server and then returns the results, if any, from the server back to the client.

TDS keeps track of the number of fields and their datatypes in the return data. This is especially useful when the client and server are on machines with different architectures.

The Sybase server uses another subroutine library named Open Server Lib to accept client requests, process the requests, and send results back to the client.

It is possible to write your own set of C subroutines to take the place of the "SQL processing" part of the server. This is referred to as an openserver application.

tbd - figures software layers and software layers with an openserver application


How Does the Client Access an Openserver?

The client can do a remote procedure call to a C subroutine in an openserver application.

The RPC include the normal:

In the above example, the client has to send an RPC directly to the openserver. Very often, the client executes a stored procedure in a regular Sybase server (by sending a text buffer "exec" command), and the stored procedure performs the RPC on behalf of the client. "select" results from the remote procedure (in this case a C subroutine), will be returned to the original client.

figure - software layers with an openserver application going through a regular server


Typical Openserver Applications

So we see that it's very easy to get from a Sybase stored procedure into a Unix C subroutine.

This type of architecture is often used in what's called a gateway openserver. (The Sybase Net-Gateway product is a special case of this which, once again, we'll get to later)

A gateway openserver is used to access other, typically non- relational, databases.

The openserver application C subroutines would each be coded to perform a specific query in the foreign database. They would, however return their results as if a normal select statement had occurred in a stored procedure.

Sybase supplies two example programs: gateway.c and utility.c


The Sybase Net-Gateway

The Sybase Net-Gateway is an openserver application written by Sybase.

When a client executes an RPC to the Net-Gateway, the C subroutine in the Net-Gateway calls a special IBM CICS transaction on behalf of the client, with the parameters sent from the client.

Sybase has written it's own software to get in and out of CICS and DB2.

The Net-Gateway C subroutine then processes the output of the CICS transaction and sends the results back to the client as if a "select" statement had occurred.

Language Handler

What happens if the client logs directly into the Net-Gateway and submits a text buffer of SQL statements to it?

There's a special CICS transaction supplied by Sybase which accepts one parameter, a string of dynamic SQL text.

When the Net-Gateway gets an interactive text buffer of SQL, it automatically acts as if a special C subroutine was called by an RPC with a single SQL text buffer parameter. This is called the default language handler.

tbd, figure - accessing cics via rpc's

The language handler calls the special language handler transaction in CICS which submits the SQL text buffer to DB2.

The language handler is intelligent enough to process dynamic results of the language handler transaction and send the results back to the client.

The client thinks he just did a select on what looks like a DB2 database, but it was actually using Sybase's TDS network protocol.

tbd, figure - accessing cics via an SQL buffer to the Net Gateway.


Utility Openserver

This is a sample application which lets a Sybase stored procedure call a C subroutine in the Utility openserver to perform Unix operations.

The utility openserver contains a procedure called "cmd". This procedure accepts a string parameter representing a Unix command to be run.

The "cmd" procedure runs the command and returns the output of the command as a series of data rows to the client.

For example:

/* show who's logged into the Unix box */ exec SERVERNAME...cmd "who" /* send unix mail to unix userid bslade */ exec SERVERNAME...cmd "echo 'body of mail msg' | mail -s 'subject' bslade"

Next chapter.