2 Replies Latest reply on Jun 7, 2018 4:52 PM by Nathan Mannheimer

    Error in a query launched thorugh python

    Andrea Grella

      Hi community!

       

      I have a python script that launches a query, taking into account some parameters:

       

      SCRIPT_REAL("

      import pyhdb as db

      connection = db.connect('host', port, 'user', 'password')

      cursor = connection.cursor()

      params = _arg1 + _arg2 + _arg3 + _arg4 + _arg5 + _arg6 + _arg7 + _arg8

      _arg1_placeholders = ','.join('?' for i in range(len(_arg1)))

      _arg2_placeholders = ','.join('?' for i in range(len(_arg2)))

      _arg3_placeholders = ','.join('?' for i in range(len(_arg3)))

      _arg4_placeholders = ','.join('?' for i in range(len(_arg4)))

      _arg5_placeholders = ','.join('?' for i in range(len(_arg5)))

      _arg6_placeholders = ','.join('?' for i in range(len(_arg6)))

      _arg7_placeholders = ','.join('?' for i in range(len(_arg7)))

      _arg8_placeholders = ','.join('?' for i in range(len(_arg8)))

      query2= 'SELECT SUM(VOL)'+\

              'FROM  table '\

              +'WHERE COUNTRY IN (' + _arg1_placeholders + ') '\

              +'AND GLOBAL_CATEGORY IN (' + _arg2_placeholders + ') '\

              +'AND GLOBAL_BRAND IN (' + _arg3_placeholders + ') '\

              +'AND GLOBAL_SUB_BRAND IN (' + _arg4_placeholders + ') '\

              +'AND TAG_REL IN (' + _arg5_placeholders + ') '\

              +'AND GLOBAL_SEGMENT IN (' + _arg6_placeholders + ') '\

              +'AND GLOBAL_BRAND_OWNER IN (' + _arg7_placeholders + ') '\

              +'AND HIER_LEVEL_NAME IN (' + _arg8_placeholders + ')'

      cursor.execute(query2, (params))

      result = cursor.fetchone()

      return result[0]

      connection.close()

      "

      , ATTR([Country]), ATTR([Global Category]), ATTR([Global Brand]),

      ATTR([Global Sub Brand]), ATTR([Period]), ATTR([Global Segment]),

      ATTR([Global Brand Owner]), ATTR([Hierarchy Market Level Name]))

       

      If I filter to see just one or two countries, it works perfectly. If I want to see many countries i obtain such error:

       

      DataError : Parameter row too large to fit into execute statement.Got: 0 bytes, allowed: 130976 bytes

       

      As it happens with countries, it also happens with other fields. Does someone know what is the problem?