i am in a situation where i want the db to delete a row when the user exits the application. even in the middle of the application. how can it be done?
to be more specific, consider a survey of 10 questions. i am storing the user's selections in a DB. now suppose the user exits at the 5th question. i want to delete the user's records then and there. so that if the user wishes to start again. s/he can start afresh.
I think you need to rethink your design. You should start a new session each time the user starts the survey. Clean up abandoned answers on a scheduled basis.
Never depend on browser close to perform actions like this.
You need a watchdog function that is called regularly. It compares it's list of logged in users with the real list. When there is a conflict it performs the SQL operation you require.
Related
I have a table in PhpMyAdmin and agents go in and edit a field in each row with something like a "yes" or "no".
Since all agents are working on the same table in PhpMyAdmin at the same time is there any way to prevent an agent from editing the field in a specific row if another agent is editing that field in that row?
I want to prevent rework from happening.
No, I cannot have each agent have their own table - in case someone asks that.
I don't believe so. You might need a tiny little UI program that allows agents to open a row (which would lock it by updating a Boolean or something) and prevent another agent from opening the row. Saving/Canceling would unlock it.
I'm hoping this will be a rather simple question to answer, as I'm not looking for any specific code. I have a table on a classic asp page populated from an sql server. I've just set the table up so that each row is clickable and takes you to a page to edit the data in the row. My question is this: Would I be better off trying to use the recordset that populated the table or should I reconnect to the db and pull just the record I want edited.
As always; It Depends. It depends on what you need to edit about the record. It depends on How far apart your DB and site are from each other. It depends on which machine, if the DB and site are on separate machines, is more powerful.
That being said, you should make a new call for that specific record. The reason mainly being because of a specification you made in your question:
...and takes you to a page to edit the data in the row
You should not try to pass a record set between pages. There are a few reasons for this
Only collect what you need
Make sure data is fresh
Consider how your program will scale
On point 1 there are two ways to look at this. One is that you are trying to pass the entire record set across a page when you only need 1 record. There are few situations where another DB call would cost more than this. The other is you are only passing one record which would make me question your design. Why does this record set have every item related to a record. You are selecting way too much for just a result list. Or if the record is that small then Why do you need the new page. Why can you not just reveal an edit template for the item if it is that minimal.
On point 2 consider the following scenario. You are discussing with a coworker how you need to change a customer's record. You pull up this result set in an application but then nature calls and you step away from you desk. The coworker gets called by the customer and asked why the record is not updated yet. To placate the customer your coworker makes the changes. Now you are using an old record set and may overwrite additional changes your coworker made while you were away. This all happens because you never update the record set, you always just pass the old one from page to page.
On point 3 we can look back a point 1 a bit. let us say that you are passing 5 fields now. You decide though that you need a comments field to attach to one of your existing fields. do you intend to pass 2000 characters of that comment field to the next page? How about if each of the 5 need a comment field? Do you intend to pass 10,000 characters for a properly paged record set of 10? do you not do record set paging and need to pass 10,000 characters for a full 126 records.
There are more reasons too. Will you be able to keep your records secure passing them this way? Will this effect your user's experience because they have a crummy computer and cannot build that quick of a post request quickly? Generally it is better to only keep what you need and in most situations your result set should not have everything you need to edit.
We have too many records in database.
Multiple users try to change one record at one time.
How to prevent the change if the record has changed since read by the client, who wants to change it? (Another user has changed the record).
We can use any DBMS: SQL, NoSQL. But now we use mongodb.
Maybe I would get request:
IF (record has not changed) UPDATE
ELSE GET modified record
I have a table
it has four fields :Phone_number(primary key),City_name,Category_product and sub_Category
I am develoing a php application such based on an sms gateway.
whenver a user sends and sms requesting a product service,
his details will be saved in this table.
Now when a user sends an SMS ,i will store the details in the table,and
wait for the user to send back an sms with further details as per required.
Now what i want to do is:
if a user does not respond in lets say 15 min his details should be deleted from the table automatically.
How should i proceed?
You add a column to your table that stores the time it was sent.
Then you have to choices, you can either run cron jobs to clean out the data, or you clean up the records that are not valid when another user sends a sms, etc. Since you store the time with the data you can easily change the timeout from 15 minutes later on, too.
You have to use some scheduling. PHP dont have any native support for scheduling. What I would suggest is create a descktop applicaion or a service which listens the table for SMS response. If it did not get response then it will delete the correspond record. Your job will be running infinitely.
If this is going to be a table with many records, you should set up a pre-order table and then copy the record over when the order is made. In this way, you can clean up the pre-order table anytime you want if it starts getting slow.
As Ben said, it should have a timestamp for checks.
In VBA (Access 2000) is there anyway to send information to a form between two open instances of the database?
For example :
User 1 has an instance open of DB.MDB on his PC and has FormOne open. User 2 has another instance of DB.MDB open on her PC and has FormOne open.
Can User 1 maniuplate the contents of a textbox on User 2's FormOne instance (ie. sending a message similar to a chat client)?
You could store data to a table and update the form or subform on a timer.
Like Remou, I think the table method is as you are going to get. You can optimize the querying by maintaining a one-record table that has the value of the last update. Then have your timer form check to see if the value has changed since the the timer last triggered, this will tell the timer to check the chat table.
In the alternative you can have records deleted as soon as they are read to keep the table small.
You will find that all the record creation/deletion will bloat your database though, so be sure to compact it regularly.
Lastly if all users have access to a shared drive you could just store the messages in a text file instead of a table.
Another issue is of course eavesdropping (with tables or files). You could minimize this by:
Obfuscating/encrypting the text before it is written and deobfuscating it when it is read. Deleting the record as soon as it is read by it's target.
Hiding the file/table. For files use: SetAttr myFile, vbSystem or vbHidden
For Tables prefix the table name with USys_ and make the table hidden.
All that said, it's still going to be a sorry substitute for a chat client. It will slow down the database and possibly slow down the shared drive. I would think long and hard about why I need this, and if it's really the best approach.