quoting entity and attribute names

John Lenton <[email protected]> Tue, 22 Jun 2004 20:06:44 -0300
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
Sender: John Lenton <[email protected]>

Hi all.

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.

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:

    [ in _addTableJoinsForAlias ]

    quoteChar = self.externalNameQuoteCharacter()
    str += quoteChar + self._internals.entityExternalNameForAlias(alias) + quoteChar + ' ' + alias

?

What I did was actually add a static method called quotedExternalName,
thus:

    def quotedExternalName(name):
        return name

which I then overrode in PostgresqlSQLExpression,

    def quotedExternalName(name):
        return '"%s"' % (name,)

and in MySQLSQLExpression,

    def quotedExternalName(name):
        return '`%s`' % (name,)

(no idea how sqlite nor oracle do this)

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ébastien has already thought about this, so he probably has
a preferred way of doing it.

So... rounding up what shouldn't've become such a long mail:
Sébastien, how had you thought you'd do this?

-- 
John Lenton ([email protected]) -- Random fortune:
Ir contra la corriente, casi nunca es conveniente.


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com