sqlalchemy - cannot update row value for integer column in postgresql table -


this dummy function wrote update counter.

def updatetable(tablename, visitorid, dtwithzone):     db_uri = app.config["sqlalchemy_database_uri"]     engine = create_engine(db_uri, connect_args={"options": "-c timezone={}".format(dtwithzone.timetz().tzinfo.zone)})      # create session     session = sessionmaker()     session.configure(bind=engine)     session = session()      meta = metadata(engine, reflect=true)     table = meta.tables[tablename]     print dir(table)     # update row database     row = session.query(table).filter(           table.c.visitorid == visitorid).first()     print 'original:', row.count     row.count = row.count + 1     print "updated {}".format(row.count)     session.commit()     conn.close() 

but when reaches line row.count = row.count + 1 throws error:

attributeerror: can't set attribute 

this table

 \d visitorinfo;              table "public.visitorinfo"     column    |           type           | modifiers  --------------+--------------------------+-----------  platform     | character varying(15)    |   browser      | character varying(10)    |   visitorid    | character varying(10)    | not null  language     | character varying(10)    |   version      | character varying(20)    |   cl_lat       | double precision         |   cl_lng       | double precision         |   count        | integer                  |   ip           | character varying(20)    |   visitor_time | timestamp time zone |  indexes:     "visitorinfo_pkey" primary key, btree ("visitorid") 

what doing wrong ?why saying cannot set attribute?

part of updated code:

# update row database row = session.query(table).filter(       table.c.visitorid == visitorid).first() print 'original:', row.count val = row.count row.count = val + 1 print "updated {}".format(row.count) 

use update query:

update public.visitorinfo set counter = counter + 1 visitorid = 'visitorid' 

make sure last 'visitorid' filled application


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -