Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 20 total
Thread Correct way to log data
Fri, Jun 22 2007 11:46 AMPermanent Link

Dave Harrison
I'm going to use a Tdbisamtable to record the time it takes for a
particular operation to complete. The record is very simple:

LogTable:
---------
Rcd_id:  AutoInc
Log_Date: TimeStamp
Description: Memo (can be quite large, typically 1k)
ElapsedTIme: Float;

Ok so before the process starts I need to append a new record to the
table and fill in all the information except for ElapsedTIme.

with taLogTable do
  begin
    Append;
    FieldByName('Log_Date').AsDateTime := Now();
    FieldByName('Description').AsString := '....';
    Post;
  end;

Then when the process completes I will come back and update the ElapsedTime.

with taLogTable do
  begin
    Edit;
    FieldByName('Elapsed_Time').AsFloat := ElapsedTime;
    Post;
  end;


So my question is can I simple assume the log table is on the current
record (last record appended) when I go to write the ElapsedTime? There
isn't anything else using this table and I thought this would be a much
quicker method than trying to get the Rcd_Id from the appended record
and then lookup the record to add the ElapsedTime (like I would with
SQL). I have to do this in 2 steps because the process that I'm timing
might fail and I need to know if it failed (missing Elapsed_Time).

Should this work?
TIA

Dave
Fri, Jun 22 2007 3:30 PMPermanent Link

"Robert"

"Dave Harrison" <daveh_18824@spammore.com> wrote in message
news:B602412F-E70D-4BBF-A664-A79FF3CC1438@news.elevatesoft.com...
> I'm going to use a Tdbisamtable to record the time it takes for a
> particular operation to complete. The record is very simple:
>
> LogTable:
> ---------
> Rcd_id:  AutoInc
> Log_Date: TimeStamp
> Description: Memo (can be quite large, typically 1k)
> ElapsedTIme: Float;
>
> Ok so before the process starts I need to append a new record to the table
> and fill in all the information except for ElapsedTIme.
>
> with taLogTable do
>   begin
>     Append;
>     FieldByName('Log_Date').AsDateTime := Now();
>     FieldByName('Description').AsString := '....';
>     Post;
>   end;
>
> Then when the process completes I will come back and update the
> ElapsedTime.
>
> with taLogTable do
>   begin
>     Edit;
>     FieldByName('Elapsed_Time').AsFloat := ElapsedTime;
>     Post;
>   end;
>
>
> So my question is can I simple assume the log table is on the current
> record (last record appended) when I go to write the ElapsedTime? There
> isn't anything else using this table and I thought this would be a much
> quicker method than trying to get the Rcd_Id from the appended record and
> then lookup the record to add the ElapsedTime (like I would with SQL). I
> have to do this in 2 steps because the process that I'm timing might fail
> and I need to know if it failed (missing Elapsed_Time).
>

Well, you are probably safe, but why not after the first post save the
rdc_id in some global, and before doing the edit do a locate ONLY if the
global and the table are different? If nothing changed, you should never
have to do the locate.

Robert


Fri, Jun 22 2007 5:58 PMPermanent Link

Dave Harrison
Robert wrote:

> "Dave Harrison" <daveh_18824@spammore.com> wrote in message
> news:B602412F-E70D-4BBF-A664-A79FF3CC1438@news.elevatesoft.com...
>
>>I'm going to use a Tdbisamtable to record the time it takes for a
>>particular operation to complete. The record is very simple:
>>
>>LogTable:
>>---------
>>Rcd_id:  AutoInc
>>Log_Date: TimeStamp
>>Description: Memo (can be quite large, typically 1k)
>>ElapsedTIme: Float;
>>
>>Ok so before the process starts I need to append a new record to the table
>>and fill in all the information except for ElapsedTIme.
>>
>>with taLogTable do
>>  begin
>>    Append;
>>    FieldByName('Log_Date').AsDateTime := Now();
>>    FieldByName('Description').AsString := '....';
>>    Post;
>>  end;
>>
>>Then when the process completes I will come back and update the
>>ElapsedTime.
>>
>>with taLogTable do
>>  begin
>>    Edit;
>>    FieldByName('Elapsed_Time').AsFloat := ElapsedTime;
>>    Post;
>>  end;
>>
>>
>>So my question is can I simple assume the log table is on the current
>>record (last record appended) when I go to write the ElapsedTime? There
>>isn't anything else using this table and I thought this would be a much
>>quicker method than trying to get the Rcd_Id from the appended record and
>>then lookup the record to add the ElapsedTime (like I would with SQL). I
>>have to do this in 2 steps because the process that I'm timing might fail
>>and I need to know if it failed (missing Elapsed_Time).
>>
>
>
> Well, you are probably safe, but why not after the first post save the
> rdc_id in some global, and before doing the edit do a locate ONLY if the
> global and the table are different? If nothing changed, you should never
> have to do the locate.
>
> Robert

Robert,
    That's what I normally would do with MySQL, re-update the record
that was just added using the rcd_id that was just generated when the
record was saved.  This rcd_id gets updated *after* the post and is
local to the current session so you're always guaranteed to get your
rcd_id that was posted and not someone else's.

I noticed with dbISAM v4 that there is a TDBISAMTable.LastAutoIncValue
that I could use. But do I access it after the table is put into Insert
mode? Or after record was posted. Either way is there any guarantee that
no one else has posted ahead of me and changed the LastAutoIncValue? (I
suppose since dbISAM uses database locking, this isn't possible?)

TIA

Dave
Sun, Jun 24 2007 1:38 PMPermanent Link

Dave Harrison
I noticed with dbISAM v4 that there is a TDBISAMTable.LastAutoIncValue
that I could use. But do I access it after the table is put into Insert
mode? Or after record was posted. Either way is there any guarantee that
no one else has posted ahead of me and changed the LastAutoIncValue? I
suppose since dbISAM uses database locking, this isn't a problem? How
does ElevateDb handle it, since it uses row locking?

Dave
Sun, Jun 24 2007 1:42 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dave


Its after post.


Roy Lambert
Mon, Jun 25 2007 12:27 AMPermanent Link

Dave Harrison
Roy Lambert wrote:
> Dave
>
>
> Its after post.
>
>
> Roy Lambert
>

Roy,
   So if 2 users add 2 new records one after another, the only way to
get a reliable LastAutoIncValue is to put the post and the
LastAutoIncValue in a transaction, correct? Otherwise user#1 could get
the LastAutoIncValue from user#2's post. Or is the LastAutoIncValue
local to the current process as it is with MySQL? TIA

Dave
Mon, Jun 25 2007 3:16 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dave

> So if 2 users add 2 new records one after another, the only way to
>get a reliable LastAutoIncValue is to put the post and the
>LastAutoIncValue in a transaction, correct? Otherwise user#1 could get
>the LastAutoIncValue from user#2's post.

That's right.

>Or is the LastAutoIncValue
>local to the current process as it is with MySQL?

That sounds weird - does it mean you can have multiple autoinc series in a single field?

Roy Lambert


Mon, Jun 25 2007 8:06 AMPermanent Link

"Robert"

"Dave Harrison" <daveh_18824@spammore.com> wrote in message
news:33651F85-4AC0-4517-A91A-B91D7926F264@news.elevatesoft.com...
> Roy Lambert wrote:
>> Dave
>>
>>
>> Its after post.
>>
>>
>> Roy Lambert
>>
>
> Roy,
>    So if 2 users add 2 new records one after another, the only way to get
> a reliable LastAutoIncValue is to put the post and the LastAutoIncValue in
> a transaction, correct? Otherwise user#1 could get the LastAutoIncValue
> from user#2's post. Or is the LastAutoIncValue local to the current
> process as it is with MySQL? TIA
>

I don't understand what's the purpose of using lastautoinc. Why not use a
ttable or a live query, and get the value off the field itself after doing
the post? After you post an insert, DBISAM will put the value of the autoinc
filed it assigned right on the record iself.

If you need to use the value later on, simply save it in some global field.
Also, remember thet your current record remains the one you added, even if
another user added another record.

Add record 1 <<<< you
Add record 2 <<<< another user
Edit current <<<< you
You'll still be editing record 1.

Remember that transactions must be kept short, and must avoid any
interaction with the user.

Robert
> Dave

Mon, Jun 25 2007 2:26 PMPermanent Link

Dave Harrison
Roy Lambert wrote:
>
>>Or is the LastAutoIncValue
>>local to the current process as it is with MySQL?
>
>
> That sounds weird - does it mean you can have multiple autoinc series in a single field?
>

With MySQL it's the same number series, with each user's last autoinc
value frozen in time (local to him). When he acceses Last_Insert_Id()
after  adding a new record 1 ms or 1 hour ago, he gets the auto inc
value of *his* last post, regardless of whether someone else had posted
100 new rows in the mean time. This is of course is done *without* using
a transaction.

Dave
Mon, Jun 25 2007 2:33 PMPermanent Link

Dave Harrison
Robert wrote:

> "Dave Harrison" <daveh_18824@spammore.com> wrote in message
> news:33651F85-4AC0-4517-A91A-B91D7926F264@news.elevatesoft.com...
>
>>Roy Lambert wrote:
>>
>>>Dave
>>>
>>>
>>>Its after post.
>>>
>>>
>>>Roy Lambert
>>>
>>
>>Roy,
>>   So if 2 users add 2 new records one after another, the only way to get
>>a reliable LastAutoIncValue is to put the post and the LastAutoIncValue in
>>a transaction, correct? Otherwise user#1 could get the LastAutoIncValue
>>from user#2's post. Or is the LastAutoIncValue local to the current
>>process as it is with MySQL? TIA
>>
>
>
> I don't understand what's the purpose of using lastautoinc. Why not use a
> ttable or a live query, and get the value off the field itself after doing
> the post? After you post an insert, DBISAM will put the value of the autoinc
> filed it assigned right on the record iself.

Ahh, well, sure if you want an easy solution. I've been using MySQL for
so long and using only static SQL, that the obvious often eludes me. Wink

The only drawback I see of doing it your way is what happens if another
user deletes the record you just added? You won't be able to retrieve it
to get the last autoinc value.

Dave
Page 1 of 2Next Page »
Jump to Page:  1 2
Image