Moodle

ADOdb Insert_ID() function under MSSQL, using placeholders doesn't work

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Database SQL/XMLDB
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

Was implementing the MSSQL when I discovered that:

  • inserting records using placeholders AND
  • retrieving the last id with Insert_ID()

are completely broken!!

Explanation from: http://docs.moodle.org/en/Development:dmllib_2.0_problems

Problem: Queries using placeholders under MSSQL are executed by one sp_executesql() procedure call. In MSSQL procedures, triggers are executed into new scopes (like "shells"), so the Insert_ID() function (internally usind SCOPE_IDENTITY()) doesn't work at all, because the insert has been executed in another scope.

Solution: Patch ADOdb driver so, each time one INSERT is going to be executed by sp_executesql(), we'll add one SCOPE_IDENTITY() in the same procedure execution (that way, both the insert and the identity will be in the same scope). Once executed, return the value of the identity by the standard Insert_ID() function. BC compatible 100% with current code if implemented that way.

Issue Links

Activity

Hide
Eloy Lafuente (stronk7) added a comment - - edited

Lucky!

searching the web... I've found one guy that, some time ago proposed one patch to fix this for one old release of ADOdb... going to apply and test.

Reference: http://phplens.com/lens/lensforum/msgs.php?id=17068&x=1

Ciao

Show
Eloy Lafuente (stronk7) added a comment - - edited Lucky! searching the web... I've found one guy that, some time ago proposed one patch to fix this for one old release of ADOdb... going to apply and test. Reference: http://phplens.com/lens/lensforum/msgs.php?id=17068&x=1 Ciao
Hide
Eloy Lafuente (stronk7) added a comment -

Here it's the pach. And works. I've been able to install HEAD under MSSQL. Going to apply it to our adodb libs and inform John Lim.

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Here it's the pach. And works. I've been able to install HEAD under MSSQL. Going to apply it to our adodb libs and inform John Lim. Ciao
Hide
Eloy Lafuente (stronk7) added a comment -

Patch applied. Comment added to readme_moodle.txt. ADOdb guy notified. Resolving as fixed. Ciao

Show
Eloy Lafuente (stronk7) added a comment - Patch applied. Comment added to readme_moodle.txt. ADOdb guy notified. Resolving as fixed. Ciao

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: