× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Sat, 8 Jun 2002, Simon Coulter wrote:

> C is fine for bits and bytes but it sucks for database work -- you might
> want to consider embedded SQL or the SQL CLI instead.

This is not really true.  Just like the statement you made about K&R doing
the world a disservice by developing C is not true.  Come on, all
languages suck.  The moronic way RPG does MODs is an example, as well as
its rotten way of doing pointers.  Shell programming and OCL has a
sometimes bewildering syntax and CL can't do anything decent with
variables.

Here is an example of how C can be rather RPG-like when doing database
work.  This sample code is from a customer maintainance program I wrote
for linux, mysql, and gtk.

[from db.h]
#include <gtk/gtk.h>

typedef struct
  {
    const gchar *cunumber;
    const gchar *cushipnum;
    const gchar *cuname;
    ...
  }
customer_record;


[from db.c]
#include "db.h"
#include <mysql/mysql.h>

customer_record customer;
MYSQL mysql;
MYSQL_RES *customerres;

int
get_record (char *record_name, int recordid)
{
  char query[MAX_QRY_LEN];
  MYSQL_ROW customerrow;

...

          memset (query, '\0', strlen (query));
          sprintf (query,
                   "SELECT
cunumber,cushipnum,cuname,cuatten,cupobox,cusuitapt,c
ustreet,cucity,custate,cupostcode,cucountry,cuareacode,cutelephon,cufaxarea,cufa
x,cudateopn,cusrvco,cusrvloc,cutaxable,cuemail,cuwebsite FROM customerp");

          if (mysql_query (&mysql, query))
            {
              cleanup (BAD_QUERY, query);
            }

          if (!(customerres = mysql_store_result (&mysql)))
            {
              cleanup (BAD_QUERY, query);
            }

...

      if (mysql_num_rows (customerres) > 0)
        {
          customerrow = mysql_fetch_row (customerres);
          customer.cunumber = customerrow[0];
          customer.cushipnum = customerrow[1];
          customer.cuname = customerrow[2];

...

        }

...

As you can see it works just like eval statements in RPG, no strncpy
required.  I can even use constants without having to use sprintf, as in:

        customer.cuname = "My Company Name";

This is far better than fixed length fields, a la RPG.

You also mentioned C's poor support for numeric types.  I guess you mean
not supporting fixed lenth numbers, like decimal(9,2).  I guess this could
be a problem (though I don't really see any reason why a very simple
solution could not be found.  Seriously, who cares if your number is 3,0
or int as long as you don't overflow your storage type?).  But consider
the stupidest numeric support on OS/400:  packed *and* not packed.  They
mean the same thing.  A packed 9,2 number is just as good as a decimal 9,2
number.  But having both sure screws things up when they are passed around
between commands, CL, and RPG.  Even RPG programs screw things up when
they are programmed defined.  There should only be one numeric fixed
length type: either packed or not packed, I don't care, but just one.
Everything on the system should know that a number is a number.

James Rich
james@eaerich.com



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.