def save(self, forceinsert=False):
		"""\
		save()

		Saves a thing to the database.
		"""
		SQLTypedBase.save(self, forceinsert)

		# Save the categories now
		t = self.table_category
		current = self.get_categories()
		for cid in current+self.categories:
			if (cid in current) and (not cid in self.categories):
				# Remove the category
				results = delete(t, (t.c.component==self.id) & (t.c.category==cid)).execute()
			
			if (not cid in current) and (cid in self.categories):
				# Add the category
				results = insert(t).execute(component=self.id, category=cid)

		# Save the Properties now
		t = self.table_property
		current = self.get_properties()
		for cid in current+self.properties.keys():
			if (cid in current) and (not cid in self.properties.keys()):
				# Remove the category
				results = delete(t, (t.c.component==self.id) & (t.c.property==cid)).execute()
			
			elif (not cid in current) and (cid in self.properties.keys()):
				# Add the category
				results = insert(t).execute(component=self.id, property=cid, value=self.properties[cid])

			else:
				# Update the property
				results = update(t, (t.c.component==self.id) & (t.c.property==cid)).execute(component=self.id, property=cid, value=self.properties[cid])
	def remove(self):
		# FIXME: Need to remove associated orders in a better way
		#delete(Order.table).execute(oid=self.id)
		# Remove any parenting on this object.
		t = Object.table
		update(t, t.c.parent==self.id, {t.c.parent: 0}).execute()
		SQLTypedBase.remove(self)
	def __init__(self, id=None, type=None):
		self.name = "Unknown object"
		self.size = 0
		self.posx = 0
		self.posy = 0
		self.posz = 0
		self.velx = 0
		self.vely = 0
		self.velz = 0
		self.parent = 0

		SQLTypedBase.__init__(self, id, type)
	def load(self, id):
		"""\
		load(id)

		Loads a thing from the database.
		"""
		SQLTypedBase.load(self, id)

		# Load the categories now
		self.categories = self.get_categories()

		# Load the properties now
		self.properties = self.get_properties()
	def remove(self):
		trans = dbconn.begin()
		try:
			# Move the other orders down
			t = self.table
			update(t, (t.c.slot >= bindparam('s')) & (t.c.oid==bindparam('o')), {'slot': t.c.slot-1}).execute(s=self.slot, o=self.oid)

			self.object.save()
			SQLTypedBase.remove(self)

			trans.commit()
		except Exception, e:
			trans.rollback()
			raise
	def from_packet(cls, user, packet):
		self = SQLTypedBase.from_packet(cls, user, packet)

		self.oid = packet.id
		del self.id

		return self
	def save(self):
		trans = dbconn.begin()
		try:
			# Update the modtime...
			self.object.save()

			if not hasattr(self, 'id'):
				id = self.realid(self.oid, self.slot)
				if id != -1:
					self.id = id

			SQLTypedBase.save(self)

			trans.commit()
		except Exception, e:
			trans.rollback()
			raise
	def to_packet(self, user, sequence):
		# Preset arguments
		self, args = SQLTypedBase.to_packet(self, user, sequence)
		return netlib.objects.Object(sequence, self.id, self.typeno, self.name, 
				self.size, 
				self.posx, self.posy, self.posz, 
				self.velx, self.vely, self.velz, 
				self.contains(), self.ordertypes(), self.orders(), 
				self.time, 
				*args)
	def to_packet(self, user, sequence):
		self, args = SQLTypedBase.to_packet(self, user, sequence)
		
		typeno = user.playing.ruleset.typeno(self)
		print self.packet(typeno)
		return self.packet(typeno)(sequence, self.oid, self.slot, typeno, self.turns(), self.resources(), *args)
	def __init__(self, oid=None, slot=None, type=None, id=None):
		if oid != None and slot != None:
			id = self.realid(oid, slot)

		self.worked = 0
		SQLTypedBase.__init__(self, id, type)