🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TFieldType from database variable type

#2629
From: Edward Diener
Date: Mon, 28 Apr 2003 23:12
37 lines
2493 bytes
Clayton Arends wrote:
> All,
>
> I'm trying to convert the numerical data type returned by OpenSchema
> to the native enumerated TFieldType.  VarTypeToDataType() works for
> many of the simpler data types (such as integer and boolean) but not
> for string and ADO types.  Please reference the following code:
>
>   Variant tvars[4] = { Unassigned(), Unassigned(), tableName,
> Unassigned() };
>
>   TADODataSet*  dataSet = new TADODataSet(NULL);
>   std::auto_ptr<TADODataSet> auto_dataSet(dataSet);
>
>   ServerData.Connection->OpenSchema(
>       siColumns, VarArrayOf(tvars, 3), EmptyParam, dataSet);
>   String  msg = "Field count: " + String(dataSet->FieldCount) + "\n";
>
>   TField* field;
>   while (!dataSet->Eof)
>   {
>     field = dataSet->Fields->FieldByName("COLUMN_NAME");
>     msg += field->AsString + " => ";
>
>     field = dataSet->Fields->FieldByName("DATA_TYPE");
>     TFieldType  fieldType = VarTypeToDataType(field->AsInteger);

field -> AsInteger is actually a C++ unsigned short in this case
(DBTYPE_UI2) and is an OLEDB Type Indicator. Not all the OLEDB Type
Indicators match the Variant types. See the Type Indicators topic in the
OLEDB Programmer's Reference in MSDN.

I don't know how to go from the OLEDB Type Indicators to an actual BCB VCL
data type, so I just test out the value of DATA_TYPE against the OLEDB types
listed in the aforementioned topic. The topic gives a pretty good
explanation of the OLEDB datatypes. If you don't have MSDN library, MS has
it on their web site for anybody to use.
Technical Details
Message-ID: <3eadb4a6$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3eada3f5$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,3600ccb9be97d4c5
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-04-28 16:12:03 PST
From: "Edward Diener" <eddielee@tropicsoft.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3eada3f5$1@newsgroups.borland.com>
Subject: Re: TFieldType from database variable type
Date: Mon, 28 Apr 2003 19:12:21 -0400
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 66.32.69.142
Message-ID: <3eadb4a6$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1051571366 66.32.69.142 (28 Apr 2003 16:09:26 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail