Board index » cppbuilder » TQuery,MyODBC, and MySQL.

TQuery,MyODBC, and MySQL.

Products:
BCB 4 professional
MySQL latest
MyODBC latest

Here's the code I'm using

bool AnAuthor::CheckIfExists(int p_ID) {
        TQuery *CheckAuthor = new TQuery(NULL);
        AnsiString strQuery;
        bool retVal;
        strQuery = "SELECT COUNT(*) AS AUTHORCOUNT FROM AUTHORS WHERE
AUTHOR_ID=" + AnsiString(p_ID);

        CheckAuthor->DatabaseName = "bookcollection";
        CheckAuthor->SQL->Add(strQuery);
        CheckAuthor->Open();
        if (CheckAuthor->FieldByName("AUTHORCOUNT")->AsInteger >= 1) {
                retVal = true;
        } else {
                retVal = false;
        }
        delete CheckAuthor;
        return retVal;

Quote
}

This way, it retrieves the recordcount exactly, but if I use

CheckAuthor->RecordCount
instead of:
CheckAuthor->FieldByName("AUTHORCOUNT").AsInteger
I get a nonsense answer (it compiles okay).

John Meyer
john_me...@geocities.com
Programmer

If we didn't have Microsoft, we'd have to blame ourselves for all of our
programs crashing

 

Re:TQuery,MyODBC, and MySQL.


I can't speak for MyODBC and MySQL, but using RecordCount is not guarrenteed
to return the exact record count.  It is usually dependent on the ODBC
driver's implementation.  I always use the "select count(*) ..." method for
getting record counts.

Mark

Quote
"John Meyer" <john_me...@geocities.com> wrote in message

news:3b4e04b0$1_2@dnews...
Quote
> Products:
> BCB 4 professional
> MySQL latest
> MyODBC latest

> Here's the code I'm using

> bool AnAuthor::CheckIfExists(int p_ID) {
>         TQuery *CheckAuthor = new TQuery(NULL);
>         AnsiString strQuery;
>         bool retVal;
>         strQuery = "SELECT COUNT(*) AS AUTHORCOUNT FROM AUTHORS WHERE
> AUTHOR_ID=" + AnsiString(p_ID);

>         CheckAuthor->DatabaseName = "bookcollection";
>         CheckAuthor->SQL->Add(strQuery);
>         CheckAuthor->Open();
>         if (CheckAuthor->FieldByName("AUTHORCOUNT")->AsInteger >= 1) {
>                 retVal = true;
>         } else {
>                 retVal = false;
>         }
>         delete CheckAuthor;
>         return retVal;
> }

> This way, it retrieves the recordcount exactly, but if I use

> CheckAuthor->RecordCount
> instead of:
> CheckAuthor->FieldByName("AUTHORCOUNT").AsInteger
> I get a nonsense answer (it compiles okay).

> John Meyer
> john_me...@geocities.com
> Programmer

> If we didn't have Microsoft, we'd have to blame ourselves for all of our
> programs crashing

Other Threads