Skip to content

mc.exec is masking last insert id on insert statement [moved] #14

Closed
@julienschmidt

Description

@julienschmidt

This is Issue 14 moved from a Google Code project.
Added by 2012-10-12T00:31:05.000Z by zdan...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.
Closed (Fixed).

Original labels: Type-Defect, Priority-High

Original description

<b>Problem summary:</b>

In connections.go mc.exec is masking the mc.insertId with 0.  To be more clear, I am running an Exec to insert into a table and getting errors while trying to read the LastInsertId() back on the a result set.  Unless I am mistaken, when doing an insert you should get a true result object back with a last insert id.  

Here is a suggested patch to fix the issue.


--- connection.go.orig  2012-10-11 18:19:59.000000000 -0600
+++ connection.go       2012-10-11 18:20:40.000000000 -0600
@@ -197,7 +197,7 @@
                return nil, e
        }

-       if mc.affectedRows == 0 {
+       if mc.affectedRows == 0 && mc.insertId == 0 {
                return driver.ResultNoRows, e
        }

@@ -222,7 +222,6 @@
        }

        mc.affectedRows = 0
-       mc.insertId = 0

        if resLen > 0 {
                _, e = mc.readUntilEOF()


PS.  Thanks for your code.  It has been a pleasure to work with your driver.


<b>Used go-mysql-version (e.g. May 26, 2012):</b>


MySQL-Server version: Custom Percona Build


Used Operation System (CenOS 5.8):


<b>Example code which reproduces the error (optional):</b>

Please see problem statement.  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions