public function prepareOptions($options, $engine, $db) {
		if (empty($options) || !is_array($options))
			return null;
		switch ($engine) {
			case 'jig':
				if (array_key_exists('order', $options))
					$options['order'] = preg_replace(
						['/(?<=\h)(ASC)(?=\W|$)/i','/(?<=\h)(DESC)(?=\W|$)/i'],
						['SORT_ASC','SORT_DESC'],$options['order']);
				break;
			case 'mongo':
				if (array_key_exists('order', $options)) {
					$sorts = explode(',', $options['order']);
					$sorting = array();
					foreach ($sorts as $sort) {
						$sp = explode(' ', trim($sort));
						$sorting[$sp[0]] = (array_key_exists(1, $sp) &&
							strtoupper($sp[1]) == 'DESC') ? -1 : 1;
					}
					$options['order'] = $sorting;
				}
				if (array_key_exists('group', $options) && is_string($options['group'])) {
					$keys = explode(',',$options['group']);
					$options['group']=array('keys'=>array(),'initial'=>array(),
						'reduce'=>'function (obj, prev) {}','finalize'=>'');
					$keys = array_combine($keys,array_fill(0,count($keys),1));
					$options['group']['keys']=$keys;
					$options['group']['initial']=$keys;
				}
				break;
			case 'sql':
				$char=substr($db->quotekey(''),0,1);
				if (array_key_exists('order', $options) &&
					FALSE===strpos($options['order'],$char))
					$options['order']=preg_replace_callback(
						'/(\w+\h?\(|'. // skip function names
						'\b(?!\w+)(?:\s+\w+)+|' . // skip field args
						'\)\s+\w+)|'. // skip function args
						'(\b\d?[a-zA-Z_](?:[\w\-.])*)/i', // match table/field keys
						function($match) use($db) {
							if (!isset($match[2]))
								return $match[1];
							return $db->quotekey($match[2]);
						}, $options['order']);
				break;
		}
		return $options;
	}