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

No comments as yet.

Anonymous - Gravatar

No comments have yet been made to this posting.

Commentors on this Post-

Leave a Comment-

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs are automatically generated. Off-topic or inappropriate comments will be edited or deleted. Email addresses will never be published. Keep it PG-13 people!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

All fields marked with "*" are required.