🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

SELECT after UPDATE

#1258
From: Drew
Date: Tue, 07 Sep 2004 08:47
118 lines
4345 bytes
I'm using BCB6 Professional, MS Access 2000 and MS Jet 4.0.

If I do an UPDATE on a able, followed immediately afterwards by a SELECT on
the same fields in the same table, the values returned by the SELECT do not
show the values that were updated by the UPDATE command.

However, if I step through the code in the debugger or explicitly wait for a
period, then the new values are returned by the SELECT.

I thought that ADO immediately wrote the new values to the table, or do I
have to wait for the ExecSQL command to complete?

The code in question is below:

//--------------------------------------------------------------------------
---------------------------------------
void __fastcall WbSvrThread::WebServerUpdateSystemParameters(TIdCommand*
ASender)
{
TADOQuery* SystemQuery;

    try
    {
        SystemQuery = new TADOQuery(NULL);
        SystemQuery->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\Hilltop
Monitoring System\\hilltop.mdb;Mode=ReadWrite|Share Deny None;Persist
Security Info=False";

        sysParams_t replyBuffer;
        AnsiString sqlString;

        sqlString.sprintf("UPDATE SystemTable SET IPConnectRetriesNormal=%s,
IPConnectRetriesFailed=%s, IPConnectTimeout=%s, TelRetriesNormal=%s,
TelRetriesFailed=%s, TelTimeout=%s, NormalScheduleFrequency=%s,
AlarmScheduleFrequency=%s, RtrFrequency=%s",
                                       ASender->Params->Strings[0],
ASender->Params->Strings[1], ASender->Params->Strings[2],
                                       ASender->Params->Strings[3],
ASender->Params->Strings[4], ASender->Params->Strings[5],
                                       ASender->Params->Strings[6],
ASender->Params->Strings[7], ASender->Params->Strings[8]);
        SystemQuery->SQL->Clear();
        SystemQuery->SQL->Add(sqlString);
        SystemQuery->Prepared = true;

        AnsiString msgType;

        try
        {
            SystemQuery->ExecSQL();

            msgType=ACK;

            // Send the confirmation to the webserver
            ASender->Thread->Connection->WriteLn(msgType);

            ParentForm->FindScanIntervals();
        }
        catch (Exception &e)
        {
            sprintf(msg, "Updating system parameters in database failed:
exception = %s", e.Message);
            Log(0, msg);

            msgType=NACK;

            // Send the negative confirmation to the webserver
            ASender->Thread->Connection->WriteLn(msgType);
        }
    }
    catch(Exception &e)
    {
        sprintf(msg, "WebServerUpdateSystemParams failed: exception = %s",
e.Message);
        Log(0, msg);
    }
    delete SystemQuery;
}


void __fastcall TForm1::FindScanIntervals(void)
{
    AnsiString sqlString;

    sqlString.sprintf("SELECT NormalScheduleFrequency,
AlarmScheduleFrequency, RtrFrequency FROM SystemTable");
    ADOQuery1->SQL->Clear();
    ADOQuery1->SQL->Add(sqlString);

    try
    {
        ADOQuery1->Open();

        if (ADOQuery1->RecordCount > 0)
        {
            NormalScanSchedule =
ADOQuery1->Fields->FieldByNumber(1)->AsInteger  * 60;
            AlarmScanSchedule =
ADOQuery1->Fields->FieldByNumber(2)->AsInteger * 60;
            RouterFrequency = ADOQuery1->Fields->FieldByNumber(3)->AsInteger
* 60;
        }

        ADOQuery1->Close();

    }
    catch(...)
    {
        Log("SQL Update failed");
    }

}


Any ideas/suggestions gratefully received.

Andrew
Technical Details
Message-ID: <413d754c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,2974e2a27d708c67,start
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Drew" <aemsley@brightwell.org.uk>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: SELECT after UPDATE
Date: Tue, 7 Sep 2004 09:47:15 +0100
Lines: 120
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: 81.137.221.84
Message-ID: <413d754c@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1094546764 81.137.221.84 (7 Sep 2004 01:46:04 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail