I'm on the Gmail site, so am not sure I can reply in-line. Sorry.

This is a basic table class, like
class Customer(base):
 __tablename__ = "customers"
 name = Column(String(50)),
 ...

When I print the type:
<class 'sqlalchemy.util._collections.result'>
And repr():
(2, u'Powersports Etc', 5554443210L, u'ahall+dbte...@autodist.com', True)


On 2/3/16, Simon King <si...@simonking.org.uk> wrote:
> On Wed, Feb 3, 2016 at 3:54 PM, Alex Hall <ah...@autodist.com> wrote:
>
>> Hello list,
>> I'm new to SQLAlchemy, but not to Python. I have an application that's
>> coming together, and relies on SQLAlchemy to talk to a database for
>> many of the app's functions. Listing tables, listing records, updating
>> records, pulling records for internal use, and so on.
>>
>> My app is working, but so far I've been writing the framework and GUI
>> with a bit of SQLite just to check that things are working how I want.
>> Now, though, I'm getting into my first "real" user-facing database
>> task: taking the values from a dialog and updating a record according
>> to those values. Thus far, I'm having no luck.
>>
>> My organization for now is DBInterface.py, which holds all my table
>> definitions, database details, and my base, session, and engine
>> objects. I can hear the groans from here; I do plan to move the table
>> definitions into a module of their own at some point, there simply
>> hasn't been a need yet. GUIManager.py imports DBInterface, and handles
>> all the GUI stuff, as the name suggests. It's where, eventually, I'll
>> take user input and use it to update records by calling functions from
>> DBInterface. That's the problem, though. In GUIManager, I have a
>> simple test:
>>
>> self.records[self.selectedRecordIndex].name="test name" #records is
>> the list of objects returned by querying the current table
>>
>> Which errors out every time:
>> AttributeError: can't set attribute
>>
>> (Yes, "name" is an attribute name of my Customer class.) From what
>> I've read thus far, updating records is as easy as modifying their
>> properties and calling session.commit(). That isn't working, though. I
>> imagine the problem is that the records in a query aren't the same as
>> the records originally created, and modify/commit only works on those
>> originals. I'm not sure if that's right, though. If it is, how could I
>> modify the originals, given that I run a new query each time the user
>> selects a table name in my GUI's list of names? If I'm wrong, how
>> would I update the record attributes and save the changes back to the
>> database? I think I'm picturing this whole thing wrong, to be honest.
>> Thanks for any help, and please let me know if I need to provide more
>> code or context.
>>
>>
> Is your query against a single mapped class, or is it against some set of
> columns? What do you get if you write:
>
>   print type(self.records[self.selectedRecordIndex])
>   print repr(self.records[self.selectedRecordIndex])
>
> ...at the point where you are trying to set the name?
>
> Simon
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to