Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

DB to use with Intel Fortran?

Ernie_P_1
Beginner
845 Views
Hello,



I have some general questions regarding databases and IVF. All programs I've ever written have used text files for input/output. I'm looking for some information on how to use fortran with different databases. I haven't been able to find much information, but I've seen that one can use embedded SQL.

Can anyone direct me tosome informationabout Fortran interfacing with various databases?

Do most people use multiple languages with one language for GUIs/databases and fortran for computation intensive programming?

Thanks
0 Kudos
1 Solution
Nick2
New Contributor I
845 Views
If you don't mind writing code to use ODBC, just write an interface to ODBC32.DLL, and you can do it all in Fortran. There's also a product which does it for you, called f90SQL. Here's a starter for writing your own interface:

interface
C see http://msdn2.microsoft.com/en-us/library/ms712455.aspx
C see also ODBC32.lib in notepad
integer(2) function SQLAllocHandle
& (HandleType,InputHandle,OutputHandlePtr)
!DEC$ATTRIBUTES STDCALL,DECORATE,ALIAS:"SQLAllocHandle"::SQLAllocHandle
!DEC$ATTRIBUTES VALUE::HandleType
!DEC$ATTRIBUTES VALUE::InputHandle
!DEC$ATTRIBUTES REFERENCE::OutputHandlePtr
integer(2) HandleType
integer(4) InputHandle,OutputHandlePtr
end function

(etc)

To use it:

iRet = SQLAllocHandle(1, 0, EnvHndl)

Microsoft has an excellent documentation of the ODBC SQLWhatever functions. MSDN, Google, and examples posted for f90SQL will be your friend if you want to go the ODBC route.

Perhaps you want to use, say, SQLCE...oh dang, ODBC is too old - there is no ODBC interface, and you must at least move to OLEDB.

This is where you can use the power of writing your app in multiple languages. What I ultimately did was write a C++/CLI library that does all the database manipulation I care about (open, write/execute non-query, read scalar), and link my Fortran with the C++/CLI library. Database programming IMO has gotten a lot easier with the latest innovations. Again, the source to learn about C++/CLI/OleDbCommand (and native versions for Oracle, SQL, etc.) is Google. CVF/IVF also have a section in their help that describes mixed mode programming (or was it mixed language programming?).

One of my coworkers writes everything in Fortran, including the windows UI. Personally, I prefer to take advantage of what each programming language does best, and to combine the result. My front end is VB.NET/C#, my floating point code is Fortran, my database writer is C++/CLI, and the piece that visualizes what's in the database is VB.NET/C#/XNA. And so, I've come full circle...

View solution in original post

0 Kudos
3 Replies
Nick2
New Contributor I
846 Views
If you don't mind writing code to use ODBC, just write an interface to ODBC32.DLL, and you can do it all in Fortran. There's also a product which does it for you, called f90SQL. Here's a starter for writing your own interface:

interface
C see http://msdn2.microsoft.com/en-us/library/ms712455.aspx
C see also ODBC32.lib in notepad
integer(2) function SQLAllocHandle
& (HandleType,InputHandle,OutputHandlePtr)
!DEC$ATTRIBUTES STDCALL,DECORATE,ALIAS:"SQLAllocHandle"::SQLAllocHandle
!DEC$ATTRIBUTES VALUE::HandleType
!DEC$ATTRIBUTES VALUE::InputHandle
!DEC$ATTRIBUTES REFERENCE::OutputHandlePtr
integer(2) HandleType
integer(4) InputHandle,OutputHandlePtr
end function

(etc)

To use it:

iRet = SQLAllocHandle(1, 0, EnvHndl)

Microsoft has an excellent documentation of the ODBC SQLWhatever functions. MSDN, Google, and examples posted for f90SQL will be your friend if you want to go the ODBC route.

Perhaps you want to use, say, SQLCE...oh dang, ODBC is too old - there is no ODBC interface, and you must at least move to OLEDB.

This is where you can use the power of writing your app in multiple languages. What I ultimately did was write a C++/CLI library that does all the database manipulation I care about (open, write/execute non-query, read scalar), and link my Fortran with the C++/CLI library. Database programming IMO has gotten a lot easier with the latest innovations. Again, the source to learn about C++/CLI/OleDbCommand (and native versions for Oracle, SQL, etc.) is Google. CVF/IVF also have a section in their help that describes mixed mode programming (or was it mixed language programming?).

One of my coworkers writes everything in Fortran, including the windows UI. Personally, I prefer to take advantage of what each programming language does best, and to combine the result. My front end is VB.NET/C#, my floating point code is Fortran, my database writer is C++/CLI, and the piece that visualizes what's in the database is VB.NET/C#/XNA. And so, I've come full circle...
0 Kudos
Ernie_P_1
Beginner
845 Views
Thanks for the great information.



Should I be able to open ODBC32.lib with notepad?

I was thinking that the makers ofF90SQL are no longer supporting that package, but I could be mistaken. Has anyone ever used ForDBC from QT Software?
0 Kudos
Nick2
New Contributor I
845 Views

Quoting - Ernie P.

Thanks for the great information.

Should I be able to open ODBC32.lib with notepad?

I was thinking that the makers ofF90SQL are no longer supporting that package, but I could be mistaken. Has anyone ever used ForDBC from QT Software?


You certainly can open ODBC32.lib with notepad, but I don't think you'll find anything too useful there. Microsoft's documentation of the ODBC functions by far beats looking through the binary file. Also, if you find C or C++ examples of how to use ODBC, that works great too.

You are correct - f90SQL is no longer supported. But I would still look into it, because if nothing else, you can get great examples. Steve (Dr Fortran) posted a version that works with IVF some time ago, and has the examples.
If you have the f90SQL figured out, and you want to move to using straight ODBC, it's not a big jump. The pattern to the madness is that something like

result=SQLWhateverFunction(2,SomeArgument)

will be written as

call f90SQLWhateverFunction(2,SomeArgument,result)
0 Kudos
Reply