On Jul 6, 4:33 am, mc <[EMAIL PROTECTED]> wrote:
> I am using 0.3.6  and reading the 0.3 doc.
>
> The problem is that actually I need it the way it works for me now,
> i.e. returning the auto_increment fields and not my primary key
> fields.
> Will upgrading sqlalchemy break this (undocumented) feature?

*rereading*  so no, this feature doesn't exist basically.  if you want
to get at defaults that were created by the database you have to post-
fetch the row as follows...note that if you are using composite (multi-
column) primary keys, you probably need to use 0.3.9/trunk:

def insert_values(table, values):
    """insert a row into a table, return the full list of values
INSERTed including defaults
    that fired off on the DB side.

    detects rows that had defaults and post-fetches.
    """

    result = table.insert().execute(**values)
    ret = values.copy()

    for col, id in zip(table.primary_key, result.last_inserted_ids()):
        ret[col.key] = id

    if result.lastrow_has_defaults():
        criterion = and_(*[col==id for col, id in
zip(table.primary_key, result.last_inserted_ids())])
        row = table.select(criterion).execute().fetchone()
        ret.update(row)
    return ret

all_inserted_values = insert_values(sometable, {'x':7, 'y':8,
'z':'somevalue'})


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to