Issue Details (XML | Word | Printable)

Key: MDL-14886
Type: Sub-task Sub-task
Status: Resolved Resolved
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Eloy Lafuente (stronk7)
Reporter: Eloy Lafuente (stronk7)
Votes: 0
Watchers: 0
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle
MDL-14679

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

Created: 18/May/08 08:51 AM   Updated: 06/Jan/09 11:31 PM
Return to search
Component/s: Database SQL/XMLDB
Affects Version/s: 2.0
Fix Version/s: 2.0

File Attachments: 1. Text File adodb-mssql.inc.php.V5.04a.patch (2 kB)

Issue Links:
Cloners
 

Participants: Eloy Lafuente (stronk7)
Security Level: None
Resolved date: 18/May/08
Affected Branches: MOODLE_20_STABLE
Fixed Branches: MOODLE_20_STABLE


 Description  « Hide
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.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Eloy Lafuente (stronk7) added a comment - 18/May/08 08:57 AM - 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


Eloy Lafuente (stronk7) added a comment - 18/May/08 09:03 AM
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


Eloy Lafuente (stronk7) made changes - 18/May/08 09:03 AM
Field Original Value New Value
Attachment adodb-mssql.inc.php.V5.04a.patch [ 14023 ]
Eloy Lafuente (stronk7) committed 1 file to 'Moodle CVS' - 18/May/08 09:06 AM
Fix MSSQL Insert_ID() to work when inserting using placeholders. MDL-14886
MODIFY lib/adodb/drivers/adodb-mssql.inc.php   Rev. 1.25    (+18 -2 lines)
Eloy Lafuente (stronk7) committed 1 file to 'Moodle CVS' - 18/May/08 09:11 AM
Document local change in drivers/adodb-mssql.inc.php. MDL-14886
MODIFY lib/adodb/readme_moodle.txt   Rev. 1.20    (+5 -1 lines)
Eloy Lafuente (stronk7) added a comment - 18/May/08 09:22 AM
Patch applied. Comment added to readme_moodle.txt. ADOdb guy notified. Resolving as fixed. Ciao

Eloy Lafuente (stronk7) made changes - 18/May/08 09:22 AM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Pablo Cecere made changes - 06/Jan/09 11:31 PM
Link This issue is a clone of MDL-17794 [ MDL-17794 ]