Browse files

MDL-30026 dml - fix sqlsrv support for session locks

  • Loading branch information...
1 parent a16230a commit dfd6a609e00c49785ba80d3fbbf0731e418b5acc @stronk7 stronk7 committed with skodak Nov 16, 2011
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/dml/sqlsrv_native_moodle_database.php
View
13 lib/dml/sqlsrv_native_moodle_database.php
@@ -1301,7 +1301,18 @@ public function get_session_lock($rowid, $timeout) {
$timeoutmilli = $timeout * 1000;
$fullname = $this->dbname.'-'.$this->prefix.'-session-'.$rowid;
- $sql = "sp_getapplock '$fullname', 'Exclusive', 'Session', $timeoutmilli";
+ // While this may work using proper {call sp_...} calls + binding +
+ // executing + consuming recordsets, the solution used for the mssql
+ // driver is working perfectly, so 100% mimic-ing that code.
+ // $sql = "sp_getapplock '$fullname', 'Exclusive', 'Session', $timeoutmilli";
+ $sql = "BEGIN
+ DECLARE @result INT
+ EXECUTE @result = sp_getapplock @Resource='$fullname',
+ @LockMode='Exclusive',
+ @LockOwner='Session',
+ @LockTimeout='$timeoutmilli'
+ SELECT @result
+ END";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = sqlsrv_query($this->sqlsrv, $sql);
$this->query_end($result);

0 comments on commit dfd6a60

Please sign in to comment.