Subversion-Projekte lars-tiefland.ci

Revision

Revision 2049 | Revision 2242 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 2049 Revision 2107
Zeile 213... Zeile 213...
213
	 * @var	array
213
	 * @var	array
214
	 */
214
	 */
215
	protected $qb_cache_join			= array();
215
	protected $qb_cache_join			= array();
Zeile 216... Zeile 216...
216
 
216
 
-
 
217
	/**
-
 
218
	 * QB Cache aliased tables list
-
 
219
	 *
-
 
220
	 * @var	array
-
 
221
	 */
-
 
222
	protected $qb_cache_aliased_tables			= array();
-
 
223
 
217
	/**
224
	/**
218
	 * QB Cache WHERE data
225
	 * QB Cache WHERE data
219
	 *
226
	 *
220
	 * @var	array
227
	 * @var	array
221
	 */
228
	 */
Zeile 1394... Zeile 1401...
1394
		}
1401
		}
Zeile 1395... Zeile 1402...
1395
 
1402
 
1396
		// ORDER BY usage is often problematic here (most notably
1403
		// ORDER BY usage is often problematic here (most notably
1397
		// on Microsoft SQL Server) and ultimately unnecessary
1404
		// on Microsoft SQL Server) and ultimately unnecessary
1398
		// for selecting COUNT(*) ...
1405
		// for selecting COUNT(*) ...
1399
		if ( ! empty($this->qb_orderby))
-
 
1400
		{
1406
		$qb_orderby       = $this->qb_orderby;
1401
			$orderby = $this->qb_orderby;
1407
		$qb_cache_orderby = $this->qb_cache_orderby;
1402
			$this->qb_orderby = NULL;
-
 
Zeile 1403... Zeile 1408...
1403
		}
1408
		$this->qb_orderby = $this->qb_cache_orderby = NULL;
1404
 
1409
 
1405
		$result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby))
1410
		$result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby) OR $this->qb_limit OR $this->qb_offset)
Zeile 1406... Zeile 1411...
1406
			? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results")
1411
			? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results")
1407
			: $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows')));
1412
			: $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows')));
1408
 
1413
 
1409
		if ($reset === TRUE)
1414
		if ($reset === TRUE)
1410
		{
-
 
1411
			$this->_reset_select();
1415
		{
1412
		}
1416
			$this->_reset_select();
1413
		// If we've previously reset the qb_orderby values, get them back
1417
		}
-
 
1418
		else
1414
		elseif ( ! isset($this->qb_orderby))
1419
		{
Zeile 1415... Zeile 1420...
1415
		{
1420
			$this->qb_orderby       = $qb_orderby;
1416
			$this->qb_orderby = $orderby;
1421
			$this->qb_cache_orderby = $qb_cache_orderby;
1417
		}
1422
		}
Zeile 2279... Zeile 2284...
2279
 
2284
 
2280
			// Grab the alias
2285
			// Grab the alias
Zeile 2281... Zeile 2286...
2281
			$table = trim(strrchr($table, ' '));
2286
			$table = trim(strrchr($table, ' '));
2282
 
2287
 
2283
			// Store the alias, if it doesn't already exist
2288
			// Store the alias, if it doesn't already exist
2284
			if ( ! in_array($table, $this->qb_aliased_tables))
2289
			if ( ! in_array($table, $this->qb_aliased_tables, TRUE))
-
 
2290
			{
-
 
2291
				$this->qb_aliased_tables[] = $table;
-
 
2292
				if ($this->qb_caching === TRUE && ! in_array($table, $this->qb_cache_aliased_tables, TRUE))
-
 
2293
				{
-
 
2294
					$this->qb_cache_aliased_tables[] = $table;
2285
			{
2295
					$this->qb_cache_exists[] = 'aliased_tables';
2286
				$this->qb_aliased_tables[] = $table;
2296
				}
2287
			}
2297
			}
Zeile 2288... Zeile 2298...
2288
		}
2298
		}
Zeile 2439... Zeile 2449...
2439
	/**
2449
	/**
2440
	 * Compile GROUP BY
2450
	 * Compile GROUP BY
2441
	 *
2451
	 *
2442
	 * Escapes identifiers in GROUP BY statements at execution time.
2452
	 * Escapes identifiers in GROUP BY statements at execution time.
2443
	 *
2453
	 *
2444
	 * Required so that aliases are tracked properly, regardless of wether
2454
	 * Required so that aliases are tracked properly, regardless of whether
2445
	 * group_by() is called prior to from(), join() and dbprefix is added
2455
	 * group_by() is called prior to from(), join() and dbprefix is added
2446
	 * only if needed.
2456
	 * only if needed.
2447
	 *
2457
	 *
2448
	 * @return	string	SQL statement
2458
	 * @return	string	SQL statement
2449
	 */
2459
	 */
Zeile 2475... Zeile 2485...
2475
	/**
2485
	/**
2476
	 * Compile ORDER BY
2486
	 * Compile ORDER BY
2477
	 *
2487
	 *
2478
	 * Escapes identifiers in ORDER BY statements at execution time.
2488
	 * Escapes identifiers in ORDER BY statements at execution time.
2479
	 *
2489
	 *
2480
	 * Required so that aliases are tracked properly, regardless of wether
2490
	 * Required so that aliases are tracked properly, regardless of whether
2481
	 * order_by() is called prior to from(), join() and dbprefix is added
2491
	 * order_by() is called prior to from(), join() and dbprefix is added
2482
	 * only if needed.
2492
	 * only if needed.
2483
	 *
2493
	 *
2484
	 * @return	string	SQL statement
2494
	 * @return	string	SQL statement
2485
	 */
2495
	 */
2486
	protected function _compile_order_by()
2496
	protected function _compile_order_by()
2487
	{
2497
	{
2488
		if (is_array($this->qb_orderby) && count($this->qb_orderby) > 0)
2498
		if (empty($this->qb_orderby))
2489
		{
2499
		{
-
 
2500
			return '';
-
 
2501
		}
-
 
2502
 
2490
			for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++)
2503
		for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++)
-
 
2504
		{
-
 
2505
			if (is_string($this->qb_orderby[$i]))
2491
			{
2506
			{
2492
				if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field']))
-
 
2493
				{
2507
				continue;
2494
					$this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']);
-
 
2495
				}
2508
			}
Zeile -... Zeile 2509...
-
 
2509
 
-
 
2510
			if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field']))
2496
 
2511
			{
2497
				$this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction'];
2512
				$this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']);
Zeile 2498... Zeile 2513...
2498
			}
2513
			}
2499
 
-
 
2500
			return $this->qb_orderby = "\nORDER BY ".implode(', ', $this->qb_orderby);
-
 
2501
		}
-
 
2502
		elseif (is_string($this->qb_orderby))
-
 
2503
		{
2514
 
Zeile 2504... Zeile 2515...
2504
			return $this->qb_orderby;
2515
			$this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction'];
2505
		}
2516
		}
Zeile 2506... Zeile 2517...
2506
 
2517
 
Zeile 2507... Zeile 2518...
2507
		return '';
2518
		return "\nORDER BY ".implode(', ', $this->qb_orderby);
Zeile 2623... Zeile 2634...
2623
			'qb_cache_groupby'		=> array(),
2634
			'qb_cache_groupby'		=> array(),
2624
			'qb_cache_having'		=> array(),
2635
			'qb_cache_having'		=> array(),
2625
			'qb_cache_orderby'		=> array(),
2636
			'qb_cache_orderby'		=> array(),
2626
			'qb_cache_set'			=> array(),
2637
			'qb_cache_set'			=> array(),
2627
			'qb_cache_exists'		=> array(),
2638
			'qb_cache_exists'		=> array(),
2628
			'qb_cache_no_escape'	=> array()
2639
			'qb_cache_no_escape'	=> array(),
-
 
2640
			'qb_cache_aliased_tables'	=> array()
2629
		));
2641
		));
Zeile 2630... Zeile 2642...
2630
 
2642
 
2631
		return $this;
2643
		return $this;
Zeile 2674... Zeile 2686...
2674
			if ($val === 'select')
2686
			if ($val === 'select')
2675
			{
2687
			{
2676
				$this->qb_no_escape = $qb_no_escape;
2688
				$this->qb_no_escape = $qb_no_escape;
2677
			}
2689
			}
2678
		}
2690
		}
2679
 
-
 
2680
		// If we are "protecting identifiers" we need to examine the "from"
-
 
2681
		// portion of the query to determine if there are any aliases
-
 
2682
		if ($this->_protect_identifiers === TRUE && count($this->qb_cache_from) > 0)
-
 
2683
		{
-
 
2684
			$this->_track_aliases($this->qb_from);
-
 
2685
		}
-
 
2686
	}
2691
	}
Zeile 2687... Zeile 2692...
2687
 
2692
 
Zeile 2688... Zeile 2693...
2688
	// --------------------------------------------------------------------
2693
	// --------------------------------------------------------------------