🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Accessing highest auto number

#2076
From: Simon Elliott
Date: Wed, 03 Dec 2003 22:04
85 lines
5877 bytes
Ted Byers <r.ted.byers@sympatico.ca> writes
>> How do you create your new databases? 

[snip code]

Thanks for this. Exactly what I need! Do you know which versions of MS
Access are covered by "Microsoft.Jet.OLEDB.4.0"? 

>But the key here is the statement "RecipeCatalog.Exec(Function("Create") <<
>ConnectionString);" when creating a new database while using the statement
>"RecipeCatalogTMP.Exec(PropertySet("ActiveConnection") << tmpCS);" when
>merely opening an existing one.  And, of course, when creating a new
>database, I must (or prefer to) use a series of SQL statements to create the
>entire structure of the database, from tables and indices to stored
>procedures 

I have a quite complex database which I'd like to be able to create. Do
I have to spend the time writing all the SQL statements to create the
tables, or is there some function of MS Access which allows me to export
the structure?

>(when I find a need for these - I am beginnng to wonder if I may
>find a performance improvement for one of my functions that has to do a
>large numer of lookups from one of my tables if I create a stored procedure
>or parameterized query for it).

I found prepared, parameterized queries to be a lot faster than using
the Append, set values, Post route. I haven't tried stored procedures
yet so don't know how performance would compare. 

One odd wrinkle with TADOQuery SQL queries: if you have a database field
called "Language", SQL insert queries will fail with a parse error. But
the MS Access SQL reference doesn't show "Language" as a reserved
word...

>It seems to me that if I can do everything with the database using a
>catalog, a connection, or a record set, submitting the tasks to the database
>as SQL statements through one of these three kinds of objects, I should
>become less vulnerable to changes made in ADO/ADOX, and it should become
>easier to adapt my code to other means of connecting to databases (such as
>via SQLAPI++).  Plus I feel a need to learn much more about SQL.  I try to
>make my code as independant of proprietary stuff as possible (witness the
>controversy that has raged in the CBX and cppbuilder nontechnical newsgroups
> for the past few months regarding FUD about the fate of VCL).  I figure
>that my code will have a longer usable life if I use the proprietary stuff
>only when absolutely necessary (e.g. to quickly develop a given application)
>and try to use languages for which there is an ANSI/ISO standard whenever
>possible.  In this context, for example, I don't see a significant advantage
>in using "Table=Variant::CreateObject("ADOX.Table");" when I can use a
>simple SQL statement instead.  Similarly, I don't see an advantage to using
>"TADOQuery".  

I don't know how to construct a parameterized query directly, without
using TADOQuery.

>I am not sure I believe that using it will reduce the amount
>of code I will have to write.  In contrast, using the VCL forms and edit
>boxes and comboboxes, &c., does provide a significant advantage since I can
>get a functional form in a matter of hours where, if I had to develop the
>same thing using the WinAPI or even MFC, it would take me days, weeks or
>even months (depending on the complexity of what I was doing).  If I am not
>mistaken, I can execute any SQL statement, that doesn't return a record set,
>using a connection object, and a recordset object otherwise.  And this
>requires only to write the SQL statements and to create the catalog and
>connection objects (and record set object when needed).

This seems like the safest way to proceed. When developing BCB
applications, I'm usually fairly careful to separate the VCL parts from
the rest, which I try to code in standard C/C++ for reuse elsewhere. But
I don't yet know enough about ADO to be able to stop using TADOQuery.

Getting back to ADO, I'm currently developing a multi-threaded
application, each thread of which must save data to the database. A
small test application showed me that as soon as you start to multi-
thread ADO calls, all sorts of mayhem ensues. If you serialise the ADO
calls with critical sections, the SQL queries take two or three times as
long to run. To overcome this, I run the ADO database code in its own
thread (with calls to CoInitializeEx and CoUninitialize) and have a
thread-safe queue to send data to this thread. Every now and again, it
seems to take ages (up to ten minutes) for the final database close and
CoUninitialize to run. Are you aware of any issues with ADO running in a
non VCL thread?
-- 
Simon Elliott
http://www.ctsn.co.uk/
Technical Details
Message-ID: <0x0o5DAm3lz$Iww1@courtlands.demon.co.uk>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!easynet-monga!easynet.net!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!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> <rUI$wAAUogz$IwA9@courtlands.demon.co.uk> <3fce1ab8@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 14:09:55 PST
Message-ID: <0x0o5DAm3lz$Iww1@courtlands.demon.co.uk>
Date: Wed, 3 Dec 2003 22:04:22 +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> <rUI$wAAUogz$IwA9@courtlands.demon.co.uk>
 <3fce1ab8@newsgroups.borland.com>
Lines: 91
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 1070489080 158.152.154.121 (3 Dec 2003 14:04:40 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!easynet-monga!easynet.net!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!courtlands.demon.co.uk!simon