Getting error sqlalchemy.exc.DataError: (pyodbc.DataError) ('22018', '[22018] [IBM][System i Access ODBC Driver]Error in assignment

50 views
Skip to first unread message

Siddhesh Naik

unread,
Sep 6, 2019, 4:15:16 AM9/6/19
to ibm_db
Hi,

I want to insert data with default Boolean values into the table using AS400 dialect and the sql alchemy. While inserting data into the table, I got following error
sqlalchemy.exc.DataError: (pyodbc.DataError) ('22018', '[22018] [IBM][System i Access ODBC Driver]Error in assignment

My code snippet is below
from sqlalchemy import *
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.pool import StaticPool


URL
= "ibm_db_sa+pyodbc400://{user}:{password}@{host}:{port}/{database}"

engine
= create_engine(URL, poolclass=StaticPool, echo=True)
meta
= MetaData(bind=engine, schema="test")
db_session
= sessionmaker(bind=engine)
model
= declarative_base(metadata=meta)


json_data
= {
       
"title": "Sample Konfabulator Widget",
       
"name": "main_window",
       
"width": 500,
       
"height": 500
   
}


class Client(model):
    __tablename__
= 'client'
    id
= Column("id", Integer, nullable=False, primary_key=True)
    name
= Column("name", String(128), nullable=True)
    age
= Column("age", Integer)
    is_active
= Column("is_active", Boolean, default=True)
    is_deleted
= Column("is_deleted", Boolean, default=False)
    client_address
= Column("client_address", Text)


def add_client(client_details):
    session
= db_session()
    client
= Client(**client_details)
    session
.add(client)
    session
.commit()
   
return True


def get_client():
    session
= db_session()
    client
= session.query(Client).filter(Client.id == "1").first()
   
print("Client_id =", client.id)
   
print("Client_name =", client.name)
    session
.close()
   
return True


client_data
= {"name": "text", "age": 30, "client_address": json.dumps(json_data)}
add_client
(client_data)
get_client
()

Add_client() and get_client() methods gives the same error.


Please help
Reply all
Reply to author
Forward
0 new messages