Article View: borland.public.cppbuilder.database.ado
Article #2628TFieldType from database variable type
From: Clayton Arends
Date: Mon, 28 Apr 2003 21:58
Date: Mon, 28 Apr 2003 21:58
39 lines
2159 bytes
2159 bytes
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);
/* if (fieldType == ftUnknown)
// what should I do here? */
msg += FieldTypeNames[fieldType] + "\n";
dataSet->Next();
}
ShowMessage(msg);
The above code will iterate through all of the fields of the table
'tableName' and add the name and textual data type of each to 'msg'.
TIA,
- Clayton
Technical Details
Message-ID:
<3eada3f5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,3600ccb9be97d4c5,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-04-28 15:04:06 PST From: "Clayton Arends" <claytonarends@hotmail.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: TFieldType from database variable type Date: Mon, 28 Apr 2003 14:58:26 -0700 Lines: 41 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: 24.30.133.15 Message-ID: <3eada3f5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1051567093 24.30.133.15 (28 Apr 2003 14:58:13 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail