farfromfearless

Printing to a matrix printer from PostgreSQL

Recently I found an interesting piece of code again which I would like to share with you. :-) I produced the code about a year ago for a project which needed offline data logging.

I used the piece of code to print a line to a matrix printer from PostgreSQL. The matrix printer was connected to the database server and supplied with endless paper. I used a matrix printer, because you can print directly to the device.

With the method, described below, it’s possible to print with a SQL query or print something initiated by a trigger. Using this method you can log specific data ‘offline’.

The print_line method consists of three files; print_line.c which contains the code to address the printer, a Makefile to compile the print_line.c file and a print_line.sql file which creates the function in SQL.

print_line.c

Makefile
MODULES = printhash
PGXS := $(shell pg_config --pgxs)
include $(PGXS)

print_line.sql
CREATE FUNCTION print_line(text) RETURNS integer
AS '/usr/local/libexec/print_line.so', 'print_line'
LANGUAGE C STRICT;

Installation:
mkdir /home/user/print_line
cd /home/user/print_line
unzip print_line.zip
make
cp print_line.so /usr/local/libexec/
// open postgresql command line client and execute:
# \i /home/user/print_line/print_line.sql

Usage:
SELECT print_line('Hello World!');

Download:
Download print_line.zip

Artikel in Linux Magazine

  • Posted: May 29, 2010
  • |
  • Author: Melvin
  • |
  • Filed under: Diversia,Games,Stories
  • |
  • Tags: No tags set for this entry.

Deze week is een interview met mij over Diversia in Linux Magazine verschenen.

“Verder spraken we voor deze editie met de ontwikkelaar van Diversia, een open source-variant op Second Life. Waarom Diversia wel een succes wordt, terwijl Second Life langzaam verandert in een spookstad, legt projectleider Melvin Rook uit in een rijk geïllustreerd artikel.”

Inmiddels heb ik ook al veel positieve en leuke reacties op het artikel ontvangen. :-)

Synology DS1010+ NAS

A while ago I decided to buy a Synology DS1010+ to backup my data. People keep me asking why I bought a Synology. Well, next to the fact it runs on open source software, Linux and has wide variety of features, I guess the following video explains everything.

More information on Synology NAS systems can be found at www.synology.com

  • Apr 2010
  • 8

Diversia ported to FreeBSD

This week I finished the FreeBSD port of Diversia. The information about the FreeBSD port can be found in the...

  • Apr 2010
  • 8

New Google design… buggy?!

Update (April 13, 2010): I asked myself how to file a bug report. It seems blogging is a way to...

  • Jul 2009
  • 1

Lightning storm Arnhem

In the weekend a lightning storm passed Arnhem. It was too hot to sleep, so I decided to film it...

  • Feb 2009
  • 20

Using wxFormBuilder with Code::Blocks on Mandriva 2009

After some puzzling I found out how to setup a nice development environment with wxFormBuilder and Code::Blocks on Mandriva Linux...

  • Feb 2009
  • 5

Hackers ahead

Someone apparently hacked into an electronic road sign in Hamilton County Monday morning, prompting stares and giggles from motorists because...

  • Jan 2009
  • 14

Texas Instruments TMP421 / 422 / 423 Linux Device Driver

Last week Raymond and me finished the Linux device driver for the Texas Instruments TMP421, TMP422 and TMP423 temperature sensors....

  • Jan 2009
  • 8

Solar powered mini car

Somehow I was reminded of an old project of mine. After a little search in my archive I found all...

  • Dec 2008
  • 11

Game development – how to begin?

How to begin with game development? That’s the very same question I asked myself a few years ago. I think,...

  • Dec 2008
  • 2

Pirates of the Amazon

Yet another brilliant firefox extension: Pirates of the Amazon Add-on “How can you compete with free? You cant!” – Lawrence...

Recent Comments-

  • Melvin Check the permissions of the binaries and run `chmod +x ` to set the execution permission.
  • Ash Hi, i run the command line, but it says permission denied :/
  • @Roosch P.s. Ik heb gelijk met het filter voor doorsturen ook ingesteld dat de mail moet worden verwijderd en het...
  • @Roosch Hey Melvin, Het is alweer een tijdje geleden dat je je oplossing op Internet hebt gezet, maar wilde je even...
  • Melvin Jon Wiley said: This is one of the many, many experiments that Google runs. Thanks for the bug report. No...