Daniel Polski wrote: > Clemens Ladisch skrev 2012-11-09 17:00: >> SELECT 'SELECT units.id AS "unit id"' AS SQL >> UNION ALL >> SELECT ', cv' || id || '.value AS ' || quote(name) FROM configtypes >> UNION ALL >> SELECT 'FROM units JOIN unit_types ON units.unit_type_id = unit_types.id' >> UNION ALL >> SELECT 'LEFT JOIN (unittype_config JOIN configvalues' || >> ' ON unittype_config.configvalue_id = configvalues.id' || >> ' AND unittype_config.configtype_id = ' || id || ') AS cv' || id || >> ' ON unit_types.id = cv' || id || '.unit_id' FROM configtypes > > Seems interesting, but I don't understand how I use this type of > construction to create the view? It builds up the requested query, but > shows the sql query as text output (not executing it)?
Yes, you have to feed the output back into SQLite; it's not possible to execute dynamic code from inside SQLite itself. As Simon said, it would be easier to just do a "SELECT id, name FROM configtypes" and construct the query in your program. (Although it would end up being the same string operations that this query does.) Anyway, it's not possible to create an _immutable_ view from that; you have to update its definition whenever the configtypes table changes. Regards, Clemens _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users