Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in pyodbc: 'pyodbc.Cursor' object has no attribute 'commit'

I want to connect to SQL SERVER database from Python with pyodbc and freetds.

My connection is OK.

My code:

class GetSystems(Resource):
def get(self):
    try:
        cur = Connection.conn.cursor()
        cur.execute(
            "SELECT id,systemName,SystemDescription FROM MEFSystem")
        rows = cur.fetchall()
        objects_list = []
        for row in rows:
            d = collections.OrderedDict()
            d['id'] = row[0]
            d['systemName'] = row[1]
            d['systemDescription'] = row[2]
            objects_list.append(d)
        logger.info(objects_list)
        cur.commit()
        cur.close()
        logger.info(objects_list)
    except Exception as inst:
        cur.rollback()
        cur.close()
        print type(inst)
        print inst.args
        print inst
        logger.error(type(inst))
        logger.error(inst.args)
        logger.error(inst)
    return objects_list

This generates an error in cur.commit(): pyodbc.Cursor object has no attribute 'commit' and returns unknown data:

[
{
    "id": 2, 
    "systemDescription": "", 
    "systemName": "\uda00\udc53\ud940\udc41"
}, 
{
    "id": 3, 
    "systemDescription": "", 
    "systemName": "\uda00\udc53\ud800\udc47"
}, 
{
    "id": 4, 
    "systemDescription": "", 
    "systemName": "\ud900\udc52\ud8c0\udc4e\ud880\udc41"
}
]

The data should be:

[
{
    "id": 2, 
    "systemDescription": "", 
    "systemName": "SIAF"
}, 
{
    "id": 3, 
    "systemDescription": "", 
    "systemName": "SIGA"
}, 
{
    "id": 4, 
    "systemDescription": "", 
    "systemName": "RENTAS"
}
]

UPDATE
I commented the commit, but return data unknown from database. look => "systemName": "\uda00\udc53\ud940\udc41", should be "systemName": "SIGA"

like image 616
Oscar Ordoñez Mego Avatar asked Nov 06 '15 18:11

Oscar Ordoñez Mego


1 Answers

The solution for the problem is the version of pyodbc, download pyodbc from this link and install.

THANKS!!!

like image 188
Oscar Ordoñez Mego Avatar answered Sep 19 '22 22:09

Oscar Ordoñez Mego