def get_record( self, db=None, number='' ): """ Get a single record by record id. This is non-standard, but I needed its functionality, and so here it is. Strictly speaking, this is just a special case of the get_records() function, and should be deprecated at some point. """ api = 'API_DoQuery' if not db: db = self.active_db schema = self.get_schema(db=db) for node in schema.findall('table/fields/field'): if node.attrib['field_type'] == 'recordid': field = node.get('id') break query = "{'%s'.EX.'%s'}" % (field, number) xml = ( E.qdbapi( E.ticket(self.auth_ticket), E.apptoken(self.token), E.query(query), ) ) return self._perform(db=db, xml=xml, api=api)
def get_changed_records( self, db=None, clear=False ): """ Another special case of get_records(), to only return changed records (new or modified). Optionally, this will clear the change flags. """ api = 'API_DoQuery' if not db: db = self.active_db options = 'sortorder-A.onlynew' xml = ( E.qdbapi( E.ticket(self.auth_ticket), E.apptoken(self.token), E.options(options), ) ) response = self._perform(db=db, xml=xml, api=api) # Now, clear the flags if clear: self._clear_flags(db=db) return response
def get_schema( self, db='' ): """ API function to get the schema for a particular database id." API_GetSchema: http://www.quickbase.com/api-guide/getschema.html """ api = 'API_GetSchema' xml = ( E.qdbapi( E.ticket(self.auth_ticket), E.apptoken(self.token), ) ) schema = self._perform(db=db, xml=xml, api=api) return schema
def get_dbid( self, app='' ): """ API function to find a database by name, and return its database id. API_FindDBByName: http://www.quickbase.com/api-guide/find_db_by_name.html """ api = 'API_FindDBByName' db = 'main' xml = ( E.qdbapi( E.ticket(self.auth_ticket), E.dbname(app), ) ) return self._perform(db=db, xml=xml, api=api)
def get_records( self, db=None, conditions={} ): """ API function to perform a query and return record(s) which satisfy the query. API_DoQuery: http://www.quickbase.com/api-guide/do_query.html """ if not conditions: raise Exception, "No query parameters specified." api = 'API_DoQuery' if not db: db = self.active_db query = [] schema = self.get_schema(db=db) for field in conditions: for f in schema.findall('table/fields/field'): if f.findtext('label') == field: for bounds in conditions[field]: query.append( "{'%s'.%s.'%s'}" % ( f.get('id'), xtn_map[bounds], conditions[field][bounds] ) ) xml = ( E.qdbapi( E.ticket(self.auth_ticket), E.apptoken(self.token), E.query('AND'.join(query)), E.clist('a'), ) ) return self._perform(db=db, xml=xml, api=api)
def get_all_records( self, db='' ): """ By default, the API_DoQuery function simply returns all records if no conditions are satisfied. So we do that here. This is, again, a special case of get_records() and should probably be deprecated. """ api = 'API_DoQuery' if not db: db = self.active_db xml = ( E.qdbapi( E.ticket(self.auth_ticket), E.apptoken(self.token), E.query(), E.clist('a'), ) ) return self._perform(db=db, xml=xml, api=api)
def _authenticate( self ): """ Internal function to login to quickbase and store the userid and ticket. """ api = 'API_Authenticate' db = 'main' xml = ( E.qdbapi( E.username(self.username), E.password(self.password), E.hours('%d' % self.timeout) ) ) creds = self._connect(db=db, xml=xml, api=api) self.userid = creds.findtext('userid') self.auth_ticket = creds.findtext('ticket') self.auth_time = time.time() return