home :: technology

Calculating Distances in Microsoft SQL Server

One feature of almost every modern commercial website is the location finder. Enter in a search address, and site displays the closest locations to it with the distances (as the crow flies).

I ran into a couple of peculiar bugs trying to calculate distances in SQL. Floating point math is never easy, and these are the issues I faced using our Microsoft SQL Server database.

See more ...

Last Updated: Tue, 14 Feb 2017

Perl DBI Issue With iSeries AS400 Returning Null Columns on 64-bit Linux

We’re having an issue with database queries to the iSeries AS400 through Perl using DBI and DBD::ODBC. The issue occurs when the SQL statement contains an outer join and the query returns rows with NULL columns:

my $sql_query = qq|select PRSK01, PSTA15
                    from TESTHA.POLMAST
                    left join TESTHA.P15POLDP
                    on POLC01 = PPOL15 where POLC01 = 003950136|;

# Execute the sql query
my $sth = $dbh->prepare( $sql_query )
                    or die $sql_query, "
\n", $DBI::errstr; my $data = $dbh->selectall_arrayref( $sth, {Columns=>{}}, @sql_data ) or die $sql_query, "
\n", $sth->errstr;

The error returned is:

DBD::ODBC::db selectall_arrayref failed: st_fetch/SQLFetch (long truncated
DBI attribute LongTruncOk not set and/or LongReadLen too small) (SQL-HY000)

See more ...

Last Updated: Wed, 08 Aug 2012

Del.icio.us Complete Firefox Plugin for Firefox 4.x+

I love del.icio.us (or the Yahoo’ed, dummied-down delicious.com) to manage my bookmarks. Unfortunately, the Firefox extension I’m used to using, del.icio.us Complete, is no longer supported, and thus doesn’t work with the latest versions of Firefox.

This is my hacked version of the Delicious Complete extension, which allows it to run in version 4.0 or later. Please note: consider the extension beta software. It works fine for me on Ubuntu and Windows XP, but I haven’t done extensive testing. Please let me know if you have any issues.

Download and Install Del.icio.us Complete

Thanks to verymurklins for providing the original hack for version 3.0

Last Updated: Sat, 24 Mar 2012

Notes from the Perl FAQ

Like the fellow that never read his car’s owner’s manual, I had never read the entire Perl FAQ. I finally did it over the holidays, and these are some notes that I took.

See more ...

Last Updated: Fri, 20 Jan 2012

No such file or directoryectory

When I execute a CVS update command at work, I often get the following error:

[caran@mater safetypublic]$ cvs -q update -AdP
: No such file or directoryectory /home/cvs/safetypublic/rsvp
cvs update: skipping directory rsvp

No such directoryectory? What the heck is that??

See more ...

Last Updated: Thu, 10 Nov 2011

Calling a Perl CGI script from within another CGI script

Awhile back we had an issue where a coworker wanted to use one of my Perl CGI scripts inside of her scripts, using the backticks method to have it spit its output to the webpage. But for some reason, my script refuse to recognize the arguments she was passing it. The weird thing was, if we ran her script from the command line, everything worked fine.

The issue is in the way CGI.pm detects whether it is being called from a web browser or from the command line. It checks for the presence of the REQUEST_METHOD environmental variable. If it is present, CGI knows to get its arguments from the web browser.

See more ...

Last Updated: Fri, 19 Nov 2010

Java Terminator: Cross-Platform Terminal Emulator

For years, I’ve been searching for a suitable terminal emulator for Cygwin, but nothing seemed as polished or had enough features to pull me away from the boring default.

I finally found the Holy Grail in a program I’ll call Java Terminator. The authors of this fine program just call it Terminator, but unfortunately a later Linux GNOME-based terminal emulator of the same name stole some of their thunder.

See more ...

Last Updated: Fri, 05 Nov 2010

Using LWP::Simple to retrieve binary data

We have a Perl CGI script at work that acts as a proxy. It grabs a pkcs12 digital certificate file from an internal server and delivers it to a user through his or her web browser. The pkcs12 file is in binary format.

Everything worked fine until put the code on a new server. Suddenly, the files downloaded by the web users were corrupted. We also began seeing the following warning in the log files:
Wide character in print at download.cgi line 124.

Here is the code…

See more ...

Last Updated: Fri, 16 Apr 2010

Installing ODBC on Linux

At work, we use Microsoft SQL Server and IBM AS400 databases. Here’s how I set our Linux boxes to allow them to connect to the databases through ODBC. There are seperate instructions for the Debian and Ubuntu (9.10 Karmic Koala) and Red Hat Enterprise Linux (RHEL4 and RHEL5) distributions.

ODBC connections require several layers of software to work. The bottom layer consists of the individual ODBC drivers for each database system. Our top layer is the DBI/DBD interface for Perl. In between these layers is the ODBC driver manager, which keeps track of the DSN’s and their corresponding ODBC drivers.

Packages and Software to Install

Ubuntu Version (tested on 9.10 Karmic Koala)
Debian Version (“unstable” distribution)

We use unixODBC as our ODBC driver manager. First, install unixODBC:
NOTE: Perl’s DBD::ODBC module requires the developer’s version of unixODBC, so install that one.

  # apt-get install unixodbc-dev

See more ...

Last Updated: Tue, 09 Mar 2010

Things I always need to look up in Perl

Here are some random Perl things I always need to look up:

See more ...

Last Updated: Mon, 21 Dec 2009

PNG Color Mismatch in IE7

Internet Explorer never fails to impress me in its ability to frustrate and complicate my web designs. The screenshot below shows a png image with a #3D6B99 background color over a div with the same #3D6B99 background color (specified in CSS).

PNG Color Mismatch

The background colors don’t match! Of course everything looks fine in Mozilla Firefox. So what’s the problem?

See more ...

Last Updated: Wed, 18 Feb 2009

Writing an Apache Module for RHEL 5

Recently, I was asked by my employer to write an Apache module. The module reads the requestor’s digital certificate and checks it against our database of active users. In this post, I’ll explain how to get started writing Apache modules, especially for Red Hat Enterprise Linux 5 (RHEL 5.2).

See more ...

Last Updated: Wed, 14 Jan 2009

Debian Upgrade Woes

We run two Debian Linux servers at work: a back-up web server and a sandbox for random Linux development. Recently, I decided to do an apt-get upgrade on the servers to update their software packages to the latest versions.

I figured it would be simple. We were already running the unstable branch. And it hadn’t been that long since I last attempted an upgrade. So, as root, I issued the following commands:

# apt-get update
# apt-get dist-upgrade

Uh-oh! I kept getting the following error:

Setting up libc6 (2.3.5-3) ...
mv: error while loading shared libraries: libacl.so.1: cannot enable
executable stack as shared object requires: Error 14 

See more ...

Last Updated: Thu, 17 Nov 2005

Javascript Support for Firefox

Making your Javascript code work on both IE and Firefox isn’t hard. Here are a few modifications to IE-only code to make it work on Firefox:

See more ...

Last Updated: Thu, 17 Nov 2005

Incorporating Blosxom in an Existing Website

Here’s how I configured my website to use Blosxom as its CMS (content management system - a fancy term for the way a site is organized). My requirements were:

  • The root URL (www.kcaran.com) had to point to blosxom.cgi.
  • The URL’s to blog entries should look like static links (e.g., http://www.kcaran.com/entries/technology/linux/debian_upgrade_woes.html
  • Files and directories outside of Blosxom should be accessible as before. My Fantasy Football pages should still reside at http://www.kcaran.com/footb/. And I should be able to create new files and directories without changing the web server configuration.
  • Once you have Blosxom configured and working the way you want, place it in a directory named blosxom under your root web directory. For me, that would be /var/www/caran/blosxom.

    [caran@mlougee caran]$ pwd
    /var/www/caran
    [caran@mlougee caran]$ ll blosxom/
    total 60
    drwxrwsr-x   9 caran    www-data  4096 Oct  7 14:17 ./
    drwxrwsr-x  25 caran    www-data  4096 Oct  7 14:27 ../
    -rw-rw-r--   1 caran    www-data    14 Sep 29 08:57 .cvsignore
    drwxrwsr-x   2 caran    www-data  4096 Oct  7 14:54 CVS/
    -rwxrwxr-x   1 caran    www-data 16784 Oct  7 14:17 blosxom.cgi*
    drwxrwsr-x   3 caran    www-data  4096 Oct  5 12:29 css/
    drwxrwsr-x   4 caran    www-data  4096 Oct  7 13:41 entries/
    -rw-r--r--   1 www-data www-data     0 Oct  7 14:16 error_log.txt
    drwxrwxr-x   3 caran    www-data  4096 Oct  7 14:54 feedback/
    drwxrwsr-x   3 caran    www-data  4096 Oct  7 14:23 flavours/
    drwxrwsr-x   3 caran    www-data  4096 Oct  4 14:34 images/
    drwxrwsr-x   4 caran    www-data  4096 Oct  5 12:30 plugins/
    

    Last Updated: Thu, 17 Nov 2005

Using CVS in a Windows environment

Managing and tracking changes made to code, otherwise known as version control, is vital to any software project, large or small. CVS, the Concurrent Versions System, is one change management application. This is a summary of how to use CVS in an environment with servers running both Unix and Microsoft Windows operating systems.

See more ...

Last Updated: Wed, 05 Oct 2005

Using Perl Under IIS

Some may consider me a masochist, but Perl is my language-of-choice for web applications, even when I am “forced” to use Microsoft’s Internet Information Services, otherwise known as IIS, for my web server.

As usual, the Microsoft server has little quirks that need to be tamed in order to write cross-platform code. Here are some tips for making your perfectly good Perl code run under IIS:

See more ...

Last Updated: Mon, 26 Sep 2005

Perl Modules Primer

Splitting a Perl application into seperate files can be trickier than doing it in other languages, like C or C++, but it is still an important part of producing maintainable code.

Creating the Package

A Perl module is a collection of code stored in a single file. By definition, all variables and function names in the module are stored in a package with the same name as the file.

For example, a module named Cgiutils would be stored in the file Cgiutils.pm. Any functions or variables in the module belongs to the Cgiutils package namespace. The beginning of the file should look like this:

See more ...

Last Updated: Mon, 26 Sep 2005

Sending an email in HTML format using Outlook

For those of you lucky enough to use Microsoft Outlook for email, here’s how to send a message in HTML format:

See more ...

Last Updated: Mon, 26 Sep 2005

SQL Server: Padding of data in columns of type ‘varchar’

I’ve been having some trouble with the way Microsoft SQL Server pads strings stored in its tables with spaces. Generally, I would assume that columns of type ‘CHAR’ would be a fixed length (and therefore padded), while columns of type ‘VARCHAR’ would be variable length. But I would be wrong.

The default behavior for SQL Server 7.0 and Server 2000 is that CHAR’s and VARCHAR’s are padded to their maximum lengths. To make the VARCHAR columns unpadded, the ‘ansi_padding’ property needs to be set to ‘off’. Unfortunately, you must do this every time you open a session with the database server. There isn’t a way to force ANSI padding off as the default.

See more ...

Last Updated: Mon, 26 Sep 2005