One of the major reasons people use Rails and Database systems is to pull useful information out of them. We have happily been using a tool called ReportMan for our Windows based applications (ActiveX and Dot Net) and found it to have a number of desirable features:
This last feature caught our eye, so we decided to try our luck at deploying it on Linux, with shell support only. A combination of scattered documentation for ReportMan under Linux and our own inexperience with Linux administration made it difficult for us to install.
Ours is a standard setup hosted at Railsplayground, using:
After a couple weeks of hitting brick walls, we shelved it, figuring there had to be a better way. We played with other free report generators, such as PDFWriter with some success, but never found anything that worked quite how we wanted. While we had a couple solutions that worked, we weren’t really happy with any of them, so we decided to take another look at ReportMan. Truly, if we had not already had such a good experience using it for stand-alone applications, we would have continued looking elsewhere. This second time, with a bit of hard work, luck, and great support from RailsPlayground we got it up and running. Hopefully, if anyone else is interested in doing this, our experiences will help move them along.
There are two central resources that we found for ReportMan:
ReportMan touts itself as also having a report server, but our only interest was in getting the command line tools up and running, so we could execute these from our Rails application. We would be using the GUI Report Designer to create our reports in MS Windows.
So our goal was fairly simple:
Get ReportMan installed on Linux, along with all the necessary dependencies, so that we could successfully create reports from the Rails environment.
Since ReportMan was programmed in Delphi, it shouldn’t be a big surprise that the Linux version was compiled with Kylix. Now information on Kylix is rather slim as well, but given its relatively short life and as it was abandoned by Borland back in 2004 or 2005. There are downloads available, but not in any obvious places or collected in any way that we were able to discover.
This was a Portugese page that we kept translated for some info on Kylix setup: http://tinyurl.com/yw9ocw
So the first key to getting everything working was that all of the ReportMan Linux executables as well as all of the correct Shared Library files (.so) needed to be located and installed on our box. At the bottom of this, we provide a link to all of the files that we used to get things working in one tar ball.
Two files need to be created in ~/.borland/
We used the [MSConnection] setting in dbxconnections, with the following parameters, as this allows us to keep the report pretty much the same without too much modification to work between Linux and Windows.
[MSCONNECTION]
BlobSize=1
Database=your_database_name
DriverName=OpenODBC
ErrorResourceFile=
HostName=localhost
LocaleCode=0000
Password=your_db_password
User_Name=root
We used the OpenODBC driver settings in dbxdrivers.
[OpenODBC]
GetDriverFunc=getSQLDriverODBC
VendorLib=/usr/lib/libodbc.so
LibraryName=/usr/lib/libdbxoodbc.so
Database=Driver={MySQL};Server=localhost;Port=3306;Option=131072;Stmt=;Database=database_name;Uid=root;Pwd=your_db_password;
User_Name=root
Password=your_db_password
See the attached reportman.tar.gz file. Under the directory kylix/kylix so files/ there are three libraries. Copy these into /usr/lib.
Run ldconfig after they’ve been copied.
unixODBC-devel provides this lib. unixODBC is currently availible in a gzip, tar format. This means that you should;
Doing so will create a unixODBC directory with all source files inside. Copy over the .so files into /usr/lib/.
Run “ldconfig” after they have been copied → if you copied them correctly you will get no message.
We provided this in the attached reportman.tar.gz file. It’s under the usr-lib/ directory, just copy this into /usr/lib and run ldconfig.
You can use your package manager to install this:
yum install mysql-connector-odbc
Then you’ll need to configure it with these two files: /etc/odbcinst.ini and /etc/odbc.inst.
/etc/odbcinst.ini:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc.so
Setup = /usr/lib/libodbcmyS.so
UsageCount = 4
When you’re done configuring ODBC, you need to run two commands to read it:
bash> odbcinst -i -d -f odbcinst.ini bash> odbcinst -i -s -f odbc.instTo use Reportman, there are command line binaries that generates reports from .rep files. So, we simply build the report on Windows and generate PDFs on our server using Rails. Inside the attached file, we included reportman. Just copy it over to /usr/local/.
The actual command to create a PDF is:
bash> /usr/local/reportman/printreptopdf open_orders.rep new_file.pdfThe use this with Rails, simply make an action in our controller that sends the PDF:
def pdf data = `sudo -u apache -H /usr/local/reportman/printreptopdf PATH/TO/REPORT.rep` send_data(data, :type => “application/pdf”, :filename => “test.pdf”) endWe’re using the sudo -u apache -H option to run the command as user apache and use apache’s home directory (this is important, reportman will look under ~/.borland for the two config files, so make sure you put -H).
Also, if you’re having trouble, reportman will send errors to STDERR. You can direct that to a file to debug:
`sudo -u apache -H /usr/local/reportman/printreptopdf PATH/TO/REPORT.rep 2>> stderr.txt`(note: DSACTIVITYOUT is the Dataset name that we chose in the ReportMan Designer)
ODBC SqlState: 42000
Native Error Code: 1064
[MySQL][ODBC 3.51 Driver][mysqld-5.0.27]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘[date_eta]-Date() AS days_out, IIf(Date()-[date_eta]>0,Date()-[date_eta],"OK") A’ at line 3
Solution> Fix the SQL statement. MS Access and MS SQL Server have significantly different SQL functions for things like string concatenation and type conversions.
Solution> You need to configure your ODBC settings. See “MySQL/unixODBC connector” section above.
Solution> Remove PARAMTITLE line or Parameter from report. Alternatively, be sure to pass it in correctly with the “-PARAMS=” statement
Once we got the program to run on the command line, we figured it would be pretty straightforward. Unfortunately, we hit a minor snag while debugging this.
Since we were running lighttpd, the command was processed as user “apache”. apache, by default, executes in /var/www
We created a symbolic link to “.borland” so we could get to dbxconnections and dbxdrivers.
We also needed to make minor changes to the report files so they would be processed correctly in Linux. In your .REP files, change the lines:
DataInfo = < item Alias = ‘MATREQ’ DatabaseAlias = ‘DATABASE_NAME_HERE’ SQL = …to use your preferred DatabaseAlias – this is needed especially if you are deploying multiple Rails apps on one server. DATABASE_NAME_HERE will be the name specified in your dbxconnections (.ini in windows) file.
Also change the lines:
DatabaseInfo = < item Alias = ‘DATABASE_NAME_HERE’ LoadParams = True LoadDriverParams = True LoginPrompt = False Driver = rpdataadoto
DatabaseInfo = < item Alias = ‘DATABASE_NAME_HERE’ LoadParams = True LoadDriverParams = True LoginPrompt = Trueand make sure that your alias name matches the DatabaseAlias that we changed above.
Once this was all done, we were finally up and running in Rails, with beautiful reports!
Here’s the tarball of all the .so files you need. It also includes Reportman and its dependencies (Kylix).