The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
database concurrency
#1
Hi Dan,
Thinking in a multi-user environment is possible create some mechanism for when I do update any line of my database, I can re-read the line of my database, before my update, and see if had changes any data since my last read?

Something like a incremental column that always that happening some update this value will be incremented. And then always before any update the system will read again and compare this control (incremental column) with my last control before update and if they are different then I know that had any changes and I abort my operation. Do you understood?

Sorry for my english, because I think in Portuguese when I write in English, really sorry.

Hugs
  Reply
#2
Sure. It would probably be hard to do with any of the existing userspice functions because it would require a lot of modification, but you can definitely do it for all your tables. It would actually be pretty easy. You can't do it technically do it "concurrently" but you can do it in 2 quick steps.

You would do make the last column in your table something like ai (for auto-increment). Let's just say the table is called "data".

So you would load the page normally with something like...

Code:
$dataQ = $db->query("SELECT * FROM data");
Code:
$data = $dataQ->results();

Then you do everything you're going to do.

Then let's say you're going back to update the table, you'll do another final check...

Code:
if(!empty($_POST)){
Code:
$checkQ = $db->query("SELECT * FROM data");
Code:
$check = $checkQ->results();

Code:
if($checkQ->ai != dataQ->ai){
//something changed!
Code:
}else{
//nothing changed
Code:
$fields = array(
Code:
'mydata' => $mydata,
Code:
'ai' => $data->ai+1,
Code:
);
Code:
$db->update('data',1,$fields);
Code:
}
This is for a 1 row database but you could just do this by row if you have many lines.
  Reply
#3
Hi Dan,
It´s great man, the US is really, really, very good, it´s excellent. I like a lot that solutions.
I try it now.
Thank you very much.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)