🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: adoquery, access table, why IsEmpty is not true even the table is empty indeed ?

#1355
From: Viatcheslav V. Vassiliev
Date: Mon, 26 Jul 2004 10:57
130 lines
5123 bytes
This should depend on OLEDB provider - ADO has no such functionality and
asks OLEDB provider.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"frankzyz" <frankzyz@etang.com> �������/�������� � �������� ���������:
news:41046b96$2@newsgroups.borland.com...
> Thank you for your careful reply.
> I found there is an hiden rule behind the ADOQuery and SQL :
> 1) if SQL is like : select * from aTable where condition,
> ADOQuery->IsEmpty() will return
>    properly true, if the table is really empty.
> 2) if SQL is like : select max(aField) as mx from aTable where condition,
> even the table is empry indeed,
> ADOQuery->IsEmpty() will return false(ie., the result is not empty) and
> record number is 1.
>
> Thank you again.
> Frank
>
>
>
> "Chemile" <chemile@qwest.net> д���ʼ�
> news:4102b55f$1@newsgroups.borland.com...
> > I use a different method to find out if a table is empty.  I modified
some
> > code from one of my programs, hopefully this will help you - as its
> written
> > for an msSQL database.
> >
> > Test the number of records returned from a query with:
pQuery->RecordCount
> > Test if a feild is null with:
> > if(!VarIsNull(pQuery->FieldValues["Name"])){ }else{ }
> > Use the second example if you just want to know the number of records in
a
> > table, without returning extra data.
> >
> > ///////////////////////////////////////////////////
> >
> >   AnsiString AqMask = "*", AqTable = "MyTable", AqCol = "MyFeild",
> AqSearch
> > = "Hello";
> >   int limit = 999;
> >
> >   TADOQuery *pQuery = new TADOQuery(0);
> >   pQuery->Connection = ADOConnection1;
> >   pQuery->CursorType = ctKeyset;
> >   pQuery->CacheSize = 10000;
> >   pQuery->CursorLocation = clUseClient;
> >   pQuery->LockType = ltReadOnly;
> >
> >   pQuery->Close();
> >   pQuery->SQL->Clear();
> >   pQuery->SQL->Add("SELECT top " + String(limit) + "  " + AqMask + "
from
> "
> > + AqTable + " WHERE LOWER(" + AqCol + ") = LOWER('" +
> ParseStream(AqSearch)
> > + "')");
> >   pQuery->Open();
> >
> >   if(pQuery->RecordCount == 0){ ShowMessage("Query Returned Zero
> Results!");
> > return; }
> >
> >   //Capture Headers//
> >   AnsiString nLine = "";
> >   nLine = "";
> >   for(int tmp = 0; tmp < pQuery->FieldList->Count; tmp++){
> >     if(nLine != "") nLine = nLine + ",";
> >     nLine = nLine + "\"" + pQuery->FieldList->Strings[tmp] + "\"";
> >   }
> >   Memo1->Lines->Add(nLine);
> >
> >   for(int tmp = 0; tmp < pQuery->RecordCount; tmp++){
> >     AnsiString pLine = "";
> >
> >     //Get Items//
> >     pLine = "";
> >     for(int tmp3 = 0; tmp3 < pQuery->FieldList->Count; tmp3++){
> >
> if(!VarIsNull(pQuery->FieldValues[pQuery->FieldList->Strings[tmp3]])){
> >         if(pLine != "") pLine = pLine + ",";
> >           pLine = pLine + "\"" +
> > pQuery->FieldValues[pQuery->FieldList->Strings[tmp3]] + "\"";
> >         }else{
> >           if(pLine != "") pLine = pLine + ",";
> >           pLine = pLine + "\"\"";
> >         }
> >       }
> >       //Use Data Here, Before its Overwritten//
> >       Memo1->Lines->Add(pLine);
> >       pQuery->Next();
> >     }
> >   }
> >
> >
> >
> > ///////////////////////////////////////////////////
> >
> >   TADOQuery *pQuery = new TADOQuery(0);
> >   pQuery->Connection = ADOConnection1;
> >   pQuery->CursorType = ctKeyset;
> >   pQuery->CacheSize = 10000;
> >   pQuery->CursorLocation = clUseClient;
> >   pQuery->LockType = ltReadOnly;
> >
> >   pQuery->Close();
> >   pQuery->SQL->Clear();
> >   pQuery->SQL->Add("SELECT count (*) from " + AqTable + " WHERE LOWER("
+
> > AqCol + ")=LOWER('" + ParseStream(AqSearch) + "')");
> >   pQuery->Open();
> >
> >   int pCount = pQuery->Fields->Fields[0]->AsInteger;
> >
> >   if(pCount > 0){
> >     //Put your code here//
> >   }
> >
> >
>
>
Technical Details
Message-ID: <4104e39a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40ffcd9b$1@newsgroups.borland.com> <4102b55f$1@newsgroups.borland.com> <41046b96$2@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,66e2b8def88d26af
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII
From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <40ffcd9b$1@newsgroups.borland.com> <4102b55f$1@newsgroups.borland.com> <41046b96$2@newsgroups.borland.com>
Subject: Re: adoquery, access table, why IsEmpty is not true even the table is empty indeed ?
Date: Mon, 26 Jul 2004 14:57:32 +0400
Lines: 132
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 213.234.218.42
Message-ID: <4104e39a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1090839450 213.234.218.42 (26 Jul 2004 03:57:30 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail