Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Restrict record view...

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2005-04-01 : 23:46:59
GOOD DAY!

Could anyone show me how to handle record viewing in SQL? Could it be done in SQL Statement?

Heres the detail sepecification of my application...

Im developing a client application that handles record viewing and processing. Currently there are 3 client application running. Particularly this application viewed unprocess record. Now after it has been process the flgProcess is set to true. Meaning only all unprocess record is viewed in my application.

Now, what I want is... the moment a certain client application viewed a specific record, those record present on that client application may not be viewed on the other two applications. Its a matter of handling record viewing, i want to restrict viewing once a client viewed a specific record. Let me illustrate...

---RECORD TO BE PROCESS-----
Record1
Record2
Record3
Record4
Record5
Record6



Now 3 client application is running at the same time....

PROCESSING NO. 1
Record1

PROCESSING NO. 2
Record2

PROCESSING NO. 3
Record3


I want to devide the process on different client application by handling viewing restriction.

Could anyone show me an idea how to do this?


Tnx

















Want Philippines to become 1st World COuntry? Go for World War 3...

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-04-02 : 12:54:43
Add an "In Use" column to the table. Manage the setting and resetting of this column from the application. Only allow the viewing of data that is not "In Use"

HTH

=================================================================
In order to improve the mind, we ought less to learn than to contemplate.
-Rene Descartes, philosopher and mathematician (1596-1650)
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2005-04-02 : 20:47:53
I got your point Bustaz Kool, you mean the moment the client viewed a certained record, I have to set the InUse column.

I already had an in use column. However, I had problem encountering deadlocks.

Is there any way to handle viewing restriction in SQL? Once a certain application viewed a certain record. Other application should not be able to access that record.


Any idea? Or I have to manage those deadlocks anyway? if its so, please show me how?

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-04-03 : 05:32:20
Having an InUse column should not cause deadlocks.
The deadlocks are a different issue, and depend on other things;
transactions, isolation level, order of read/insert/update, do you close the connections after reading etc...

The flow for the clients should be;
0. connect, begin transaction
1. Lock the records that are to be retrieved (update)
2. Retrieve the records
3. commit, disconnect

And do the above in a stored procedure!

Edit:
Maybe You should let the client only lock a certain amount of records,
and only for aspecified amount of time.
Use a lockdate column,
and all records where datediff(minute,lockdate,getdate()) > 9 -- 10 minute locks allowed
are considered unlocked.

That way they will not be locked indefinetely if the client never releases them.

rockmoose
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2005-04-04 : 23:52:11
TNX! rockmoose

Your idea is helpfull!
Tnx for that concepts it put up a great help for me.




Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-11-22 : 02:01:19
quote:
Originally posted by rockmoose

Having an InUse column should not cause deadlocks.
The deadlocks are a different issue, and depend on other things;
transactions, isolation level, order of read/insert/update, do you close the connections after reading etc...

The flow for the clients should be;
0. connect, begin transaction
1. Lock the records that are to be retrieved (update)
2. Retrieve the records
3. commit, disconnect

And do the above in a stored procedure!

Edit:
Maybe You should let the client only lock a certain amount of records,
and only for aspecified amount of time.
Use a lockdate column,
and all records where datediff(minute,lockdate,getdate()) > 9 -- 10 minute locks allowed
are considered unlocked.

That way they will not be locked indefinetely if the client never releases them.

rockmoose



I've seen it with my two eyes. Same record was fetch by the client. Do we have an issue of simultaneous pick and update?

Heres my code...

BEGIN TRANSACTION

update fetching set fetching.CapturedDateTime = getdate()
,fetching.CapturedBy = @UserName
from tblFetch as fetching
where fetching.tID in (select top 1 tID
from tblFetch
where CapturedBy = '0'
or datediff(minute,CapturedDateTime,getdate()) >= 15
order by tID asc
)

-- Show the record for picking.
SELECT top 1
s.SubscriberName as SubscriberName
,t.TransAmount
,t.tID
,s1.SubscriberName as upline
FROM tblFetch as fetching
INNER JOIN tblTransactions as t on t.tID = loading.tID
INNER JOIN tblArrivals as sa on sa.aid = t.aid
LEFT JOIN tblSubscribers as s on s.CellphoneNo = t.CellphoneNo
LEFT JOIN tblSubscribers as s1 on s.refCellphone = s1.CellphoneNo
where fetching.CapturedBy = cast(@UserName as numeric(18)) and fetching.CapturedDateTime is null
order by t.sysDateTime

-- Rollback transaction if error occurs.
if @@error <> 0
begin
ROLLBACK TRANSACTION
end


COMMIT TRANSACTION


For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-11-22 : 02:02:36
quote:
Originally posted by jonasalbert20

quote:
Originally posted by rockmoose

Having an InUse column should not cause deadlocks.
The deadlocks are a different issue, and depend on other things;
transactions, isolation level, order of read/insert/update, do you close the connections after reading etc...

The flow for the clients should be;
0. connect, begin transaction
1. Lock the records that are to be retrieved (update)
2. Retrieve the records
3. commit, disconnect

And do the above in a stored procedure!

Edit:
Maybe You should let the client only lock a certain amount of records,
and only for aspecified amount of time.
Use a lockdate column,
and all records where datediff(minute,lockdate,getdate()) > 9 -- 10 minute locks allowed
are considered unlocked.

That way they will not be locked indefinetely if the client never releases them.

rockmoose



Sorry for multiple posting. here's my final edited post.

I've seen it with my two eyes. Same record was fetch by the client. Do we have an issue of simultaneous pick and update?

Heres my code...

BEGIN TRANSACTION

-- Update that the record has been picked by user for viewing.
update fetching set fetching.CapturedDateTime = getdate()
,fetching.CapturedBy = @UserName
from tblFetch as fetching
where fetching.tID in (select top 1 tID
from tblFetch
where CapturedBy = '0'
order by tID asc
)
-- Rollback transaction if error occurs.
if @@error <> 0
begin
ROLLBACK TRANSACTION
end

-- Show the record for picking.
SELECT top 1
s.SubscriberName as SubscriberName
,t.TransAmount
,t.tID
,s1.SubscriberName as upline
FROM tblFetch as fetching
INNER JOIN tblTransactions as t on t.tID = loading.tID
INNER JOIN tblArrivals as sa on sa.aid = t.aid
LEFT JOIN tblSubscribers as s on s.CellphoneNo = t.CellphoneNo
LEFT JOIN tblSubscribers as s1 on s.refCellphone = s1.CellphoneNo
where fetching.CapturedBy = cast(@UserName as numeric(18)) and fetching.CapturedDateTime is null
order by t.sysDateTime

-- Rollback transaction if error occurs.
if @@error <> 0
begin
ROLLBACK TRANSACTION
end


COMMIT TRANSACTION





For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...



For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page
   

- Advertisement -