Re: [Modeling-users] quoting entity and attribute names
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-06-23 17:17:55
|
That's it, you got it right: the intention was to use externalNameQuoteCharacter() into sqlStringForSchemaObjectName(), the latter being the method responsible for quoting (or not). I think we can make externalNameQuoteCharacter a class variable (possibly the empty string), and then sqlStringForSchemaObjectName(name) return the "quoted" name if variable is set, or otherwise the name, intact. Now of course sqlStringForSchemaObjectName() should be called wherever tables', columns' names are referenced... If by now you only need to quote tables' names, I'd suggest you quickly patch the assembleDelete|Select|UpdateStatement...(). Please note this is a quick answer that needs some more thinking, at least for me ;), to determine where and when the quoting should be applied (without too much overhead) -- S=E9bastien. John Lenton <jo...@vi...> wrote: > Hi all. >=20 > In a project I'm currently working on there is a class that we'd like > to call "User", but we can't call it that and use Modeling in its > current state: it's not quoting the names of entities (nor > attributes), and user is a reserved word. >=20 > I looked into it, and I actually got it working, but I then saw that > in SQLExpression there's a method `externalNameQuoteCharacter'; is the > purpose of this method to be used (something like) this: >=20 > [ in _addTableJoinsForAlias ] >=20 > quoteChar =3D self.externalNameQuoteCharacter() > str +=3D quoteChar + self._internals.entityExternalNameForAlias(alias= ) + quoteChar + ' ' + alias >=20 > ? >=20 > What I did was actually add a static method called quotedExternalName, > thus: >=20 > def quotedExternalName(name): > return name >=20 > which I then overrode in PostgresqlSQLExpression, >=20 > def quotedExternalName(name): > return '"%s"' % (name,) >=20 > and in MySQLSQLExpression, >=20 > def quotedExternalName(name): > return '`%s`' % (name,) >=20 > (no idea how sqlite nor oracle do this) >=20 > this and the appropriate modifications where the SQL is computed got > me to where I could use the objects in Modeling once the database was > created (I didn't run extensive tests, however); on looking into what > it took to make mdl_generate_DB_schema quote its chars I came across > that method that I'd overlooked before, which gave me pause, because > obviously S=E9bastien has already thought about this, so he probably has > a preferred way of doing it. >=20 > So... rounding up what shouldn't've become such a long mail: > S=E9bastien, how had you thought you'd do this? >=20 > --=20 > John Lenton (jo...@vi...) -- Random fortune: > Ir contra la corriente, casi nunca es conveniente. |