Question regarding databases..

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


  I wasn't sure if this should go in this usenet or in something like
Perl.DBI.etc, so I apologize if this is in the wrong place.

  Pretty simple question. I would like to create a Perl shell script
that actively monitors a table in a database. Let's exemplify this
before i go any further...

Let's say I have a table with some data:

ID    Name       Info      is_processed

where ID, Name and Info are just arbitrary bits of data, not important
to this specifically. I'd also like an "is_processed" field that'll be
either 1 or 0. The idea behind this backend shell script is so that
some frontend application can add data to the database quickly and get
a quick response for the user on the website. The backend script will
be actively monitoring the database, and whenever it sees something
whose "is_processed" value is 0, it says "hey, let me process that,"
and if the action is successful changes the value to 1 and never has to
touch that record again. The "is_processed" value might be zero for two
reasons: 1) That record was just added by the frontend script (webpage)
and hasn't yet been touched by the backend script, or 2) The backend
script wasn't able to process that recordset on a previous attempt.

That's the idea... the only problem is, I don't know how to make this
database connection "live," ie I don't know how to write a program that
just sits there running, looking for changes in a database, without
ever terminating (unless by command).

Any ideas? Your help is more than greatly appreciated.


Re: Question regarding databases..

Quoted text here. Click to load it

[further description snipped]

Quoted text here. Click to load it

You can use the sleep statement in your Perl program to have your
program periodically wake up and check the database table to see if
anything has changed. You can make the period whatever you like, in
multiples of 1 second. However, that is not the most efficient
solution, because your program might be doing a lot of checking with
nothing to do.

A better solution involves having some mechanism to activate your
program when there is something to do. The simplest way is to just
execute it -- however this involves some program activation and
database connection delays. A better solution is for your program to
start execution, connect to the database, and then wait for some event
to occur. There are several such mechanisms, depending upon your
platform. These include, for Unix at least, signals, shared memory,
I/O, semaphores, mutexes, etc. See 'perldoc perlipc' for more

 Posted Via Premium Usenet Newsgroup Services

Site Timeline