from __future__ import absolute_import

from struct import pack

from vertica_python.vertica.messages.message import FrontendMessage

class Query(FrontendMessage):

    def __init__(self, query_string):
        self.query_string = query_string

    def to_bytes(self):
        encoded = self.query_string.encode('utf-8')
        return self.message_string(pack('{0}sx'.format(len(encoded)), encoded))


Query._message_id('Q')

@@ -266,23 +266,10 @@
 f):%0A
-        encoded
+%09s
  = s
@@ -284,16 +284,86 @@
 y_string
+%0A%09if (isinstance(s,str)):%0A%09%09s = unicode(s,'utf-8')%0A        encoded = s
 .encode(

convert to unicode first