One thing I really love about working in Micro Focus is that innovation does not need to be revolution.
Musings on the sort of innovation you'll be learning
about at MF World.
Many years ago I was sat in a computer lab' at Daresbury Laboratory listening, young and innocent, to a brilliant scientist and one of my mentors at the time. Paul's response to my remark that re-writing some piece of code seemed easier than extending the existing code-base has stuck with me ever since. "It will always seem easier to re-write something than to figure out how it works" (or words to that effect - it was a while ago).
Here at Micro Focus we are doing some very exciting stuff with our technology. But we are doing the hard thing; this is innovation without revolution. Take cloud computing, where we implement standard COBOL technologies and mainframe emulation - then just put it in the cloud. Nothing thrown away, everything gained.
Perhaps at this point I should introduce myself. I am Alex Turner - a senior principal software systems developer at Micro Focus. What does that mean? I means I write a lot of code and get very excited about technologies that work well! I even have a personal blog called 'nerds-central'; maybe that says it all?
On the themes of innovation without revolution and cool stuff, I have recently been playing with COBOL.net. This stuff seems amazingly powerful to me because it does all the things native COBOL does (within reason) plus all the things that any other .net language (C# or VB) can do. Yes - really. But I don't like to take people's word for this sort of thing, I so have pushed further.
"Can we do something a bit off the beaten track? How about accessing MySQL on Windows from COBOL using ADO.net" (my brain talking). Now that is the kind of innovation that I like, take a bunch of things then work well and get some synergy from making them cooperate.
Talking To MySQL From COBOL Over ADO.net
The short answer to my mental questions is 'yes'; you definitely can connect COBOL to MySQL on Windows using ADO.net. What is more, it is very easy, and very fast. If you want a longer answer (with bits of code and stuff) then read on.
The first thing to do is install the MySQL ADO.net connector (here) and then fire up Visual Studio with COBOL (I used COBOL for Visual Studio which came with Net Express 5.1). Now add the MySQL connector as a reference to your project.
Now you will need to create a MySQL DbConnection. To keep the code neat, I suggest adding this to the repository paragraph of configuration section:
repository.
class cls-mysql-connection
as "MySql.Data.MySqlClient.MySqlConnection"
Now openning the connection is dead simple, you construct it
and call Open:
set sqlConnection to cls-mysql-connection::"New"()
move
"database=cobol_test;
server=localhost;user id=root; pwd=passWordHere;"
to sqlConnection::"ConnectionString"
invoke sqlConnection::"Open"()
You might want to put the open in a try block something like
this:
try
invoke sqlConnection::"Open"()
ex
invoke self::"WriteLine"(ex)
raise ex
end-try.
Finally, here is a lump of code which will read a record set from a query:
set command to dbh::"CreateCommand"()
move "SELECT * FROM junk" to command::"CommandText"
set reader to command::"ExecuteReader"()
set hasMore to reader::"Read"()
perform until hasMore = false
set hasMore to reader::"Read"()
invoke type "Console"::"WriteLine"("Key={0}, Value='{1}'"
reader::"Item"(0) reader::"Item"(1))
end-perform
Where ex, and hasMore are defined as:
01 hasMore condition-value.
01 ex type "Exception".
Conclusions
I really wanted to make this a brief 'taster'. The code examples are just enough to show the possibilities available by coupling COBOL with the .net framework. What I find really exciting is
that this new code can happily co-exist in the same program with more traditional procedural COBOL. As COBOL is a naturally data centric language, the potential of this and more sophisticate approaches seem endless.
Labels: COBOL, cobol.net, innovation
You should take a look at the EXEC ADO syntax provided with Net Express for .NET.
This provides the capability of connecting to data stores via ADO.NET using standard EXEC SQL syntax with applications compiled with the SQL(DBMAN=ADO) compiler directive, which simplifies the user program further than what you've demonstrated here.