Article View: comp.lang.pascal.delphi.databases
Article #95Re: Bug in Delphi when posting/appending records?
From: Christian R. Conrad
Date: Wed, 24 Jun 1998 00:00
Date: Wed, 24 Jun 1998 00:00
52 lines
3219 bytes
3219 bytes
On 20 Jun 1998 10:28:18 +0200, toreau@sn.no (Tore Aursand) wrote:
> Yourname@somwhere.COM (Your Name) wrote:
> > Haven't you put a >0 condition in the field id when you
> > designed the table?
> Nope. I've tried setting NewID := !0 (which means *not* 0), but
> it doesn't work what ever I do.
What, does "!0" mean "not 0" in your _database_ manager?
In Delphi, it doesn't. (This ain't C++ Builder, y'know! :-)
"Not 0" in Delphi is "not (<VariableX> = 0)". But that is a Boolean
expression, so if your ID field is an integer, it's the wrong type.
Maybe what Delphi is complaining about is that "field 'id' must have a
*unique* value"? And another user is inserting/has inserted the same
one you just determined as the next free one? That's the only thing
that comes to mind, anyway. It's a bit difficult to help you, since
you didn't tell us what kind of database management system you use.
Anyway, your method of going to the last record and using its ID value
does *not* generate a unique ID -- obviously, it just copies the last
one that is already in your database! Unless you forgot to tell us
about a "NewID := Table1.[ID] _+_1_;"...?
But still, that's no good method either. For one thing, if your data
set is filtered (a TTable with a filter, or a TQuery with a limiting
"where" clause), or ordered according to something other than "ID" (a
TTable with an index property set, or a TQuery with an "Order By"
clause), then you'll get not the last record added, but, say, your
customer data for mr Zzyzygy, who might have been added six monhs ago.
It is best to let the database system handle this by itself. This
means, if you use a relational database server, to use a trigger or
stored procedure (probably with a help table of just one record, the
last used ID, which you read and update), or if you use local tables,
to use a field of type Counter/AutoIncrement. Paradox tables have had
that for a long time, and I think the latest DBase tables have it too.
HTH!
Christian R. Conrad
--
Proud and sole owner of all opinions (except quotes) expressed above!
======================================================================
I work at Hedengren, in Finland. Country codes
are two letters, e-mail addresses are lowercase.
======================================================================
"Wave goodbye to RISC. It's the rotary engine of computing."
Brad Aisa, in comp.lang.pascal.delphi.advocacy
Technical Details
Message-ID:
<35916a5a.51447317@news.eunet.fi>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<k/Zi1ErRvWaU092yn@sn.no> <6md99i$3mc$1@internet-gw.telecom.pt> </yti1ErRvexW092yn@sn.no>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: ffff5,14c9d3dfb74f9fb9 X-Google-Attributes: gidffff5,public X-Google-Thread: ff75c,14c9d3dfb74f9fb9 X-Google-Attributes: gidff75c,public From: christian.conrad@myEmployer.itsCountry (Christian R. Conrad) Subject: Re: Bug in Delphi when posting/appending records? Date: 1998/06/24 Message-ID: <35916a5a.51447317@news.eunet.fi> X-Deja-AN: 365764560 References: <k/Zi1ErRvWaU092yn@sn.no> <6md99i$3mc$1@internet-gw.telecom.pt> </yti1ErRvexW092yn@sn.no> Organization: Oy Tositieto - Realdata Ab Reply-To: christian.conrad@myEmployer.itsCountry Newsgroups: comp.lang.pascal.delphi.databases,borland.public.delphi.database.desktop