🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How do I submit an SQL statement to an Access database using code?

#2174
From: Viatcheslav V. Vassiliev
Date: Fri, 31 Oct 2003 19:03
104 lines
4852 bytes
I will show JScript code - you should have no problems translating it into
C++ Builder:

//---------------------------
var connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb";

//This you have yet
var cat = new ActiveXObject("ADOX.Catalog");
cat.Create(connStr);
cat = null;

var conn = new ActiveXObject("ADODB.Connection");
conn.Open(connStr);
conn.Execute("CREATE TABLE JUNK (NDX COUNTER(1, 1) NOT NULL CONSTRAINT
PRIMKEY PRIMARY KEY, " +
 "NAMEVALUE VARCHAR(60) WITH COMPRESSION NOT NULL)");
conn.Execute("CREATE TABLE TABLE2 (NDX INTEGER NOT NULL CONSTRAINT PRIMKEY
PRIMARY KEY, " +
 "COL2 VARCHAR(20) WITH COMPRESSION, CONSTRAINT FORKEY FOREIGN KEY (NDX)
REFERENCES JUNK(NDX) " +
 "ON UPDATE CASCADE ON DELETE SET NULL)");
conn = null;
//----------------------------



The code shows also how to create autoincrement column and set it as primary
key. It also shows how to set Unicode compression on string field.

//------------------------------------------
Regards,
Viatcheslav V. Vassiliev
http://www.managed-vcl.com
http://www.oledbdirect.com




"Ted Byers" <r.ted.byers@sympatico.ca> �������/�������� � ��������
���������: news:3fa29d35$1@newsgroups.borland.com...
> I am using BCB5Pro for this.
>
> Here is my "New" event handler so far (along with a trivial table
> definition, for test purposes):
>
> void __fastcall TCookbookMainForm::New1Click(TObject *Sender)
> {
>   if(OpenDialog->Execute()) {
>     if(FileExists(OpenDialog->FileName)) {
>       ShowMessage("File exist and will be recreated");
>       DeleteFile(OpenDialog->FileName);
>     }
>     RecipeCatalog=Variant::CreateObject("ADOX.Catalog");;
>     RecipeCatalog.Exec(Function("Create") <<
>               ("Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source="+OpenDialog->FileName));
>     AnsiString SQLstatement("CREATE TABLE JUNK( NDX INTEGER NOT NULL,
> NAMEVALUE VARCHAR(60) NOT NULL )");
>   }
> }
>
> How to I send the SQLstatement to the new Access database?
>
> Also, can anyone show me the syntax for creating using SQL an AutoNumber
> field to be used as an index and as a link between two tables (presumably
> within a CREATE SCHEMA statement), and how such a pair of tables is
updated?
> That is, suppose I want two tables, one of which gives each possible
> ingredient for recipes an index number and the second uses these index
> numbers to identify the ingredients used within each recipe (obviously
> neither field can be NULL), and that I have a form on which there is a
table
> into which ingredients and instructions for a recipe can be entered (and,
of
> course, all ingredient indices must exist in the ingredients table).  And,
> of course, for the ingredients table, all values in both fields MUST be
> unique!  Populating such a form FROM an existing database is not a problem
> (i.e. I already have code to do it), but creating a NEW database with the
> right structure (i.e. so the user can keep recipes for Chinese cuisine
> separate from recipes for Greek cuisine) and sending user supplied data to
> it is something I haven't quite figured out.
>
> I don't know, yet, but I believe it should be possible to handle ALL of
this
> through SQL code, but I don't kow SQL well enough to produce it quickly.
If
> I am right, then the answer to my first question along with some sample
SQL
> would solve the remaining issues I have with this project.  A head start
> would therefore be appreciated.
>
> One constraint to how I approach this is that I do not want my program to
be
> dependant on any DLLs other than what ships with Windows!  Not do I want
it
> dependant on BDE (even if it is possible to link with BDE in such a way
that
> I wouldn't have to ship extra DLLs).
>
> Thanks for your time.
>
> Ted
>
>
Technical Details
Message-ID: <3fa2b26b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3fa29d35$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,d26ef4716ff1429f
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-10-31 11:09:32 PST
From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3fa29d35$1@newsgroups.borland.com>
Subject: Re: How do I submit an SQL statement to an Access database using code?
Date: Fri, 31 Oct 2003 22:03:03 +0300
Lines: 106
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 213.234.218.42
Message-ID: <3fa2b26b@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1067627115 213.234.218.42 (31 Oct 2003 11:05:15 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail