🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #2887

Re: Oracle. How to get negative numbers ?

#2887
From: Arnie Mauer
Date: Tue, 25 Feb 2003 13:12
107 lines
4296 bytes
Victor,

I'm going to check into the (9,0) definition.  It certainly isn't large
enough to represent a 32 bit signed int.

We started with Oracle, now also support DB2 and I'm currently working on
SQL Server.  With Oracle, we use NUMBER(5) and NUMBER(10) for small int and
int, respectively.  However, for static fields, Oracle thinks they are a
TFloatField *.  Every else in the world uses INTEGER and the static fields
are represented as integer type.  Naturally, this screwed us when porting to
DB2 (that and a LOT of other things).

My mandate was to support these DBs (and maybe Teradata, ugh!) at runtime.
So, we know what the DB server type is at runtime.  This info is kept in the
Registry for any of our DB definitions.

At FormCreate time (or in the form's constructor) we determine the DB type,
and if it's not Oracle, we change the field types.  Kind of dirty and a
pain, but it works.  An example.

In the .h file:

   TFloatField *queryPSN;                        // NUMBER(10)
   TFloatField *queryCOUNTRYCODE;  // NUMBER(5)

In the cpp file:

   if ( m_DbType != DBTYPE_ORACLE )
   {
      XlReplaceFloat( this, & queryPSN );
      XlReplaceFloat( this, & queryCOUNTRYCODE, true );
   }

The XlReplaceFloat() function looks like:

__declspec( dllexport )
void XlReplaceFloat( TForm * frm, TFloatField ** fld, bool bSmall )
//
// Created for the port to DB2.
//
// Converts a persistent TFloatField to a TIntegerField.
//
// Oracle reports a NUMBER(n) field as a Float.  Therefore, persistent
//    fields, usually used only in OnCalcField events for "calculating"
//    (usually formatting) fields in data aware controls.  DB2 uses
//    integer fields and so we have a mismatch.
//
////////////////////////////////////////////////////////////////////////////
/

{
   TField * f = *fld;
   TDataSet * ds = f->DataSet;
   TFields * fs = ds->Fields;
   fs->Remove( f );
   TComponent * c = frm->FindComponent( f->Name );
   if ( c )
      frm->RemoveComponent( c );
   else
      throw Exception( AnsiString( "Unable to find component " +
f->Name ) );
   TField * fn;
   if ( bSmall )
      fn = new TSmallintField( frm );
   else
      fn = new TIntegerField( frm );
   fn->FieldName = f->FieldName;
   fn->FieldKind = fkData;
   fn->DataSet = ds;
   fn->Name = f->Name;
   *fld = (TFloatField *) fn;
   delete f;
}

Good luck,

- Arnie

"Victor Cazacov" <victor@kazakov.net> wrote in message
news:3e5b26d3$1@newsgroups.borland.com...
> VC> Yes, I have project with static fields that are shown in dbgrids and
>  VC> other controls.
>
> I want to add that problem remains while accessing runtime created fields
by
> name.
>
> CREATE TABLE XX_TST(
>   F_INT NUMBER(9,0)
>  )
>
> ADOQuery->SQL->Text = "SELECT * FROM XX_TST"
>
>   ADOQuery1->Open();
>   ADOQuery1->Edit();
>   ADOQuery1->FieldByName("F_INT")->AsInteger = -10;    // Negative value
!!!
>   ADOQuery1->Post();
>   ADOQuery1->Requery();
>   Caption = ADOQuery1->FieldByName("F_INT")->AsInteger;
>
> Caption == "10".  Sign is lost.
>
> --
> Reagrds, Victor
>
>
Technical Details
Message-ID: <3e5b6bac$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e5a01b5$1@newsgroups.borland.com> <3e5a2a63@newsgroups.borland.com> <3e5a34d0@newsgroups.borland.com> <3e5a5db0$1@newsgroups.borland.com> <3e5b217f@newsgroups.borland.com> <3e5b26d3$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,e2ba085cccbd09f0
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-02-25 05:24:44 PST
From: "Arnie Mauer" <amauer@vrms.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3e5a01b5$1@newsgroups.borland.com> <3e5a2a63@newsgroups.borland.com> <3e5a34d0@newsgroups.borland.com> <3e5a5db0$1@newsgroups.borland.com> <3e5b217f@newsgroups.borland.com> <3e5b26d3$1@newsgroups.borland.com>
Subject: Re: Oracle. How to get negative numbers ?
Date: Tue, 25 Feb 2003 08:12:18 -0500
Lines: 109
Organization: VRMS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 209.140.211.97
Message-ID: <3e5b6bac$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1046178732 209.140.211.97 (25 Feb 2003 05:12:12 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail