Thanks for your answer, Anthony. Its not necessary to change the code for
this since the id is already known if its being inserted anyway :) . I
just didn't expect that behavior.
On Tuesday, August 6, 2013 11:34:07 PM UTC-5, Anthony wrote:
>
> The DAL does this to get the id for MySQL inserts:
>
> self.execute('select last_insert_id();')
>
> Unfortunately, the value of last_insert_id() is only updated when the id
> is auto-generated, so it stores the last auto-generated id (which you
> observed), not the last id.
>
> In order to get the last id (whether auto-generated or not), you need to
> use the MySQL
> mysql_insert_id()<http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.html>C
> API function. I'm not sure if this is available via the pymysql driver,
> but the MySQLdb driver connection object does include a conn.insert_id()
> method to access this function (see
> http://mysql-python.sourceforge.net/MySQLdb.html#mysql-c-api-function-mapping).
>
> Perhaps the DAL code can be changed to use that method when the MySQLdb
> driver is being used. If you'd like, you can open a Google Code
> issue<https://code.google.com/p/web2py/issues/list>about this (and reference
> this thread).
>
> Anthony
>
> On Tuesday, August 6, 2013 11:41:03 PM UTC-4, Jim Gregory wrote:
>>
>> I'm porting a legacy table to a new table having a different schema. The
>> old table had a field (order_number) that was unique and autoincrementing
>> but not the primary key. I want to use those old values as the primary key
>> in the new table.
>
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.