@@ -18,12 +18,15 @@ def __init__(self, connxml):
1818 self ._authentication = connxml .get ('authentication' )
1919 self ._class = connxml .get ('class' )
2020 self ._port = connxml .get ('port' , None )
21+ self ._query_band = connxml .get ('query-band-spec' , None )
22+ self ._initial_sql = connxml .get ('one-time-sql' , None )
2123
2224 def __repr__ (self ):
2325 return "'<Connection server='{}' dbname='{}' @ {}>'" .format (self ._server , self ._dbname , hex (id (self )))
2426
2527 @classmethod
26- def from_attributes (cls , server , dbname , username , dbclass , port = None , authentication = '' ):
28+ def from_attributes (cls , server , dbname , username , dbclass , port = None , query_band = None ,
29+ initial_sql = None , authentication = '' ):
2730 """Creates a new connection that can be added into a Data Source.
2831 defaults to `''` which will be treated as 'prompt' by Tableau."""
2932
@@ -34,6 +37,8 @@ def from_attributes(cls, server, dbname, username, dbclass, port=None, authentic
3437 xml .username = username
3538 xml .dbclass = dbclass
3639 xml .port = port
40+ xml .query_band = query_band
41+ xml .initial_sql = initial_sql
3742
3843 return xml
3944
@@ -149,3 +154,55 @@ def port(self, value):
149154 pass
150155 else :
151156 self ._connectionXML .set ('port' , value )
157+
158+ @property
159+ def query_band (self ):
160+ """Query band passed on connection to database."""
161+ return self ._query_band
162+
163+ @query_band .setter
164+ def query_band (self , value ):
165+ """Set the connection's query_band property.
166+
167+ Args:
168+ value: New query_band value. String.
169+
170+ Returns:
171+ Nothing.
172+ """
173+
174+ self ._query_band = value
175+ # If query band is None we remove the element and don't write it to XML
176+ if value is None :
177+ try :
178+ del self ._connectionXML .attrib ['query-band-spec' ]
179+ except KeyError :
180+ pass
181+ else :
182+ self ._connectionXML .set ('query-band-spec' , value )
183+
184+ @property
185+ def initial_sql (self ):
186+ """Initial SQL to be run."""
187+ return self ._initial_sql
188+
189+ @initial_sql .setter
190+ def initial_sql (self , value ):
191+ """Set the connection's initial_sql property.
192+
193+ Args:
194+ value: New initial_sql value. String.
195+
196+ Returns:
197+ Nothing.
198+ """
199+
200+ self ._initial_sql = value
201+ # If initial_sql is None we remove the element and don't write it to XML
202+ if value is None :
203+ try :
204+ del self ._connectionXML .attrib ['one-time-sql' ]
205+ except KeyError :
206+ pass
207+ else :
208+ self ._connectionXML .set ('one-time-sql' , value )
0 commit comments