python - Warning: Data truncated for column 'src_address' at row 1 -
from pox.core import core import pox.openflow.libopenflow_01 of import re import datetime import time sqlalchemy import create_engine, foreignkey sqlalchemy import column, date, integer, string sqlalchemy.ext.declarative import declarative_base sqlalchemy.orm import relationship, backref sqlalchemy import create_engine sqlalchemy.orm import sessionmaker sqlalchemy.sql.expression import exists log = core.getlogger() engine = create_engine('mysql://root@192.168.129.139/nwtopology', echo=false) base = declarative_base() session = sessionmaker(bind=engine) session = session() class sourcetoport(base): """""" __tablename__ = 'source_to_port' id = column(integer, primary_key=true) port_no = column(integer) src_address = column(string(16),index=true) #----------------------------------------- def __init__(self, src_address,port_no): """""" self.src_address = src_address self.port_no = port_no #create tables base.metadata.create_all(engine) def act_like_switch (self, packet, packet_in): """ implement switch-like behavior. """ # learn port source mac #print "recieved port ",packet_in.in_port , "source ",packet.src ,"dest" , packet.dst self.mac_to_port[packet.src]=packet_in.in_port r_res = session.query(sourcetoport).filter_by(src_address=str(packet.src)).first() if r_res none: print "inserting entry" start = time.time() entry = sourcetoport(src_address=str(packet.src) , port_no=packet_in.in_port) #add record session object session.add(entry) #add record session object session.commit() end = time.time() elapsed = end - start print "elapsed insert time ",elapsed else: print "entry present"
i have network sending packets 1 host another.the expected behaviour first time src_address,port pair should inserted sql database , thereafter should retrieve operation.i have tested functionlity working correctly local database using sqlite.then shifted remote database using mysql.
now find
if r_res none:
is true,meaning
r_res = session.query(sourcetoport).filter_by(src_address=str(packet.src)).first()
is failing.
i suspect has wrong query / add mysql different sqlite.
it did print out warning below when inserting entry. /usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py:330: warning: data truncated column 'src_address' @ row 1 cursor.execute(statement, parameters)
i can't figure out seems problem.
based on comments have printed out size of src_address trying insert.
print 'length of src addreess',len(str(packet.src)) prints 17
and have increased size of src_address 17,32 , 64.still same error
the following approach might save time in future.
there 1 more way of updating columns without recreating table - using alter table query.
alter table source_to_port modify src_address varchar(32);
see more discussion in this answer
Comments
Post a Comment