Board index » delphi » User Name when logging into database?

User Name when logging into database?

Hi everyone,

I'm using a TDatabase with default options to connect to an Oracle
database. I would like to be able to "catch" the username keyed in by
the user at the login prompt, so that I can generate change information
for the record, such as a "LastChangedBy" field. How do I go about doing
it?

Also, I'm wondering about concurrency control when multiple users update
the database. When I use a TQuery component to post my updates, does the
TDatabase component takes care of it by locking the table, or do I need
to do it manually? TTable has a LockTable property but not TQuery... :(

Thanks in advance..

Regards,
Veronica Tan

 

Re:User Name when logging into database?


Argh, I just played around with the login parameters, and found that
I can capture the username by using
     Database1.Params.Values['USER NAME']

I'm still stuck on the concurrency control issue though, so would
appreciate some help there. Another qn I just thought of:
Do I can have specify "commit" to save my changes to the database, or
does TQuery do it for me automatically when I do an insert/update?

Thanks and best regards,
Veronica Tan

Quote
Veronica Tan wrote:

> Hi everyone,

> I'm using a TDatabase with default options to connect to an Oracle
> database. I would like to be able to "catch" the username keyed in by
> the user at the login prompt, so that I can generate change information
> for the record, such as a "LastChangedBy" field. How do I go about doing
> it?

> Also, I'm wondering about concurrency control when multiple users update
> the database. When I use a TQuery component to post my updates, does the
> TDatabase component takes care of it by locking the table, or do I need
> to do it manually? TTable has a LockTable property but not TQuery... :(

> Thanks in advance..

> Regards,
> Veronica Tan

Re:User Name when logging into database?


Quote
Veronica Tan wrote in message <362697BD.A55C7...@post1.com>...

>I'm still stuck on the concurrency control issue though, so would
>appreciate some help there. Another qn I just thought of:

Oracle should take care of it for you. (unless you're using cachedupdates =
true, see below)

Quote
>Do I can have specify "commit" to save my changes to the database, or
>does TQuery do it for me automatically when I do an insert/update?

You can do it either way.
If you set query1.cachedupdates to true, you can use the following code to
do your commits.
(I pulled this out of the help file)

    try
      Query1.ApplyUpdates; {try to write the updates to the database};
      Session.Databases[0].Commit; {on success, commit the changes};
    except
      Session.Databases[0].Rollback; {on failure, undo the changes};
    raise; {raise the exception to prevent a call to CommitUpdates!}
    end;
    Query1.CommitUpdates; {on success, clear the cache}

If query1.cachedupdates is false, Oracle/BDE will automatically commit as
you do the insert/update.
In my experience, cachedupdates is slower for large numbers, but it does
give you the option of rolling back. The other downside of cachedupdates is
that if someone modifies the record between when the time you pick it up,
and the time you commit, their changes may not be reflected correctly

Dominic

Other Threads