def test_sqla_utf8_chain():
    """Test insert and select of a UTF-8 string."""
    from sqlalchemy import Table, Column
    from sqlalchemy.types import CHAR, VARBINARY
    from sqlalchemy.ext.declarative import declarative_base
    from invenio_ext.sqlalchemy import db
    print('Test UTF-8 support... \t', end='')
    tmptable = 'test__invenio__utf8'
    beta_in_utf8 = 'β'
    Base = declarative_base()
    table = Table(tmptable, Base.metadata, Column('x', CHAR(1)), Column('y',
        VARBINARY(2)))
    if table.exists(bind=db.engine):
        table.drop(bind=db.engine)
    table.create(bind=db.engine)
    db.engine.execute(table.insert(), x=beta_in_utf8, y=beta_in_utf8)
    result = db.engine.execute(table.select().where(table.c.x ==
        beta_in_utf8).where(table.c.y == beta_in_utf8))
    assert result.rowcount == 1
    for row in result:
        assert row['x'] == beta_in_utf8.decode('utf-8')
        assert row['y'] == beta_in_utf8
    table.drop(bind=db.engine)
    print(' [OK]')
