def _gen_sql(table_name, mappings):
    pk = None
    sql = ['-- generating SQL for %s...' % table_name, 'create table %s (' % table_name]
    for f in sorted(mappings.values(), lambda x, y: cmp(x._order, y._order)):
        if not hasattr(f, 'ddl'):
            raise StandardError(n % 'no ddl in field "%s".')
        ddl = f.ddl
        nullable = f.nullable
        if f.primary_key:
            pk = f.name
        sql.append(nullable and '  %s %s,' % (f.name, ddl) or '  %s %s not null,' % (f.name, ddl))
    sql.append('  primary key(%s)' % pk)
    sql.append(');')
    return '\n'.join(sql)
dataset/ETHPy150Open michaelliao/transwarp/transwarp/db.py/_gen_sql/swapped operands of `%`