X-Post on stackoverflow: <http://stackoverflow.com/posts/31307677>

I use SQLAlchemy with Python3 and sqlite3.

I tried to `add()` and new object into a sqlite database and got this
error message.

    sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError)
    Error binding parameter 3 - probably unsupported type.
    SQL: 'INSERT INTO "TrainingUnit"
    (oid, "order", date, level, sets, repetitions, machine)
    VALUES (?, ?, ?, ?, ?, ?, ?)']
    [parameters: (6, 0, '2014-12-12', Decimal('75'), None, None, 1)]

I understand that "parameter 3" means the fourth one because the
counting begins with 0. I think the problem here is the `Decimal()`. I
don't understand why SQLAlchemy add this here? What is this
'Decimal()'? Is it Python, SQL, ...?

The scheme itself is generated automaticly from SQLA with that statement

    CREATE TABLE "TrainingUnit" (
            oid INTEGER NOT NULL, 
            "order" INTEGER, 
            date DATE, 
            level INTEGER, 
            sets INTEGER, 
            repetitions INTEGER, 
            machine INTEGER, 
            PRIMARY KEY (oid), 
            FOREIGN KEY(machine) REFERENCES "Machine" (oid)
    )

...out of that SQLAlchemy/Python class definition

    class TrainingUnit(_Base):
        __tablename__ = 'TrainingUnit'
    
        _oid = sa.Column('oid', sa.Integer, primary_key=True)
        _order = sa.Column('order', sa.Integer)
        _date = sa.Column('date', sa.Date)
        _level = sa.Column('level', sa.Integer)
        _sets = sa.Column('sets', sa.Integer)
        _repetitions = sa.Column('repetitions', sa.Integer)
        _machine_fk = sa.Column('machine', sa.Integer,
    sa.ForeignKey('Machine.oid')) _machine = sao.relationship("Machine")
        ...

This is a part of the `add()` using code. It copy/convert "objects"
from a PostgreSQL database to a SQLite database using SQLAlchemy. This
worked fine for two other tables.

    pstr = 'postgres://puser@localhost/' + dbname
    sstr = 'sqlite:///' + dbname + '.db'
    pengine = sa.create_engine(pstr, echo = False)
    sengine = sa.create_engine(sstr, echo = True)

    # create and open the SQLite database
    create_database(sengine.url)
    mod._Base.metadata.create_all(sengine)
    ssession = sao.sessionmaker(bind = sengine)()

    # open the PostgreSQL database
    psession = sao.sessionmaker(bind = pengine)()

    # ...

    # TrainingUnit
    for t in psession.query(mod.TrainingUnit).all():
        sas.make_transient(t)
        ssession.add(t)
    ssession.commit()

    psession.close()
    ssession.close()

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to