Hi All

       I am using Sqlalchemy 0.6.6 + cx_oracle5.0.3+python 2.6.4 and
oracle 10g from linux.

      when I tried the sqlalchemy autoload feature

      tbl=Table('autoload_test', meta,
autoload=True,autoload_with=engine, schema=None)

      Here I am getting tbl.columns.keys() are all lower case even if
my column names are in upper case in DB . I checked the issue and
found the reason

          in get_columns method (sqlalchemy/dialects/oracle/base.py)
after fetching the column names in the loop before assigning the
column name to colname variable normalize_name(sqlalchemy/dialects/
oracle/base.py) method is calling and finally the colname varaiable
will set as a value of name key and finally the dict will append to a
list in the loop.

 cdict = {

            'name': colname,

            'type': coltype,

            'nullable': nullable,

            'default': default,

        }

columns.append(cdict)

 Here In normalize_name method

   the code is
+++++++++++++++++++++++++++++++++++++++++++++++++
        if name.upper() == name and \

               not
self.identifier_preparer._requires_quotes(name.lower()):

              return name.lower()

        else:

               return name
++++++++++++++++++++++++++++++++++++++++++++++++++


the  _requires_quotes(sqlalchemy/sql/compiler.py) method will return a
Boolean value
++++++++++++++++++++++++++++++++++++++++++++++++++
def _requires_quotes(self, value):

    """Return True if the given identifier requires quoting."""

    lc_value = value.lower()

    return (lc_value in self.reserved_words

            or value[0] in self.illegal_initial_characters

            or not self.legal_characters.match(unicode(value))

            or (lc_value != value))
++++++++++++++++++++++++++++++++++++++++++++++++++

 Here the problem is lc_value!=value checking ,suppose my column name
is 'FIRST_NAME' in normalize_name method we called this method
"self.identifier_preparer._requires_quotes(name.lower())" ,so value
='first_name'
and lc_value = value.lower() => 'fist_name'

* In this case the last checking 'first_name'!='first_name' will
always fail and all four condition in my case is false now so
_requires_quotes will return False
e
*  so now in normalize_name method    return name.lower() will invoke
and i will get column name in upper case.
t
when I modified the code in normalize_name method like below

        if name.upper() == name and \

               not self.identifier_preparer._requires_quotes(name):

              return name.lower()

        else:

               return name


   I am getting table column names in upper case (ie how they are  in
DB, here I am not using any quoted column names') . . Now SQLServer
+SqlAlchemy +autoload give upper case column names in upper case but
when connecting with oracle upper case column names will be converted
to lower case.Anybody have an idea why requires_quotes method is
called like this?

  thanks:
          Anoop

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

Reply via email to