Board index » delphi » Complex SQL Question - I Think :-P

Complex SQL Question - I Think :-P

Ok Heres what I need to do:
I have a table with collums ICN and TtG (Time to Go)
I want to be able to take 4 from the value of all the TtG values on the
table ( all diferent )
and delete the record if the TtG for that record drops below 3 and call a
procedure outside the SQL statment transmitting ICN and PASSWORD of the
deleted/to be deleted record.
- I have a timer that triggers every 4 seconds this will be used to tell the
query component to do its thing..
- the default value for TtG is 300 it can ither be a string or a integer -
which ever takes youre fancy...

Feel Free to use more components (TQuerys Etc..) if you need to..
I have tried a few things and am still trying - thought id pick ur brains
and see wot u come up with :-)

Thanks
Nic Colledge
n...@micc.globalnet.co.uk

 

Re:Complex SQL Question - I Think :-P


On Fri, 3 Sep 1999 19:16:22 +0100, "Joe 90" <j...@micc.globalnet.co.uk>
wrote:

Quote
}Ok Heres what I need to do:
}I have a table with collums ICN and TtG (Time to Go)
}I want to be able to take 4 from the value of all the TtG values on the
}table ( all diferent )
}and delete the record if the TtG for that record drops below 3 and call a
}procedure outside the SQL statment transmitting ICN and PASSWORD of the
}deleted/to be deleted record.
}- I have a timer that triggers every 4 seconds this will be used to tell the
}query component to do its thing..
}- the default value for TtG is 300 it can ither be a string or a integer -
}which ever takes youre fancy...
}
}Feel Free to use more components (TQuerys Etc..) if you need to..
}I have tried a few things and am still trying - thought id pick ur brains
}and see wot u come up with :-)

I won't be supplying any code with this.  Just some ideas I've used
for doing on-screen statistics on data!

Create a new thread object and make your procedure part of that
object.
This thread object will create a new TSessions, TDatabase, TQuery &
TTable when it starts executing.  Put everything in a try/finally
construct to free these objects when the thread has run.

The thread will run the query that decreases the value of TtG.
It will then open a TTable with a filter on (TtG < 3).  It is indexed,
isn't it?
Create a "while not eof" loop on the table and call the procedure for
each record.
Change the SQL on the query to delete all records where TtG < 3.

On your OnTimer event you check whether the thread is still running.
If it is running then exit and wait for the next timer event!

To check the status of the thread you might want to create a boolean
property on the main form which is updated when the thread starts and
when it stops.  OTOH you can check the value of the thread variable
which should set it to nil when it completes execution.  If the thread
isn't nil you can also check whether the thread has been terminated
and re-create it if it has.  But that shouldn't be necessary if you
always allow the thread to execute fully.

The main reason why I would put this in a thread is because it may
take more than 4 seconds for all of this to occur.

Hope that helped!

Cheers...

Other Threads