Josh Stratton wrote:
>
> I just figured the mapper had to be called every time as it didn't
> just compile the class, but actually needed a database table to map to
> and wasn't sure what was done under the hood to setup that up and if
> it was valid for another database.
>
>>> Just to be sure, but would using a mapper setup as described above
>>> prevent normal autoincrementing for merge's or saveOrUpdate's into a
>>> table or do those only work with straight inserts?
>>
>> im not sure what you mean here but using mappers is a prerequisite
>> using a merge, if you're referring to session.merge().
>
> I was referring to a session.merge(), but from what I understand of
> sqlalchemy, you can do inserts into a table without the primary key
> and if it's an integer, it will provide a primary key on the insert.
> When using a session and adding data with a session.merge() I seem to
> be getting errors of not being about to add data due to lack of a
> primary key.  If I had a table with an integer primary key 'userId'
> and String 'userName', I mapped a class that just had a 'userName'
> string field, and merged it into the database, would you expect a
> primary key to be provided as a non-session insert would?  If so, are
> you aware of any complications to this specifically with sqlite?

the "autoincrement on primary key" behavior is database specific.  If you
are using SQLite or Mysql for example, you will need to specify the column
as primary key in your database - otherwise they do not provide
"autoincrementing" behavior.   If using postgres or oracle you could use a
sequence instead.  Otherwise you need to manually generate primary key
identifiers.

as far as mapper behavior and such, the questions you're asking are fairly
fundamental and are likely answered if you take a run through the Object
Relational tutorial on the SQLAlchemy site.





>
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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