The f90SQL library

 

As a programmer that is equally comfortable working with several computer languages, there is no doubt in my mind that Fortran is still the language of choice for high performance scientific and engineering applications. Besides the fact that the language was originally designed for this purpose, Fortran compilers have a long history of optimization and improvements geared to maximize their performance in number crunching applications. Other languages, for example C, have evolved into complex programming environments that offer great flexibility and even new programming paradigms (OOP). However, this same complexity has resulted in compilers that produce less-than optimal executables. Until recently, C++ compilers were among the poorest performers for numerical applications. This situation has improved with the use of templates and the penetration of C++ in the scientific and engineering community, but C++, as well as most other general-purpose languages, still lag behind most Fortran compilers in terms of pure numerical performance. In this sense, the relative simplicity and rigidity of Fortran has been one of its main assets.

 

In spite of Fortran's leading position in terms of numerical performance, we have to recognize that it is far behind many other programming languages in terms of flexibility, user interactivity features, and accessibility to new technologies. While most Windows compilers include excellent libraries to access databases and take advantage of  interoperability features of the current Windows' data-oriented technologies, Fortran compilers are still restricted to the most primitive file-handling capabilities. Fortran programmers that attempt to take advantage of these technologies often face the intimidating prospect of having to call operating system services with a language that simply was not designed for that purpose.

 

Most scientist and engineers that need to handle large amounts of data are aware of the convenience of keeping this information in databases. Database Management Systems (DBMS) offer a myriad of tools that facilitate the organization and maintenance of large bodies of data, and in most cases they also have some of the tools necessary for simple analyses and reporting. One of the most exciting developments in databases technology it the current tendency towards source interoperability. The idea behind this is to offer end-users a framework to access data that is independent of the format and, in many cases, the location of the data. In Microsoft Windows, this interoperability is achieved through Open Database Connectivity (ODBC). The ODBC is an Application Programming Interface (API), i.e. a more or less coherent library of functions and subroutines that can be called from your application to access different database management systems. One of the main advantages of using ODBC is that a single application can access different databases with the same source code. Applications call functions in the ODBC interface, which are implemented in database-specific modules called drivers. The use of drivers isolates applications from database-specific calls in the same way that printer drivers isolate word processing programs from printer-specific commands. Because drivers are loaded at run time, a user only has to add a new driver to access a new DBMS; it is not necessary to recompile or relink the application.

 

Although Microsoft's ODBC Software Development Kit claims that the ODBC's API is language-independent, the truth is that Microsoft Window's APIs are difficult to use in any language other than C. For a Fortran programmer, direct calls to the ODBC-API means that a large amount of developing time will have to be devoted to deal with the problem of passing pointers, converting strings from C to Fortran format, taking care of whether variables are passed by value or by reference and a myriad of other little details. The complications that result from calling these functions from Fortran are usually enough to discourage programmers from using them. Many programmers decide to develop their numerical applications in C or Visual Basic because they needed access to information stored in databases, even though Fortran could produce better performance. The objective of f90SQL is to eliminate this dichotomy.

 

f90SQL is a Fortran interface to Microsoft's ODBC-API version 3.5. The subroutines in f90SQL work as a wrap around the API. This allows Fortran programmers to use ODBC functions using the calling conventions and data types they are used to. f90SQL isolates Fortran programmers from the details of developing applications that call an API designed with C programmers in mind. My main motivation for developing f90SQL was the possibility of combining the best of both worlds. Through the use of ODBC, you get the convenience of fast and relatively easy access to data stored in many different formats. With Fortran you get an optimized language to perform numerical computations on your data. Additionally, if you use one of the many DBMSs on the market, you also get the benefits of an environment that would let you manipulate and maintain your data in the most efficient way.

 

Because f90SQL is just a jacket to access the ODBC functionality from Fortran, you still need to understand the concepts behind this API. A good portion of this manual is dedicated to explaining these fundamentals. Although f90SQL offers some added functionality to the API, most f90SQL subroutines are direct equivalents to Microsoft's ODBC-API functions. I believe Microsoft did a good job documenting their ODBC-API for C programmers, and this manual does not attempt to be an original piece of work. Rather it is a fast way to introduce you to the use of the f90SQL interface to Microsoft's ODBC. Because of this, the manual draws strongly from the documentation included in the ODBC Software Development Kit released by Microsoft. This SDK is freely available from Microsoft Website (http://www.microsoft.com). I recommend that you download the kit and peruse its help files, as it contains much information and details not included here. Many of the code examples in the Microsoft's SDK (the kit is addressed to C programmers, so all its code is in C) have been adapted to Fortran and f90SQL in this manual.