Example #1
0
	def create_item_query(self, data):
		"""
		Given `data` as a dict of column => value constraints,
		create a query that will load some object(s). 
		"""
		if not(self.table):
			raise NotImplementedError('%s::create_item_query()' % self.__class__.__name__)
		from modu import persist
		return sql.build_select(self.table, data)
Example #2
0
	def _check_code(urlcode):
		if not(origin_id):
			attribs = {
				check_field:			urlcode
			}
		else:
			attribs = {
				'id':					sql.NOT(origin_id),
				check_field:			urlcode
			}
		return pool.runQuery(sql.build_select(table, attribs))
Example #3
0
	def do_load(self):
		load_query = sql.build_select('session', {'id':self.id()})
		record = self._pool.runQuery(load_query)
		
		if(record):
			record = record[0]
			record['id'] = self.id()
			if(record['data']):
				data = record['data']
				if(hasattr(data, 'tostring')):
					data = data.tostring()
				record['data'] = cPickle.loads(data)
			else:
				record['data'] = None
			return record
		else:
			return None
Example #4
0
	def test_build_select_distinct(self):
		query = sql.build_select('table', {'col1':'col1_data', 'col2':'col2_data', '__select_keyword':'DISTINCT'});
		expecting = "SELECT DISTINCT * FROM `table` WHERE `col1` = 'col1_data' AND `col2` = 'col2_data'"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #5
0
	def test_build_select_order(self):
		query = sql.build_select('table', {'col1':'col1_data', 'col2':'col2_data', '__order_by':'id DESC'});
		expecting = "SELECT * FROM `table` WHERE `col1` = 'col1_data' AND `col2` = 'col2_data' ORDER BY id DESC"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #6
0
	def test_build_select2(self):
		query = sql.build_select('table', col2='col2_data', col1='col1_data');
		expecting = "SELECT * FROM `table` WHERE `col1` = 'col1_data' AND `col2` = 'col2_data'"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #7
0
	def test_build_select_dot_syntax(self):
		query = sql.build_select('db.table', {'t.col2':'col2_data', 's.col1':'col1_data'});
		expecting = "SELECT * FROM db.`table` WHERE s.`col1` = 'col1_data' AND t.`col2` = 'col2_data'"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #8
0
	def test_build_select_lt(self):
		query = sql.build_select('table', {'col1':sql.LT("somestring")});
		expecting = "SELECT * FROM `table` WHERE `col1` < 'somestring'"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #9
0
	def test_build_select_raw(self):
		query = sql.build_select('table', {'col1':sql.RAW("%s = ENCRYPT('something', SUBSTRING(col1,1,2))")});
		expecting = "SELECT * FROM `table` WHERE `col1` = ENCRYPT('something', SUBSTRING(col1,1,2))"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #10
0
	def test_build_select_none(self):
		query = sql.build_select('table', {'col1':None});
		expecting = "SELECT * FROM `table` WHERE ISNULL(`col1`)"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #11
0
	def test_build_select_in_limit(self):
		query = sql.build_select('table', {'col1':['col1_data', 'col2_data'], '__limit':5});
		expecting = "SELECT * FROM `table` WHERE `col1` IN ('col1_data', 'col2_data') LIMIT 5"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #12
0
	def test_build_select_not_in(self):
		query = sql.build_select('table', {'col1':sql.NOT(['col1_data', 'col2_data'])});
		expecting = "SELECT * FROM `table` WHERE `col1` NOT IN ('col1_data', 'col2_data')"
		self.failUnlessEqual(query, expecting, 'Got "%s" when expecting "%s"' % (sql, expecting))
Example #13
0
def export_query_builder(req, itemdef, attribs):
	return sql.build_select(itemdef.name, attribs)