I am still trying different solutions for my I18N database content problem.

Currently I am looking a solution similar to http://code.google.com/p/django-pluggable-model-i18n/ , it would be neat to have something similar within SA out of the box. Also I think there approach in replacing values within the "base" table to do the default handling would cause problems in SA (wouldn't it consider that as a change and commit it on next commit?).

Anyhow my problem is that I get an exception when I do the following:

a1 = Country_D.__table__.alias('a1')
a2 = Country_T.__table__.alias('a2')

s = sa.select([a1, sa.func.coalesce(a2.c.name, a1.c.name).label('name')], sa.and_(a1.c.id == a2.c.countries_d_id, a2.c.lang_code5 == getCurrentUserLang), use_labels=True)

class Country(BaseExt):
    pass

sao.mapper(Country, s.alias('csel'))

print s

SELECT a1.id AS a1_id, a1.iso2 AS a1_iso2, a1.iso3 AS a1_iso3, a1.name AS a1_name, a1.created_at AS a1_created_at, a1.updated_at AS a1_updated_at, coalesce(a2.name, a1.name) AS name
FROM countries_d AS a1, countries_t AS a2
WHERE a1.id = a2.countries_d_id AND a2.lang_code5 = :lang_code5_1

Using the above in the IB Expert tool works fine (just replace lang_code5_1 with a string), however when I do the following:

for cs in session.query(db.Country):
    print cs

I get this exception.

Traceback (most recent call last):
  File "saTest.py", line 41, in <module>
    for cs in session.query(db.Country):
File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py", line 1361, in __iter__
    return self._execute_and_instances(context)
File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py", line 1364, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, mapper=self._mapper_zero_or_none()) File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\session.py", line 753, in execute
    clause, params or {})
File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py", line 824, in execute
    return Connection.executors[c](self, object, multiparams, params)
File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py", line 874, in _execute_clauseelement
    return self.__execute_context(context)
File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py", line 896, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context) File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py", line 950, in _cursor_execute
    self._handle_dbapi_exception(e, statement, parameters, cursor, context)
File "c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\engine\base.py", line 931, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.ProgrammingError: (ProgrammingError) (-206, 'isc_dsql_prepare: \n Dynamic SQL Error\n SQL error code = -206\n Column unknown\n A2.COUNTRIES_D_ID\n At line 4, column 18') 'SELECT csel.a1_id AS csel_a1_id, csel.a1_iso2 AS csel_a1_iso2, csel.a1_iso3 AS csel_a1_iso3, csel.a1_name AS csel_a1_name, csel.a1_created_at AS csel_a1_created_at, csel.a1_updated_at AS csel_a1_updated_at, csel.name AS csel_name \nFROM (SELECT a1.id AS a1_id, a1.iso2 AS a1_iso2, a1.iso3 AS a1_iso3, a1.name AS a1_name, a1.created_at AS a1_created_at, a1.updated_at AS a1_updated_at, coalesce(a2.name, a1.name) AS name \nFROM countries_d a1, countries_t a2 \nWHERE a1.id = a2.countries_d_id AND a2.lang_code5 = ?) csel' ['DE_de']

I can't see what I am doing wrong as the doc for "use_labels" states that the "c." collection will also use the generated names.

Werner

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to