Skip to main content

4GL's virtues (Part 1) Extensibility with C

One of 4GL's virtues is it's extensibility with C. You can call custom C programs from within 4GL code and pass values between them byval or byref.
Is there something that cannot be done by using 4GL? you need to interact with the OS? do you want do to something more advanced? Call C to the rescue.

A trivial example is generating random numbers, ie random - generic serial numbers. There is a session directive supported by Ingres that sets the seed so it makes it easy to fill a tablefield with random numbers (a part of a larger code sample follows) :


set random_seed


while rowno <= quantity do

loadtable cylki (sn = 'GE'+ varchar(random()));

rowno = rowno + 1;

endwhile;


Which loads a tablefield with as many SN's as the quantity variable directs.

But the set random_seed directive and the random function are supported on Ingres 2.6 onwards.What to do with older Ingres version? Replace functionality by calling a C program.

So the 4GL code now becomes :
while rowno <= quantity

callproc get_rnumber (byref(h_randno),rowno);

loadtable cylki (sn = 'GE'+varchar(h_randno));

rowno = rowno + 1;

endwhile;

And the get_rnumber C program :
#include 
#include 
#include 





Hence achieving the same functionality.
I think this is one of 4GL's greatest virtues : plug in ability

Comments

Popular posts from this blog

The Advent of SQL 2024 Has Commenced

  It's Advent - the time of year when we countdown the days to Christmas - and if your are a programmer complete daily coding challenges with the Advent of Code, the Advent of Perl, the Advent of Java, Javascriptmas, etc. Now we have the Advent of SQL too with 24 SQL challenges to complete before Christmas! https://www.i-programmer.info/news/204-challenges/17678-the-advent-of-sql-2024-has-commenced.html

Greenplum's Cloudberry Fork Enters Apache Incubator

  Cloudberry is the open source equivalent of Greenplum. Now it is fostered by the Apache Foundation as it acquires incubating status. It all began about six months ago. Greenplum's Github repositories was archived and went dark. This meant no more free new releases or security and bug fixes for its users. Why? Because in May 2024, Tanzu made the decision to close-source the project. https://www.i-programmer.info/news/84-database/17694-greenplums-cloudberry-fork-enters-apache-incubator-.html