🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Accessing highest auto number

#2074
From: Simon Elliott
Date: Wed, 03 Dec 2003 16:06
72 lines
3592 bytes
Ted Byers <r.ted.byers@sympatico.ca> writes
>If I understand you correctly, in a nutshell you have a lookup table in one
>table that you must use in another.  Is that right?

Yes.

>If I am right, here is what I did.

[snip]

Thanks for this detailed and comprehensive description. I've implemented
a solution along these lines, and it seems to work well. There doesn't
seem to be too much of a performance hit from the extra SELECT query.

>The biggest difference between what you're doing and what I'm doing is that
>I am doing everything in code using ADO/ADOX, and I have avoided using any
>of the database related VCL components.  

Me too, except that my TADOConnection and TADOQuery objects are all
created by a data module. All the rest is done in code. 

>I haven't looked into using
>parameterized SQL statements.  Do you have any idea how to create and use
>these in code?  

TADOQuery *adoqFoo1;
TADOQuery *adoqFoo2;

...

adoqFoo1->Active = false;
adoqFoo1->SQL->Clear();
adoqFoo1->SQL->Add("INSERT INTO tblFoo (FooSerial,TimeIn)");
adoqFoo1->SQL->Add("VALUES (:FooSerial,:TimeIn)");
adoqFoo1->Prepared = true;

adoqFoo2->Active = false;
adoqFoo2->SQL->Clear();
adoqFoo2->SQL->Add("UPDATE tblFoo SET tblFoo.TimeIn = :TimeIn");
adoqFoo2->SQL->Add("WHERE tblFoo.FooSerial=:FooSerial");
adoqFoo2->Prepared = true;

...

adoqFoo1->Parameters->ParamByName("FooSerial")->Value = ulSern;
adoqFoo1->Parameters->ParamByName("TimeIn")->Value =
TimeToDateTime(timeIn);
adoqFoo1->ExecSQL();

adoqFoo2->Parameters->ParamByName("FooSerial")->Value = ulSern;
adoqFoo2->Parameters->ParamByName("TimeIn")->Value =
TimeToDateTime(timeLog);
adoqFoo2->ExecSQL();

>In my case, it MUST be done in code because the user has the
>liberty to create as many database files as he likes, and I have to create
>the correct structure for each database he creates.  (My application comes
>with one database that is read only, and can create two kinds of database
>for user data, one of which is unique and the other can be represented in as
>many files as the user wishes, which will depend on how the user conceives
>of relationships in his data - imagine a folder full of such files as
>representing a bookshelf full of recipe books).

How do you create your new databases? Are you doing

Catalog=Variant::CreateObject("ADOX.Catalog");
Table=Variant::CreateObject("ADOX.Table");

or have you discovered another method?
-- 
Simon Elliott
http://www.ctsn.co.uk/
Technical Details
Message-ID: <rUI$wAAUogz$IwA9@courtlands.demon.co.uk>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!courtlands.demon.co.uk!simon
References: <vIB+nCAzsMz$IwBT@courtlands.demon.co.uk> <3fccec42$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,3afd7f6873225c1f
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-12-03 08:40:23 PST
Message-ID: <rUI$wAAUogz$IwA9@courtlands.demon.co.uk>
Date: Wed, 3 Dec 2003 16:06:44 +0000
From: Simon Elliott <simon@nospam.demon.co.uk>
Reply-To: Simon Elliott <news@nospam.demon.co.uk>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Re: Accessing highest auto number
References: <vIB+nCAzsMz$IwBT@courtlands.demon.co.uk>
 <3fccec42$1@newsgroups.borland.com>
Lines: 78
Organization: Courtlands Technical Services
MIME-Version: 1.0
X-Newsreader: Turnpike Integrated Version 4.02 U <aLIvuQCpEWZ0Tu7eytpxRhrSSE>
NNTP-Posting-Host: 158.152.154.121
X-Trace: newsgroups.borland.com 1070467874 158.152.154.121 (3 Dec 2003 08:11:14 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!courtlands.demon.co.uk!simon