Actually, MSSQL uses the same protocol as Sybase, and I believe if you write the code to be compatible with Sybase's CTLIB API it'll work with MSSQL as well.
You can also use the ODBC API. If GNU APL supported it, you might also get support for other databases with ODBC drivers for free.
If you want to look at implementing support for a new database API in GNU APL, start by looking at the file apl-sqlite.cc. In the function init_provider_map(), the available database types are registered (currently sqlite and postgres).
Next, you have to actually write the provider, in this case CtlibProvider, it should be a class that subclasses Provider. You need to implement the methods get_name() and open_database(). Whatever is returned from get_name() is what you use on the left-hand side of a call to SQL∆Connect. Once this function is called, the open_database() method of the provider is called. This method should return an instance of Connection.
The
Connection class contains a set of methods that you need to implement in order to provide all the functionality. This includes:
- make_prepared_query() prepares an SQL query for execution.
- make_prepared_update() does the same as the above, but for update statements which doesn't return any data. Some SQL API's (such as Sqlite) doesn't make a distiction so they do the same thing in both methods.
- transaction_begin/commit/rollback does what the name suggests.
- fill_tables() adds the names of all the tables to the provided vector.
- fill_columns() adds the names of the columns for a given table to the provided vector.
- make_positional_param() returns the name of a positional parameter. The APL API always uses the question mark (?) to specify positional parameters, but different databases uses different syntax. Postgres uses ?1, ?2, etc, but sqlite uses plain ? symbols. This method provides a mechanism by which the APL syntax can be converted to the format.
In writing this, I realised that there is a pretty bad bug in the implementation of replace_bind_args(). It will replace question marks even in strings, meaning that you can't create a query with an explicit ? in a string. I'll look into fixing that.
If you need more advice, please please let me know.
Regards,
Elias