Subject Re: [firebird-support] Re: VB + Firebird Lock
Author The Wogster
kevtey wrote:
> --- In firebird-support@yahoogroups.com, "Ann W. Harrison"
> <aharrison@...> wrote:
>
>>kevtey wrote:
>>
>>>>>hie im new in firebird. i would like to know how can i impliment
>>>>>record locking in firebird?
>>
>>The short answer is don't use it. You don't need it, and it will
>>only cause you trouble. If you'd like a longer and more pertinent
>>answer, please explain what you're trying to do.
>>
>>
>>Regards
>>
>>
>>Ann
>>
>
> i have an application written using visual basic 6.0 . Im using ADO to
> update the field..basically i assign a value to the field in client
> side first b4 posting the data to the server.
> eg. rs("field").value = txtvalue
> rs.update
>
> the reason i needed a lock is this to do this.
> 1. User 1 press edit -> Record in db is lock for editing,updating and
> deleting.
> 2. User 1 key in all the information and press save button. lock is
> release
>
> currently i face the problem is
> while user 1 still updating the record the 2nd user already delete
> that particular record.
>
> i tried to use "select * from table where id='zzz' with lock" when
> user1 press edit button.but the error happen! user 2 cant able to read
> the particular record that is being update by user1
>
> is there a way to cater this problem? currently im using zstylegroup
> provider.
>
> im not sure if the way im doing it is correct or wrong. if you want i
> can post up my coding here.
>

First of all, locking isn't the answer, with real databases (like
Firebird), saves should happen during short lived transactions. Part of
the problem with VB in general is that it encourages long lived
transactions. It's possible for someone to hit edit, then go on a
months holidays, effectively locking the record for a month.

What you want is to not lock the record when you hit the edit button,
but to lock the record through a transaction, when your saving the
update. For example start transaction, then do the update, then close
the transaction.

eg:

rem start transaction
rs.("field1").value = txt1value
rs.("field2").value = txt2value
rs.update
rem end transaction


Second of all "SELECT *" is a horrible way to access data, instead use
the field names, within the SELECT statement, the order of fields in a
database is not guaranteed, for some reason a DBA could rearrange the
fields in a table, and if your program ASSUMES that the fields are in a
specific order, that could create problems. Programmers should ALWAYS
assume that they do not have control of the database.

W













>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>