Mailing List Archive



Back to the month index Back to the list index

Howie (caffeine@toodarkpark.org)
Sun, 16 Nov 1997 22:35:00 -0500 (EST)


Date: Sun, 16 Nov 1997 22:35:00 -0500 (EST)
From: Howie <caffeine@toodarkpark.org>
Subject: Re: Datatypes
Message-ID: <Pine.LNX.3.96.971116220736.1275C-100000@brap.toodarkpark.org>

On Sun, 16 Nov 1997, Chris Lambrou wrote:

> I asked this question before and I got a hundred or so angry answers
> directing me to the FAQ. So I'll be more specific this time:
>
> I've written a utility called mSQL Keeper (demo/download at
> <http://www.cglis.com/msql_keeper>). This thing works with mSQL 1x and
> now I'm working on adding functionality for mSQL 2x. My problem is
> datatypes. I've seen mSQL 2 intallations with the mSQL 1x datatypes
> plus TEXT, DATE and MONEY, and other with the mSQL 1x datatypes plus
> TEXT. The provider that I'm on has an mSQL 2 installation with just the
> TEXT new data type.
>
> I need to automatically configure the Keeper according to what datatypes
> are available to that installation. So I'm asking if it's possible,
> thru Perl/Msql.pm to retrieve the datatypes available to that particular
> installation. Is this possible?

each field will have its type set in the m_field structure. note that i
have no idea what this would be in perl as i've only worked with the C
API, but there ought to be some functions to show the field types.

---[ CUT: msql.h ]---
typedef struct field_s {
        char *name,
                *table;
        int type,
                length,
                flags;
} m_field;

....
#define INT_TYPE 1
#define CHAR_TYPE 2
#define REAL_TYPE 3
#define IDENT_TYPE 4
#define NULL_TYPE 5
#define TEXT_TYPE 6
#define DATE_TYPE 7
#define UINT_TYPE 8
#define MONEY_TYPE 9
#define TIME_TYPE 10
#define LAST_REAL_TYPE 10
#define IDX_TYPE 253
#define SYSVAR_TYPE 254
#define ANY_TYPE 255
---[ CUT ]---

you can use this code:

---[ CUT ]---
m_result *fieldRes;
m_field *field;
int msql=0;

<do all the connection stuff>

if( ( fieldRes = msqlListFields( msql, "someTable" ) ) )
{
  while( ( field = msqlFetchField( fieldRes ) ) )
  {
    switch( field->type )
    {
       case CHAR_TYPE:
         printf( "%s is a CHAR field.\n", field->name );
       break;

       default:
         do_stuff();
       break;
     }
  }
  msqlFreeResult( fieldRes );
}
---[ CUT ]---

this way, you shouldn't have to worry if a mSQL installation supports a
specific datatype. if you're interested, i still have some src lying
around that accomplishes most of what you want it to do. its in C and
Objective-C, tho.

---
Howie <caffeine@toodarkpark.org>   NeXTmail accepted as of Sat-15-Nov
URL: http://www.toodarkpark.org    Business: http://www.cgishop.com
Unix, Motif, NEXTSTEP              CGI/Database programming in C,ObjC,PERL