c.execute("INSERT INTO register(owner,username,password,salt) VALUES('%s','%s','%s','')" % (jabberID, username, password))
def removeRegistration(self, jabberID):
""" Removes a registration from the XDB. """
self.db_ping()
c=self.db.cursor()
c.execute("DELETE FROM settings USING settings, register WHERE settings.ownerID = register.id AND register.owner = '%s'" % jabberID)
c.execute("DELETE FROM list_attributes USING list_attributes, register WHERE list_attributes.ownerID = register.id AND register.owner = '%s'" % jabberID)
c.execute("DELETE FROM register WHERE owner = '%s'" % jabberID)
def getSettingList(self, jabberID):
""" Gets a list of all settings for a user from the XDB. """
self.db_ping()
c=self.db.cursor()
c.execute("SELECT settings.variable,settings.value FROM settings, register WHERE settings.ownerID = register.id AND register.owner = '%s'" % (jabberID))
results = []
ret = c.fetchone()
while ret:
(variable) = ret[0]
(value) = ret[1]
results[variable] = value
ret = c.fetchone()
return results
def getSetting(self, jabberID, variable):
""" Gets a user setting from the XDB. """
self.db_ping()
c=self.db.cursor()
c.execute("SELECT settings.value FROM settings, register WHERE settings.ownerID = register.id AND register.owner = '%s' AND settings.variable = '%s'" % (jabberID, variable))
ret = c.fetchone()
if ret:
(value) = ret[0]
return value
else:
return None
def setSetting(self, jabberID, variable, value):
""" Sets a user setting in the XDB. """
self.db_ping()
c=self.db.cursor()
c.execute("DELETE FROM settings USING settings, register WHERE settings.ownerID = register.id AND register.owner = '%s' AND settings.variable = '%s'" % (jabberID, variable))
c.execute("INSERT INTO settings(ownerID,variable,value) VALUES((SELECT id FROM register WHERE owner = '%s'),'%s','%s')" % (jabberID, variable, value))
def getListEntry(self, type, jabberID, legacyID):
""" Retrieves a legacy ID entry from a list in
the XDB, based off the type and jabberID you provide. """
self.db_ping()
attributes = {}
c=self.db.cursor()
c.execute("SELECT list_attributes.attribute, list_attributes.value FROM list_attributes, register WHERE list_attributes.ownerID = register.id AND register.owner = '%s' AND list_attributes.type = '%s' AND list_attributes.jid = '%s'" % (jabberID, type, legacyID))
ret = c.fetchone()
while ret:
(attribute,value) = ret[0:1]
attributes[attribute] = value
ret = c.fetchone()
return attributes
def getListTypes(self, jabberID):
""" Returns an array containing a list of all list types
associated with a user. """
self.db_ping()
types = []
c=self.db.cursor()
c.execute("SELECT list_attributes.type FROM list_attributes, register WHERE list_attributes.ownerID = register.id AND register.owner = '%s'" % (jabberID))
ret = c.fetchone()
while ret:
(type) = ret[0]
types.append(type)
ret = c.fetchone()
return types
def getList(self, type, jabberID):
""" Retrieves an array containing an entire list of a
jabberID's from the XDB, based off the type and jabberID
you provide. """
self.db_ping()
entities = []
c=self.db.cursor()
c.execute("SELECT list_attributes.jid FROM list_attributes, register WHERE list_attributes.ownerID = register.id AND register.owner = '%s' AND list_attributes.type = '%s'" % (jabberID, type))
ret = c.fetchone()
while ret:
(jid) = ret[0]
entity = []
entity.append(jid)
attributes = {}
self.db_ping()
ic = self.db.cursor()
ic.execute("SELECT list_attributes.attribute, list_attributes.value FROM list_attributes, register WHERE list_attributes.ownerID = register.id AND register.owner = '%s' AND list_attributes.type = '%s' AND list_attributes.jid = '%s'" % (jabberID, type, jid))
""" Updates or adds a legacy ID entry to a list in
the XDB, based off the type and jabberID you provide. """
self.db_ping()
c=self.db.cursor()
c.execute("DELETE FROM list_attributes USING list_attributes, register WHERE list_attributes.ownerID = register.id AND register.owner = '%s' AND list_attributes.type = '%s' AND list_attributes.jid = '%s'" % (jabberID, type, legacyID))
for p in payload.keys():
c.execute("INSERT INTO list_attributes(ownerID,type,jid,attribute,value) VALUES((SELECT id FROM register WHERE owner = '%s'),'%s','%s','%s','%s')" % (jabberID, type, legacyID, p, payload[p].replace("'", "\\'")))
the XDB, based off the type and jabberID you provide. """
self.db_ping()
c=self.db.cursor()
c.execute("DELETE FROM list_attributes USING list_attributes, register WHERE list_attributes.ownerID = register.id AND register.owner = '%s' AND list_attributes.type = '%s' AND list_attributes.jid = '%s'" % (jabberID, type, legacyID))