I've not been able to get that version working. Tried % method to pass 
params into format a string. Also tried string,format() method with {} 
syntax. No joy.
For example:

@compiles(stripctrl)
def stripctrl_default(element, compiler, **kw):

    args = list(element.clauses)
  return
    'REPLACE(REPLACE(REPLACE(%s, CHR(9), %s), CHR(10), %s), CHR(13), %s)' % 
(compiler.process(args[0]), '', '', '')

Or:

@compiles(stripctrl)
def stripctrl_default(element, compiler, **kw):

    args = list(element.clauses)
    return
    'REPLACE(REPLACE(REPLACE({1}, CHR(9), {2}), CHR(10), {2}), CHR(13), 
{2})'.format(compiler.process(args[0]), '')

Or: (double quotes around whole string with two singles inside each time)
@compiles(stripctrl)
def stripctrl_default(element, compiler, **kw):

    args = list(element.clauses)
    return
    "REPLACE(REPLACE(REPLACE(%s, CHR(9), ''), CHR(10), ''), CHR(13), '')" % 
(compiler.process(args[0]),)
gives:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'


Splitting string into two lines to comply with PEP ..
@compiles(stripctrl)
def stripctrl_default(element, compiler, **kw):

    args = list(element.clauses)
    return
    "REPLACE(REPLACE(REPLACE(%s, CHR(9), ''), CHR(10), ''), CHR(13), '')"
    % (compiler.process(args[0]),)

   % (compiler.process(args[0]),)
    ^
SyntaxError: invalid syntax

Then get  back to first error with this
@compiles(stripctrl)
def stripctrl_default(element, compiler, **kw):

    args = list(element.clauses)
    return
    "REPLACE(REPLACE(REPLACE(%s, CHR(9), ''), CHR(10), ''), CHR(13), '')" \
        % (compiler.process(args[0]),)


TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'


There's a similar issue here, but can't seem to reconcile to my issue:
https://stackoverflow.com/questions/15036594/python-3-3-typeerror-unsupported-operand-types-for-nonetype-and-str

On Friday, 9 February 2018 23:28:10 UTC, Jonathan Vanasco wrote:
>
> that won't work as you expect.
>
> You're applying the python character replacements to the arguments, and 
> then emitting that in sql.  You'll end up with the same 
> InstrumentedAttribute issue, because you're trying to operate on the Python 
> column instance in the orm defintion.
>
> the string returned by the custom compiler should be a sql function, 
> something like:
>
>     """REPLACE(REPLACE(REPLACE(%s, CHR(9), ''), CHR(10), ''), CHR(13), 
> '')""""  % compiler.process(args[0])
>
> That would create sql from your example that reads:
>
>     SELECT REPLACE(REPLACE(REPLACE(<whatever the dynamic table/column 
> alias is>, CHR(9), ''), CHR(10), ''), CHR(13), '') LIMIT 1;
>
> If you just want to insert data, you could just use a python function that 
> does that string cleanup.
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to