All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
DataLoader3.DataQuery Class Reference

Public Member Functions

def __init__
 
def query
 

Public Attributes

 url
 

Detailed Description

Supports simple user queries through the use of QueryEngine.
    (https://cdcvs.fnal.gov/redmine/projects/qengine/wiki)

Definition at line 135 of file DataLoader3.py.

Constructor & Destructor Documentation

def DataLoader3.DataQuery.__init__ (   self,
  url 
)
Class constructor.

    Args:
 url - Http URL to QueryEngine.

Definition at line 140 of file DataLoader3.py.

141  def __init__(self, url):
142  """ Class constructor.
143 
144  Args:
145  url - Http URL to QueryEngine.
146  """
147  self.url = url

Member Function Documentation

def DataLoader3.DataQuery.query (   self,
  database,
  table,
  columns,
  where = None,
  order = None,
  limit = None,
  echoUrl = False 
)
Executes a simple query and returns the results in a list.  List data will
    be in the same order as listed in the columns attribute.

    Args:
 database - The name of the database to be queried.  (This database must
            be in QueryEngine's configuration file.)
 table - The name of the table to query on.
 columns - A comma separated string of the table columns to be returned.
 where - (optional) <column>:<op>:<value> - can be repeated; seperated by ampersand (&)
         op can be: lt, le, eq, ne, ge, gt
 order - (optional) A comma separated string of columns designating row order in the returned list.
         Start the string with a minus (-) for descending order.
 limit - (optional) - A integer designating the maximum number of rows to be returned.

Definition at line 148 of file DataLoader3.py.

149  def query(self, database, table, columns, where=None, order=None, limit=None, echoUrl=False):
150  """ Executes a simple query and returns the results in a list. List data will
151  be in the same order as listed in the columns attribute.
152 
153  Args:
154  database - The name of the database to be queried. (This database must
155  be in QueryEngine's configuration file.)
156  table - The name of the table to query on.
157  columns - A comma separated string of the table columns to be returned.
158  where - (optional) <column>:<op>:<value> - can be repeated; seperated by ampersand (&)
159  op can be: lt, le, eq, ne, ge, gt
160  order - (optional) A comma separated string of columns designating row order in the returned list.
161  Start the string with a minus (-) for descending order.
162  limit - (optional) - A integer designating the maximum number of rows to be returned.
163  """
164 
165  parameters = [
166  ('dbname', database),
167  ('t', table),
168  ('c', columns),
169  ('x', 'no'),
170  ]
171  if where is not None:
172  parameters.append(('w', where))
173  if order is not None:
174  parameters.append(('o', order))
175  if limit is not None:
176  parameters.append(('l', limit))
177  fullUrl = self.url + '?' + urllib.parse.urlencode(parameters, doseq=True)
178  if echoUrl:
179  print(("Url: %s" % fullUrl))
180  req = urllib.request.Request(fullUrl)
181  ssl_cert_file = os.environ.get("SSL_CERT_FILE")
182  try:
183  resp = urllib.request.urlopen(req) if ssl_cert_file else urllib.request.urlopen(req, context=ssl.SSLContext())
184  except urllib.error.HTTPError as val:
185  retValue = False
186  code = "%s %s" % (val.code, val.msg)
187  text = val.read().decode()
188  print(f"\n*** ", code, text)
189  except urllib.error.URLError:
190  if fullUrl.lower().startswith("https") and ssl_cert_file:
191  print("\n*** Please verify CA certificate provided with SSL_CERT_FILE environment variable!\n")
192  pass
193  else:
194  text = resp.read().decode()
195  data = text.split('\n')
196  return data[1:]
197 
198  return []
do one_file $F done echo for F in find $TOP name CMakeLists txt print
void decode(std::any const &src, Interval< Args...> &iv)
Decodes an interval.

Member Data Documentation

DataLoader3.DataQuery.url

Definition at line 146 of file DataLoader3.py.


The documentation for this class was generated from the following file: