Example #1
0
	def sql_str(self):
		from germ.lib.db_iface import db_iface

		string = self._sql_str()

		if string is None:
			from germ.error.error import error
			raise error(error.error, 'Invalid SQL String', 'attr: %s' % \
					self.__class__.__name__)

		return db_iface.escape_string(string)
Example #2
0
	def __session_val(self, match):
		if match.group(2) is not None:
			varname = match.group(2)[1:]
			ent_str = match.group(1)

			from helper import get_entity
			entity = get_entity(ent_str, self.__session,
					self.__ent.get_globals())

			val = entity.magic_var(varname)
			if val is None:
				from germ.error.error import error
				raise error(error.error, 'Invalid magic variable',
						'entity: %s, varname: %s' % (ent_str, varname))

			return str(val)

		varname = match.group(1)

		val = self.__ent.magic_var(varname)
		if val is not None:
			return val

		if not self.__session.has_key(varname):
			# this will evaluate all comparisons to NULL, i.e. false
			return 'NULL'

		val = self.__session[varname]

		if not isinstance(val, str):
			from germ.error.error import error
			raise error(error.fail, "Session variables for use in an " \
					"SQL condition must be strings",
					"variable: %s, type: %s" % (varname, type(val)))

		from germ.lib.db_iface import db_iface

		return "'%s'" % db_iface.escape_string(val)