I migrated to 0.9.2 as I understood the literal_processor was new feature.

I always get this error from listing shown below:

    def literal_processor(self, dialect):
                                        ^
IndentationError: unindent does not match any outer indentation level


ArrayType is obviously just a stub in this listing.

Apologies in advance if this is some obvious Python formatting issue of mine, 
I'm still learning this language.




#===== Begin Listing =============================

import os

import sqlalchemy
from sqlalchemy.orm import sessionmaker
from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy import func
from sqlalchemy.types import UserDefinedType

from sqlalchemy.sql.expression import BindParameter
from sqlalchemy.ext.compiler import compiles

#================================================
class LiteralBindParam(BindParameter):
   pass

@compiles(LiteralBindParam) 
def literal_bind(element, compiler, **kw):
   kw['literal_binds'] = True
   return compiler.visit_bindparam(element, **kw)

#================================================
class ArrayType(UserDefinedType):
    def get_col_spec(self):
        return "ARRAY"

    def column_expression(self, col):
       return None

   def literal_processor(self, dialect):
      def process(value):
         return "int_array(1, 2, 3, 4, 5)"
      return process

#================================================
dbUser = os.environ.get('uid')
dbPwd = os.environ.get('pwd')
oraSID = os.environ.get('sid')
connstr = 'oracle://%s:%s@%s' % (dbUser, dbPwd, oraSID)

#================================================
engine = sqlalchemy.create_engine(connstr)
metadata = MetaData(engine)
Base = declarative_base(metadata=metadata)
dialectMgr = DialectManager()
sessionMaker = sessionmaker(bind=engine)
session = sessionMaker()

a = LiteralBindParam(None, ArrayType())

session.execute(func.some_db_func(a)).scalar()

#===== End Listing ===============================

----- Original Message -----


> Regarding the following:
>> if the type of the LiteralBindParameter implements “literal_processor()”, 
>> that controls how the literal value is rendered into the statement. 
> 
> How does one implement the "literal_processor()" for a new type?  Is 
> literal_processor() method applicable for UserDefinedTypes?

the method is literal_processor: 
http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#sqlalchemy.types.TypeEngine.literal_processor
  

its new as of 0.9 and applies to any type, including UserDefinedType.  If you 
don’t see it taking effect, that’s a bug.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to