Browse Source

Remove kohana-database source code

Hamilton Turner 10 years ago
parent
commit
085b8b549a
82 changed files with 0 additions and 9218 deletions
  1. 0 0
      frameworks/PHP/php-kohana/modules/.gitignore
  2. 0 12
      frameworks/PHP/php-kohana/modules/database/classes/Config/Database.php
  3. 0 15
      frameworks/PHP/php-kohana/modules/database/classes/Config/Database/Reader.php
  4. 0 15
      frameworks/PHP/php-kohana/modules/database/classes/Config/Database/Writer.php
  5. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/DB.php
  6. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database.php
  7. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Exception.php
  8. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Expression.php
  9. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/MySQL.php
  10. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/MySQL/Result.php
  11. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/PDO.php
  12. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query.php
  13. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder.php
  14. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Delete.php
  15. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Insert.php
  16. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Join.php
  17. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Select.php
  18. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Update.php
  19. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Where.php
  20. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Result.php
  21. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Database/Result/Cached.php
  22. 0 15
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Config/Database.php
  23. 0 66
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Config/Database/Reader.php
  24. 0 110
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Config/Database/Writer.php
  25. 0 139
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/DB.php
  26. 0 726
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database.php
  27. 0 11
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Exception.php
  28. 0 138
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Expression.php
  29. 0 443
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/MySQL.php
  30. 0 71
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/MySQL/Result.php
  31. 0 247
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/PDO.php
  32. 0 262
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query.php
  33. 0 248
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder.php
  34. 0 99
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Delete.php
  35. 0 181
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Insert.php
  36. 0 149
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Join.php
  37. 0 446
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Select.php
  38. 0 140
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Update.php
  39. 0 180
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Where.php
  40. 0 338
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Result.php
  41. 0 51
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Result/Cached.php
  42. 0 63
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Model/Database.php
  43. 0 239
      frameworks/PHP/php-kohana/modules/database/classes/Kohana/Session/Database.php
  44. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Model/Database.php
  45. 0 3
      frameworks/PHP/php-kohana/modules/database/classes/Session/Database.php
  46. 0 56
      frameworks/PHP/php-kohana/modules/database/config/database.php
  47. 0 27
      frameworks/PHP/php-kohana/modules/database/config/session.php
  48. 0 23
      frameworks/PHP/php-kohana/modules/database/config/userguide.php
  49. 0 116
      frameworks/PHP/php-kohana/modules/database/guide/database/config.md
  50. 0 52
      frameworks/PHP/php-kohana/modules/database/guide/database/examples.md
  51. 0 17
      frameworks/PHP/php-kohana/modules/database/guide/database/index.md
  52. 0 7
      frameworks/PHP/php-kohana/modules/database/guide/database/menu.md
  53. 0 5
      frameworks/PHP/php-kohana/modules/database/guide/database/query.md
  54. 0 251
      frameworks/PHP/php-kohana/modules/database/guide/database/query/builder.md
  55. 0 67
      frameworks/PHP/php-kohana/modules/database/guide/database/query/parameterized.md
  56. 0 105
      frameworks/PHP/php-kohana/modules/database/guide/database/results.md
  57. 0 49
      frameworks/PHP/php-kohana/modules/orm/auth-schema-mysql.sql
  58. 0 53
      frameworks/PHP/php-kohana/modules/orm/auth-schema-postgresql.sql
  59. 0 3
      frameworks/PHP/php-kohana/modules/orm/classes/Auth/ORM.php
  60. 0 291
      frameworks/PHP/php-kohana/modules/orm/classes/Kohana/Auth/ORM.php
  61. 0 2354
      frameworks/PHP/php-kohana/modules/orm/classes/Kohana/ORM.php
  62. 0 198
      frameworks/PHP/php-kohana/modules/orm/classes/Kohana/ORM/Validation/Exception.php
  63. 0 31
      frameworks/PHP/php-kohana/modules/orm/classes/Model/Auth/Role.php
  64. 0 204
      frameworks/PHP/php-kohana/modules/orm/classes/Model/Auth/User.php
  65. 0 77
      frameworks/PHP/php-kohana/modules/orm/classes/Model/Auth/User/Token.php
  66. 0 7
      frameworks/PHP/php-kohana/modules/orm/classes/Model/Role.php
  67. 0 7
      frameworks/PHP/php-kohana/modules/orm/classes/Model/User.php
  68. 0 7
      frameworks/PHP/php-kohana/modules/orm/classes/Model/User/Token.php
  69. 0 3
      frameworks/PHP/php-kohana/modules/orm/classes/ORM.php
  70. 0 10
      frameworks/PHP/php-kohana/modules/orm/classes/ORM/Validation/Exception.php
  71. 0 23
      frameworks/PHP/php-kohana/modules/orm/config/userguide.php
  72. 0 13
      frameworks/PHP/php-kohana/modules/orm/guide/orm/examples.md
  73. 0 119
      frameworks/PHP/php-kohana/modules/orm/guide/orm/examples/simple.md
  74. 0 137
      frameworks/PHP/php-kohana/modules/orm/guide/orm/examples/validation.md
  75. 0 41
      frameworks/PHP/php-kohana/modules/orm/guide/orm/filters.md
  76. 0 22
      frameworks/PHP/php-kohana/modules/orm/guide/orm/index.md
  77. 0 10
      frameworks/PHP/php-kohana/modules/orm/guide/orm/menu.md
  78. 0 28
      frameworks/PHP/php-kohana/modules/orm/guide/orm/models.md
  79. 0 123
      frameworks/PHP/php-kohana/modules/orm/guide/orm/relationships.md
  80. 0 16
      frameworks/PHP/php-kohana/modules/orm/guide/orm/upgrading.md
  81. 0 94
      frameworks/PHP/php-kohana/modules/orm/guide/orm/using.md
  82. 0 111
      frameworks/PHP/php-kohana/modules/orm/guide/orm/validation.md

+ 0 - 0
frameworks/PHP/php-kohana/modules/orm/guide/orm/tutorials.md → frameworks/PHP/php-kohana/modules/.gitignore


+ 0 - 12
frameworks/PHP/php-kohana/modules/database/classes/Config/Database.php

@@ -1,12 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-/**
- * Transparent extension for the Kohana_Config_Database class
- *
- * @package    Kohana/Database
- * @category   Configuration
- * @author     Kohana Team
- * @copyright  (c) 2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Config_Database extends Kohana_Config_Database {}

+ 0 - 15
frameworks/PHP/php-kohana/modules/database/classes/Config/Database/Reader.php

@@ -1,15 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-/**
- * Transparent extension of the Kohana_Config_Database_Reader class
- *
- * @package    Kohana/Database
- * @category   Configuration
- * @author     Kohana Team
- * @copyright  (c) 2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Config_Database_Reader extends Kohana_Config_Database_Reader
-{
-	
-}

+ 0 - 15
frameworks/PHP/php-kohana/modules/database/classes/Config/Database/Writer.php

@@ -1,15 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-/**
- * Transparent extension for the Kohana_Config_Database_Writer class
- *
- * @package    Kohana/Database
- * @category   Configuration
- * @author     Kohana Team
- * @copyright  (c) 2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Config_Database_Writer extends Kohana_Config_Database_Writer
-{
-	
-}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/DB.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class DB extends Kohana_DB {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-abstract class Database extends Kohana_Database {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Exception.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Exception extends Kohana_Database_Exception {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Expression.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Expression extends Kohana_Database_Expression {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/MySQL.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_MySQL extends Kohana_Database_MySQL {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/MySQL/Result.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_MySQL_Result extends Kohana_Database_MySQL_Result {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/PDO.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_PDO extends Kohana_Database_PDO {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Query extends Kohana_Database_Query {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-abstract class Database_Query_Builder extends Kohana_Database_Query_Builder {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Delete.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Query_Builder_Delete extends Kohana_Database_Query_Builder_Delete {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Insert.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Query_Builder_Insert extends Kohana_Database_Query_Builder_Insert {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Join.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Query_Builder_Join extends Kohana_Database_Query_Builder_Join {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Select.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Query_Builder_Select extends Kohana_Database_Query_Builder_Select {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Update.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Query_Builder_Update extends Kohana_Database_Query_Builder_Update {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Query/Builder/Where.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-abstract class Database_Query_Builder_Where extends Kohana_Database_Query_Builder_Where {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Result.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-abstract class Database_Result extends Kohana_Database_Result {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Database/Result/Cached.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Database_Result_Cached extends Kohana_Database_Result_Cached {}

+ 0 - 15
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Config/Database.php

@@ -1,15 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-/**
- * Backwards compatibility extension for the database writer.
- *
- * @package    Kohana/Database
- * @category   Configuration
- * @author     Kohana Team
- * @copyright  (c) 2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Kohana_Config_Database extends Kohana_Config_Database_Writer
-{
-
-}

+ 0 - 66
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Config/Database/Reader.php

@@ -1,66 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-/**
- * Database reader for the kohana config system
- *
- * @package    Kohana/Database
- * @category   Configuration
- * @author     Kohana Team
- * @copyright  (c) 2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Kohana_Config_Database_Reader implements Kohana_Config_Reader
-{
-	protected $_db_instance;
-
-	protected $_table_name  = 'config';
-
-	/**
-	 * Constructs the database reader object
-	 *
-	 * @param array Configuration for the reader
-	 */
-	public function __construct(array $config = NULL)
-	{
-		if (isset($config['instance']))
-		{
-			$this->_db_instance = $config['instance'];
-		}
-		elseif ($this->_db_instance === NULL)
-		{
-			$this->_db_instance = Database::$default;
-		}
-
-		if (isset($config['table_name']))
-		{
-			$this->_table_name = $config['table_name'];
-		}
-	}
-
-	/**
-	 * Tries to load the specificed configuration group
-	 *
-	 * Returns FALSE if group does not exist or an array if it does
-	 *
-	 * @param  string $group Configuration group
-	 * @return boolean|array
-	 */
-	public function load($group)
-	{
-		/**
-		 * Prevents the catch-22 scenario where the database config reader attempts to load the 
-		 * database connections details from the database.
-		 *
-		 * @link http://dev.kohanaframework.org/issues/4316
-		 */
-		if ($group === 'database')
-			return FALSE;
-
-		$query = DB::select('config_key', 'config_value')
-			->from($this->_table_name)
-			->where('group_name', '=', $group)
-			->execute($this->_db_instance);
-
-		return count($query) ? array_map('unserialize', $query->as_array('config_key', 'config_value')) : FALSE;
-	}
-}

+ 0 - 110
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Config/Database/Writer.php

@@ -1,110 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-/**
- * Database writer for the config system
- *
- * @package    Kohana
- * @category   Configuration
- * @author     Kohana Team
- * @copyright  (c) 2007-2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Kohana_Config_Database_Writer extends Config_Database_Reader implements Kohana_Config_Writer
-{
-	protected $_loaded_keys = array();
-
-	/**
-	 * Tries to load the specificed configuration group
-	 *
-	 * Returns FALSE if group does not exist or an array if it does
-	 *
-	 * @param  string $group Configuration group
-	 * @return boolean|array
-	 */
-	public function load($group)
-	{
-		$config = parent::load($group);
-
-		if ($config !== FALSE)
-		{
-			$this->_loaded_keys[$group] = array_combine(array_keys($config), array_keys($config));
-		}
-
-		return $config;
-	}
-
-	/**
-	 * Writes the passed config for $group
-	 *
-	 * Returns chainable instance on success or throws 
-	 * Kohana_Config_Exception on failure
-	 *
-	 * @param string      $group  The config group
-	 * @param string      $key    The config key to write to
-	 * @param array       $config The configuration to write
-	 * @return boolean
-	 */
-	public function write($group, $key, $config)
-	{
-		$config = serialize($config);
-
-		// Check to see if we've loaded the config from the table already
-		if (isset($this->_loaded_keys[$group][$key]))
-		{
-			$this->_update($group, $key, $config);
-		}
-		else
-		{
-			// Attempt to run an insert query
-			// This may fail if the config key already exists in the table
-			// and we don't know about it
-			try
-			{
-				$this->_insert($group, $key, $config);
-			}
-			catch (Database_Exception $e)
-			{
-				// Attempt to run an update instead
-				$this->_update($group, $key, $config);
-			}
-		}
-
-		return TRUE;
-	}
-
-	/**
-	 * Insert the config values into the table
-	 *
-	 * @param string      $group  The config group
-	 * @param string      $key    The config key to write to
-	 * @param array       $config The serialized configuration to write
-	 * @return boolean
-	 */
-	protected function _insert($group, $key, $config)
-	{
-		DB::insert($this->_table_name, array('group_name', 'config_key', 'config_value'))
-			->values(array($group, $key, $config))
-			->execute($this->_db_instance);
-
-		return $this;
-	}
-
-	/**
-	 * Update the config values in the table
-	 *
-	 * @param string      $group  The config group
-	 * @param string      $key    The config key to write to
-	 * @param array       $config The serialized configuration to write
-	 * @return boolean
-	 */
-	protected function _update($group, $key, $config)
-	{
-		DB::update($this->_table_name)
-			->set(array('config_value' => $config))
-			->where('group_name', '=', $group)
-			->where('config_key', '=', $key)
-			->execute($this->_db_instance);
-
-		return $this;
-	}
-}

+ 0 - 139
frameworks/PHP/php-kohana/modules/database/classes/Kohana/DB.php

@@ -1,139 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Provides a shortcut to get Database related objects for [making queries](../database/query).
- *
- * Shortcut     | Returned Object
- * -------------|---------------
- * [`DB::query()`](#query)   | [Database_Query]
- * [`DB::insert()`](#insert) | [Database_Query_Builder_Insert]
- * [`DB::select()`](#select),<br />[`DB::select_array()`](#select_array) | [Database_Query_Builder_Select]
- * [`DB::update()`](#update) | [Database_Query_Builder_Update]
- * [`DB::delete()`](#delete) | [Database_Query_Builder_Delete]
- * [`DB::expr()`](#expr)     | [Database_Expression]
- *
- * You pass the same parameters to these functions as you pass to the objects they return.
- *
- * @package    Kohana/Database
- * @category   Base
- * @author     Kohana Team
- * @copyright  (c) 2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_DB {
-
-	/**
-	 * Create a new [Database_Query] of the given type.
-	 *
-	 *     // Create a new SELECT query
-	 *     $query = DB::query(Database::SELECT, 'SELECT * FROM users');
-	 *
-	 *     // Create a new DELETE query
-	 *     $query = DB::query(Database::DELETE, 'DELETE FROM users WHERE id = 5');
-	 *
-	 * Specifying the type changes the returned result. When using
-	 * `Database::SELECT`, a [Database_Query_Result] will be returned.
-	 * `Database::INSERT` queries will return the insert id and number of rows.
-	 * For all other queries, the number of affected rows is returned.
-	 *
-	 * @param   integer  $type  type: Database::SELECT, Database::UPDATE, etc
-	 * @param   string   $sql   SQL statement
-	 * @return  Database_Query
-	 */
-	public static function query($type, $sql)
-	{
-		return new Database_Query($type, $sql);
-	}
-
-	/**
-	 * Create a new [Database_Query_Builder_Select]. Each argument will be
-	 * treated as a column. To generate a `foo AS bar` alias, use an array.
-	 *
-	 *     // SELECT id, username
-	 *     $query = DB::select('id', 'username');
-	 *
-	 *     // SELECT id AS user_id
-	 *     $query = DB::select(array('id', 'user_id'));
-	 *
-	 * @param   mixed   $columns  column name or array($column, $alias) or object
-	 * @return  Database_Query_Builder_Select
-	 */
-	public static function select($columns = NULL)
-	{
-		return new Database_Query_Builder_Select(func_get_args());
-	}
-
-	/**
-	 * Create a new [Database_Query_Builder_Select] from an array of columns.
-	 *
-	 *     // SELECT id, username
-	 *     $query = DB::select_array(array('id', 'username'));
-	 *
-	 * @param   array   $columns  columns to select
-	 * @return  Database_Query_Builder_Select
-	 */
-	public static function select_array(array $columns = NULL)
-	{
-		return new Database_Query_Builder_Select($columns);
-	}
-
-	/**
-	 * Create a new [Database_Query_Builder_Insert].
-	 *
-	 *     // INSERT INTO users (id, username)
-	 *     $query = DB::insert('users', array('id', 'username'));
-	 *
-	 * @param   string  $table    table to insert into
-	 * @param   array   $columns  list of column names or array($column, $alias) or object
-	 * @return  Database_Query_Builder_Insert
-	 */
-	public static function insert($table = NULL, array $columns = NULL)
-	{
-		return new Database_Query_Builder_Insert($table, $columns);
-	}
-
-	/**
-	 * Create a new [Database_Query_Builder_Update].
-	 *
-	 *     // UPDATE users
-	 *     $query = DB::update('users');
-	 *
-	 * @param   string  $table  table to update
-	 * @return  Database_Query_Builder_Update
-	 */
-	public static function update($table = NULL)
-	{
-		return new Database_Query_Builder_Update($table);
-	}
-
-	/**
-	 * Create a new [Database_Query_Builder_Delete].
-	 *
-	 *     // DELETE FROM users
-	 *     $query = DB::delete('users');
-	 *
-	 * @param   string  $table  table to delete from
-	 * @return  Database_Query_Builder_Delete
-	 */
-	public static function delete($table = NULL)
-	{
-		return new Database_Query_Builder_Delete($table);
-	}
-
-	/**
-	 * Create a new [Database_Expression] which is not escaped. An expression
-	 * is the only way to use SQL functions within query builders.
-	 *
-	 *     $expression = DB::expr('COUNT(users.id)');
-	 *     $query = DB::update('users')->set(array('login_count' => DB::expr('login_count + 1')))->where('id', '=', $id);
-	 *     $users = ORM::factory('user')->where(DB::expr("BINARY `hash`"), '=', $hash)->find();
-	 *
-	 * @param   string  $string  expression
-	 * @param   array   parameters
-	 * @return  Database_Expression
-	 */
-	public static function expr($string, $parameters = array())
-	{
-		return new Database_Expression($string, $parameters);
-	}
-
-} // End DB

+ 0 - 726
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database.php

@@ -1,726 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database connection wrapper/helper.
- *
- * You may get a database instance using `Database::instance('name')` where
- * name is the [config](database/config) group.
- *
- * This class provides connection instance management via Database Drivers, as
- * well as quoting, escaping and other related functions. Querys are done using
- * [Database_Query] and [Database_Query_Builder] objects, which can be easily
- * created using the [DB] helper class.
- *
- * @package    Kohana/Database
- * @category   Base
- * @author     Kohana Team
- * @copyright  (c) 2008-2012 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-abstract class Kohana_Database {
-
-	// Query types
-	const SELECT =  1;
-	const INSERT =  2;
-	const UPDATE =  3;
-	const DELETE =  4;
-
-	/**
-	 * @var  string  default instance name
-	 */
-	public static $default = 'default';
-
-	/**
-	 * @var  array  Database instances
-	 */
-	public static $instances = array();
-
-	/**
-	 * Get a singleton Database instance. If configuration is not specified,
-	 * it will be loaded from the database configuration file using the same
-	 * group as the name.
-	 *
-	 *     // Load the default database
-	 *     $db = Database::instance();
-	 *
-	 *     // Create a custom configured instance
-	 *     $db = Database::instance('custom', $config);
-	 *
-	 * @param   string   $name    instance name
-	 * @param   array    $config  configuration parameters
-	 * @return  Database
-	 */
-	public static function instance($name = NULL, array $config = NULL)
-	{
-		if ($name === NULL)
-		{
-			// Use the default instance name
-			$name = Database::$default;
-		}
-
-		if ( ! isset(Database::$instances[$name]))
-		{
-			if ($config === NULL)
-			{
-				// Load the configuration for this database
-				$config = Kohana::$config->load('database')->$name;
-			}
-
-			if ( ! isset($config['type']))
-			{
-				throw new Kohana_Exception('Database type not defined in :name configuration',
-					array(':name' => $name));
-			}
-
-			// Set the driver class name
-			$driver = 'Database_'.ucfirst($config['type']);
-
-			// Create the database connection instance
-			$driver = new $driver($name, $config);
-
-			// Store the database instance
-			Database::$instances[$name] = $driver;
-		}
-
-		return Database::$instances[$name];
-	}
-
-	/**
-	 * @var  string  the last query executed
-	 */
-	public $last_query;
-
-	// Character that is used to quote identifiers
-	protected $_identifier = '"';
-
-	// Instance name
-	protected $_instance;
-
-	// Raw server connection
-	protected $_connection;
-
-	// Configuration array
-	protected $_config;
-
-	/**
-	 * Stores the database configuration locally and name the instance.
-	 *
-	 * [!!] This method cannot be accessed directly, you must use [Database::instance].
-	 *
-	 * @return  void
-	 */
-	public function __construct($name, array $config)
-	{
-		// Set the instance name
-		$this->_instance = $name;
-
-		// Store the config locally
-		$this->_config = $config;
-
-		if (empty($this->_config['table_prefix']))
-		{
-			$this->_config['table_prefix'] = '';
-		}
-	}
-
-	/**
-	 * Disconnect from the database when the object is destroyed.
-	 *
-	 *     // Destroy the database instance
-	 *     unset(Database::instances[(string) $db], $db);
-	 *
-	 * [!!] Calling `unset($db)` is not enough to destroy the database, as it
-	 * will still be stored in `Database::$instances`.
-	 *
-	 * @return  void
-	 */
-	public function __destruct()
-	{
-		$this->disconnect();
-	}
-
-	/**
-	 * Returns the database instance name.
-	 *
-	 *     echo (string) $db;
-	 *
-	 * @return  string
-	 */
-	public function __toString()
-	{
-		return $this->_instance;
-	}
-
-	/**
-	 * Connect to the database. This is called automatically when the first
-	 * query is executed.
-	 *
-	 *     $db->connect();
-	 *
-	 * @throws  Database_Exception
-	 * @return  void
-	 */
-	abstract public function connect();
-
-	/**
-	 * Disconnect from the database. This is called automatically by [Database::__destruct].
-	 * Clears the database instance from [Database::$instances].
-	 *
-	 *     $db->disconnect();
-	 *
-	 * @return  boolean
-	 */
-	public function disconnect()
-	{
-		unset(Database::$instances[$this->_instance]);
-
-		return TRUE;
-	}
-
-	/**
-	 * Set the connection character set. This is called automatically by [Database::connect].
-	 *
-	 *     $db->set_charset('utf8');
-	 *
-	 * @throws  Database_Exception
-	 * @param   string   $charset  character set name
-	 * @return  void
-	 */
-	abstract public function set_charset($charset);
-
-	/**
-	 * Perform an SQL query of the given type.
-	 *
-	 *     // Make a SELECT query and use objects for results
-	 *     $db->query(Database::SELECT, 'SELECT * FROM groups', TRUE);
-	 *
-	 *     // Make a SELECT query and use "Model_User" for the results
-	 *     $db->query(Database::SELECT, 'SELECT * FROM users LIMIT 1', 'Model_User');
-	 *
-	 * @param   integer  $type       Database::SELECT, Database::INSERT, etc
-	 * @param   string   $sql        SQL query
-	 * @param   mixed    $as_object  result object class string, TRUE for stdClass, FALSE for assoc array
-	 * @param   array    $params     object construct parameters for result class
-	 * @return  object   Database_Result for SELECT queries
-	 * @return  array    list (insert id, row count) for INSERT queries
-	 * @return  integer  number of affected rows for all other queries
-	 */
-	abstract public function query($type, $sql, $as_object = FALSE, array $params = NULL);
-
-	/**
-	 * Start a SQL transaction
-	 *
-	 *     // Start the transactions
-	 *     $db->begin();
-	 *
-	 *     try {
-	 *          DB::insert('users')->values($user1)...
-	 *          DB::insert('users')->values($user2)...
-	 *          // Insert successful commit the changes
-	 *          $db->commit();
-	 *     }
-	 *     catch (Database_Exception $e)
-	 *     {
-	 *          // Insert failed. Rolling back changes...
-	 *          $db->rollback();
-	 *      }
-	 *
-	 * @param string $mode  transaction mode
-	 * @return  boolean
-	 */
-	abstract public function begin($mode = NULL);
-
-	/**
-	 * Commit the current transaction
-	 *
-	 *     // Commit the database changes
-	 *     $db->commit();
-	 *
-	 * @return  boolean
-	 */
-	abstract public function commit();
-
-	/**
-	 * Abort the current transaction
-	 *
-	 *     // Undo the changes
-	 *     $db->rollback();
-	 *
-	 * @return  boolean
-	 */
-	abstract public function rollback();
-
-	/**
-	 * Count the number of records in a table.
-	 *
-	 *     // Get the total number of records in the "users" table
-	 *     $count = $db->count_records('users');
-	 *
-	 * @param   mixed    $table  table name string or array(query, alias)
-	 * @return  integer
-	 */
-	public function count_records($table)
-	{
-		// Quote the table name
-		$table = $this->quote_table($table);
-
-		return $this->query(Database::SELECT, 'SELECT COUNT(*) AS total_row_count FROM '.$table, FALSE)
-			->get('total_row_count');
-	}
-
-	/**
-	 * Returns a normalized array describing the SQL data type
-	 *
-	 *     $db->datatype('char');
-	 *
-	 * @param   string  $type  SQL data type
-	 * @return  array
-	 */
-	public function datatype($type)
-	{
-		static $types = array
-		(
-			// SQL-92
-			'bit'                           => array('type' => 'string', 'exact' => TRUE),
-			'bit varying'                   => array('type' => 'string'),
-			'char'                          => array('type' => 'string', 'exact' => TRUE),
-			'char varying'                  => array('type' => 'string'),
-			'character'                     => array('type' => 'string', 'exact' => TRUE),
-			'character varying'             => array('type' => 'string'),
-			'date'                          => array('type' => 'string'),
-			'dec'                           => array('type' => 'float', 'exact' => TRUE),
-			'decimal'                       => array('type' => 'float', 'exact' => TRUE),
-			'double precision'              => array('type' => 'float'),
-			'float'                         => array('type' => 'float'),
-			'int'                           => array('type' => 'int', 'min' => '-2147483648', 'max' => '2147483647'),
-			'integer'                       => array('type' => 'int', 'min' => '-2147483648', 'max' => '2147483647'),
-			'interval'                      => array('type' => 'string'),
-			'national char'                 => array('type' => 'string', 'exact' => TRUE),
-			'national char varying'         => array('type' => 'string'),
-			'national character'            => array('type' => 'string', 'exact' => TRUE),
-			'national character varying'    => array('type' => 'string'),
-			'nchar'                         => array('type' => 'string', 'exact' => TRUE),
-			'nchar varying'                 => array('type' => 'string'),
-			'numeric'                       => array('type' => 'float', 'exact' => TRUE),
-			'real'                          => array('type' => 'float'),
-			'smallint'                      => array('type' => 'int', 'min' => '-32768', 'max' => '32767'),
-			'time'                          => array('type' => 'string'),
-			'time with time zone'           => array('type' => 'string'),
-			'timestamp'                     => array('type' => 'string'),
-			'timestamp with time zone'      => array('type' => 'string'),
-			'varchar'                       => array('type' => 'string'),
-
-			// SQL:1999
-			'binary large object'               => array('type' => 'string', 'binary' => TRUE),
-			'blob'                              => array('type' => 'string', 'binary' => TRUE),
-			'boolean'                           => array('type' => 'bool'),
-			'char large object'                 => array('type' => 'string'),
-			'character large object'            => array('type' => 'string'),
-			'clob'                              => array('type' => 'string'),
-			'national character large object'   => array('type' => 'string'),
-			'nchar large object'                => array('type' => 'string'),
-			'nclob'                             => array('type' => 'string'),
-			'time without time zone'            => array('type' => 'string'),
-			'timestamp without time zone'       => array('type' => 'string'),
-
-			// SQL:2003
-			'bigint'    => array('type' => 'int', 'min' => '-9223372036854775808', 'max' => '9223372036854775807'),
-
-			// SQL:2008
-			'binary'            => array('type' => 'string', 'binary' => TRUE, 'exact' => TRUE),
-			'binary varying'    => array('type' => 'string', 'binary' => TRUE),
-			'varbinary'         => array('type' => 'string', 'binary' => TRUE),
-		);
-
-		if (isset($types[$type]))
-			return $types[$type];
-
-		return array();
-	}
-
-	/**
-	 * List all of the tables in the database. Optionally, a LIKE string can
-	 * be used to search for specific tables.
-	 *
-	 *     // Get all tables in the current database
-	 *     $tables = $db->list_tables();
-	 *
-	 *     // Get all user-related tables
-	 *     $tables = $db->list_tables('user%');
-	 *
-	 * @param   string   $like  table to search for
-	 * @return  array
-	 */
-	abstract public function list_tables($like = NULL);
-
-	/**
-	 * Lists all of the columns in a table. Optionally, a LIKE string can be
-	 * used to search for specific fields.
-	 *
-	 *     // Get all columns from the "users" table
-	 *     $columns = $db->list_columns('users');
-	 *
-	 *     // Get all name-related columns
-	 *     $columns = $db->list_columns('users', '%name%');
-	 *
-	 *     // Get the columns from a table that doesn't use the table prefix
-	 *     $columns = $db->list_columns('users', NULL, FALSE);
-	 *
-	 * @param   string  $table       table to get columns from
-	 * @param   string  $like        column to search for
-	 * @param   boolean $add_prefix  whether to add the table prefix automatically or not
-	 * @return  array
-	 */
-	abstract public function list_columns($table, $like = NULL, $add_prefix = TRUE);
-
-	/**
-	 * Extracts the text between parentheses, if any.
-	 *
-	 *     // Returns: array('CHAR', '6')
-	 *     list($type, $length) = $db->_parse_type('CHAR(6)');
-	 *
-	 * @param   string  $type
-	 * @return  array   list containing the type and length, if any
-	 */
-	protected function _parse_type($type)
-	{
-		if (($open = strpos($type, '(')) === FALSE)
-		{
-			// No length specified
-			return array($type, NULL);
-		}
-
-		// Closing parenthesis
-		$close = strrpos($type, ')', $open);
-
-		// Length without parentheses
-		$length = substr($type, $open + 1, $close - 1 - $open);
-
-		// Type without the length
-		$type = substr($type, 0, $open).substr($type, $close + 1);
-
-		return array($type, $length);
-	}
-
-	/**
-	 * Return the table prefix defined in the current configuration.
-	 *
-	 *     $prefix = $db->table_prefix();
-	 *
-	 * @return  string
-	 */
-	public function table_prefix()
-	{
-		return $this->_config['table_prefix'];
-	}
-
-	/**
-	 * Quote a value for an SQL query.
-	 *
-	 *     $db->quote(NULL);   // 'NULL'
-	 *     $db->quote(10);     // 10
-	 *     $db->quote('fred'); // 'fred'
-	 *
-	 * Objects passed to this function will be converted to strings.
-	 * [Database_Expression] objects will be compiled.
-	 * [Database_Query] objects will be compiled and converted to a sub-query.
-	 * All other objects will be converted using the `__toString` method.
-	 *
-	 * @param   mixed   $value  any value to quote
-	 * @return  string
-	 * @uses    Database::escape
-	 */
-	public function quote($value)
-	{
-		if ($value === NULL)
-		{
-			return 'NULL';
-		}
-		elseif ($value === TRUE)
-		{
-			return "'1'";
-		}
-		elseif ($value === FALSE)
-		{
-			return "'0'";
-		}
-		elseif (is_object($value))
-		{
-			if ($value instanceof Database_Query)
-			{
-				// Create a sub-query
-				return '('.$value->compile($this).')';
-			}
-			elseif ($value instanceof Database_Expression)
-			{
-				// Compile the expression
-				return $value->compile($this);
-			}
-			else
-			{
-				// Convert the object to a string
-				return $this->quote( (string) $value);
-			}
-		}
-		elseif (is_array($value))
-		{
-			return '('.implode(', ', array_map(array($this, __FUNCTION__), $value)).')';
-		}
-		elseif (is_int($value))
-		{
-			return (int) $value;
-		}
-		elseif (is_float($value))
-		{
-			// Convert to non-locale aware float to prevent possible commas
-			return sprintf('%F', $value);
-		}
-
-		return $this->escape($value);
-	}
-
-	/**
-	 * Quote a database column name and add the table prefix if needed.
-	 *
-	 *     $column = $db->quote_column($column);
-	 *
-	 * You can also use SQL methods within identifiers.
-	 *
-	 *     $column = $db->quote_column(DB::expr('COUNT(`column`)'));
-	 *
-	 * Objects passed to this function will be converted to strings.
-	 * [Database_Expression] objects will be compiled.
-	 * [Database_Query] objects will be compiled and converted to a sub-query.
-	 * All other objects will be converted using the `__toString` method.
-	 *
-	 * @param   mixed   $column  column name or array(column, alias)
-	 * @return  string
-	 * @uses    Database::quote_identifier
-	 * @uses    Database::table_prefix
-	 */
-	public function quote_column($column)
-	{
-		// Identifiers are escaped by repeating them
-		$escaped_identifier = $this->_identifier.$this->_identifier;
-
-		if (is_array($column))
-		{
-			list($column, $alias) = $column;
-			$alias = str_replace($this->_identifier, $escaped_identifier, $alias);
-		}
-
-		if ($column instanceof Database_Query)
-		{
-			// Create a sub-query
-			$column = '('.$column->compile($this).')';
-		}
-		elseif ($column instanceof Database_Expression)
-		{
-			// Compile the expression
-			$column = $column->compile($this);
-		}
-		else
-		{
-			// Convert to a string
-			$column = (string) $column;
-
-			$column = str_replace($this->_identifier, $escaped_identifier, $column);
-
-			if ($column === '*')
-			{
-				return $column;
-			}
-			elseif (strpos($column, '.') !== FALSE)
-			{
-				$parts = explode('.', $column);
-
-				if ($prefix = $this->table_prefix())
-				{
-					// Get the offset of the table name, 2nd-to-last part
-					$offset = count($parts) - 2;
-
-					// Add the table prefix to the table name
-					$parts[$offset] = $prefix.$parts[$offset];
-				}
-
-				foreach ($parts as & $part)
-				{
-					if ($part !== '*')
-					{
-						// Quote each of the parts
-						$part = $this->_identifier.$part.$this->_identifier;
-					}
-				}
-
-				$column = implode('.', $parts);
-			}
-			else
-			{
-				$column = $this->_identifier.$column.$this->_identifier;
-			}
-		}
-
-		if (isset($alias))
-		{
-			$column .= ' AS '.$this->_identifier.$alias.$this->_identifier;
-		}
-
-		return $column;
-	}
-
-	/**
-	 * Quote a database table name and adds the table prefix if needed.
-	 *
-	 *     $table = $db->quote_table($table);
-	 *
-	 * Objects passed to this function will be converted to strings.
-	 * [Database_Expression] objects will be compiled.
-	 * [Database_Query] objects will be compiled and converted to a sub-query.
-	 * All other objects will be converted using the `__toString` method.
-	 *
-	 * @param   mixed   $table  table name or array(table, alias)
-	 * @return  string
-	 * @uses    Database::quote_identifier
-	 * @uses    Database::table_prefix
-	 */
-	public function quote_table($table)
-	{
-		// Identifiers are escaped by repeating them
-		$escaped_identifier = $this->_identifier.$this->_identifier;
-
-		if (is_array($table))
-		{
-			list($table, $alias) = $table;
-			$alias = str_replace($this->_identifier, $escaped_identifier, $alias);
-		}
-
-		if ($table instanceof Database_Query)
-		{
-			// Create a sub-query
-			$table = '('.$table->compile($this).')';
-		}
-		elseif ($table instanceof Database_Expression)
-		{
-			// Compile the expression
-			$table = $table->compile($this);
-		}
-		else
-		{
-			// Convert to a string
-			$table = (string) $table;
-
-			$table = str_replace($this->_identifier, $escaped_identifier, $table);
-
-			if (strpos($table, '.') !== FALSE)
-			{
-				$parts = explode('.', $table);
-
-				if ($prefix = $this->table_prefix())
-				{
-					// Get the offset of the table name, last part
-					$offset = count($parts) - 1;
-
-					// Add the table prefix to the table name
-					$parts[$offset] = $prefix.$parts[$offset];
-				}
-
-				foreach ($parts as & $part)
-				{
-					// Quote each of the parts
-					$part = $this->_identifier.$part.$this->_identifier;
-				}
-
-				$table = implode('.', $parts);
-			}
-			else
-			{
-				// Add the table prefix
-				$table = $this->_identifier.$this->table_prefix().$table.$this->_identifier;
-			}
-		}
-
-		if (isset($alias))
-		{
-			// Attach table prefix to alias
-			$table .= ' AS '.$this->_identifier.$this->table_prefix().$alias.$this->_identifier;
-		}
-
-		return $table;
-	}
-
-	/**
-	 * Quote a database identifier
-	 *
-	 * Objects passed to this function will be converted to strings.
-	 * [Database_Expression] objects will be compiled.
-	 * [Database_Query] objects will be compiled and converted to a sub-query.
-	 * All other objects will be converted using the `__toString` method.
-	 *
-	 * @param   mixed   $value  any identifier
-	 * @return  string
-	 */
-	public function quote_identifier($value)
-	{
-		// Identifiers are escaped by repeating them
-		$escaped_identifier = $this->_identifier.$this->_identifier;
-
-		if (is_array($value))
-		{
-			list($value, $alias) = $value;
-			$alias = str_replace($this->_identifier, $escaped_identifier, $alias);
-		}
-
-		if ($value instanceof Database_Query)
-		{
-			// Create a sub-query
-			$value = '('.$value->compile($this).')';
-		}
-		elseif ($value instanceof Database_Expression)
-		{
-			// Compile the expression
-			$value = $value->compile($this);
-		}
-		else
-		{
-			// Convert to a string
-			$value = (string) $value;
-
-			$value = str_replace($this->_identifier, $escaped_identifier, $value);
-
-			if (strpos($value, '.') !== FALSE)
-			{
-				$parts = explode('.', $value);
-
-				foreach ($parts as & $part)
-				{
-					// Quote each of the parts
-					$part = $this->_identifier.$part.$this->_identifier;
-				}
-
-				$value = implode('.', $parts);
-			}
-			else
-			{
-				$value = $this->_identifier.$value.$this->_identifier;
-			}
-		}
-
-		if (isset($alias))
-		{
-			$value .= ' AS '.$this->_identifier.$alias.$this->_identifier;
-		}
-
-		return $value;
-	}
-
-	/**
-	 * Sanitize a string by escaping characters that could cause an SQL
-	 * injection attack.
-	 *
-	 *     $value = $db->escape('any string');
-	 *
-	 * @param   string   $value  value to quote
-	 * @return  string
-	 */
-	abstract public function escape($value);
-
-} // End Database_Connection

+ 0 - 11
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Exception.php

@@ -1,11 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database exceptions.
- *
- * @package    Kohana/Database
- * @category   Exceptions
- * @author     Kohana Team
- * @copyright  (c) 2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Exception extends Kohana_Exception {}

+ 0 - 138
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Expression.php

@@ -1,138 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database expressions can be used to add unescaped SQL fragments to a
- * [Database_Query_Builder] object.
- *
- * For example, you can use an expression to generate a column alias:
- *
- *     // SELECT CONCAT(first_name, last_name) AS full_name
- *     $query = DB::select(array(DB::expr('CONCAT(first_name, last_name)'), 'full_name')));
- *
- * More examples are available on the [Query Builder](database/query/builder#database-expressions) page
- * 
- * @package    Kohana/Database
- * @category   Base
- * @author     Kohana Team
- * @copyright  (c) 2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Expression {
-
-	// Unquoted parameters
-	protected $_parameters;
-
-	// Raw expression string
-	protected $_value;
-
-	/**
-	 * Sets the expression string.
-	 *
-	 *     $expression = new Database_Expression('COUNT(users.id)');
-	 *
-	 * @param   string  $value      raw SQL expression string
-	 * @param   array   $parameters unquoted parameter values
-	 * @return  void
-	 */
-	public function __construct($value, $parameters = array())
-	{
-		// Set the expression string
-		$this->_value = $value;
-		$this->_parameters = $parameters;
-	}
-
-	/**
-	 * Bind a variable to a parameter.
-	 *
-	 * @param   string  $param  parameter key to replace
-	 * @param   mixed   $var    variable to use
-	 * @return  $this
-	 */
-	public function bind($param, & $var)
-	{
-		$this->_parameters[$param] =& $var;
-
-		return $this;
-	}
-
-	/**
-	 * Set the value of a parameter.
-	 *
-	 * @param   string  $param  parameter key to replace
-	 * @param   mixed   $value  value to use
-	 * @return  $this
-	 */
-	public function param($param, $value)
-	{
-		$this->_parameters[$param] = $value;
-
-		return $this;
-	}
-
-	/**
-	 * Add multiple parameter values.
-	 *
-	 * @param   array   $params list of parameter values
-	 * @return  $this
-	 */
-	public function parameters(array $params)
-	{
-		$this->_parameters = $params + $this->_parameters;
-
-		return $this;
-	}
-
-	/**
-	 * Get the expression value as a string.
-	 *
-	 *     $sql = $expression->value();
-	 *
-	 * @return  string
-	 */
-	public function value()
-	{
-		return (string) $this->_value;
-	}
-
-	/**
-	 * Return the value of the expression as a string.
-	 *
-	 *     echo $expression;
-	 *
-	 * @return  string
-	 * @uses    Database_Expression::value
-	 */
-	public function __toString()
-	{
-		return $this->value();
-	}
-
-	/**
-	 * Compile the SQL expression and return it. Replaces any parameters with
-	 * their given values.
-	 *
-	 * @param   mixed    Database instance or name of instance
-	 * @return  string
-	 */
-	public function compile($db = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		$value = $this->value();
-
-		if ( ! empty($this->_parameters))
-		{
-			// Quote all of the parameter values
-			$params = array_map(array($db, 'quote'), $this->_parameters);
-
-			// Replace the values in the expression
-			$value = strtr($value, $params);
-		}
-
-		return $value;
-	}
-
-} // End Database_Expression

+ 0 - 443
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/MySQL.php

@@ -1,443 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * MySQL database connection.
- *
- * @package    Kohana/Database
- * @category   Drivers
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_MySQL extends Database {
-
-	// Database in use by each connection
-	protected static $_current_databases = array();
-
-	// Use SET NAMES to set the character set
-	protected static $_set_names;
-
-	// Identifier for this connection within the PHP driver
-	protected $_connection_id;
-
-	// MySQL uses a backtick for identifiers
-	protected $_identifier = '`';
-
-	public function connect()
-	{
-		if ($this->_connection)
-			return;
-
-		if (Database_MySQL::$_set_names === NULL)
-		{
-			// Determine if we can use mysql_set_charset(), which is only
-			// available on PHP 5.2.3+ when compiled against MySQL 5.0+
-			Database_MySQL::$_set_names = ! function_exists('mysql_set_charset');
-		}
-
-		// Extract the connection parameters, adding required variabels
-		extract($this->_config['connection'] + array(
-			'database'   => '',
-			'hostname'   => '',
-			'username'   => '',
-			'password'   => '',
-			'persistent' => FALSE,
-		));
-
-		// Prevent this information from showing up in traces
-		unset($this->_config['connection']['username'], $this->_config['connection']['password']);
-
-		try
-		{
-			if ($persistent)
-			{
-				// Create a persistent connection
-				$this->_connection = mysql_pconnect($hostname, $username, $password);
-			}
-			else
-			{
-				// Create a connection and force it to be a new link
-				$this->_connection = mysql_connect($hostname, $username, $password, TRUE);
-			}
-		}
-		catch (Exception $e)
-		{
-			// No connection exists
-			$this->_connection = NULL;
-
-			throw new Database_Exception(':error',
-				array(':error' => $e->getMessage()),
-				$e->getCode());
-		}
-
-		// \xFF is a better delimiter, but the PHP driver uses underscore
-		$this->_connection_id = sha1($hostname.'_'.$username.'_'.$password);
-
-		$this->_select_db($database);
-
-		if ( ! empty($this->_config['charset']))
-		{
-			// Set the character set
-			$this->set_charset($this->_config['charset']);
-		}
-
-		if ( ! empty($this->_config['connection']['variables']))
-		{
-			// Set session variables
-			$variables = array();
-
-			foreach ($this->_config['connection']['variables'] as $var => $val)
-			{
-				$variables[] = 'SESSION '.$var.' = '.$this->quote($val);
-			}
-
-			mysql_query('SET '.implode(', ', $variables), $this->_connection);
-		}
-	}
-
-	/**
-	 * Select the database
-	 *
-	 * @param   string  $database Database
-	 * @return  void
-	 */
-	protected function _select_db($database)
-	{
-		if ( ! mysql_select_db($database, $this->_connection))
-		{
-			// Unable to select database
-			throw new Database_Exception(':error',
-				array(':error' => mysql_error($this->_connection)),
-				mysql_errno($this->_connection));
-		}
-
-		Database_MySQL::$_current_databases[$this->_connection_id] = $database;
-	}
-
-	public function disconnect()
-	{
-		try
-		{
-			// Database is assumed disconnected
-			$status = TRUE;
-
-			if (is_resource($this->_connection))
-			{
-				if ($status = mysql_close($this->_connection))
-				{
-					// Clear the connection
-					$this->_connection = NULL;
-
-					// Clear the instance
-					parent::disconnect();
-				}
-			}
-		}
-		catch (Exception $e)
-		{
-			// Database is probably not disconnected
-			$status = ! is_resource($this->_connection);
-		}
-
-		return $status;
-	}
-
-	public function set_charset($charset)
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		if (Database_MySQL::$_set_names === TRUE)
-		{
-			// PHP is compiled against MySQL 4.x
-			$status = (bool) mysql_query('SET NAMES '.$this->quote($charset), $this->_connection);
-		}
-		else
-		{
-			// PHP is compiled against MySQL 5.x
-			$status = mysql_set_charset($charset, $this->_connection);
-		}
-
-		if ($status === FALSE)
-		{
-			throw new Database_Exception(':error',
-				array(':error' => mysql_error($this->_connection)),
-				mysql_errno($this->_connection));
-		}
-	}
-
-	public function query($type, $sql, $as_object = FALSE, array $params = NULL)
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		if (Kohana::$profiling)
-		{
-			// Benchmark this query for the current instance
-			$benchmark = Profiler::start("Database ({$this->_instance})", $sql);
-		}
-
-		if ( ! empty($this->_config['connection']['persistent']) AND $this->_config['connection']['database'] !== Database_MySQL::$_current_databases[$this->_connection_id])
-		{
-			// Select database on persistent connections
-			$this->_select_db($this->_config['connection']['database']);
-		}
-
-		// Execute the query
-		if (($result = mysql_query($sql, $this->_connection)) === FALSE)
-		{
-			if (isset($benchmark))
-			{
-				// This benchmark is worthless
-				Profiler::delete($benchmark);
-			}
-
-			throw new Database_Exception(':error [ :query ]',
-				array(':error' => mysql_error($this->_connection), ':query' => $sql),
-				mysql_errno($this->_connection));
-		}
-
-		if (isset($benchmark))
-		{
-			Profiler::stop($benchmark);
-		}
-
-		// Set the last query
-		$this->last_query = $sql;
-
-		if ($type === Database::SELECT)
-		{
-			// Return an iterator of results
-			return new Database_MySQL_Result($result, $sql, $as_object, $params);
-		}
-		elseif ($type === Database::INSERT)
-		{
-			// Return a list of insert id and rows created
-			return array(
-				mysql_insert_id($this->_connection),
-				mysql_affected_rows($this->_connection),
-			);
-		}
-		else
-		{
-			// Return the number of rows affected
-			return mysql_affected_rows($this->_connection);
-		}
-	}
-
-	public function datatype($type)
-	{
-		static $types = array
-		(
-			'blob'                      => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '65535'),
-			'bool'                      => array('type' => 'bool'),
-			'bigint unsigned'           => array('type' => 'int', 'min' => '0', 'max' => '18446744073709551615'),
-			'datetime'                  => array('type' => 'string'),
-			'decimal unsigned'          => array('type' => 'float', 'exact' => TRUE, 'min' => '0'),
-			'double'                    => array('type' => 'float'),
-			'double precision unsigned' => array('type' => 'float', 'min' => '0'),
-			'double unsigned'           => array('type' => 'float', 'min' => '0'),
-			'enum'                      => array('type' => 'string'),
-			'fixed'                     => array('type' => 'float', 'exact' => TRUE),
-			'fixed unsigned'            => array('type' => 'float', 'exact' => TRUE, 'min' => '0'),
-			'float unsigned'            => array('type' => 'float', 'min' => '0'),
-			'int unsigned'              => array('type' => 'int', 'min' => '0', 'max' => '4294967295'),
-			'integer unsigned'          => array('type' => 'int', 'min' => '0', 'max' => '4294967295'),
-			'longblob'                  => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '4294967295'),
-			'longtext'                  => array('type' => 'string', 'character_maximum_length' => '4294967295'),
-			'mediumblob'                => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '16777215'),
-			'mediumint'                 => array('type' => 'int', 'min' => '-8388608', 'max' => '8388607'),
-			'mediumint unsigned'        => array('type' => 'int', 'min' => '0', 'max' => '16777215'),
-			'mediumtext'                => array('type' => 'string', 'character_maximum_length' => '16777215'),
-			'national varchar'          => array('type' => 'string'),
-			'numeric unsigned'          => array('type' => 'float', 'exact' => TRUE, 'min' => '0'),
-			'nvarchar'                  => array('type' => 'string'),
-			'point'                     => array('type' => 'string', 'binary' => TRUE),
-			'real unsigned'             => array('type' => 'float', 'min' => '0'),
-			'set'                       => array('type' => 'string'),
-			'smallint unsigned'         => array('type' => 'int', 'min' => '0', 'max' => '65535'),
-			'text'                      => array('type' => 'string', 'character_maximum_length' => '65535'),
-			'tinyblob'                  => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '255'),
-			'tinyint'                   => array('type' => 'int', 'min' => '-128', 'max' => '127'),
-			'tinyint unsigned'          => array('type' => 'int', 'min' => '0', 'max' => '255'),
-			'tinytext'                  => array('type' => 'string', 'character_maximum_length' => '255'),
-			'year'                      => array('type' => 'string'),
-		);
-
-		$type = str_replace(' zerofill', '', $type);
-
-		if (isset($types[$type]))
-			return $types[$type];
-
-		return parent::datatype($type);
-	}
-
-	/**
-	 * Start a SQL transaction
-	 *
-	 * @link http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
-	 *
-	 * @param string $mode  Isolation level
-	 * @return boolean
-	 */
-	public function begin($mode = NULL)
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		if ($mode AND ! mysql_query("SET TRANSACTION ISOLATION LEVEL $mode", $this->_connection))
-		{
-			throw new Database_Exception(':error',
-				array(':error' => mysql_error($this->_connection)),
-				mysql_errno($this->_connection));
-		}
-
-		return (bool) mysql_query('START TRANSACTION', $this->_connection);
-	}
-
-	/**
-	 * Commit a SQL transaction
-	 *
-	 * @return boolean
-	 */
-	public function commit()
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		return (bool) mysql_query('COMMIT', $this->_connection);
-	}
-
-	/**
-	 * Rollback a SQL transaction
-	 *
-	 * @return boolean
-	 */
-	public function rollback()
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		return (bool) mysql_query('ROLLBACK', $this->_connection);
-	}
-
-	public function list_tables($like = NULL)
-	{
-		if (is_string($like))
-		{
-			// Search for table names
-			$result = $this->query(Database::SELECT, 'SHOW TABLES LIKE '.$this->quote($like), FALSE);
-		}
-		else
-		{
-			// Find all table names
-			$result = $this->query(Database::SELECT, 'SHOW TABLES', FALSE);
-		}
-
-		$tables = array();
-		foreach ($result as $row)
-		{
-			$tables[] = reset($row);
-		}
-
-		return $tables;
-	}
-
-	public function list_columns($table, $like = NULL, $add_prefix = TRUE)
-	{
-		// Quote the table name
-		$table = ($add_prefix === TRUE) ? $this->quote_table($table) : $table;
-
-		if (is_string($like))
-		{
-			// Search for column names
-			$result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table.' LIKE '.$this->quote($like), FALSE);
-		}
-		else
-		{
-			// Find all column names
-			$result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table, FALSE);
-		}
-
-		$count = 0;
-		$columns = array();
-		foreach ($result as $row)
-		{
-			list($type, $length) = $this->_parse_type($row['Type']);
-
-			$column = $this->datatype($type);
-
-			$column['column_name']      = $row['Field'];
-			$column['column_default']   = $row['Default'];
-			$column['data_type']        = $type;
-			$column['is_nullable']      = ($row['Null'] == 'YES');
-			$column['ordinal_position'] = ++$count;
-
-			switch ($column['type'])
-			{
-				case 'float':
-					if (isset($length))
-					{
-						list($column['numeric_precision'], $column['numeric_scale']) = explode(',', $length);
-					}
-				break;
-				case 'int':
-					if (isset($length))
-					{
-						// MySQL attribute
-						$column['display'] = $length;
-					}
-				break;
-				case 'string':
-					switch ($column['data_type'])
-					{
-						case 'binary':
-						case 'varbinary':
-							$column['character_maximum_length'] = $length;
-						break;
-						case 'char':
-						case 'varchar':
-							$column['character_maximum_length'] = $length;
-						case 'text':
-						case 'tinytext':
-						case 'mediumtext':
-						case 'longtext':
-							$column['collation_name'] = $row['Collation'];
-						break;
-						case 'enum':
-						case 'set':
-							$column['collation_name'] = $row['Collation'];
-							$column['options'] = explode('\',\'', substr($length, 1, -1));
-						break;
-					}
-				break;
-			}
-
-			// MySQL attributes
-			$column['comment']      = $row['Comment'];
-			$column['extra']        = $row['Extra'];
-			$column['key']          = $row['Key'];
-			$column['privileges']   = $row['Privileges'];
-
-			$columns[$row['Field']] = $column;
-		}
-
-		return $columns;
-	}
-
-	public function escape($value)
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		if (($value = mysql_real_escape_string( (string) $value, $this->_connection)) === FALSE)
-		{
-			throw new Database_Exception(':error',
-				array(':error' => mysql_error($this->_connection)),
-				mysql_errno($this->_connection));
-		}
-
-		// SQL standard is to use single-quotes for all values
-		return "'$value'";
-	}
-
-} // End Database_MySQL

+ 0 - 71
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/MySQL/Result.php

@@ -1,71 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * MySQL database result.   See [Results](/database/results) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query/Result
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_MySQL_Result extends Database_Result {
-
-	protected $_internal_row = 0;
-
-	public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
-	{
-		parent::__construct($result, $sql, $as_object, $params);
-
-		// Find the number of rows in the result
-		$this->_total_rows = mysql_num_rows($result);
-	}
-
-	public function __destruct()
-	{
-		if (is_resource($this->_result))
-		{
-			mysql_free_result($this->_result);
-		}
-	}
-
-	public function seek($offset)
-	{
-		if ($this->offsetExists($offset) AND mysql_data_seek($this->_result, $offset))
-		{
-			// Set the current row to the offset
-			$this->_current_row = $this->_internal_row = $offset;
-
-			return TRUE;
-		}
-		else
-		{
-			return FALSE;
-		}
-	}
-
-	public function current()
-	{
-		if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
-			return NULL;
-
-		// Increment internal row for optimization assuming rows are fetched in order
-		$this->_internal_row++;
-
-		if ($this->_as_object === TRUE)
-		{
-			// Return an stdClass
-			return mysql_fetch_object($this->_result);
-		}
-		elseif (is_string($this->_as_object))
-		{
-			// Return an object of given class name
-			return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params);
-		}
-		else
-		{
-			// Return an array of the row
-			return mysql_fetch_assoc($this->_result);
-		}
-	}
-
-} // End Database_MySQL_Result_Select

+ 0 - 247
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/PDO.php

@@ -1,247 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * PDO database connection.
- *
- * @package    Kohana/Database
- * @category   Drivers
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_PDO extends Database {
-
-	// PDO uses no quoting for identifiers
-	protected $_identifier = '';
-
-	public function __construct($name, array $config)
-	{
-		parent::__construct($name, $config);
-
-		if (isset($this->_config['identifier']))
-		{
-			// Allow the identifier to be overloaded per-connection
-			$this->_identifier = (string) $this->_config['identifier'];
-		}
-	}
-
-	public function connect()
-	{
-		if ($this->_connection)
-			return;
-
-		// Extract the connection parameters, adding required variabels
-		extract($this->_config['connection'] + array(
-			'dsn'        => '',
-			'username'   => NULL,
-			'password'   => NULL,
-			'persistent' => FALSE,
-		));
-
-		// Clear the connection parameters for security
-		unset($this->_config['connection']);
-
-		// Force PDO to use exceptions for all errors
-		$options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
-
-		if ( ! empty($persistent))
-		{
-			// Make the connection persistent
-			$options[PDO::ATTR_PERSISTENT] = TRUE;
-		}
-
-		try
-		{
-			// Create a new PDO connection
-			$this->_connection = new PDO($dsn, $username, $password, $options);
-		}
-		catch (PDOException $e)
-		{
-			throw new Database_Exception(':error',
-				array(':error' => $e->getMessage()),
-				$e->getCode());
-		}
-	}
-
-	/**
-	 * Create or redefine a SQL aggregate function.
-	 *
-	 * [!!] Works only with SQLite
-	 *
-	 * @link http://php.net/manual/function.pdo-sqlitecreateaggregate
-	 *
-	 * @param   string      $name       Name of the SQL function to be created or redefined
-	 * @param   callback    $step       Called for each row of a result set
-	 * @param   callback    $final      Called after all rows of a result set have been processed
-	 * @param   integer     $arguments  Number of arguments that the SQL function takes
-	 *
-	 * @return  boolean
-	 */
-	public function create_aggregate($name, $step, $final, $arguments = -1)
-	{
-		$this->_connection or $this->connect();
-
-		return $this->_connection->sqliteCreateAggregate(
-			$name, $step, $final, $arguments
-		);
-	}
-
-	/**
-	 * Create or redefine a SQL function.
-	 *
-	 * [!!] Works only with SQLite
-	 *
-	 * @link http://php.net/manual/function.pdo-sqlitecreatefunction
-	 *
-	 * @param   string      $name       Name of the SQL function to be created or redefined
-	 * @param   callback    $callback   Callback which implements the SQL function
-	 * @param   integer     $arguments  Number of arguments that the SQL function takes
-	 *
-	 * @return  boolean
-	 */
-	public function create_function($name, $callback, $arguments = -1)
-	{
-		$this->_connection or $this->connect();
-
-		return $this->_connection->sqliteCreateFunction(
-			$name, $callback, $arguments
-		);
-	}
-
-	public function disconnect()
-	{
-		// Destroy the PDO object
-		$this->_connection = NULL;
-
-		return parent::disconnect();
-	}
-
-	public function set_charset($charset)
-	{
-		// Make sure the database is connected
-		$this->_connection OR $this->connect();
-
-		// This SQL-92 syntax is not supported by all drivers
-		$this->_connection->exec('SET NAMES '.$this->quote($charset));
-	}
-
-	public function query($type, $sql, $as_object = FALSE, array $params = NULL)
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		if (Kohana::$profiling)
-		{
-			// Benchmark this query for the current instance
-			$benchmark = Profiler::start("Database ({$this->_instance})", $sql);
-		}
-
-		try
-		{
-			$result = $this->_connection->query($sql);
-		}
-		catch (Exception $e)
-		{
-			if (isset($benchmark))
-			{
-				// This benchmark is worthless
-				Profiler::delete($benchmark);
-			}
-
-			// Convert the exception in a database exception
-			throw new Database_Exception(':error [ :query ]',
-				array(
-					':error' => $e->getMessage(),
-					':query' => $sql
-				),
-				$e->getCode());
-		}
-
-		if (isset($benchmark))
-		{
-			Profiler::stop($benchmark);
-		}
-
-		// Set the last query
-		$this->last_query = $sql;
-
-		if ($type === Database::SELECT)
-		{
-			// Convert the result into an array, as PDOStatement::rowCount is not reliable
-			if ($as_object === FALSE)
-			{
-				$result->setFetchMode(PDO::FETCH_ASSOC);
-			}
-			elseif (is_string($as_object))
-			{
-				$result->setFetchMode(PDO::FETCH_CLASS, $as_object, $params);
-			}
-			else
-			{
-				$result->setFetchMode(PDO::FETCH_CLASS, 'stdClass');
-			}
-
-			$result = $result->fetchAll();
-
-			// Return an iterator of results
-			return new Database_Result_Cached($result, $sql, $as_object, $params);
-		}
-		elseif ($type === Database::INSERT)
-		{
-			// Return a list of insert id and rows created
-			return array(
-				$this->_connection->lastInsertId(),
-				$result->rowCount(),
-			);
-		}
-		else
-		{
-			// Return the number of rows affected
-			return $result->rowCount();
-		}
-	}
-
-	public function begin($mode = NULL)
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		return $this->_connection->beginTransaction();
-	}
-
-	public function commit()
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		return $this->_connection->commit();
-	}
-
-	public function rollback()
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		return $this->_connection->rollBack();
-	}
-
-	public function list_tables($like = NULL)
-	{
-		throw new Kohana_Exception('Database method :method is not supported by :class',
-			array(':method' => __FUNCTION__, ':class' => __CLASS__));
-	}
-
-	public function list_columns($table, $like = NULL, $add_prefix = TRUE)
-	{
-		throw new Kohana_Exception('Database method :method is not supported by :class',
-			array(':method' => __FUNCTION__, ':class' => __CLASS__));
-	}
-
-	public function escape($value)
-	{
-		// Make sure the database is connected
-		$this->_connection or $this->connect();
-
-		return $this->_connection->quote($value);
-	}
-
-} // End Database_PDO

+ 0 - 262
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query.php

@@ -1,262 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query wrapper.  See [Parameterized Statements](database/query/parameterized) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Query {
-
-	// Query type
-	protected $_type;
-
-	// Execute the query during a cache hit
-	protected $_force_execute = FALSE;
-
-	// Cache lifetime
-	protected $_lifetime = NULL;
-
-	// SQL statement
-	protected $_sql;
-
-	// Quoted query parameters
-	protected $_parameters = array();
-
-	// Return results as associative arrays or objects
-	protected $_as_object = FALSE;
-
-	// Parameters for __construct when using object results
-	protected $_object_params = array();
-
-	/**
-	 * Creates a new SQL query of the specified type.
-	 *
-	 * @param   integer  $type  query type: Database::SELECT, Database::INSERT, etc
-	 * @param   string   $sql   query string
-	 * @return  void
-	 */
-	public function __construct($type, $sql)
-	{
-		$this->_type = $type;
-		$this->_sql = $sql;
-	}
-
-	/**
-	 * Return the SQL query string.
-	 *
-	 * @return  string
-	 */
-	public function __toString()
-	{
-		try
-		{
-			// Return the SQL string
-			return $this->compile(Database::instance());
-		}
-		catch (Exception $e)
-		{
-			return Kohana_Exception::text($e);
-		}
-	}
-
-	/**
-	 * Get the type of the query.
-	 *
-	 * @return  integer
-	 */
-	public function type()
-	{
-		return $this->_type;
-	}
-
-	/**
-	 * Enables the query to be cached for a specified amount of time.
-	 *
-	 * @param   integer  $lifetime  number of seconds to cache, 0 deletes it from the cache
-	 * @param   boolean  whether or not to execute the query during a cache hit
-	 * @return  $this
-	 * @uses    Kohana::$cache_life
-	 */
-	public function cached($lifetime = NULL, $force = FALSE)
-	{
-		if ($lifetime === NULL)
-		{
-			// Use the global setting
-			$lifetime = Kohana::$cache_life;
-		}
-
-		$this->_force_execute = $force;
-		$this->_lifetime = $lifetime;
-
-		return $this;
-	}
-
-	/**
-	 * Returns results as associative arrays
-	 *
-	 * @return  $this
-	 */
-	public function as_assoc()
-	{
-		$this->_as_object = FALSE;
-
-		$this->_object_params = array();
-
-		return $this;
-	}
-
-	/**
-	 * Returns results as objects
-	 *
-	 * @param   string  $class  classname or TRUE for stdClass
-	 * @param   array   $params
-	 * @return  $this
-	 */
-	public function as_object($class = TRUE, array $params = NULL)
-	{
-		$this->_as_object = $class;
-
-		if ($params)
-		{
-			// Add object parameters
-			$this->_object_params = $params;
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Set the value of a parameter in the query.
-	 *
-	 * @param   string   $param  parameter key to replace
-	 * @param   mixed    $value  value to use
-	 * @return  $this
-	 */
-	public function param($param, $value)
-	{
-		// Add or overload a new parameter
-		$this->_parameters[$param] = $value;
-
-		return $this;
-	}
-
-	/**
-	 * Bind a variable to a parameter in the query.
-	 *
-	 * @param   string  $param  parameter key to replace
-	 * @param   mixed   $var    variable to use
-	 * @return  $this
-	 */
-	public function bind($param, & $var)
-	{
-		// Bind a value to a variable
-		$this->_parameters[$param] =& $var;
-
-		return $this;
-	}
-
-	/**
-	 * Add multiple parameters to the query.
-	 *
-	 * @param   array  $params  list of parameters
-	 * @return  $this
-	 */
-	public function parameters(array $params)
-	{
-		// Merge the new parameters in
-		$this->_parameters = $params + $this->_parameters;
-
-		return $this;
-	}
-
-	/**
-	 * Compile the SQL query and return it. Replaces any parameters with their
-	 * given values.
-	 *
-	 * @param   mixed  $db  Database instance or name of instance
-	 * @return  string
-	 */
-	public function compile($db = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		// Import the SQL locally
-		$sql = $this->_sql;
-
-		if ( ! empty($this->_parameters))
-		{
-			// Quote all of the values
-			$values = array_map(array($db, 'quote'), $this->_parameters);
-
-			// Replace the values in the SQL
-			$sql = strtr($sql, $values);
-		}
-
-		return $sql;
-	}
-
-	/**
-	 * Execute the current query on the given database.
-	 *
-	 * @param   mixed    $db  Database instance or name of instance
-	 * @param   string   result object classname, TRUE for stdClass or FALSE for array
-	 * @param   array    result object constructor arguments
-	 * @return  object   Database_Result for SELECT queries
-	 * @return  mixed    the insert id for INSERT queries
-	 * @return  integer  number of affected rows for all other queries
-	 */
-	public function execute($db = NULL, $as_object = NULL, $object_params = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		if ($as_object === NULL)
-		{
-			$as_object = $this->_as_object;
-		}
-
-		if ($object_params === NULL)
-		{
-			$object_params = $this->_object_params;
-		}
-
-		// Compile the SQL query
-		$sql = $this->compile($db);
-
-		if ($this->_lifetime !== NULL AND $this->_type === Database::SELECT)
-		{
-			// Set the cache key based on the database instance name and SQL
-			$cache_key = 'Database::query("'.$db.'", "'.$sql.'")';
-
-			// Read the cache first to delete a possible hit with lifetime <= 0
-			if (($result = Kohana::cache($cache_key, NULL, $this->_lifetime)) !== NULL
-				AND ! $this->_force_execute)
-			{
-				// Return a cached result
-				return new Database_Result_Cached($result, $sql, $as_object, $object_params);
-			}
-		}
-
-		// Execute the query
-		$result = $db->query($this->_type, $sql, $as_object, $object_params);
-
-		if (isset($cache_key) AND $this->_lifetime > 0)
-		{
-			// Cache the result array
-			Kohana::cache($cache_key, $result->as_array(), $this->_lifetime);
-		}
-
-		return $result;
-	}
-
-} // End Database_Query

+ 0 - 248
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder.php

@@ -1,248 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query builder. See [Query Builder](/database/query/builder) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-abstract class Kohana_Database_Query_Builder extends Database_Query {
-
-	/**
-	 * Compiles an array of JOIN statements into an SQL partial.
-	 *
-	 * @param   object  $db     Database instance
-	 * @param   array   $joins  join statements
-	 * @return  string
-	 */
-	protected function _compile_join(Database $db, array $joins)
-	{
-		$statements = array();
-
-		foreach ($joins as $join)
-		{
-			// Compile each of the join statements
-			$statements[] = $join->compile($db);
-		}
-
-		return implode(' ', $statements);
-	}
-
-	/**
-	 * Compiles an array of conditions into an SQL partial. Used for WHERE
-	 * and HAVING.
-	 *
-	 * @param   object  $db          Database instance
-	 * @param   array   $conditions  condition statements
-	 * @return  string
-	 */
-	protected function _compile_conditions(Database $db, array $conditions)
-	{
-		$last_condition = NULL;
-
-		$sql = '';
-		foreach ($conditions as $group)
-		{
-			// Process groups of conditions
-			foreach ($group as $logic => $condition)
-			{
-				if ($condition === '(')
-				{
-					if ( ! empty($sql) AND $last_condition !== '(')
-					{
-						// Include logic operator
-						$sql .= ' '.$logic.' ';
-					}
-
-					$sql .= '(';
-				}
-				elseif ($condition === ')')
-				{
-					$sql .= ')';
-				}
-				else
-				{
-					if ( ! empty($sql) AND $last_condition !== '(')
-					{
-						// Add the logic operator
-						$sql .= ' '.$logic.' ';
-					}
-
-					// Split the condition
-					list($column, $op, $value) = $condition;
-
-					if ($value === NULL)
-					{
-						if ($op === '=')
-						{
-							// Convert "val = NULL" to "val IS NULL"
-							$op = 'IS';
-						}
-						elseif ($op === '!=')
-						{
-							// Convert "val != NULL" to "valu IS NOT NULL"
-							$op = 'IS NOT';
-						}
-					}
-
-					// Database operators are always uppercase
-					$op = strtoupper($op);
-
-					if ($op === 'BETWEEN' AND is_array($value))
-					{
-						// BETWEEN always has exactly two arguments
-						list($min, $max) = $value;
-
-						if ((is_string($min) AND array_key_exists($min, $this->_parameters)) === FALSE)
-						{
-							// Quote the value, it is not a parameter
-							$min = $db->quote($min);
-						}
-
-						if ((is_string($max) AND array_key_exists($max, $this->_parameters)) === FALSE)
-						{
-							// Quote the value, it is not a parameter
-							$max = $db->quote($max);
-						}
-
-						// Quote the min and max value
-						$value = $min.' AND '.$max;
-					}
-					elseif ((is_string($value) AND array_key_exists($value, $this->_parameters)) === FALSE)
-					{
-						// Quote the value, it is not a parameter
-						$value = $db->quote($value);
-					}
-
-					if ($column)
-					{
-						if (is_array($column))
-						{
-							// Use the column name
-							$column = $db->quote_identifier(reset($column));
-						}
-						else
-						{
-							// Apply proper quoting to the column
-							$column = $db->quote_column($column);
-						}
-					}
-
-					// Append the statement to the query
-					$sql .= trim($column.' '.$op.' '.$value);
-				}
-
-				$last_condition = $condition;
-			}
-		}
-
-		return $sql;
-	}
-
-	/**
-	 * Compiles an array of set values into an SQL partial. Used for UPDATE.
-	 *
-	 * @param   object  $db      Database instance
-	 * @param   array   $values  updated values
-	 * @return  string
-	 */
-	protected function _compile_set(Database $db, array $values)
-	{
-		$set = array();
-		foreach ($values as $group)
-		{
-			// Split the set
-			list ($column, $value) = $group;
-
-			// Quote the column name
-			$column = $db->quote_column($column);
-
-			if ((is_string($value) AND array_key_exists($value, $this->_parameters)) === FALSE)
-			{
-				// Quote the value, it is not a parameter
-				$value = $db->quote($value);
-			}
-
-			$set[$column] = $column.' = '.$value;
-		}
-
-		return implode(', ', $set);
-	}
-
-	/**
-	 * Compiles an array of GROUP BY columns into an SQL partial.
-	 *
-	 * @param   object  $db       Database instance
-	 * @param   array   $columns
-	 * @return  string
-	 */
-	protected function _compile_group_by(Database $db, array $columns)
-	{
-		$group = array();
-
-		foreach ($columns as $column)
-		{
-			if (is_array($column))
-			{
-				// Use the column alias
-				$column = $db->quote_identifier(end($column));
-			}
-			else
-			{
-				// Apply proper quoting to the column
-				$column = $db->quote_column($column);
-			}
-
-			$group[] = $column;
-		}
-
-		return 'GROUP BY '.implode(', ', $group);
-	}
-
-	/**
-	 * Compiles an array of ORDER BY statements into an SQL partial.
-	 *
-	 * @param   object  $db       Database instance
-	 * @param   array   $columns  sorting columns
-	 * @return  string
-	 */
-	protected function _compile_order_by(Database $db, array $columns)
-	{
-		$sort = array();
-		foreach ($columns as $group)
-		{
-			list ($column, $direction) = $group;
-
-			if (is_array($column))
-			{
-				// Use the column alias
-				$column = $db->quote_identifier(end($column));
-			}
-			else
-			{
-				// Apply proper quoting to the column
-				$column = $db->quote_column($column);
-			}
-
-			if ($direction)
-			{
-				// Make the direction uppercase
-				$direction = ' '.strtoupper($direction);
-			}
-
-			$sort[] = $column.$direction;
-		}
-
-		return 'ORDER BY '.implode(', ', $sort);
-	}
-
-	/**
-	 * Reset the current builder status.
-	 *
-	 * @return  $this
-	 */
-	abstract public function reset();
-
-} // End Database_Query_Builder

+ 0 - 99
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Delete.php

@@ -1,99 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query builder for DELETE statements. See [Query Builder](/database/query/builder) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Query_Builder_Delete extends Database_Query_Builder_Where {
-
-	// DELETE FROM ...
-	protected $_table;
-
-	/**
-	 * Set the table for a delete.
-	 *
-	 * @param   mixed  $table  table name or array($table, $alias) or object
-	 * @return  void
-	 */
-	public function __construct($table = NULL)
-	{
-		if ($table)
-		{
-			// Set the inital table name
-			$this->_table = $table;
-		}
-
-		// Start the query with no SQL
-		return parent::__construct(Database::DELETE, '');
-	}
-
-	/**
-	 * Sets the table to delete from.
-	 *
-	 * @param   mixed  $table  table name or array($table, $alias) or object
-	 * @return  $this
-	 */
-	public function table($table)
-	{
-		$this->_table = $table;
-
-		return $this;
-	}
-
-	/**
-	 * Compile the SQL query and return it.
-	 *
-	 * @param   mixed  $db  Database instance or name of instance
-	 * @return  string
-	 */
-	public function compile($db = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		// Start a deletion query
-		$query = 'DELETE FROM '.$db->quote_table($this->_table);
-
-		if ( ! empty($this->_where))
-		{
-			// Add deletion conditions
-			$query .= ' WHERE '.$this->_compile_conditions($db, $this->_where);
-		}
-
-		if ( ! empty($this->_order_by))
-		{
-			// Add sorting
-			$query .= ' '.$this->_compile_order_by($db, $this->_order_by);
-		}
-
-		if ($this->_limit !== NULL)
-		{
-			// Add limiting
-			$query .= ' LIMIT '.$this->_limit;
-		}
-
-		$this->_sql = $query;
-
-		return parent::compile($db);
-	}
-
-	public function reset()
-	{
-		$this->_table = NULL;
-		$this->_where = array();
-
-		$this->_parameters = array();
-
-		$this->_sql = NULL;
-
-		return $this;
-	}
-
-} // End Database_Query_Builder_Delete

+ 0 - 181
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Insert.php

@@ -1,181 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query builder for INSERT statements. See [Query Builder](/database/query/builder) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Query_Builder_Insert extends Database_Query_Builder {
-
-	// INSERT INTO ...
-	protected $_table;
-
-	// (...)
-	protected $_columns = array();
-
-	// VALUES (...)
-	protected $_values = array();
-
-	/**
-	 * Set the table and columns for an insert.
-	 *
-	 * @param   mixed  $table    table name or array($table, $alias) or object
-	 * @param   array  $columns  column names
-	 * @return  void
-	 */
-	public function __construct($table = NULL, array $columns = NULL)
-	{
-		if ($table)
-		{
-			// Set the inital table name
-			$this->_table = $table;
-		}
-
-		if ($columns)
-		{
-			// Set the column names
-			$this->_columns = $columns;
-		}
-
-		// Start the query with no SQL
-		return parent::__construct(Database::INSERT, '');
-	}
-
-	/**
-	 * Sets the table to insert into.
-	 *
-	 * @param   mixed  $table  table name or array($table, $alias) or object
-	 * @return  $this
-	 */
-	public function table($table)
-	{
-		$this->_table = $table;
-
-		return $this;
-	}
-
-	/**
-	 * Set the columns that will be inserted.
-	 *
-	 * @param   array  $columns  column names
-	 * @return  $this
-	 */
-	public function columns(array $columns)
-	{
-		$this->_columns = $columns;
-
-		return $this;
-	}
-
-	/**
-	 * Adds or overwrites values. Multiple value sets can be added.
-	 *
-	 * @param   array   $values  values list
-	 * @param   ...
-	 * @return  $this
-	 */
-	public function values(array $values)
-	{
-		if ( ! is_array($this->_values))
-		{
-			throw new Kohana_Exception('INSERT INTO ... SELECT statements cannot be combined with INSERT INTO ... VALUES');
-		}
-
-		// Get all of the passed values
-		$values = func_get_args();
-
-		$this->_values = array_merge($this->_values, $values);
-
-		return $this;
-	}
-
-	/**
-	 * Use a sub-query to for the inserted values.
-	 *
-	 * @param   object  $query  Database_Query of SELECT type
-	 * @return  $this
-	 */
-	public function select(Database_Query $query)
-	{
-		if ($query->type() !== Database::SELECT)
-		{
-			throw new Kohana_Exception('Only SELECT queries can be combined with INSERT queries');
-		}
-
-		$this->_values = $query;
-
-		return $this;
-	}
-
-	/**
-	 * Compile the SQL query and return it.
-	 *
-	 * @param   mixed  $db  Database instance or name of instance
-	 * @return  string
-	 */
-	public function compile($db = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		// Start an insertion query
-		$query = 'INSERT INTO '.$db->quote_table($this->_table);
-
-		// Add the column names
-		$query .= ' ('.implode(', ', array_map(array($db, 'quote_column'), $this->_columns)).') ';
-
-		if (is_array($this->_values))
-		{
-			// Callback for quoting values
-			$quote = array($db, 'quote');
-
-			$groups = array();
-			foreach ($this->_values as $group)
-			{
-				foreach ($group as $offset => $value)
-				{
-					if ((is_string($value) AND array_key_exists($value, $this->_parameters)) === FALSE)
-					{
-						// Quote the value, it is not a parameter
-						$group[$offset] = $db->quote($value);
-					}
-				}
-
-				$groups[] = '('.implode(', ', $group).')';
-			}
-
-			// Add the values
-			$query .= 'VALUES '.implode(', ', $groups);
-		}
-		else
-		{
-			// Add the sub-query
-			$query .= (string) $this->_values;
-		}
-
-		$this->_sql = $query;
-
-		return parent::compile($db);;
-	}
-
-	public function reset()
-	{
-		$this->_table = NULL;
-
-		$this->_columns =
-		$this->_values  = array();
-
-		$this->_parameters = array();
-
-		$this->_sql = NULL;
-
-		return $this;
-	}
-
-} // End Database_Query_Builder_Insert

+ 0 - 149
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Join.php

@@ -1,149 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query builder for JOIN statements. See [Query Builder](/database/query/builder) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Query_Builder_Join extends Database_Query_Builder {
-
-	// Type of JOIN
-	protected $_type;
-
-	// JOIN ...
-	protected $_table;
-
-	// ON ...
-	protected $_on = array();
-
-	// USING ...
-	protected $_using = array();
-
-	/**
-	 * Creates a new JOIN statement for a table. Optionally, the type of JOIN
-	 * can be specified as the second parameter.
-	 *
-	 * @param   mixed   $table  column name or array($column, $alias) or object
-	 * @param   string  $type   type of JOIN: INNER, RIGHT, LEFT, etc
-	 * @return  void
-	 */
-	public function __construct($table, $type = NULL)
-	{
-		// Set the table to JOIN on
-		$this->_table = $table;
-
-		if ($type !== NULL)
-		{
-			// Set the JOIN type
-			$this->_type = (string) $type;
-		}
-	}
-
-	/**
-	 * Adds a new condition for joining.
-	 *
-	 * @param   mixed   $c1  column name or array($column, $alias) or object
-	 * @param   string  $op  logic operator
-	 * @param   mixed   $c2  column name or array($column, $alias) or object
-	 * @return  $this
-	 */
-	public function on($c1, $op, $c2)
-	{
-		if ( ! empty($this->_using))
-		{
-			throw new Kohana_Exception('JOIN ... ON ... cannot be combined with JOIN ... USING ...');
-		}
-
-		$this->_on[] = array($c1, $op, $c2);
-
-		return $this;
-	}
-
-	/**
-	 * Adds a new condition for joining.
-	 *
-	 * @param   string  $columns  column name
-	 * @return  $this
-	 */
-	public function using($columns)
-	{
-		if ( ! empty($this->_on))
-		{
-			throw new Kohana_Exception('JOIN ... ON ... cannot be combined with JOIN ... USING ...');
-		}
-
-		$columns = func_get_args();
-
-		$this->_using = array_merge($this->_using, $columns);
-
-		return $this;
-	}
-
-	/**
-	 * Compile the SQL partial for a JOIN statement and return it.
-	 *
-	 * @param   mixed  $db  Database instance or name of instance
-	 * @return  string
-	 */
-	public function compile($db = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		if ($this->_type)
-		{
-			$sql = strtoupper($this->_type).' JOIN';
-		}
-		else
-		{
-			$sql = 'JOIN';
-		}
-
-		// Quote the table name that is being joined
-		$sql .= ' '.$db->quote_table($this->_table);
-
-		if ( ! empty($this->_using))
-		{
-			// Quote and concat the columns
-			$sql .= ' USING ('.implode(', ', array_map(array($db, 'quote_column'), $this->_using)).')';
-		}
-		else
-		{
-			$conditions = array();
-			foreach ($this->_on as $condition)
-			{
-				// Split the condition
-				list($c1, $op, $c2) = $condition;
-
-				if ($op)
-				{
-					// Make the operator uppercase and spaced
-					$op = ' '.strtoupper($op);
-				}
-
-				// Quote each of the columns used for the condition
-				$conditions[] = $db->quote_column($c1).$op.' '.$db->quote_column($c2);
-			}
-
-			// Concat the conditions "... AND ..."
-			$sql .= ' ON ('.implode(' AND ', $conditions).')';
-		}
-
-		return $sql;
-	}
-
-	public function reset()
-	{
-		$this->_type =
-		$this->_table = NULL;
-
-		$this->_on = array();
-	}
-
-} // End Database_Query_Builder_Join

+ 0 - 446
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Select.php

@@ -1,446 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query builder for SELECT statements. See [Query Builder](/database/query/builder) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Query_Builder_Select extends Database_Query_Builder_Where {
-
-	// SELECT ...
-	protected $_select = array();
-
-	// DISTINCT
-	protected $_distinct = FALSE;
-
-	// FROM ...
-	protected $_from = array();
-
-	// JOIN ...
-	protected $_join = array();
-
-	// GROUP BY ...
-	protected $_group_by = array();
-
-	// HAVING ...
-	protected $_having = array();
-
-	// OFFSET ...
-	protected $_offset = NULL;
-
-    // UNION ...
-    protected $_union = array();
-
-	// The last JOIN statement created
-	protected $_last_join;
-
-	/**
-	 * Sets the initial columns to select from.
-	 *
-	 * @param   array  $columns  column list
-	 * @return  void
-	 */
-	public function __construct(array $columns = NULL)
-	{
-		if ( ! empty($columns))
-		{
-			// Set the initial columns
-			$this->_select = $columns;
-		}
-
-		// Start the query with no actual SQL statement
-		parent::__construct(Database::SELECT, '');
-	}
-
-	/**
-	 * Enables or disables selecting only unique columns using "SELECT DISTINCT"
-	 *
-	 * @param   boolean  $value  enable or disable distinct columns
-	 * @return  $this
-	 */
-	public function distinct($value)
-	{
-		$this->_distinct = (bool) $value;
-
-		return $this;
-	}
-
-	/**
-	 * Choose the columns to select from.
-	 *
-	 * @param   mixed  $columns  column name or array($column, $alias) or object
-	 * @return  $this
-	 */
-	public function select($columns = NULL)
-	{
-		$columns = func_get_args();
-
-		$this->_select = array_merge($this->_select, $columns);
-
-		return $this;
-	}
-
-	/**
-	 * Choose the columns to select from, using an array.
-	 *
-	 * @param   array  $columns  list of column names or aliases
-	 * @return  $this
-	 */
-	public function select_array(array $columns)
-	{
-		$this->_select = array_merge($this->_select, $columns);
-
-		return $this;
-	}
-
-	/**
-	 * Choose the tables to select "FROM ..."
-	 *
-	 * @param   mixed  $table  table name or array($table, $alias) or object
-	 * @return  $this
-	 */
-	public function from($tables)
-	{
-		$tables = func_get_args();
-
-		$this->_from = array_merge($this->_from, $tables);
-
-		return $this;
-	}
-
-	/**
-	 * Adds addition tables to "JOIN ...".
-	 *
-	 * @param   mixed   $table  column name or array($column, $alias) or object
-	 * @param   string  $type   join type (LEFT, RIGHT, INNER, etc)
-	 * @return  $this
-	 */
-	public function join($table, $type = NULL)
-	{
-		$this->_join[] = $this->_last_join = new Database_Query_Builder_Join($table, $type);
-
-		return $this;
-	}
-
-	/**
-	 * Adds "ON ..." conditions for the last created JOIN statement.
-	 *
-	 * @param   mixed   $c1  column name or array($column, $alias) or object
-	 * @param   string  $op  logic operator
-	 * @param   mixed   $c2  column name or array($column, $alias) or object
-	 * @return  $this
-	 */
-	public function on($c1, $op, $c2)
-	{
-		$this->_last_join->on($c1, $op, $c2);
-
-		return $this;
-	}
-
-	/**
-	 * Adds "USING ..." conditions for the last created JOIN statement.
-	 *
-	 * @param   string  $columns  column name
-	 * @return  $this
-	 */
-	public function using($columns)
-	{
-		$columns = func_get_args();
-
-		call_user_func_array(array($this->_last_join, 'using'), $columns);
-
-		return $this;
-	}
-
-	/**
-	 * Creates a "GROUP BY ..." filter.
-	 *
-	 * @param   mixed   $columns  column name or array($column, $alias) or object
-	 * @return  $this
-	 */
-	public function group_by($columns)
-	{
-		$columns = func_get_args();
-
-		$this->_group_by = array_merge($this->_group_by, $columns);
-
-		return $this;
-	}
-
-	/**
-	 * Alias of and_having()
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function having($column, $op, $value = NULL)
-	{
-		return $this->and_having($column, $op, $value);
-	}
-
-	/**
-	 * Creates a new "AND HAVING" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function and_having($column, $op, $value = NULL)
-	{
-		$this->_having[] = array('AND' => array($column, $op, $value));
-
-		return $this;
-	}
-
-	/**
-	 * Creates a new "OR HAVING" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function or_having($column, $op, $value = NULL)
-	{
-		$this->_having[] = array('OR' => array($column, $op, $value));
-
-		return $this;
-	}
-
-	/**
-	 * Alias of and_having_open()
-	 *
-	 * @return  $this
-	 */
-	public function having_open()
-	{
-		return $this->and_having_open();
-	}
-
-	/**
-	 * Opens a new "AND HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_having_open()
-	{
-		$this->_having[] = array('AND' => '(');
-
-		return $this;
-	}
-
-	/**
-	 * Opens a new "OR HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_having_open()
-	{
-		$this->_having[] = array('OR' => '(');
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "AND HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function having_close()
-	{
-		return $this->and_having_close();
-	}
-
-	/**
-	 * Closes an open "AND HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_having_close()
-	{
-		$this->_having[] = array('AND' => ')');
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "OR HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_having_close()
-	{
-		$this->_having[] = array('OR' => ')');
-
-		return $this;
-	}
-
-	/**
-	 * Adds an other UNION clause.
-	 *
-	 * @param mixed $select  if string, it must be the name of a table. Else
-	 *  must be an instance of Database_Query_Builder_Select
-	 * @param boolean $all  decides if it's an UNION or UNION ALL clause
-	 * @return $this
-	 */
-	public function union($select, $all = TRUE)
-	{
-		if (is_string($select))
-		{
-			$select = DB::select()->from($select);
-		}
-		if ( ! $select instanceof Database_Query_Builder_Select)
-			throw new Kohana_Exception('first parameter must be a string or an instance of Database_Query_Builder_Select');
-		$this->_union []= array('select' => $select, 'all' => $all);
-		return $this;
-	}
-
-	/**
-	 * Start returning results after "OFFSET ..."
-	 *
-	 * @param   integer   $number  starting result number or NULL to reset
-	 * @return  $this
-	 */
-	public function offset($number)
-	{
-		$this->_offset = $number;
-
-		return $this;
-	}
-
-	/**
-	 * Compile the SQL query and return it.
-	 *
-	 * @param   mixed  $db  Database instance or name of instance
-	 * @return  string
-	 */
-	public function compile($db = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		// Callback to quote columns
-		$quote_column = array($db, 'quote_column');
-
-		// Callback to quote tables
-		$quote_table = array($db, 'quote_table');
-
-		// Start a selection query
-		$query = 'SELECT ';
-
-		if ($this->_distinct === TRUE)
-		{
-			// Select only unique results
-			$query .= 'DISTINCT ';
-		}
-
-		if (empty($this->_select))
-		{
-			// Select all columns
-			$query .= '*';
-		}
-		else
-		{
-			// Select all columns
-			$query .= implode(', ', array_unique(array_map($quote_column, $this->_select)));
-		}
-
-		if ( ! empty($this->_from))
-		{
-			// Set tables to select from
-			$query .= ' FROM '.implode(', ', array_unique(array_map($quote_table, $this->_from)));
-		}
-
-		if ( ! empty($this->_join))
-		{
-			// Add tables to join
-			$query .= ' '.$this->_compile_join($db, $this->_join);
-		}
-
-		if ( ! empty($this->_where))
-		{
-			// Add selection conditions
-			$query .= ' WHERE '.$this->_compile_conditions($db, $this->_where);
-		}
-
-		if ( ! empty($this->_group_by))
-		{
-			// Add grouping
-			$query .= ' '.$this->_compile_group_by($db, $this->_group_by);
-		}
-
-		if ( ! empty($this->_having))
-		{
-			// Add filtering conditions
-			$query .= ' HAVING '.$this->_compile_conditions($db, $this->_having);
-		}
-
-		if ( ! empty($this->_order_by))
-		{
-			// Add sorting
-			$query .= ' '.$this->_compile_order_by($db, $this->_order_by);
-		}
-
-		if ($this->_limit !== NULL)
-		{
-			// Add limiting
-			$query .= ' LIMIT '.$this->_limit;
-		}
-
-		if ($this->_offset !== NULL)
-		{
-			// Add offsets
-			$query .= ' OFFSET '.$this->_offset;
-		}
-
-		if ( ! empty($this->_union))
-		{
-			foreach ($this->_union as $u) {
-				$query .= ' UNION ';
-				if ($u['all'] === TRUE)
-				{
-					$query .= 'ALL ';
-				}
-				$query .= $u['select']->compile($db);
-			}
-		}
-
-		$this->_sql = $query;
-
-		return parent::compile($db);
-	}
-
-	public function reset()
-	{
-		$this->_select   =
-		$this->_from     =
-		$this->_join     =
-		$this->_where    =
-		$this->_group_by =
-		$this->_having   =
-		$this->_order_by =
-		$this->_union = array();
-
-		$this->_distinct = FALSE;
-
-		$this->_limit     =
-		$this->_offset    =
-		$this->_last_join = NULL;
-
-		$this->_parameters = array();
-
-		$this->_sql = NULL;
-
-		return $this;
-	}
-
-} // End Database_Query_Select

+ 0 - 140
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Update.php

@@ -1,140 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query builder for UPDATE statements. See [Query Builder](/database/query/builder) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Query_Builder_Update extends Database_Query_Builder_Where {
-
-	// UPDATE ...
-	protected $_table;
-
-	// SET ...
-	protected $_set = array();
-
-	/**
-	 * Set the table for a update.
-	 *
-	 * @param   mixed  $table  table name or array($table, $alias) or object
-	 * @return  void
-	 */
-	public function __construct($table = NULL)
-	{
-		if ($table)
-		{
-			// Set the inital table name
-			$this->_table = $table;
-		}
-
-		// Start the query with no SQL
-		return parent::__construct(Database::UPDATE, '');
-	}
-
-	/**
-	 * Sets the table to update.
-	 *
-	 * @param   mixed  $table  table name or array($table, $alias) or object
-	 * @return  $this
-	 */
-	public function table($table)
-	{
-		$this->_table = $table;
-
-		return $this;
-	}
-
-	/**
-	 * Set the values to update with an associative array.
-	 *
-	 * @param   array   $pairs  associative (column => value) list
-	 * @return  $this
-	 */
-	public function set(array $pairs)
-	{
-		foreach ($pairs as $column => $value)
-		{
-			$this->_set[] = array($column, $value);
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Set the value of a single column.
-	 *
-	 * @param   mixed  $column  table name or array($table, $alias) or object
-	 * @param   mixed  $value   column value
-	 * @return  $this
-	 */
-	public function value($column, $value)
-	{
-		$this->_set[] = array($column, $value);
-
-		return $this;
-	}
-
-	/**
-	 * Compile the SQL query and return it.
-	 *
-	 * @param   mixed  $db  Database instance or name of instance
-	 * @return  string
-	 */
-	public function compile($db = NULL)
-	{
-		if ( ! is_object($db))
-		{
-			// Get the database instance
-			$db = Database::instance($db);
-		}
-
-		// Start an update query
-		$query = 'UPDATE '.$db->quote_table($this->_table);
-
-		// Add the columns to update
-		$query .= ' SET '.$this->_compile_set($db, $this->_set);
-
-		if ( ! empty($this->_where))
-		{
-			// Add selection conditions
-			$query .= ' WHERE '.$this->_compile_conditions($db, $this->_where);
-		}
-
-		if ( ! empty($this->_order_by))
-		{
-			// Add sorting
-			$query .= ' '.$this->_compile_order_by($db, $this->_order_by);
-		}
-
-		if ($this->_limit !== NULL)
-		{
-			// Add limiting
-			$query .= ' LIMIT '.$this->_limit;
-		}
-
-		$this->_sql = $query;
-
-		return parent::compile($db);
-	}
-
-	public function reset()
-	{
-		$this->_table = NULL;
-
-		$this->_set   =
-		$this->_where = array();
-
-		$this->_limit = NULL;
-
-		$this->_parameters = array();
-
-		$this->_sql = NULL;
-
-		return $this;
-	}
-
-
-} // End Database_Query_Builder_Update

+ 0 - 180
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Query/Builder/Where.php

@@ -1,180 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database query builder for WHERE statements. See [Query Builder](/database/query/builder) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-abstract class Kohana_Database_Query_Builder_Where extends Database_Query_Builder {
-
-	// WHERE ...
-	protected $_where = array();
-
-	// ORDER BY ...
-	protected $_order_by = array();
-
-	// LIMIT ...
-	protected $_limit = NULL;
-
-	/**
-	 * Alias of and_where()
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function where($column, $op, $value)
-	{
-		return $this->and_where($column, $op, $value);
-	}
-
-	/**
-	 * Creates a new "AND WHERE" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function and_where($column, $op, $value)
-	{
-		$this->_where[] = array('AND' => array($column, $op, $value));
-
-		return $this;
-	}
-
-	/**
-	 * Creates a new "OR WHERE" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function or_where($column, $op, $value)
-	{
-		$this->_where[] = array('OR' => array($column, $op, $value));
-
-		return $this;
-	}
-
-	/**
-	 * Alias of and_where_open()
-	 *
-	 * @return  $this
-	 */
-	public function where_open()
-	{
-		return $this->and_where_open();
-	}
-
-	/**
-	 * Opens a new "AND WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_where_open()
-	{
-		$this->_where[] = array('AND' => '(');
-
-		return $this;
-	}
-
-	/**
-	 * Opens a new "OR WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_where_open()
-	{
-		$this->_where[] = array('OR' => '(');
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function where_close()
-	{
-		return $this->and_where_close();
-	}
-
-	/**
-	 * Closes an open "WHERE (...)" grouping or removes the grouping when it is
-	 * empty.
-	 *
-	 * @return  $this
-	 */
-	public function where_close_empty()
-	{
-		$group = end($this->_where);
-
-		if ($group AND reset($group) === '(')
-		{
-			array_pop($this->_where);
-
-			return $this;
-		}
-
-		return $this->where_close();
-	}
-
-	/**
-	 * Closes an open "WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_where_close()
-	{
-		$this->_where[] = array('AND' => ')');
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_where_close()
-	{
-		$this->_where[] = array('OR' => ')');
-
-		return $this;
-	}
-
-	/**
-	 * Applies sorting with "ORDER BY ..."
-	 *
-	 * @param   mixed   $column     column name or array($column, $alias) or object
-	 * @param   string  $direction  direction of sorting
-	 * @return  $this
-	 */
-	public function order_by($column, $direction = NULL)
-	{
-		$this->_order_by[] = array($column, $direction);
-
-		return $this;
-	}
-
-	/**
-	 * Return up to "LIMIT ..." results
-	 *
-	 * @param   integer  $number  maximum results to return or NULL to reset
-	 * @return  $this
-	 */
-	public function limit($number)
-	{
-		$this->_limit = $number;
-
-		return $this;
-	}
-
-} // End Database_Query_Builder_Where

+ 0 - 338
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Result.php

@@ -1,338 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database result wrapper.  See [Results](/database/results) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query/Result
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-abstract class Kohana_Database_Result implements Countable, Iterator, SeekableIterator, ArrayAccess {
-
-	// Executed SQL for this result
-	protected $_query;
-
-	// Raw result resource
-	protected $_result;
-
-	// Total number of rows and current row
-	protected $_total_rows  = 0;
-	protected $_current_row = 0;
-
-	// Return rows as an object or associative array
-	protected $_as_object;
-
-	// Parameters for __construct when using object results
-	protected $_object_params = NULL;
-
-	/**
-	 * Sets the total number of rows and stores the result locally.
-	 *
-	 * @param   mixed   $result     query result
-	 * @param   string  $sql        SQL query
-	 * @param   mixed   $as_object
-	 * @param   array   $params
-	 * @return  void
-	 */
-	public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
-	{
-		// Store the result locally
-		$this->_result = $result;
-
-		// Store the SQL locally
-		$this->_query = $sql;
-
-		if (is_object($as_object))
-		{
-			// Get the object class name
-			$as_object = get_class($as_object);
-		}
-
-		// Results as objects or associative arrays
-		$this->_as_object = $as_object;
-
-		if ($params)
-		{
-			// Object constructor params
-			$this->_object_params = $params;
-		}
-	}
-
-	/**
-	 * Result destruction cleans up all open result sets.
-	 *
-	 * @return  void
-	 */
-	abstract public function __destruct();
-
-	/**
-	 * Get a cached database result from the current result iterator.
-	 *
-	 *     $cachable = serialize($result->cached());
-	 *
-	 * @return  Database_Result_Cached
-	 * @since   3.0.5
-	 */
-	public function cached()
-	{
-		return new Database_Result_Cached($this->as_array(), $this->_query, $this->_as_object);
-	}
-
-	/**
-	 * Return all of the rows in the result as an array.
-	 *
-	 *     // Indexed array of all rows
-	 *     $rows = $result->as_array();
-	 *
-	 *     // Associative array of rows by "id"
-	 *     $rows = $result->as_array('id');
-	 *
-	 *     // Associative array of rows, "id" => "name"
-	 *     $rows = $result->as_array('id', 'name');
-	 *
-	 * @param   string  $key    column for associative keys
-	 * @param   string  $value  column for values
-	 * @return  array
-	 */
-	public function as_array($key = NULL, $value = NULL)
-	{
-		$results = array();
-
-		if ($key === NULL AND $value === NULL)
-		{
-			// Indexed rows
-
-			foreach ($this as $row)
-			{
-				$results[] = $row;
-			}
-		}
-		elseif ($key === NULL)
-		{
-			// Indexed columns
-
-			if ($this->_as_object)
-			{
-				foreach ($this as $row)
-				{
-					$results[] = $row->$value;
-				}
-			}
-			else
-			{
-				foreach ($this as $row)
-				{
-					$results[] = $row[$value];
-				}
-			}
-		}
-		elseif ($value === NULL)
-		{
-			// Associative rows
-
-			if ($this->_as_object)
-			{
-				foreach ($this as $row)
-				{
-					$results[$row->$key] = $row;
-				}
-			}
-			else
-			{
-				foreach ($this as $row)
-				{
-					$results[$row[$key]] = $row;
-				}
-			}
-		}
-		else
-		{
-			// Associative columns
-
-			if ($this->_as_object)
-			{
-				foreach ($this as $row)
-				{
-					$results[$row->$key] = $row->$value;
-				}
-			}
-			else
-			{
-				foreach ($this as $row)
-				{
-					$results[$row[$key]] = $row[$value];
-				}
-			}
-		}
-
-		$this->rewind();
-
-		return $results;
-	}
-
-	/**
-	 * Return the named column from the current row.
-	 *
-	 *     // Get the "id" value
-	 *     $id = $result->get('id');
-	 *
-	 * @param   string  $name     column to get
-	 * @param   mixed   $default  default value if the column does not exist
-	 * @return  mixed
-	 */
-	public function get($name, $default = NULL)
-	{
-		$row = $this->current();
-
-		if ($this->_as_object)
-		{
-			if (isset($row->$name))
-				return $row->$name;
-		}
-		else
-		{
-			if (isset($row[$name]))
-				return $row[$name];
-		}
-
-		return $default;
-	}
-
-	/**
-	 * Implements [Countable::count], returns the total number of rows.
-	 *
-	 *     echo count($result);
-	 *
-	 * @return  integer
-	 */
-	public function count()
-	{
-		return $this->_total_rows;
-	}
-
-	/**
-	 * Implements [ArrayAccess::offsetExists], determines if row exists.
-	 *
-	 *     if (isset($result[10]))
-	 *     {
-	 *         // Row 10 exists
-	 *     }
-	 *
-	 * @param   int     $offset
-	 * @return  boolean
-	 */
-	public function offsetExists($offset)
-	{
-		return ($offset >= 0 AND $offset < $this->_total_rows);
-	}
-
-	/**
-	 * Implements [ArrayAccess::offsetGet], gets a given row.
-	 *
-	 *     $row = $result[10];
-	 *
-	 * @param   int     $offset
-	 * @return  mixed
-	 */
-	public function offsetGet($offset)
-	{
-		if ( ! $this->seek($offset))
-			return NULL;
-
-		return $this->current();
-	}
-
-	/**
-	 * Implements [ArrayAccess::offsetSet], throws an error.
-	 *
-	 * [!!] You cannot modify a database result.
-	 *
-	 * @param   int     $offset
-	 * @param   mixed   $value
-	 * @return  void
-	 * @throws  Kohana_Exception
-	 */
-	final public function offsetSet($offset, $value)
-	{
-		throw new Kohana_Exception('Database results are read-only');
-	}
-
-	/**
-	 * Implements [ArrayAccess::offsetUnset], throws an error.
-	 *
-	 * [!!] You cannot modify a database result.
-	 *
-	 * @param   int     $offset
-	 * @return  void
-	 * @throws  Kohana_Exception
-	 */
-	final public function offsetUnset($offset)
-	{
-		throw new Kohana_Exception('Database results are read-only');
-	}
-
-	/**
-	 * Implements [Iterator::key], returns the current row number.
-	 *
-	 *     echo key($result);
-	 *
-	 * @return  integer
-	 */
-	public function key()
-	{
-		return $this->_current_row;
-	}
-
-	/**
-	 * Implements [Iterator::next], moves to the next row.
-	 *
-	 *     next($result);
-	 *
-	 * @return  $this
-	 */
-	public function next()
-	{
-		++$this->_current_row;
-		return $this;
-	}
-
-	/**
-	 * Implements [Iterator::prev], moves to the previous row.
-	 *
-	 *     prev($result);
-	 *
-	 * @return  $this
-	 */
-	public function prev()
-	{
-		--$this->_current_row;
-		return $this;
-	}
-
-	/**
-	 * Implements [Iterator::rewind], sets the current row to zero.
-	 *
-	 *     rewind($result);
-	 *
-	 * @return  $this
-	 */
-	public function rewind()
-	{
-		$this->_current_row = 0;
-		return $this;
-	}
-
-	/**
-	 * Implements [Iterator::valid], checks if the current row exists.
-	 *
-	 * [!!] This method is only used internally.
-	 *
-	 * @return  boolean
-	 */
-	public function valid()
-	{
-		return $this->offsetExists($this->_current_row);
-	}
-
-} // End Database_Result

+ 0 - 51
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Database/Result/Cached.php

@@ -1,51 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Object used for caching the results of select queries.  See [Results](/database/results#select-cached) for usage and examples.
- *
- * @package    Kohana/Database
- * @category   Query/Result
- * @author     Kohana Team
- * @copyright  (c) 2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Database_Result_Cached extends Database_Result {
-
-	public function __construct(array $result, $sql, $as_object = NULL)
-	{
-		parent::__construct($result, $sql, $as_object);
-
-		// Find the number of rows in the result
-		$this->_total_rows = count($result);
-	}
-
-	public function __destruct()
-	{
-		// Cached results do not use resources
-	}
-
-	public function cached()
-	{
-		return $this;
-	}
-
-	public function seek($offset)
-	{
-		if ($this->offsetExists($offset))
-		{
-			$this->_current_row = $offset;
-
-			return TRUE;
-		}
-		else
-		{
-			return FALSE;
-		}
-	}
-
-	public function current()
-	{
-		// Return an array of the row
-		return $this->valid() ? $this->_result[$this->_current_row] : NULL;
-	}
-
-} // End Database_Result_Cached

+ 0 - 63
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Model/Database.php

@@ -1,63 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database Model base class.
- *
- * @package    Kohana/Database
- * @category   Models
- * @author     Kohana Team
- * @copyright  (c) 2008-2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-abstract class Kohana_Model_Database extends Model {
-
-	/**
-	 * Create a new model instance. A [Database] instance or configuration
-	 * group name can be passed to the model. If no database is defined, the
-	 * "default" database group will be used.
-	 *
-	 *     $model = Model::factory($name);
-	 *
-	 * @param   string   $name  model name
-	 * @param   mixed    $db    Database instance object or string
-	 * @return  Model
-	 */
-	public static function factory($name, $db = NULL)
-	{
-		// Add the model prefix
-		$class = 'Model_'.$name;
-
-		return new $class($db);
-	}
-
-	// Database instance
-	protected $_db;
-
-	/**
-	 * Loads the database.
-	 *
-	 *     $model = new Foo_Model($db);
-	 *
-	 * @param   mixed  $db  Database instance object or string
-	 * @return  void
-	 */
-	public function __construct($db = NULL)
-	{
-		if ($db)
-		{
-			// Set the instance or name
-			$this->_db = $db;
-		}
-		elseif ( ! $this->_db)
-		{
-			// Use the default name
-			$this->_db = Database::$default;
-		}
-
-		if (is_string($this->_db))
-		{
-			// Load the database
-			$this->_db = Database::instance($this->_db);
-		}
-	}
-
-} // End Model

+ 0 - 239
frameworks/PHP/php-kohana/modules/database/classes/Kohana/Session/Database.php

@@ -1,239 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * Database-based session class.
- *
- * Sample schema:
- *
- *     CREATE TABLE  `sessions` (
- *         `session_id` VARCHAR( 24 ) NOT NULL,
- *         `last_active` INT UNSIGNED NOT NULL,
- *         `contents` TEXT NOT NULL,
- *         PRIMARY KEY ( `session_id` ),
- *         INDEX ( `last_active` )
- *     ) ENGINE = MYISAM ;
- *
- * @package    Kohana/Database
- * @category   Session
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class Kohana_Session_Database extends Session {
-
-	// Database instance
-	protected $_db;
-
-	// Database table name
-	protected $_table = 'sessions';
-
-	// Database column names
-	protected $_columns = array(
-		'session_id'  => 'session_id',
-		'last_active' => 'last_active',
-		'contents'    => 'contents'
-	);
-
-	// Garbage collection requests
-	protected $_gc = 500;
-
-	// The current session id
-	protected $_session_id;
-
-	// The old session id
-	protected $_update_id;
-
-	public function __construct(array $config = NULL, $id = NULL)
-	{
-		if ( ! isset($config['group']))
-		{
-			// Use the default group
-			$config['group'] = Database::$default;
-		}
-
-		// Load the database
-		$this->_db = Database::instance($config['group']);
-
-		if (isset($config['table']))
-		{
-			// Set the table name
-			$this->_table = (string) $config['table'];
-		}
-
-		if (isset($config['gc']))
-		{
-			// Set the gc chance
-			$this->_gc = (int) $config['gc'];
-		}
-
-		if (isset($config['columns']))
-		{
-			// Overload column names
-			$this->_columns = $config['columns'];
-		}
-
-		parent::__construct($config, $id);
-
-		if (mt_rand(0, $this->_gc) === $this->_gc)
-		{
-			// Run garbage collection
-			// This will average out to run once every X requests
-			$this->_gc();
-		}
-	}
-
-	public function id()
-	{
-		return $this->_session_id;
-	}
-
-	protected function _read($id = NULL)
-	{
-		if ($id OR $id = Cookie::get($this->_name))
-		{
-			$result = DB::select(array($this->_columns['contents'], 'contents'))
-				->from($this->_table)
-				->where($this->_columns['session_id'], '=', ':id')
-				->limit(1)
-				->param(':id', $id)
-				->execute($this->_db);
-
-			if ($result->count())
-			{
-				// Set the current session id
-				$this->_session_id = $this->_update_id = $id;
-
-				// Return the contents
-				return $result->get('contents');
-			}
-		}
-
-		// Create a new session id
-		$this->_regenerate();
-
-		return NULL;
-	}
-
-	protected function _regenerate()
-	{
-		// Create the query to find an ID
-		$query = DB::select($this->_columns['session_id'])
-			->from($this->_table)
-			->where($this->_columns['session_id'], '=', ':id')
-			->limit(1)
-			->bind(':id', $id);
-
-		do
-		{
-			// Create a new session id
-			$id = str_replace('.', '-', uniqid(NULL, TRUE));
-
-			// Get the the id from the database
-			$result = $query->execute($this->_db);
-		}
-		while ($result->count());
-
-		return $this->_session_id = $id;
-	}
-
-	protected function _write()
-	{
-		if ($this->_update_id === NULL)
-		{
-			// Insert a new row
-			$query = DB::insert($this->_table, $this->_columns)
-				->values(array(':new_id', ':active', ':contents'));
-		}
-		else
-		{
-			// Update the row
-			$query = DB::update($this->_table)
-				->value($this->_columns['last_active'], ':active')
-				->value($this->_columns['contents'], ':contents')
-				->where($this->_columns['session_id'], '=', ':old_id');
-
-			if ($this->_update_id !== $this->_session_id)
-			{
-				// Also update the session id
-				$query->value($this->_columns['session_id'], ':new_id');
-			}
-		}
-
-		$query
-			->param(':new_id',   $this->_session_id)
-			->param(':old_id',   $this->_update_id)
-			->param(':active',   $this->_data['last_active'])
-			->param(':contents', $this->__toString());
-
-		// Execute the query
-		$query->execute($this->_db);
-
-		// The update and the session id are now the same
-		$this->_update_id = $this->_session_id;
-
-		// Update the cookie with the new session id
-		Cookie::set($this->_name, $this->_session_id, $this->_lifetime);
-
-		return TRUE;
-	}
-
-	/**
-	 * @return  bool
-	 */
-	protected function _restart()
-	{
-		$this->_regenerate();
-
-		return TRUE;
-	}
-
-	protected function _destroy()
-	{
-		if ($this->_update_id === NULL)
-		{
-			// Session has not been created yet
-			return TRUE;
-		}
-
-		// Delete the current session
-		$query = DB::delete($this->_table)
-			->where($this->_columns['session_id'], '=', ':id')
-			->param(':id', $this->_update_id);
-
-		try
-		{
-			// Execute the query
-			$query->execute($this->_db);
-
-			// Delete the cookie
-			Cookie::delete($this->_name);
-		}
-		catch (Exception $e)
-		{
-			// An error occurred, the session has not been deleted
-			return FALSE;
-		}
-
-		return TRUE;
-	}
-
-	protected function _gc()
-	{
-		if ($this->_lifetime)
-		{
-			// Expire sessions when their lifetime is up
-			$expires = $this->_lifetime;
-		}
-		else
-		{
-			// Expire sessions after one month
-			$expires = Date::MONTH;
-		}
-
-		// Delete all sessions that have expired
-		DB::delete($this->_table)
-			->where($this->_columns['last_active'], '<', ':time')
-			->param(':time', time() - $expires)
-			->execute($this->_db);
-	}
-
-} // End Session_Database

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Model/Database.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-abstract class Model_Database extends Kohana_Model_Database {}

+ 0 - 3
frameworks/PHP/php-kohana/modules/database/classes/Session/Database.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class Session_Database extends Kohana_Session_Database {}

+ 0 - 56
frameworks/PHP/php-kohana/modules/database/config/database.php

@@ -1,56 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-
-return array
-(
-	'default' => array
-	(
-		'type'       => 'MySQL',
-		'connection' => array(
-			/**
-			 * The following options are available for MySQL:
-			 *
-			 * string   hostname     server hostname, or socket
-			 * string   database     database name
-			 * string   username     database username
-			 * string   password     database password
-			 * boolean  persistent   use persistent connections?
-			 * array    variables    system variables as "key => value" pairs
-			 *
-			 * Ports and sockets may be appended to the hostname.
-			 */
-			'hostname'   => 'localhost',
-			'database'   => 'kohana',
-			'username'   => FALSE,
-			'password'   => FALSE,
-			'persistent' => FALSE,
-		),
-		'table_prefix' => '',
-		'charset'      => 'utf8',
-		'caching'      => FALSE,
-	),
-	'alternate' => array(
-		'type'       => 'PDO',
-		'connection' => array(
-			/**
-			 * The following options are available for PDO:
-			 *
-			 * string   dsn         Data Source Name
-			 * string   username    database username
-			 * string   password    database password
-			 * boolean  persistent  use persistent connections?
-			 */
-			'dsn'        => 'mysql:host=localhost;dbname=kohana',
-			'username'   => 'root',
-			'password'   => 'r00tdb',
-			'persistent' => FALSE,
-		),
-		/**
-		 * The following extra options are available for PDO:
-		 *
-		 * string   identifier  set the escaping identifier
-		 */
-		'table_prefix' => '',
-		'charset'      => 'utf8',
-		'caching'      => FALSE,
-	),
-);

+ 0 - 27
frameworks/PHP/php-kohana/modules/database/config/session.php

@@ -1,27 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-return array(
-	'database' => array(
-		/**
-		 * Database settings for session storage.
-		 *
-		 * string   group  configuation group name
-		 * string   table  session table name
-		 * integer  gc     number of requests before gc is invoked
-		 * columns  array  custom column names
-		 */
-		'group'   => 'default',
-		'table'   => 'sessions',
-		'gc'      => 500,
-		'columns' => array(
-			/**
-			 * session_id:  session identifier
-			 * last_active: timestamp of the last activity
-			 * contents:    serialized session data
-			 */
-			'session_id'  => 'session_id',
-			'last_active' => 'last_active',
-			'contents'    => 'contents'
-		),
-	),
-);

+ 0 - 23
frameworks/PHP/php-kohana/modules/database/config/userguide.php

@@ -1,23 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-return array(
-	// Leave this alone
-	'modules' => array(
-
-		// This should be the path to this modules userguide pages, without the 'guide/'. Ex: '/guide/modulename/' would be 'modulename'
-		'database' => array(
-
-			// Whether this modules userguide pages should be shown
-			'enabled' => TRUE,
-			
-			// The name that should show up on the userguide index page
-			'name' => 'Database',
-
-			// A short description of this module, shown on the index page
-			'description' => 'Database agnostic querying and result management.',
-			
-			// Copyright message, shown in the footer for this module
-			'copyright' => '&copy; 2008–2012 Kohana Team',
-		)	
-	)
-);

+ 0 - 116
frameworks/PHP/php-kohana/modules/database/guide/database/config.md

@@ -1,116 +0,0 @@
-# Configuration
-
-The default config file is located in `MODPATH/database/config/database.php`.  You should copy this file to `APPPATH/config/database.php` and make changes there, in keeping with the [cascading filesystem](../kohana/files).
-
-The database configuration file contains an array of configuration groups. The structure of each database configuration group, called an "instance", looks like this:
-
-    string INSTANCE_NAME => array(
-        'type'         => string DATABASE_TYPE,
-        'connection'   => array CONNECTION_ARRAY,
-        'table_prefix' => string TABLE_PREFIX,
-        'charset'      => string CHARACTER_SET,
-    ),
-	
-Understanding each of these settings is important.
-
-INSTANCE_NAME
-:  Connections can be named anything you want, but you should always have at least one connection called "default".
-
-DATABASE_TYPE
-:  One of the installed database drivers. Kohana comes with "mysql" and "pdo" drivers.  Drivers must extend the Database class.
-
-CONNECTION_ARRAY
-:  Specific driver options for connecting to your database. (Driver options are explained [below](#connection-settings).)
-
-TABLE_PREFIX
-:  Prefix that will be added to all table names by the [query builder](#query_building).
-
-
-## Example
-
-The example file below shows 2 MySQL connections, one local and one remote.
-
-    return array
-    (
-        'default' => array
-        (
-            'type'       => 'mysql',
-            'connection' => array(
-                'hostname'   => 'localhost',
-                'username'   => 'dbuser',
-                'password'   => 'mypassword',
-                'persistent' => FALSE,
-                'database'   => 'my_db_name',
-            ),
-            'table_prefix' => '',
-            'charset'      => 'utf8',
-        ),
-        'remote' => array(
-            'type'       => 'mysql',
-            'connection' => array(
-                'hostname'   => '55.55.55.55',
-                'username'   => 'remote_user',
-                'password'   => 'mypassword',
-                'persistent' => FALSE,
-                'database'   => 'my_remote_db_name',
-            ),
-            'table_prefix' => '',
-            'charset'      => 'utf8',
-        ),
-    );
-
-## Connections and Instances
-
-Each configuration group is referred to as a database instance. Each instance can be accessed by calling [Database::instance].  If you don't provide a parameter, the default instance is used.
-
-	// This would connect to the database defined as 'default'
-    $default = Database::instance();
-	
-	// This would connect to the database defined as 'remote'
-    $remote  = Database::instance('remote');
-
-To disconnect the database, simply destroy the object:
-
-    unset($default)
-	
-	// Or
-	
-	unset(Database::$instances['default']);
-
-If you want to disconnect all of the database instances at once:
-
-    Database::$instances = array();
-
-## Connection Settings
-
-Every database driver has different connection settings.
-
-### MySQL
-
-A [MySQL database](http://www.php.net/manual/en/book.mysql.php) can accept the following options in the `connection` array:
-
-Type      | Option     |  Description               | Default value
-----------|------------|----------------------------| -------------------------
-`string`  | hostname   | Hostname of the database   | `localhost`
-`integer` | port       | Port number                | `NULL`
-`string`  | socket     | UNIX socket                | `NULL`
-`string`  | username   | Database username          | `NULL`
-`string`  | password   | Database password          | `NULL`
-`boolean` | persistent | Persistent connections     | `FALSE`
-`string`  | database   | Database name              | `kohana`
-
-### PDO
-
-A [PDO database](http://php.net/manual/en/book.pdo.php) can accept these options in the `connection` array:
-
-Type      | Option     |  Description               | Default value
-----------|------------|----------------------------| -------------------------
-`string`  | dsn        | PDO data source identifier | `localhost`
-`array`   | options    | Driver-specific options    | none
-`string`  | username   | Database username          | `NULL`
-`string`  | password   | Database password          | `NULL`
-`boolean` | persistent | Persistent connections     | `FALSE`
-
-The connection character set should be configured using the DSN string or `options` array.
-
-[!!] If you are using PDO and are not sure what to use for the `dsn` option, review [PDO::__construct](http://php.net/pdo.construct).

+ 0 - 52
frameworks/PHP/php-kohana/modules/database/guide/database/examples.md

@@ -1,52 +0,0 @@
-# Examples
-
-Here are some "real world" examples of using the database library to construct your queries and use the results.
-
-## Examples of Parameterized Statements
-
-TODO: 4-6 examples of parameterized statements of varying complexity, including a good bind() example.
-
-## Pagination and search/filter
-
-In this example, we loop through an array of whitelisted input fields and for each allowed non-empty value we add it to the search query. We make a clone of the query and then execute that query to count the total number of results. The count is then passed to the [Pagination](../pagination) class to determine the search offset. The last few lines search with Pagination's items_per_page and offset values to return a page of results based on the current page the user is on.
-
-	$query = DB::select()->from('users');
-	
-	//only search for these fields
-	$form_inputs = array('first_name', 'last_name', 'email');
-	foreach ($form_inputs as $name) 
-	{
-		$value = Arr::get($_GET, $name, FALSE);
-		if ($value !== FALSE AND $value != '')
-		{
-			$query->where($name, 'like', '%'.$value.'%');
-		}
-	}
-	
-	//copy the query & execute it
-	$pagination_query = clone $query;
-	$count = $pagination_query->select(DB::expr('COUNT(*)) AS mycount')->execute()->get('mycount');
-	
-	//pass the total item count to Pagination
-	$config = Kohana::$config->load('pagination');
-	$pagination = Pagination::factory(array(
-		'total_items' => $count,
-		'current_page'   => array('source' => 'route', 'key' => 'page'), 
-		'items_per_page' => 20,
-		'view'           => 'pagination/pretty',
-		'auto_hide'      => TRUE,
-	));
-	$page_links = $pagination->render();
-	
-	//search for results starting at the offset calculated by the Pagination class
-	$query->order_by('last_name', 'asc')
-		->order_by('first_name', 'asc')
-		->limit($pagination->items_per_page)
-		->offset($pagination->offset);
-	$results = $query->execute()->as_array();
-
-## Having
-
-TODO: example goes here
-
-[!!]  We could use more examples on this page. 

+ 0 - 17
frameworks/PHP/php-kohana/modules/database/guide/database/index.md

@@ -1,17 +0,0 @@
-# Database 
-
-Kohana 3.0 comes with a robust module for working with databases. By default, the database module supports drivers for [MySQL](http://php.net/mysql) and [PDO](http://php.net/pdo), but new drivers can be made for other database servers.
-
-The database module is included with the Kohana 3.0 install, but needs to be enabled before you can use it. To enable, open your `application/bootstrap.php` file and modify the call to [Kohana::modules] by including the database module like so:
-
-    Kohana::modules(array(
-        ...
-        'database' => MODPATH.'database',
-        ...
-    ));
-
-Next, you will then need to [configure](config) the database module to connect to your database.
-
-Once that is done then you can make [queries](query) and use the [results](results).
-
-The database module also provides a [config driver](../api/Kohana_Config_Database) (for storing [configuration](../kohana/files/config) in the database) and a [session driver](Session_Database).

+ 0 - 7
frameworks/PHP/php-kohana/modules/database/guide/database/menu.md

@@ -1,7 +0,0 @@
-## [Database]()
-- [Configuration](config)
-- [Querying](query)
-   - [Parameterized Statements](query/parameterized)
-   - [Query Builder](query/builder)
-- [Results](results)
-- [Examples](examples)

+ 0 - 5
frameworks/PHP/php-kohana/modules/database/guide/database/query.md

@@ -1,5 +0,0 @@
-# Making Queries
-
-There are two different ways to make queries. The simplest way to make a query is to use [Database_Query], via [DB::query], to manually create queries. These queries are called [parameterized statements](query/parameterized) and allow you to set query parameters which are automatically escaped. The second way to make a query is by building the query using method calls. This is done using the [query builder](query/builder).
-
-[!!] All queries are run using the `execute` method, which accepts a [Database] object or instance name. See [Database_Query::execute] for more information.

+ 0 - 251
frameworks/PHP/php-kohana/modules/database/guide/database/query/builder.md

@@ -1,251 +0,0 @@
-# Query Builder
-
-Creating queries dynamically using objects and methods allows queries to be written very quickly in an agnostic way. Query building also adds identifier (table and column name) quoting, as well as value quoting.
-
-## Select
-
-Each type of database query is represented by a different class, each with their own methods. For instance, to create a SELECT query, we use [DB::select] which is a shortcut to return a new [Database_Query_Builder_Select] object:
-
-    $query = DB::select();
-
-Query Builder methods return a reference to itself so that method chaining may be used. Select queries ussually require a table and they are referenced using the `from()` method. The `from()` method takes one parameter which can be the table name (string), an array of two strings (table name and alias), or an object (See Subqueries in the Advanced Queries section below). 
-
-    $query = DB::select()->from('users');
-
-Limiting the results of queries is done using the `where()`, `and_where()` and `or_where()` methods. These methods take three parameters: a column, an operator, and a value. 
-
-    $query = DB::select()->from('users')->where('username', '=', 'john');
-
-Multiple `where()` methods may be used to string together multiple clauses connected by the boolean operator in the method's prefix. The `where()` method is a wrapper that just calls `and_where()`. 
-
-    $query = DB::select()->from('users')->where('username', '=', 'john')->or_where('username', '=', 'jane');
-	
-You can use any operator you want.  Examples include `IN`, `BETWEEN`, `>`, `=<`, `!=`, etc.  Use an array for operators that require more than one value.
-
-	$query = DB::select()->from('users')->where('logins', '<=', 1);
-	
-	$query = DB::select()->from('users')->where('logins', '>', 50);
-	
-	$query = DB::select()->from('users')->where('username', 'IN', array('john','mark','matt'));
-	
-	$query = DB::select()->from('users')->where('joindate', 'BETWEEN', array($then, $now));
-
-By default, [DB::select] will select all columns (`SELECT * ...`), but you can also specify which columns you want returned by passing parameters to [DB::select]:
-
-    $query = DB::select('username', 'password')->from('users')->where('username', '=', 'john');
-
-Now take a minute to look at what this method chain is doing. First, we create a new selection object using the [DB::select] method. Next, we set table(s) using the `from()` method. Last, we search for a specific records using the `where()` method. We can display the SQL that will be executed by casting the query to a string:
-
-    echo Debug::vars((string) $query);
-    // Should display:
-    // SELECT `username`, `password` FROM `users` WHERE `username` = 'john'
-
-Notice how the column and table names are automatically escaped, as well as the values? This is one of the key benefits of using the query builder.
-
-### Select - AS (column aliases)
-
-It is also possible to create `AS` aliases when selecting, by passing an array as each parameter to [DB::select]:
-
-    $query = DB::select(array('username', 'u'), array('password', 'p'))->from('users');
-
-This query would generate the following SQL:
-
-    SELECT `username` AS `u`, `password` AS `p` FROM `users`
-
-### Select - DISTINCT
-
-Unique column values may be turned on or off (default) by passing TRUE or FALSE, respectively, to the `distinct()` method.
-
-    $query = DB::select('username')->distinct(TRUE)->from('posts');
-
-This query would generate the following SQL:
-
-    SELECT DISTINCT `username` FROM `posts`
-
-### Select - LIMIT & OFFSET
-
-When querying large sets of data, it is often better to limit the results and page through the data one chunk at a time. This is done using the `limit()` and `offset()` methods.
-
-    $query = DB::select()->from(`posts`)->limit(10)->offset(30);
-
-This query would generate the following SQL:
-
-    SELECT * FROM `posts` LIMIT 10 OFFSET 30
-
-### Select - ORDER BY
-
-Often you will want the results in a particular order and rather than sorting the results, it's better to have the results returned to you in the correct order. You can do this by using the order_by() method. It takes the column name and an optional direction string as the parameters. Multiple `order_by()` methods can be used to add additional sorting capability.
-
-    $query = DB::select()->from(`posts`)->order_by(`published`, `DESC`);
-
-This query would generate the following SQL:
-
-    SELECT * FROM `posts` ORDER BY `published` DESC
-
-[!!] For a complete list of methods available while building a select query see [Database_Query_Builder_Select].
-
-## Insert
-
-To create records into the database, use [DB::insert] to create an INSERT query, using `values()` to pass in the data:
-
-    $query = DB::insert('users', array('username', 'password'))->values(array('fred', 'p@5sW0Rd'));
-
-This query would generate the following SQL:
-
-    INSERT INTO `users` (`username`, `password`) VALUES ('fred', 'p@5sW0Rd')
-
-[!!] For a complete list of methods available while building an insert query see [Database_Query_Builder_Insert].
-
-## Update
-
-To modify an existing record, use [DB::update] to create an UPDATE query:
-
-    $query = DB::update('users')->set(array('username' => 'jane'))->where('username', '=', 'john');
-
-This query would generate the following SQL:
-
-    UPDATE `users` SET `username` = 'jane' WHERE `username` = 'john'
-
-[!!] For a complete list of methods available while building an update query see [Database_Query_Builder_Update].
-
-## Delete
-
-To remove an existing record, use [DB::delete] to create a DELETE query:
-
-    $query = DB::delete('users')->where('username', 'IN', array('john', 'jane'));
-
-This query would generate the following SQL:
-
-    DELETE FROM `users` WHERE `username` IN ('john', 'jane')
-
-[!!] For a complete list of methods available while building a delete query see [Database_Query_Builder_Delete].
-
-## Advanced Queries
-
-### Joins
-
-Multiple tables can be joined using the `join()` and `on()` methods. The `join()` method takes two parameters. The first is either a table name, an array containing the table and alias, or an object (subquery or expression). The second parameter is the join type: LEFT, RIGHT, INNER, etc.
-
-The `on()` method sets the conditions for the previous `join()` method and is very similar to the `where()` method in that it takes three parameters; left column (name or object), an operator, and the right column (name or object). Multiple `on()` methods may be used to supply multiple conditions and they will be appended with an 'AND' operator. 
-
-    // This query will find all the posts related to "smith" with JOIN
-    $query = DB::select('authors.name', 'posts.content')->from('authors')->join('posts')->on('authors.id', '=', 'posts.author_id')->where('authors.name', '=', 'smith');
-
-This query would generate the following SQL:
-
-    SELECT `authors`.`name`, `posts`.`content` FROM `authors` JOIN `posts` ON (`authors`.`id` = `posts`.`author_id`) WHERE `authors`.`name` = 'smith'
-
-If you want to do a LEFT, RIGHT or INNER JOIN you would do it like this `join('colum_name', 'type_of_join')`:
-
-    // This query will find all the posts related to "smith" with LEFT JOIN
-    $query = DB::select()->from('authors')->join('posts', 'LEFT')->on('authors.id', '=', 'posts.author_id')->where('authors.name', '=', 'smith');
-
-This query would generate the following SQL:
-
-    SELECT `authors`.`name`, `posts`.`content` FROM `authors` LEFT JOIN `posts` ON (`authors`.`id` = `posts`.`author_id`) WHERE `authors`.`name` = 'smith'
-
-[!!] When joining multiple tables with similar column names, it's best to prefix the columns with the table name or table alias to avoid errors. Ambiguous column names should also be aliased so that they can be referenced easier.
-
-### Database Functions
-
-Eventually you will probably run into a situation where you need to call `COUNT` or some other database function within your query. The query builder supports these functions using the `Database_Expression` class:
-
-    $query = DB::select(array(DB::expr('COUNT(`username`)'), 'total_users'))->from('users');
-
-This looks almost exactly the same as a standard `AS` alias, but note how the column name is put in a call to `DB::expr()`. Any time `DB::expr()` is used, the column name will **not** be escaped. This query would generate the following SQL:
-
-    SELECT COUNT(`username`) AS `total_users` FROM `users`
-
-[!!] When building complex queries and you need to get a count of the total rows that will be returned, build the expression with an empty column list first. Then clone the query and add the COUNT function to one copy and the columns list to the other. This will cut down on the total lines of code and make updating the query easier.
-
-    $query = DB::select()->from('users')
-        ->join('posts')->on('posts.username', '=', 'users.username')
-        ->where('users.active', '=', TRUE)
-        ->where('posts.created', '>=', $yesterday);
-    
-    $total = clone $query;
-    $total->select(array(DB::expr('COUNT( DISTINCT `username`)'), 'unique_users'));
-    $query->select('posts.username')->distinct();
-
-### Aggregate Functions
-
-Aggregate functions like `COUNT()`, `SUM()`, `AVG()`, etc. will most likely be used with the `group_by()` and possibly the `having()` methods in order to group and filter the results on a set of columns.
-
-    $query = DB::select('username', array(DB::expr('COUNT(`id`)'), 'total_posts')
-        ->from('posts')->group_by('username')->having('total_posts', '>=', 10);
-
-This will generate the following query:
-
-    SELECT `username`, COUNT(`id`) AS `total_posts` FROM `posts` GROUP BY `username` HAVING `total_posts` >= 10
-
-### Subqueries
-
-Query Builder objects can be passed as parameters to many of the methods to create subqueries. Let's take the previous example query and pass it to a new query.
-
-    $sub = DB::select('username', array(DB::expr('COUNT(`id`)'), 'total_posts')
-        ->from('posts')->group_by('username')->having('total_posts', '>=', 10);
-    
-    $query = DB::select('profiles.*', 'posts.total_posts')->from('profiles')
-        ->join(array($sub, 'posts'), 'INNER')->on('profiles.username', '=', 'posts.username');
-
-This will generate the following query:
-
-    SELECT `profiles`.*, `posts`.`total_posts` FROM `profiles` INNER JOIN
-    ( SELECT `username`, COUNT(`id`) AS `total_posts` FROM `posts` GROUP BY `username` HAVING `total_posts` >= 10 ) AS posts
-    ON `profiles`.`username` = `posts`.`username`
-
-Insert queries can also use a select query for the input values
-
-    $sub = DB::select('username', array(DB::expr('COUNT(`id`)'), 'total_posts')
-        ->from('posts')->group_by('username')->having('total_posts', '>=', 10);
-    
-    $query = DB::insert('post_totals', array('username', 'posts'))->select($sub);
-
-This will generate the following query:
-
-    INSERT INTO `post_totals` (`username`, `posts`) 
-    SELECT `username`, COUNT(`id`) AS `total_posts` FROM `posts` GROUP BY `username` HAVING `total_posts` >= 10 
-
-### Boolean Operators and Nested Clauses 
-
-Multiple Where and Having clauses are added to the query with Boolean operators connecting each expression. The default operator for both methods is AND which is the same as the and_ prefixed method. The OR operator can be specified by prefixing the methods with or_. Where and Having clauses can be nested or grouped by post fixing either method with _open and then followed by a method with a _close. 
-
-    $query = DB::select()->from('users')
-        ->where_open()
-            ->or_where('id', 'IN', $expired)
-            ->and_where_open()
-                ->where('last_login', '<=', $last_month)
-                ->or_where('last_login', 'IS', NULL)
-            ->and_where_close()
-        ->where_close()
-        ->and_where('removed','IS', NULL);
-
-This will generate the following query:
-
-    SELECT * FROM `users` WHERE ( `id` IN (1, 2, 3, 5) OR ( `last_login` <= 1276020805 OR `last_login` IS NULL ) ) AND `removed` IS NULL 
-
-### Database Expressions
-
-There are cases were you need a complex expression or other database functions, which you don't want the Query Builder to try and escape. In these cases, you will need to use a database expression created with [DB::expr].  **A database expression is taken as direct input and no escaping is performed.**
-
-    $query = DB::update('users')->set(array('login_count' => DB::expr('login_count + 1')))->where('id', '=', $id);
-
-This will generate the following query, assuming `$id = 45`:
-
-    UPDATE `users` SET `login_count` = `login_count` + 1 WHERE `id` = 45
-
-Another example to calculate the distance of two geographical points:
-
-    $query = DB::select(array(DB::expr('degrees(acos(sin(radians('.$lat.')) * sin(radians(`latitude`)) + cos(radians('.$lat.')) * cos(radians(`latitude`)) * cos(radians(abs('.$lng.' - `longitude`))))) * 69.172'), 'distance'))->from('locations');
-
-[!!] You must validate or escape any user input inside of DB::expr as it will obviously not be escaped it for you.
-
-## Executing
-
-Once you are done building, you can execute the query using `execute()` and use [the results](results).
-
-    $result = $query->execute();
-
-To use a different database [config group](config) pass either the name or the config object to `execute()`.
-
-	$result = $query->execute('config_name')

+ 0 - 67
frameworks/PHP/php-kohana/modules/database/guide/database/query/parameterized.md

@@ -1,67 +0,0 @@
-# Parameterized Statements
-
-Using parameterized statements allows you to write SQL queries manually while still escaping the query values automatically to prevent [SQL injection](http://wikipedia.org/wiki/SQL_Injection). Creating a query is simple:
-
-    $query = DB::query(Database::SELECT, 'SELECT * FROM users WHERE username = :user');
-
-The [DB::query] method is just a shortcut that creates a new [Database_Query] class for us, to allow method chaining. The query contains a `:user` parameter, which we will get to in a second.
-
-The first parameter of [DB::query] is the type of query.  It should be `Database::SELECT`, `Database::INSERT`, `Database::UPDATE`, or `Database::DELETE`.  This is done for compatibility reasons for drivers, and to easily determine what `execute()` should return.
-
-The second parameter is the query itself.  Rather than trying to concatenate your query and variables together, you should make use of [Database_Query::param].  This will make your queries much easier to mantain, and will escape the values to prevent [SQL injection](http://wikipedia.org/wiki/SQL_Injection). 
-
-## Parameters
-
-Our example query earlier contains a `:user` parameter, which we can assign to a value using [Database_Query::param] like so:
-
-    $query->param(':user', 'john');
-
-[!!] Parameter names can be any unique string, as they are replaced using [strtr](http://php.net/strtr). It is highly recommended to **not** use dollars signs as parameter names to prevent confusion.  Colons are commonly used.
-
-You can also update the `:user` parameter by calling [Database_Query::param] again:
-
-    $query->param(':user', $_GET['search']);
-
-If you want to set multiple parameters at once, you can use [Database_Query::parameters].
-	
-	$query = DB::query(Database::SELECT, 'SELECT * FROM users WHERE username = :user AND status = :status');
-
-	$query->parameters(array(
-		':user' => 'john',
-		':status' => 'active',
-	));
-
-It is also possible to bind a parameter to a variable, using a [variable reference]((http://php.net/language.references.whatdo)). This can be extremely useful when running the same query many times:
-
-    $query = DB::query(Database::INSERT, 'INSERT INTO users (username, password) VALUES (:user, :pass)')
-        ->bind(':user', $username)
-        ->bind(':pass', $password);
-
-    foreach ($new_users as $username => $password)
-    {
-        $query->execute();
-    }
-
-In the above example, the variables `$username` and `$password` are changed for every loop of the `foreach` statement. When the parameter changes, it effectively changes the `:user` and `:pass` query parameters. Careful parameter binding can save a lot of code when it is used properly.
-
-The only difference between `param()` and `bind()` is that `bind()` passes the variable by reference rather than by assignment (copied), so future changes to the variable can be "seen" by the query. 
-
-[!!] Although all parameters are escaped to prevent SQL injection, it is still a good idea to validate/sanitize your input.
-
-## Display the raw query
-
-If you want to display the SQL that will be executed, you can simply echo the query:
-
-    echo $query;
-    // Should display:
-    // SELECT * FROM users WHERE username = 'john'
-
-## Executing
-
-Once you have assigned something to each of the parameters, you can execute the query using `execute()` and use [the results](results).
-
-    $result = $query->execute();
-
-To use a different database [config group](config) pass either the name or the config object to `execute()`.
-
-	$result = $query->execute('config_name')

+ 0 - 105
frameworks/PHP/php-kohana/modules/database/guide/database/results.md

@@ -1,105 +0,0 @@
-# Results
-
-## Execute
-
-Once you have a query object built, either through a parameterized statement or through the builder, you must then `execute()` the query and retrieve the results. Depending on the query type used, the results returned will vary. 
-
-## Select
-
-[DB::select] will return a [Database_Result] object which you can then iterate over. This example shows how you can iterate through the [Database_Result] using a foreach.
-
-	$results = DB::select()->from('users')->where('verified', '=', 0)->execute();
-	foreach($results as $user)
-	{
-		// Send reminder email to $user['email']
-		echo $user['email']." needs to verify his/her account\n";
-	}
-
-### Select - `as_object()` and `as_assoc()`
-
-When iterating over a result set, the default type will be an associative array with the column names or aliases as the keys. As an option, before calling `execute()`, you can specify to return the result rows as an object by using the `as_object()` method. The `as_object()` method takes one parameter, the name of the class of your choice, but will default to TRUE which uses the `stdClass`. Here is the example again using `stdClass`.
-
-	$results = DB::select()->from('users')->where('verified', '=', 0)->as_object()->execute();
-	foreach($results as $user)
-	{
-		// Send reminder email to $user->email
-		echo $user->email." needs to verify his/her account\n";
-	}
-
-[!!] The method `as_assoc()` will remove the object name and return the results set back to an associative array. Since this is the default, this method is seldom required.
-
-### Select - `as_array()`
-
-Sometimes you will require the results as a pure array rather than as an object. The `Database_Result` method `as_array()` will return an array of all rows. 
-
-	$results = DB::select('id', 'email')->from('users')->execute();
-	$users = $results->as_array();
-	foreach($users as $user)
-	{
-		echo 'User ID: '.$user['id'];
-		echo 'User Email: '.$user['email'];
-	}
-
-It also accepts two parameters that can be very helpful: `$key` and `$value`. When passing a value to `$key` you will index the resulting array by the column specified.
-
-	$results = DB::select('id', 'email')->from('users')->execute();
-	$users = $results->as_array('id');
-	foreach($users as $id => $user)
-	{
-		echo 'User ID: '.$id;
-		echo 'User Email: '.$user['email'];
-	}
-
-The second parameter, `$value`, will reference the column specified and return that value rather than the whole row.  This is particularly useful when making `<select>` dropdowns.
-
-	$results = DB::select('id', 'name')->from('users')->execute();
-	$users = $results->as_array('id','name');
-	// Show a dropdown with all users in it.
-	echo Form::select('author', $users)
-
-To return a non-associative array, leave `$key` as NULL and just pass a `$value`.
-
-	$results = DB::select('email')->from('users')->execute();
-	$users = $results->as_array(NULL, 'email');
-	foreach($users as $email)
-	{
-		echo 'User Email: '.$email;
-	}
-
-### Select - `get()`
-
-Sometime you only want a single value from a query. The `get()` method returns the value of the named column from the current row. The second parameter, `$default`, is used to supply a default value when the result is NULL.
-
-	$total_users = DB::select(array(DB::expr('COUNT(`username`)'), 'total_users'))->from('users')->execute()->get('total_users', 0);
-
-### Select - `cached()`
-
-The mysql database driver returns a `Database_Result` that works with a MySQL Resource data type. Since this resource lives outside of PHP environment, it can't be serialized which means it also can't be cached. To get around this the `Database_Result` object has the `cached()` method that returns a `Database_Result_Cached` object of the result set. The `Database_Result_Cached` can be serialized and cached, but can take up more memory. 
-
-[!!] NOTE: Currently, the PDO diver always returns a class of `Database_Result_Cached`, so `cached()` just returns itself.
-
-The `cached()` function doesn't actually do any caching, it simply returns the result in a way that can be serialized and cached.  You will need to use the [Cache Module](../cache) or some other caching method.
-
-### Select - `count()`
-
-The `Database_Result` object implements the `Countable` Interface. The method `count()` returns the total row count in the result set. 
-
-[!!] NOTE: This is the count of the current result set, not a count of how many records are in the database. This is important to point out especially when using `limit()` and `offset()` in your query.
-
-[!!] For a complete list of methods available when working with a result set see [Database_Result].
-
-## Insert
-
-[DB::insert] returns an array of two values: the last insert id and the number of affected rows.
-	
-	$insert = DB::insert('tools')
-		->columns(array('name', 'model', 'description'))
-		->values(array('Skil 3400 10" Table Saw', '3400', 'Powerful 15 amp motor; weighs just 54-pounds'));
-		
-	list($insert_id, $affected_rows) = $insert->execute();
-
-## Update & Delete
-
-[DB::update] and [DB::delete] both return the number of affected rows as an integer.
-
-	$rows_deleted = DB::delete('tools')->where('model', 'like', '3400')->execute();

+ 0 - 49
frameworks/PHP/php-kohana/modules/orm/auth-schema-mysql.sql

@@ -1,49 +0,0 @@
-CREATE TABLE IF NOT EXISTS `roles` (
-  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
-  `name` varchar(32) NOT NULL,
-  `description` varchar(255) NOT NULL,
-  PRIMARY KEY  (`id`),
-  UNIQUE KEY `uniq_name` (`name`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
-
-INSERT INTO `roles` (`id`, `name`, `description`) VALUES(1, 'login', 'Login privileges, granted after account confirmation');
-INSERT INTO `roles` (`id`, `name`, `description`) VALUES(2, 'admin', 'Administrative user, has access to everything.');
-
-CREATE TABLE IF NOT EXISTS `roles_users` (
-  `user_id` int(10) UNSIGNED NOT NULL,
-  `role_id` int(10) UNSIGNED NOT NULL,
-  PRIMARY KEY  (`user_id`,`role_id`),
-  KEY `fk_role_id` (`role_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE IF NOT EXISTS `users` (
-  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
-  `email` varchar(254) NOT NULL,
-  `username` varchar(32) NOT NULL DEFAULT '',
-  `password` varchar(64) NOT NULL,
-  `logins` int(10) UNSIGNED NOT NULL DEFAULT '0',
-  `last_login` int(10) UNSIGNED,
-  PRIMARY KEY  (`id`),
-  UNIQUE KEY `uniq_username` (`username`),
-  UNIQUE KEY `uniq_email` (`email`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
-
-CREATE TABLE IF NOT EXISTS `user_tokens` (
-  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
-  `user_id` int(11) UNSIGNED NOT NULL,
-  `user_agent` varchar(40) NOT NULL,
-  `token` varchar(40) NOT NULL,
-  `created` int(10) UNSIGNED NOT NULL,
-  `expires` int(10) UNSIGNED NOT NULL,
-  PRIMARY KEY  (`id`),
-  UNIQUE KEY `uniq_token` (`token`),
-  KEY `fk_user_id` (`user_id`),
-  KEY `expires` (`expires`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
-
-ALTER TABLE `roles_users`
-  ADD CONSTRAINT `roles_users_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
-  ADD CONSTRAINT `roles_users_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE;
-
-ALTER TABLE `user_tokens`
-  ADD CONSTRAINT `user_tokens_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

+ 0 - 53
frameworks/PHP/php-kohana/modules/orm/auth-schema-postgresql.sql

@@ -1,53 +0,0 @@
-CREATE TABLE roles
-(
-  id serial,
-  "name" varchar(32) NOT NULL,
-  description text NOT NULL,
-  CONSTRAINT roles_id_pkey PRIMARY KEY (id),
-  CONSTRAINT roles_name_key UNIQUE (name)
-);
-
-CREATE TABLE roles_users
-(
-  user_id integer,
-  role_id integer
-);
-
-CREATE TABLE users
-(
-  id serial,
-  email varchar(254) NOT NULL,
-  username varchar(32) NOT NULL,
-  "password" varchar(64) NOT NULL,
-  logins integer NOT NULL DEFAULT 0,
-  last_login integer,
-  CONSTRAINT users_id_pkey PRIMARY KEY (id),
-  CONSTRAINT users_username_key UNIQUE (username),
-  CONSTRAINT users_email_key UNIQUE (email),
-  CONSTRAINT users_logins_check CHECK (logins >= 0)
-);
-
-CREATE TABLE user_tokens
-(
-  id serial,
-  user_id integer NOT NULL,
-  user_agent varchar(40) NOT NULL,
-  token character varying(32) NOT NULL,
-  created integer NOT NULL,
-  expires integer NOT NULL,
-  CONSTRAINT user_tokens_id_pkey PRIMARY KEY (id),
-  CONSTRAINT user_tokens_token_key UNIQUE (token)
-);
-
-CREATE INDEX user_id_idx ON roles_users (user_id);
-CREATE INDEX role_id_idx ON roles_users (role_id);
-
-ALTER TABLE roles_users
-  ADD CONSTRAINT user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
-  ADD CONSTRAINT role_id_fkey FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE;
-
-ALTER TABLE user_tokens
-  ADD CONSTRAINT user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
-
-INSERT INTO roles (name, description) VALUES ('login', 'Login privileges, granted after account confirmation');
-INSERT INTO roles (name, description) VALUES ('admin', 'Administrative user, has access to everything.');

+ 0 - 3
frameworks/PHP/php-kohana/modules/orm/classes/Auth/ORM.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-
-class Auth_ORM extends Kohana_Auth_ORM { }

+ 0 - 291
frameworks/PHP/php-kohana/modules/orm/classes/Kohana/Auth/ORM.php

@@ -1,291 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-/**
- * ORM Auth driver.
- *
- * @package    Kohana/Auth
- * @author     Kohana Team
- * @copyright  (c) 2007-2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Kohana_Auth_ORM extends Auth {
-
-	/**
-	 * Checks if a session is active.
-	 *
-	 * @param   mixed    $role Role name string, role ORM object, or array with role names
-	 * @return  boolean
-	 */
-	public function logged_in($role = NULL)
-	{
-		// Get the user from the session
-		$user = $this->get_user();
-
-		if ( ! $user)
-			return FALSE;
-
-		if ($user instanceof Model_User AND $user->loaded())
-		{
-			// If we don't have a roll no further checking is needed
-			if ( ! $role)
-				return TRUE;
-
-			if (is_array($role))
-			{
-				// Get all the roles
-				$roles = ORM::factory('Role')
-							->where('name', 'IN', $role)
-							->find_all()
-							->as_array(NULL, 'id');
-
-				// Make sure all the roles are valid ones
-				if (count($roles) !== count($role))
-					return FALSE;
-			}
-			else
-			{
-				if ( ! is_object($role))
-				{
-					// Load the role
-					$roles = ORM::factory('Role', array('name' => $role));
-
-					if ( ! $roles->loaded())
-						return FALSE;
-				}
-			}
-
-			return $user->has('roles', $roles);
-		}
-	}
-
-	/**
-	 * Logs a user in.
-	 *
-	 * @param   string   $username
-	 * @param   string   $password
-	 * @param   boolean  $remember  enable autologin
-	 * @return  boolean
-	 */
-	protected function _login($user, $password, $remember)
-	{
-		if ( ! is_object($user))
-		{
-			$username = $user;
-
-			// Load the user
-			$user = ORM::factory('User');
-			$user->where($user->unique_key($username), '=', $username)->find();
-		}
-
-		if (is_string($password))
-		{
-			// Create a hashed password
-			$password = $this->hash($password);
-		}
-
-		// If the passwords match, perform a login
-		if ($user->has('roles', ORM::factory('Role', array('name' => 'login'))) AND $user->password === $password)
-		{
-			if ($remember === TRUE)
-			{
-				// Token data
-				$data = array(
-					'user_id'    => $user->pk(),
-					'expires'    => time() + $this->_config['lifetime'],
-					'user_agent' => sha1(Request::$user_agent),
-				);
-
-				// Create a new autologin token
-				$token = ORM::factory('User_Token')
-							->values($data)
-							->create();
-
-				// Set the autologin cookie
-				Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
-			}
-
-			// Finish the login
-			$this->complete_login($user);
-
-			return TRUE;
-		}
-
-		// Login failed
-		return FALSE;
-	}
-
-	/**
-	 * Forces a user to be logged in, without specifying a password.
-	 *
-	 * @param   mixed    $user                    username string, or user ORM object
-	 * @param   boolean  $mark_session_as_forced  mark the session as forced
-	 * @return  boolean
-	 */
-	public function force_login($user, $mark_session_as_forced = FALSE)
-	{
-		if ( ! is_object($user))
-		{
-			$username = $user;
-
-			// Load the user
-			$user = ORM::factory('User');
-			$user->where($user->unique_key($username), '=', $username)->find();
-		}
-
-		if ($mark_session_as_forced === TRUE)
-		{
-			// Mark the session as forced, to prevent users from changing account information
-			$this->_session->set('auth_forced', TRUE);
-		}
-
-		// Run the standard completion
-		$this->complete_login($user);
-	}
-
-	/**
-	 * Logs a user in, based on the authautologin cookie.
-	 *
-	 * @return  mixed
-	 */
-	public function auto_login()
-	{
-		if ($token = Cookie::get('authautologin'))
-		{
-			// Load the token and user
-			$token = ORM::factory('User_Token', array('token' => $token));
-
-			if ($token->loaded() AND $token->user->loaded())
-			{
-				if ($token->user_agent === sha1(Request::$user_agent))
-				{
-					// Save the token to create a new unique token
-					$token->save();
-
-					// Set the new token
-					Cookie::set('authautologin', $token->token, $token->expires - time());
-
-					// Complete the login with the found data
-					$this->complete_login($token->user);
-
-					// Automatic login was successful
-					return $token->user;
-				}
-
-				// Token is invalid
-				$token->delete();
-			}
-		}
-
-		return FALSE;
-	}
-
-	/**
-	 * Gets the currently logged in user from the session (with auto_login check).
-	 * Returns $default if no user is currently logged in.
-	 *
-	 * @param   mixed    $default to return in case user isn't logged in
-	 * @return  mixed
-	 */
-	public function get_user($default = NULL)
-	{
-		$user = parent::get_user($default);
-
-		if ($user === $default)
-		{
-			// check for "remembered" login
-			if (($user = $this->auto_login()) === FALSE)
-				return $default;
-		}
-
-		return $user;
-	}
-
-	/**
-	 * Log a user out and remove any autologin cookies.
-	 *
-	 * @param   boolean  $destroy     completely destroy the session
-	 * @param	boolean  $logout_all  remove all tokens for user
-	 * @return  boolean
-	 */
-	public function logout($destroy = FALSE, $logout_all = FALSE)
-	{
-		// Set by force_login()
-		$this->_session->delete('auth_forced');
-
-		if ($token = Cookie::get('authautologin'))
-		{
-			// Delete the autologin cookie to prevent re-login
-			Cookie::delete('authautologin');
-
-			// Clear the autologin token from the database
-			$token = ORM::factory('User_Token', array('token' => $token));
-
-			if ($token->loaded() AND $logout_all)
-			{
-				// Delete all user tokens. This isn't the most elegant solution but does the job
-				$tokens = ORM::factory('User_Token')->where('user_id','=',$token->user_id)->find_all();
-				
-				foreach ($tokens as $_token)
-				{
-					$_token->delete();
-				}
-			}
-			elseif ($token->loaded())
-			{
-				$token->delete();
-			}
-		}
-
-		return parent::logout($destroy);
-	}
-
-	/**
-	 * Get the stored password for a username.
-	 *
-	 * @param   mixed   $user  username string, or user ORM object
-	 * @return  string
-	 */
-	public function password($user)
-	{
-		if ( ! is_object($user))
-		{
-			$username = $user;
-
-			// Load the user
-			$user = ORM::factory('User');
-			$user->where($user->unique_key($username), '=', $username)->find();
-		}
-
-		return $user->password;
-	}
-
-	/**
-	 * Complete the login for a user by incrementing the logins and setting
-	 * session data: user_id, username, roles.
-	 *
-	 * @param   object  $user  user ORM object
-	 * @return  void
-	 */
-	protected function complete_login($user)
-	{
-		$user->complete_login();
-
-		return parent::complete_login($user);
-	}
-
-	/**
-	 * Compare password with original (hashed). Works for current (logged in) user
-	 *
-	 * @param   string  $password
-	 * @return  boolean
-	 */
-	public function check_password($password)
-	{
-		$user = $this->get_user();
-
-		if ( ! $user)
-			return FALSE;
-
-		return ($this->hash($password) === $user->password);
-	}
-
-} // End Auth ORM

+ 0 - 2354
frameworks/PHP/php-kohana/modules/orm/classes/Kohana/ORM.php

@@ -1,2354 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * [Object Relational Mapping][ref-orm] (ORM) is a method of abstracting database
- * access to standard PHP calls. All table rows are represented as model objects,
- * with object properties representing row data. ORM in Kohana generally follows
- * the [Active Record][ref-act] pattern.
- *
- * [ref-orm]: http://wikipedia.org/wiki/Object-relational_mapping
- * [ref-act]: http://wikipedia.org/wiki/Active_record
- *
- * @package    Kohana/ORM
- * @author     Kohana Team
- * @copyright  (c) 2007-2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Kohana_ORM extends Model implements serializable {
-
-	/**
-	 * Stores column information for ORM models
-	 * @var array
-	 */
-	protected static $_column_cache = array();
-	
-	/**
-	 * Initialization storage for ORM models
-	 * @var array
-	 */
-	protected static $_init_cache = array();
-
-	/**
-	 * Creates and returns a new model. 
-	 * Model name must be passed with its' original casing, e.g.
-	 * 
-	 *    $model = ORM::factory('User_Token');
-	 *
-	 * @chainable
-	 * @param   string  $model  Model name
-	 * @param   mixed   $id     Parameter for find()
-	 * @return  ORM
-	 */
-	public static function factory($model, $id = NULL)
-	{
-		// Set class name
-		$model = 'Model_'.$model;
-
-		return new $model($id);
-	}
-
-	/**
-	 * "Has one" relationships
-	 * @var array
-	 */
-	protected $_has_one = array();
-
-	/**
-	 * "Belongs to" relationships
-	 * @var array
-	 */
-	protected $_belongs_to = array();
-
-	/**
-	 * "Has many" relationships
-	 * @var array
-	 */
-	protected $_has_many = array();
-
-	/**
-	 * Relationships that should always be joined
-	 * @var array
-	 */
-	protected $_load_with = array();
-
-	/**
-	 * Validation object created before saving/updating
-	 * @var Validation
-	 */
-	protected $_validation = NULL;
-
-	/**
-	 * Current object
-	 * @var array
-	 */
-	protected $_object = array();
-
-	/**
-	 * @var array
-	 */
-	protected $_changed = array();
-
-	/**
-	 * @var array
-	 */
-	protected $_original_values = array();
-
-	/**
-	 * @var array
-	 */
-	protected $_related = array();
-
-	/**
-	 * @var bool
-	 */
-	protected $_valid = FALSE;
-
-	/**
-	 * @var bool
-	 */
-	protected $_loaded = FALSE;
-
-	/**
-	 * @var bool
-	 */
-	protected $_saved = FALSE;
-
-	/**
-	 * @var array
-	 */
-	protected $_sorting;
-
-	/**
-	 * Foreign key suffix
-	 * @var string
-	 */
-	protected $_foreign_key_suffix = '_id';
-
-	/**
-	 * Model name
-	 * @var string
-	 */
-	protected $_object_name;
-
-	/**
-	 * Plural model name
-	 * @var string
-	 */
-	protected $_object_plural;
-
-	/**
-	 * Table name
-	 * @var string
-	 */
-	protected $_table_name;
-
-	/**
-	 * Table columns
-	 * @var array
-	 */
-	protected $_table_columns;
-
-	/**
-	 * Auto-update columns for updates
-	 * @var string
-	 */
-	protected $_updated_column = NULL;
-
-	/**
-	 * Auto-update columns for creation
-	 * @var string
-	 */
-	protected $_created_column = NULL;
-
-	/**
-	 * Auto-serialize and unserialize columns on get/set
-	 * @var array
-	 */
-	protected $_serialize_columns = array();
-
-	/**
-	 * Table primary key
-	 * @var string
-	 */
-	protected $_primary_key = 'id';
-
-	/**
-	 * Primary key value
-	 * @var mixed
-	 */
-	protected $_primary_key_value;
-
-	/**
-	 * Model configuration, table names plural?
-	 * @var bool
-	 */
-	protected $_table_names_plural = TRUE;
-
-	/**
-	 * Model configuration, reload on wakeup?
-	 * @var bool
-	 */
-	protected $_reload_on_wakeup = TRUE;
-
-	/**
-	 * Database Object
-	 * @var Database
-	 */
-	protected $_db = NULL;
-
-	/**
-	 * Database config group
-	 * @var String
-	 */
-	protected $_db_group = NULL;
-
-	/**
-	 * Database methods applied
-	 * @var array
-	 */
-	protected $_db_applied = array();
-
-	/**
-	 * Database methods pending
-	 * @var array
-	 */
-	protected $_db_pending = array();
-
-	/**
-	 * Reset builder
-	 * @var bool
-	 */
-	protected $_db_reset = TRUE;
-
-	/**
-	 * Database query builder
-	 * @var Database_Query_Builder_Select
-	 */
-	protected $_db_builder;
-
-	/**
-	 * With calls already applied
-	 * @var array
-	 */
-	protected $_with_applied = array();
-
-	/**
-	 * Data to be loaded into the model from a database call cast
-	 * @var array
-	 */
-	protected $_cast_data = array();
-
-	/**
-	 * The message filename used for validation errors.
-	 * Defaults to ORM::$_object_name
-	 * @var string
-	 */
-	protected $_errors_filename = NULL;
-
-	/**
-	 * Constructs a new model and loads a record if given
-	 *
-	 * @param   mixed $id Parameter for find or object to load
-	 */
-	public function __construct($id = NULL)
-	{
-		$this->_initialize();
-
-		if ($id !== NULL)
-		{
-			if (is_array($id))
-			{
-				foreach ($id as $column => $value)
-				{
-					// Passing an array of column => values
-					$this->where($column, '=', $value);
-				}
-
-				$this->find();
-			}
-			else
-			{
-				// Passing the primary key
-				$this->where($this->_object_name.'.'.$this->_primary_key, '=', $id)->find();
-			}
-		}
-		elseif ( ! empty($this->_cast_data))
-		{
-			// Load preloaded data from a database call cast
-			$this->_load_values($this->_cast_data);
-
-			$this->_cast_data = array();
-		}
-	}
-
-	/**
-	 * Prepares the model database connection, determines the table name,
-	 * and loads column information.
-	 *
-	 * @return void
-	 */
-	protected function _initialize()
-	{
-		// Set the object name and plural name
-		$this->_object_name = strtolower(substr(get_class($this), 6));
-		
-		// Check if this model has already been initialized
-		if ( ! $init = Arr::get(ORM::$_init_cache, $this->_object_name, FALSE))
-		{
-			$init = array(
-				'_belongs_to' => array(),
-				'_has_one'    => array(),
-				'_has_many'   => array(),
-			);
-			
-			// Set the object plural name if none predefined
-			if ( ! isset($this->_object_plural))
-			{
-				$init['_object_plural'] = Inflector::plural($this->_object_name);
-			}
-
-			if ( ! $this->_errors_filename)
-			{
-				$init['_errors_filename'] = $this->_object_name;
-			}
-
-			if ( ! is_object($this->_db))
-			{
-				// Get database instance
-				$init['_db'] = Database::instance($this->_db_group);
-			}
-
-			if (empty($this->_table_name))
-			{
-				// Table name is the same as the object name
-				$init['_table_name'] = $this->_object_name;
-
-				if ($this->_table_names_plural === TRUE)
-				{
-					// Make the table name plural
-					$init['_table_name'] = Arr::get($init, '_object_plural', $this->_object_plural);
-				}
-			}
-			
-			$defaults = array();
-
-			foreach ($this->_belongs_to as $alias => $details)
-			{
-				if ( ! isset($details['model']))
-				{
-					$defaults['model'] = str_replace(' ', '_', ucwords(str_replace('_', ' ', $alias)));
-				}
-				
-				$defaults['foreign_key'] = $alias.$this->_foreign_key_suffix;
-
-				$init['_belongs_to'][$alias] = array_merge($defaults, $details);
-			}
-
-			foreach ($this->_has_one as $alias => $details)
-			{
-				if ( ! isset($details['model']))
-				{
-					$defaults['model'] = str_replace(' ', '_', ucwords(str_replace('_', ' ', $alias)));
-				}
-				
-				$defaults['foreign_key'] = $this->_object_name.$this->_foreign_key_suffix;
-
-				$init['_has_one'][$alias] = array_merge($defaults, $details);
-			}
-
-			foreach ($this->_has_many as $alias => $details)
-			{
-				if ( ! isset($details['model']))
-				{
-					$defaults['model'] = str_replace(' ', '_', ucwords(str_replace('_', ' ', Inflector::singular($alias))));
-				}
-				
-				$defaults['foreign_key'] = $this->_object_name.$this->_foreign_key_suffix;
-				$defaults['through'] = NULL;
-				
-				if ( ! isset($details['far_key']))
-				{
-					$defaults['far_key'] = Inflector::singular($alias).$this->_foreign_key_suffix;
-				}
-				
-				$init['_has_many'][$alias] = array_merge($defaults, $details);
-			}
-			
-			ORM::$_init_cache[$this->_object_name] = $init;
-		}
-		
-		// Assign initialized properties to the current object
-		foreach ($init as $property => $value)
-		{
-			$this->{$property} = $value;
-		}
-		
-		// Load column information
-		$this->reload_columns();
-
-		// Clear initial model state
-		$this->clear();
-	}
-
-	/**
-	 * Initializes validation rules, and labels
-	 *
-	 * @return void
-	 */
-	protected function _validation()
-	{
-		// Build the validation object with its rules
-		$this->_validation = Validation::factory($this->_object)
-			->bind(':model', $this)
-			->bind(':original_values', $this->_original_values)
-			->bind(':changed', $this->_changed);
-
-		foreach ($this->rules() as $field => $rules)
-		{
-			$this->_validation->rules($field, $rules);
-		}
-
-		// Use column names by default for labels
-		$columns = array_keys($this->_table_columns);
-
-		// Merge user-defined labels
-		$labels = array_merge(array_combine($columns, $columns), $this->labels());
-
-		foreach ($labels as $field => $label)
-		{
-			$this->_validation->label($field, $label);
-		}
-	}
-
-	/**
-	 * Reload column definitions.
-	 *
-	 * @chainable
-	 * @param   boolean $force Force reloading
-	 * @return  ORM
-	 */
-	public function reload_columns($force = FALSE)
-	{
-		if ($force === TRUE OR empty($this->_table_columns))
-		{
-			if (isset(ORM::$_column_cache[$this->_object_name]))
-			{
-				// Use cached column information
-				$this->_table_columns = ORM::$_column_cache[$this->_object_name];
-			}
-			else
-			{
-				// Grab column information from database
-				$this->_table_columns = $this->list_columns();
-
-				// Load column cache
-				ORM::$_column_cache[$this->_object_name] = $this->_table_columns;
-			}
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Unloads the current object and clears the status.
-	 *
-	 * @chainable
-	 * @return ORM
-	 */
-	public function clear()
-	{
-		// Create an array with all the columns set to NULL
-		$values = array_combine(array_keys($this->_table_columns), array_fill(0, count($this->_table_columns), NULL));
-
-		// Replace the object and reset the object status
-		$this->_object = $this->_changed = $this->_related = $this->_original_values = array();
-
-		// Replace the current object with an empty one
-		$this->_load_values($values);
-
-		// Reset primary key
-		$this->_primary_key_value = NULL;
-		
-		// Reset the loaded state
-		$this->_loaded = FALSE;
-
-		$this->reset();
-
-		return $this;
-	}
-
-	/**
-	 * Reloads the current object from the database.
-	 *
-	 * @chainable
-	 * @return ORM
-	 */
-	public function reload()
-	{
-		$primary_key = $this->pk();
-
-		// Replace the object and reset the object status
-		$this->_object = $this->_changed = $this->_related = $this->_original_values = array();
-
-		// Only reload the object if we have one to reload
-		if ($this->_loaded)
-			return $this->clear()
-				->where($this->_object_name.'.'.$this->_primary_key, '=', $primary_key)
-				->find();
-		else
-			return $this->clear();
-	}
-
-	/**
-	 * Checks if object data is set.
-	 *
-	 * @param  string $column Column name
-	 * @return boolean
-	 */
-	public function __isset($column)
-	{
-		return (isset($this->_object[$column]) OR
-			isset($this->_related[$column]) OR
-			isset($this->_has_one[$column]) OR
-			isset($this->_belongs_to[$column]) OR
-			isset($this->_has_many[$column]));
-	}
-
-	/**
-	 * Unsets object data.
-	 *
-	 * @param  string $column Column name
-	 * @return void
-	 */
-	public function __unset($column)
-	{
-		unset($this->_object[$column], $this->_changed[$column], $this->_related[$column]);
-	}
-
-	/**
-	 * Displays the primary key of a model when it is converted to a string.
-	 *
-	 * @return string
-	 */
-	public function __toString()
-	{
-		return (string) $this->pk();
-	}
-
-	/**
-	 * Allows serialization of only the object data and state, to prevent
-	 * "stale" objects being unserialized, which also requires less memory.
-	 *
-	 * @return string
-	 */
-	public function serialize()
-	{
-		// Store only information about the object
-		foreach (array('_primary_key_value', '_object', '_changed', '_loaded', '_saved', '_sorting', '_original_values') as $var)
-		{
-			$data[$var] = $this->{$var};
-		}
-
-		return serialize($data);
-	}
-
-	/**
-	 * Check whether the model data has been modified.
-	 * If $field is specified, checks whether that field was modified.
-	 *
-	 * @param string  $field  field to check for changes
-	 * @return  bool  Whether or not the field has changed
-	 */
-	public function changed($field = NULL)
-	{
-		return ($field === NULL)
-			? $this->_changed
-			: Arr::get($this->_changed, $field);
-	}
-
-	/**
-	 * Prepares the database connection and reloads the object.
-	 *
-	 * @param string $data String for unserialization
-	 * @return  void
-	 */
-	public function unserialize($data)
-	{
-		// Initialize model
-		$this->_initialize();
-
-		foreach (unserialize($data) as $name => $var)
-		{
-			$this->{$name} = $var;
-		}
-
-		if ($this->_reload_on_wakeup === TRUE)
-		{
-			// Reload the object
-			$this->reload();
-		}
-	}
-
-	/**
-	 * Handles retrieval of all model values, relationships, and metadata.
-	 * [!!] This should not be overridden.
-	 *
-	 * @param   string $column Column name
-	 * @return  mixed
-	 */
-	public function __get($column)
-	{
-		return $this->get($column);
-	}
-	
-	/**
-	 * Handles getting of column
-	 * Override this method to add custom get behavior
-	 *
-	 * @param   string $column Column name
-	 * @throws Kohana_Exception
-	 * @return mixed
-	 */
-	public function get($column)
-	{
-		if (array_key_exists($column, $this->_object))
-		{
-			return (in_array($column, $this->_serialize_columns))
-				? $this->_unserialize_value($this->_object[$column])
-				: $this->_object[$column];
-		}
-		elseif (isset($this->_related[$column]))
-		{
-			// Return related model that has already been fetched
-			return $this->_related[$column];
-		}
-		elseif (isset($this->_belongs_to[$column]))
-		{
-			$model = $this->_related($column);
-
-			// Use this model's column and foreign model's primary key
-			$col = $model->_object_name.'.'.$model->_primary_key;
-			$val = $this->_object[$this->_belongs_to[$column]['foreign_key']];
-
-			// Make sure we don't run WHERE "AUTO_INCREMENT column" = NULL queries. This would
-			// return the last inserted record instead of an empty result.
-			// See: http://mysql.localhost.net.ar/doc/refman/5.1/en/server-session-variables.html#sysvar_sql_auto_is_null
-			if ($val !== NULL)
-			{
-				$model->where($col, '=', $val)->find();
-			}
-
-			return $this->_related[$column] = $model;
-		}
-		elseif (isset($this->_has_one[$column]))
-		{
-			$model = $this->_related($column);
-
-			// Use this model's primary key value and foreign model's column
-			$col = $model->_object_name.'.'.$this->_has_one[$column]['foreign_key'];
-			$val = $this->pk();
-
-			$model->where($col, '=', $val)->find();
-
-			return $this->_related[$column] = $model;
-		}
-		elseif (isset($this->_has_many[$column]))
-		{
-			$model = ORM::factory($this->_has_many[$column]['model']);
-
-			if (isset($this->_has_many[$column]['through']))
-			{
-				// Grab has_many "through" relationship table
-				$through = $this->_has_many[$column]['through'];
-
-				// Join on through model's target foreign key (far_key) and target model's primary key
-				$join_col1 = $through.'.'.$this->_has_many[$column]['far_key'];
-				$join_col2 = $model->_object_name.'.'.$model->_primary_key;
-
-				$model->join($through)->on($join_col1, '=', $join_col2);
-
-				// Through table's source foreign key (foreign_key) should be this model's primary key
-				$col = $through.'.'.$this->_has_many[$column]['foreign_key'];
-				$val = $this->pk();
-			}
-			else
-			{
-				// Simple has_many relationship, search where target model's foreign key is this model's primary key
-				$col = $model->_object_name.'.'.$this->_has_many[$column]['foreign_key'];
-				$val = $this->pk();
-			}
-
-			return $model->where($col, '=', $val);
-		}
-		else
-		{
-			throw new Kohana_Exception('The :property property does not exist in the :class class',
-				array(':property' => $column, ':class' => get_class($this)));
-		}
-	}
-
-	/**
-	 * Base set method.
-	 * [!!] This should not be overridden.
-	 *
-	 * @param  string $column  Column name
-	 * @param  mixed  $value   Column value
-	 * @return void
-	 */
-	public function __set($column, $value)
-	{
-		$this->set($column, $value);
-	}
-
-	/**
-	 * Handles setting of columns
-	 * Override this method to add custom set behavior
-	 *
-	 * @param  string $column Column name
-	 * @param  mixed  $value  Column value
-	 * @throws Kohana_Exception
-	 * @return ORM
-	 */
-	public function set($column, $value)
-	{
-		if ( ! isset($this->_object_name))
-		{
-			// Object not yet constructed, so we're loading data from a database call cast
-			$this->_cast_data[$column] = $value;
-			
-			return $this;
-		}
-		
-		if (in_array($column, $this->_serialize_columns))
-		{
-			$value = $this->_serialize_value($value);
-		}
-
-		if (array_key_exists($column, $this->_object))
-		{
-			// Filter the data
-			$value = $this->run_filter($column, $value);
-
-			// See if the data really changed
-			if ($value !== $this->_object[$column])
-			{
-				$this->_object[$column] = $value;
-
-				// Data has changed
-				$this->_changed[$column] = $column;
-
-				// Object is no longer saved or valid
-				$this->_saved = $this->_valid = FALSE;
-			}
-		}
-		elseif (isset($this->_belongs_to[$column]))
-		{
-			// Update related object itself
-			$this->_related[$column] = $value;
-
-			// Update the foreign key of this model
-			$this->_object[$this->_belongs_to[$column]['foreign_key']] = ($value instanceof ORM)
-				? $value->pk()
-				: NULL;
-
-			$this->_changed[$column] = $this->_belongs_to[$column]['foreign_key'];
-		}
-		else
-		{
-			throw new Kohana_Exception('The :property: property does not exist in the :class: class',
-				array(':property:' => $column, ':class:' => get_class($this)));
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Set values from an array with support for one-one relationships.  This method should be used
-	 * for loading in post data, etc.
-	 *
-	 * @param  array $values   Array of column => val
-	 * @param  array $expected Array of keys to take from $values
-	 * @return ORM
-	 */
-	public function values(array $values, array $expected = NULL)
-	{
-		// Default to expecting everything except the primary key
-		if ($expected === NULL)
-		{
-			$expected = array_keys($this->_table_columns);
-
-			// Don't set the primary key by default
-			unset($values[$this->_primary_key]);
-		}
-
-		foreach ($expected as $key => $column)
-		{
-			if (is_string($key))
-			{
-				// isset() fails when the value is NULL (we want it to pass)
-				if ( ! array_key_exists($key, $values))
-					continue;
-
-				// Try to set values to a related model
-				$this->{$key}->values($values[$key], $column);
-			}
-			else
-			{
-				// isset() fails when the value is NULL (we want it to pass)
-				if ( ! array_key_exists($column, $values))
-					continue;
-
-				// Update the column, respects __set()
-				$this->$column = $values[$column];
-			}
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Returns the values of this object as an array, including any related one-one
-	 * models that have already been loaded using with()
-	 *
-	 * @return array
-	 */
-	public function as_array()
-	{
-		$object = array();
-
-		foreach ($this->_object as $column => $value)
-		{
-			// Call __get for any user processing
-			$object[$column] = $this->__get($column);
-		}
-
-		foreach ($this->_related as $column => $model)
-		{
-			// Include any related objects that are already loaded
-			$object[$column] = $model->as_array();
-		}
-
-		return $object;
-	}
-
-	/**
-	 * Binds another one-to-one object to this model.  One-to-one objects
-	 * can be nested using 'object1:object2' syntax
-	 *
-	 * @param  string $target_path Target model to bind to
-	 * @return ORM
-	 */
-	public function with($target_path)
-	{
-		if (isset($this->_with_applied[$target_path]))
-		{
-			// Don't join anything already joined
-			return $this;
-		}
-
-		// Split object parts
-		$aliases = explode(':', $target_path);
-		$target = $this;
-		foreach ($aliases as $alias)
-		{
-			// Go down the line of objects to find the given target
-			$parent = $target;
-			$target = $parent->_related($alias);
-
-			if ( ! $target)
-			{
-				// Can't find related object
-				return $this;
-			}
-		}
-
-		// Target alias is at the end
-		$target_alias = $alias;
-
-		// Pop-off top alias to get the parent path (user:photo:tag becomes user:photo - the parent table prefix)
-		array_pop($aliases);
-		$parent_path = implode(':', $aliases);
-
-		if (empty($parent_path))
-		{
-			// Use this table name itself for the parent path
-			$parent_path = $this->_object_name;
-		}
-		else
-		{
-			if ( ! isset($this->_with_applied[$parent_path]))
-			{
-				// If the parent path hasn't been joined yet, do it first (otherwise LEFT JOINs fail)
-				$this->with($parent_path);
-			}
-		}
-
-		// Add to with_applied to prevent duplicate joins
-		$this->_with_applied[$target_path] = TRUE;
-
-		// Use the keys of the empty object to determine the columns
-		foreach (array_keys($target->_object) as $column)
-		{
-			$name = $target_path.'.'.$column;
-			$alias = $target_path.':'.$column;
-
-			// Add the prefix so that load_result can determine the relationship
-			$this->select(array($name, $alias));
-		}
-
-		if (isset($parent->_belongs_to[$target_alias]))
-		{
-			// Parent belongs_to target, use target's primary key and parent's foreign key
-			$join_col1 = $target_path.'.'.$target->_primary_key;
-			$join_col2 = $parent_path.'.'.$parent->_belongs_to[$target_alias]['foreign_key'];
-		}
-		else
-		{
-			// Parent has_one target, use parent's primary key as target's foreign key
-			$join_col1 = $parent_path.'.'.$parent->_primary_key;
-			$join_col2 = $target_path.'.'.$parent->_has_one[$target_alias]['foreign_key'];
-		}
-
-		// Join the related object into the result
-		$this->join(array($target->_table_name, $target_path), 'LEFT')->on($join_col1, '=', $join_col2);
-
-		return $this;
-	}
-
-	/**
-	 * Initializes the Database Builder to given query type
-	 *
-	 * @param  integer $type Type of Database query
-	 * @return ORM
-	 */
-	protected function _build($type)
-	{
-		// Construct new builder object based on query type
-		switch ($type)
-		{
-			case Database::SELECT:
-				$this->_db_builder = DB::select();
-			break;
-			case Database::UPDATE:
-				$this->_db_builder = DB::update(array($this->_table_name, $this->_object_name));
-			break;
-			case Database::DELETE:
-				// Cannot use an alias for DELETE queries
-				$this->_db_builder = DB::delete($this->_table_name);
-		}
-
-		// Process pending database method calls
-		foreach ($this->_db_pending as $method)
-		{
-			$name = $method['name'];
-			$args = $method['args'];
-
-			$this->_db_applied[$name] = $name;
-
-			call_user_func_array(array($this->_db_builder, $name), $args);
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Finds and loads a single database row into the object.
-	 *
-	 * @chainable
-	 * @throws Kohana_Exception
-	 * @return ORM
-	 */
-	public function find()
-	{
-		if ($this->_loaded)
-			throw new Kohana_Exception('Method find() cannot be called on loaded objects');
-
-		if ( ! empty($this->_load_with))
-		{
-			foreach ($this->_load_with as $alias)
-			{
-				// Bind auto relationships
-				$this->with($alias);
-			}
-		}
-
-		$this->_build(Database::SELECT);
-
-		return $this->_load_result(FALSE);
-	}
-
-	/**
-	 * Finds multiple database rows and returns an iterator of the rows found.
-	 *
-	 * @throws Kohana_Exception
-	 * @return Database_Result
-	 */
-	public function find_all()
-	{
-		if ($this->_loaded)
-			throw new Kohana_Exception('Method find_all() cannot be called on loaded objects');
-
-		if ( ! empty($this->_load_with))
-		{
-			foreach ($this->_load_with as $alias)
-			{
-				// Bind auto relationships
-				$this->with($alias);
-			}
-		}
-
-		$this->_build(Database::SELECT);
-
-		return $this->_load_result(TRUE);
-	}
-
-	/**
-	 * Returns an array of columns to include in the select query. This method
-	 * can be overridden to change the default select behavior.
-	 *
-	 * @return array Columns to select
-	 */
-	protected function _build_select()
-	{
-		$columns = array();
-
-		foreach ($this->_table_columns as $column => $_)
-		{
-			$columns[] = array($this->_object_name.'.'.$column, $column);
-		}
-
-		return $columns;
-	}
-
-	/**
-	 * Loads a database result, either as a new record for this model, or as
-	 * an iterator for multiple rows.
-	 *
-	 * @chainable
-	 * @param  bool $multiple Return an iterator or load a single row
-	 * @return ORM|Database_Result
-	 */
-	protected function _load_result($multiple = FALSE)
-	{
-		$this->_db_builder->from(array($this->_table_name, $this->_object_name));
-
-		if ($multiple === FALSE)
-		{
-			// Only fetch 1 record
-			$this->_db_builder->limit(1);
-		}
-
-		// Select all columns by default
-		$this->_db_builder->select_array($this->_build_select());
-
-		if ( ! isset($this->_db_applied['order_by']) AND ! empty($this->_sorting))
-		{
-			foreach ($this->_sorting as $column => $direction)
-			{
-				if (strpos($column, '.') === FALSE)
-				{
-					// Sorting column for use in JOINs
-					$column = $this->_object_name.'.'.$column;
-				}
-
-				$this->_db_builder->order_by($column, $direction);
-			}
-		}
-
-		if ($multiple === TRUE)
-		{
-			// Return database iterator casting to this object type
-			$result = $this->_db_builder->as_object(get_class($this))->execute($this->_db);
-
-			$this->reset();
-
-			return $result;
-		}
-		else
-		{
-			// Load the result as an associative array
-			$result = $this->_db_builder->as_assoc()->execute($this->_db);
-
-			$this->reset();
-
-			if ($result->count() === 1)
-			{
-				// Load object values
-				$this->_load_values($result->current());
-			}
-			else
-			{
-				// Clear the object, nothing was found
-				$this->clear();
-			}
-
-			return $this;
-		}
-	}
-
-	/**
-	 * Loads an array of values into into the current object.
-	 *
-	 * @chainable
-	 * @param  array $values Values to load
-	 * @return ORM
-	 */
-	protected function _load_values(array $values)
-	{
-		if (array_key_exists($this->_primary_key, $values))
-		{
-			if ($values[$this->_primary_key] !== NULL)
-			{
-				// Flag as loaded and valid
-				$this->_loaded = $this->_valid = TRUE;
-
-				// Store primary key
-				$this->_primary_key_value = $values[$this->_primary_key];
-			}
-			else
-			{
-				// Not loaded or valid
-				$this->_loaded = $this->_valid = FALSE;
-			}
-		}
-
-		// Related objects
-		$related = array();
-
-		foreach ($values as $column => $value)
-		{
-			if (strpos($column, ':') === FALSE)
-			{
-				// Load the value to this model
-				$this->_object[$column] = $value;
-			}
-			else
-			{
-				// Column belongs to a related model
-				list ($prefix, $column) = explode(':', $column, 2);
-
-				$related[$prefix][$column] = $value;
-			}
-		}
-
-		if ( ! empty($related))
-		{
-			foreach ($related as $object => $values)
-			{
-				// Load the related objects with the values in the result
-				$this->_related($object)->_load_values($values);
-			}
-		}
-
-		if ($this->_loaded)
-		{
-			// Store the object in its original state
-			$this->_original_values = $this->_object;
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Rule definitions for validation
-	 *
-	 * @return array
-	 */
-	public function rules()
-	{
-		return array();
-	}
-
-	/**
-	 * Filters a value for a specific column
-	 *
-	 * @param  string $field  The column name
-	 * @param  string $value  The value to filter
-	 * @return string
-	 */
-	protected function run_filter($field, $value)
-	{
-		$filters = $this->filters();
-
-		// Get the filters for this column
-		$wildcards = empty($filters[TRUE]) ? array() : $filters[TRUE];
-
-		// Merge in the wildcards
-		$filters = empty($filters[$field]) ? $wildcards : array_merge($wildcards, $filters[$field]);
-
-		// Bind the field name and model so they can be used in the filter method
-		$_bound = array
-		(
-			':field' => $field,
-			':model' => $this,
-		);
-
-		foreach ($filters as $array)
-		{
-			// Value needs to be bound inside the loop so we are always using the
-			// version that was modified by the filters that already ran
-			$_bound[':value'] = $value;
-
-			// Filters are defined as array($filter, $params)
-			$filter = $array[0];
-			$params = Arr::get($array, 1, array(':value'));
-
-			foreach ($params as $key => $param)
-			{
-				if (is_string($param) AND array_key_exists($param, $_bound))
-				{
-					// Replace with bound value
-					$params[$key] = $_bound[$param];
-				}
-			}
-
-			if (is_array($filter) OR ! is_string($filter))
-			{
-				// This is either a callback as an array or a lambda
-				$value = call_user_func_array($filter, $params);
-			}
-			elseif (strpos($filter, '::') === FALSE)
-			{
-				// Use a function call
-				$function = new ReflectionFunction($filter);
-
-				// Call $function($this[$field], $param, ...) with Reflection
-				$value = $function->invokeArgs($params);
-			}
-			else
-			{
-				// Split the class and method of the rule
-				list($class, $method) = explode('::', $filter, 2);
-
-				// Use a static method call
-				$method = new ReflectionMethod($class, $method);
-
-				// Call $Class::$method($this[$field], $param, ...) with Reflection
-				$value = $method->invokeArgs(NULL, $params);
-			}
-		}
-
-		return $value;
-	}
-
-	/**
-	 * Filter definitions for validation
-	 *
-	 * @return array
-	 */
-	public function filters()
-	{
-		return array();
-	}
-
-	/**
-	 * Label definitions for validation
-	 *
-	 * @return array
-	 */
-	public function labels()
-	{
-		return array();
-	}
-
-	/**
-	 * Validates the current model's data
-	 *
-	 * @param  Validation $extra_validation Validation object
-	 * @throws ORM_Validation_Exception
-	 * @return ORM
-	 */
-	public function check(Validation $extra_validation = NULL)
-	{
-		// Determine if any external validation failed
-		$extra_errors = ($extra_validation AND ! $extra_validation->check());
-
-		// Always build a new validation object
-		$this->_validation();
-
-		$array = $this->_validation;
-
-		if (($this->_valid = $array->check()) === FALSE OR $extra_errors)
-		{
-			$exception = new ORM_Validation_Exception($this->errors_filename(), $array);
-
-			if ($extra_errors)
-			{
-				// Merge any possible errors from the external object
-				$exception->add_object('_external', $extra_validation);
-			}
-			throw $exception;
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Insert a new object to the database
-	 * @param  Validation $validation Validation object
-	 * @throws Kohana_Exception
-	 * @return ORM
-	 */
-	public function create(Validation $validation = NULL)
-	{
-		if ($this->_loaded)
-			throw new Kohana_Exception('Cannot create :model model because it is already loaded.', array(':model' => $this->_object_name));
-
-		// Require model validation before saving
-		if ( ! $this->_valid OR $validation)
-		{
-			$this->check($validation);
-		}
-
-		$data = array();
-		foreach ($this->_changed as $column)
-		{
-			// Generate list of column => values
-			$data[$column] = $this->_object[$column];
-		}
-
-		if (is_array($this->_created_column))
-		{
-			// Fill the created column
-			$column = $this->_created_column['column'];
-			$format = $this->_created_column['format'];
-
-			$data[$column] = $this->_object[$column] = ($format === TRUE) ? time() : date($format);
-		}
-
-		$result = DB::insert($this->_table_name)
-			->columns(array_keys($data))
-			->values(array_values($data))
-			->execute($this->_db);
-
-		if ( ! array_key_exists($this->_primary_key, $data))
-		{
-			// Load the insert id as the primary key if it was left out
-			$this->_object[$this->_primary_key] = $this->_primary_key_value = $result[0];
-		}
-		else
-		{
-			$this->_primary_key_value = $this->_object[$this->_primary_key];
-		}
-
-		// Object is now loaded and saved
-		$this->_loaded = $this->_saved = TRUE;
-
-		// All changes have been saved
-		$this->_changed = array();
-		$this->_original_values = $this->_object;
-
-		return $this;
-	}
-
-	/**
-	 * Updates a single record or multiple records
-	 *
-	 * @chainable
-	 * @param  Validation $validation Validation object
-	 * @throws Kohana_Exception
-	 * @return ORM
-	 */
-	public function update(Validation $validation = NULL)
-	{
-		if ( ! $this->_loaded)
-			throw new Kohana_Exception('Cannot update :model model because it is not loaded.', array(':model' => $this->_object_name));
-
-		// Run validation if the model isn't valid or we have additional validation rules.
-		if ( ! $this->_valid OR $validation)
-		{
-			$this->check($validation);
-		}
-
-		if (empty($this->_changed))
-		{
-			// Nothing to update
-			return $this;
-		}
-
-		$data = array();
-		foreach ($this->_changed as $column)
-		{
-			// Compile changed data
-			$data[$column] = $this->_object[$column];
-		}
-
-		if (is_array($this->_updated_column))
-		{
-			// Fill the updated column
-			$column = $this->_updated_column['column'];
-			$format = $this->_updated_column['format'];
-
-			$data[$column] = $this->_object[$column] = ($format === TRUE) ? time() : date($format);
-		}
-
-		// Use primary key value
-		$id = $this->pk();
-
-		// Update a single record
-		DB::update($this->_table_name)
-			->set($data)
-			->where($this->_primary_key, '=', $id)
-			->execute($this->_db);
-
-		if (isset($data[$this->_primary_key]))
-		{
-			// Primary key was changed, reflect it
-			$this->_primary_key_value = $data[$this->_primary_key];
-		}
-
-		// Object has been saved
-		$this->_saved = TRUE;
-
-		// All changes have been saved
-		$this->_changed = array();
-		$this->_original_values = $this->_object;
-
-		return $this;
-	}
-
-	/**
-	 * Updates or Creates the record depending on loaded()
-	 *
-	 * @chainable
-	 * @param  Validation $validation Validation object
-	 * @return ORM
-	 */
-	public function save(Validation $validation = NULL)
-	{
-		return $this->loaded() ? $this->update($validation) : $this->create($validation);
-	}
-
-	/**
-	 * Deletes a single record while ignoring relationships.
-	 *
-	 * @chainable
-	 * @throws Kohana_Exception
-	 * @return ORM
-	 */
-	public function delete()
-	{
-		if ( ! $this->_loaded)
-			throw new Kohana_Exception('Cannot delete :model model because it is not loaded.', array(':model' => $this->_object_name));
-
-		// Use primary key value
-		$id = $this->pk();
-
-		// Delete the object
-		DB::delete($this->_table_name)
-			->where($this->_primary_key, '=', $id)
-			->execute($this->_db);
-
-		return $this->clear();
-	}
-
-	/**
-	 * Tests if this object has a relationship to a different model,
-	 * or an array of different models. When providing far keys, the number
-	 * of relations must equal the number of keys.
-	 * 
-	 *
-	 *     // Check if $model has the login role
-	 *     $model->has('roles', ORM::factory('role', array('name' => 'login')));
-	 *     // Check for the login role if you know the roles.id is 5
-	 *     $model->has('roles', 5);
-	 *     // Check for all of the following roles
-	 *     $model->has('roles', array(1, 2, 3, 4));
-	 *     // Check if $model has any roles
-	 *     $model->has('roles')
-	 *
-	 * @param  string  $alias    Alias of the has_many "through" relationship
-	 * @param  mixed   $far_keys Related model, primary key, or an array of primary keys
-	 * @return boolean
-	 */
-	public function has($alias, $far_keys = NULL)
-	{
-		$count = $this->count_relations($alias, $far_keys);
-		if ($far_keys === NULL)
-		{
-			return (bool) $count;
-		}
-		else
-		{
-			return $count === count($far_keys);
-		}
-
-	}
-
-	/**
-	 * Tests if this object has a relationship to a different model,
-	 * or an array of different models. When providing far keys, this function
-	 * only checks that at least one of the relationships is satisfied.
-	 *
-	 *     // Check if $model has the login role
-	 *     $model->has('roles', ORM::factory('role', array('name' => 'login')));
-	 *     // Check for the login role if you know the roles.id is 5
-	 *     $model->has('roles', 5);
-	 *     // Check for any of the following roles
-	 *     $model->has('roles', array(1, 2, 3, 4));
-	 *     // Check if $model has any roles
-	 *     $model->has('roles')
-	 *
-	 * @param  string  $alias    Alias of the has_many "through" relationship
-	 * @param  mixed   $far_keys Related model, primary key, or an array of primary keys
-	 * @return boolean
-	 */
-	public function has_any($alias, $far_keys = NULL)
-	{
-		return (bool) $this->count_relations($alias, $far_keys);
-	}
-
-	/**
-	 * Returns the number of relationships 
-	 *
-	 *     // Counts the number of times the login role is attached to $model
-	 *     $model->has('roles', ORM::factory('role', array('name' => 'login')));
-	 *     // Counts the number of times role 5 is attached to $model
-	 *     $model->has('roles', 5);
-	 *     // Counts the number of times any of roles 1, 2, 3, or 4 are attached to
-	 *     // $model
-	 *     $model->has('roles', array(1, 2, 3, 4));
-	 *     // Counts the number roles attached to $model
-	 *     $model->has('roles')
-	 *
-	 * @param  string  $alias    Alias of the has_many "through" relationship
-	 * @param  mixed   $far_keys Related model, primary key, or an array of primary keys
-	 * @return integer
-	 */
-	public function count_relations($alias, $far_keys = NULL)
-	{
-		if ($far_keys === NULL)
-		{
-			return (int) DB::select(array(DB::expr('COUNT(*)'), 'records_found'))
-				->from($this->_has_many[$alias]['through'])
-				->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
-				->execute($this->_db)->get('records_found');
-		}
-
-		$far_keys = ($far_keys instanceof ORM) ? $far_keys->pk() : $far_keys;
-
-		// We need an array to simplify the logic
-		$far_keys = (array) $far_keys;
-
-		// Nothing to check if the model isn't loaded or we don't have any far_keys
-		if ( ! $far_keys OR ! $this->_loaded)
-			return 0;
-
-		$count = (int) DB::select(array(DB::expr('COUNT(*)'), 'records_found'))
-			->from($this->_has_many[$alias]['through'])
-			->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
-			->where($this->_has_many[$alias]['far_key'], 'IN', $far_keys)
-			->execute($this->_db)->get('records_found');
-
-		// Rows found need to match the rows searched
-		return (int) $count;
-	}
-
-	/**
-	 * Adds a new relationship to between this model and another.
-	 *
-	 *     // Add the login role using a model instance
-	 *     $model->add('roles', ORM::factory('role', array('name' => 'login')));
-	 *     // Add the login role if you know the roles.id is 5
-	 *     $model->add('roles', 5);
-	 *     // Add multiple roles (for example, from checkboxes on a form)
-	 *     $model->add('roles', array(1, 2, 3, 4));
-	 *
-	 * @param  string  $alias    Alias of the has_many "through" relationship
-	 * @param  mixed   $far_keys Related model, primary key, or an array of primary keys
-	 * @return ORM
-	 */
-	public function add($alias, $far_keys)
-	{
-		$far_keys = ($far_keys instanceof ORM) ? $far_keys->pk() : $far_keys;
-
-		$columns = array($this->_has_many[$alias]['foreign_key'], $this->_has_many[$alias]['far_key']);
-		$foreign_key = $this->pk();
-
-		$query = DB::insert($this->_has_many[$alias]['through'], $columns);
-
-		foreach ( (array) $far_keys as $key)
-		{
-			$query->values(array($foreign_key, $key));
-		}
-
-		$query->execute($this->_db);
-
-		return $this;
-	}
-
-	/**
-	 * Removes a relationship between this model and another.
-	 *
-	 *     // Remove a role using a model instance
-	 *     $model->remove('roles', ORM::factory('role', array('name' => 'login')));
-	 *     // Remove the role knowing the primary key
-	 *     $model->remove('roles', 5);
-	 *     // Remove multiple roles (for example, from checkboxes on a form)
-	 *     $model->remove('roles', array(1, 2, 3, 4));
-	 *     // Remove all related roles
-	 *     $model->remove('roles');
-	 *
-	 * @param  string $alias    Alias of the has_many "through" relationship
-	 * @param  mixed  $far_keys Related model, primary key, or an array of primary keys
-	 * @return ORM
-	 */
-	public function remove($alias, $far_keys = NULL)
-	{
-		$far_keys = ($far_keys instanceof ORM) ? $far_keys->pk() : $far_keys;
-
-		$query = DB::delete($this->_has_many[$alias]['through'])
-			->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk());
-
-		if ($far_keys !== NULL)
-		{
-			// Remove all the relationships in the array
-			$query->where($this->_has_many[$alias]['far_key'], 'IN', (array) $far_keys);
-		}
-
-		$query->execute($this->_db);
-
-		return $this;
-	}
-
-	/**
-	 * Count the number of records in the table.
-	 *
-	 * @return integer
-	 */
-	public function count_all()
-	{
-		$selects = array();
-
-		foreach ($this->_db_pending as $key => $method)
-		{
-			if ($method['name'] == 'select')
-			{
-				// Ignore any selected columns for now
-				$selects[] = $method;
-				unset($this->_db_pending[$key]);
-			}
-		}
-
-		if ( ! empty($this->_load_with))
-		{
-			foreach ($this->_load_with as $alias)
-			{
-				// Bind relationship
-				$this->with($alias);
-			}
-		}
-
-		$this->_build(Database::SELECT);
-
-		$records = $this->_db_builder->from(array($this->_table_name, $this->_object_name))
-			->select(array(DB::expr('COUNT(*)'), 'records_found'))
-			->execute($this->_db)
-			->get('records_found');
-
-		// Add back in selected columns
-		$this->_db_pending += $selects;
-
-		$this->reset();
-
-		// Return the total number of records in a table
-		return $records;
-	}
-
-	/**
-	 * Proxy method to Database list_columns.
-	 *
-	 * @return array
-	 */
-	public function list_columns()
-	{
-		// Proxy to database
-		return $this->_db->list_columns($this->_table_name);
-	}
-
-	/**
-	 * Returns an ORM model for the given one-one related alias
-	 *
-	 * @param  string $alias Alias name
-	 * @return ORM
-	 */
-	protected function _related($alias)
-	{
-		if (isset($this->_related[$alias]))
-		{
-			return $this->_related[$alias];
-		}
-		elseif (isset($this->_has_one[$alias]))
-		{
-			return $this->_related[$alias] = ORM::factory($this->_has_one[$alias]['model']);
-		}
-		elseif (isset($this->_belongs_to[$alias]))
-		{
-			return $this->_related[$alias] = ORM::factory($this->_belongs_to[$alias]['model']);
-		}
-		else
-		{
-			return FALSE;
-		}
-	}
-
-	/**
-	 * Returns the value of the primary key
-	 *
-	 * @return mixed Primary key
-	 */
-	public function pk()
-	{
-		return $this->_primary_key_value;
-	}
-
-	/**
-	 * Returns last executed query
-	 *
-	 * @return string
-	 */
-	public function last_query()
-	{
-		return $this->_db->last_query;
-	}
-
-	/**
-	 * Clears query builder.  Passing FALSE is useful to keep the existing
-	 * query conditions for another query.
-	 *
-	 * @param bool $next Pass FALSE to avoid resetting on the next call
-	 * @return ORM
-	 */
-	public function reset($next = TRUE)
-	{
-		if ($next AND $this->_db_reset)
-		{
-			$this->_db_pending   = array();
-			$this->_db_applied   = array();
-			$this->_db_builder   = NULL;
-			$this->_with_applied = array();
-		}
-
-		// Reset on the next call?
-		$this->_db_reset = $next;
-
-		return $this;
-	}
-
-	protected function _serialize_value($value)
-	{
-		return json_encode($value);
-	}
-
-	protected function _unserialize_value($value)
-	{
-		return json_decode($value, TRUE);
-	}
-
-	public function object_name()
-	{
-		return $this->_object_name;
-	}
-
-	public function object_plural()
-	{
-		return $this->_object_plural;
-	}
-
-	public function loaded()
-	{
-		return $this->_loaded;
-	}
-
-	public function saved()
-	{
-		return $this->_saved;
-	}
-
-	public function primary_key()
-	{
-		return $this->_primary_key;
-	}
-
-	public function table_name()
-	{
-		return $this->_table_name;
-	}
-
-	public function table_columns()
-	{
-		return $this->_table_columns;
-	}
-
-	public function has_one()
-	{
-		return $this->_has_one;
-	}
-
-	public function belongs_to()
-	{
-		return $this->_belongs_to;
-	}
-
-	public function has_many()
-	{
-		return $this->_has_many;
-	}
-
-	public function load_with()
-	{
-		return $this->_load_with;
-	}
-
-	public function original_values()
-	{
-		return $this->_original_values;
-	}
-
-	public function created_column()
-	{
-		return $this->_created_column;
-	}
-
-	public function updated_column()
-	{
-		return $this->_updated_column;
-	}
-
-	public function validation()
-	{
-		if ( ! isset($this->_validation))
-		{
-			// Initialize the validation object
-			$this->_validation();
-		}
-
-		return $this->_validation;
-	}
-
-	public function object()
-	{
-		return $this->_object;
-	}
-
-	public function errors_filename()
-	{
-		return $this->_errors_filename;
-	}
-
-	/**
-	 * Alias of and_where()
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function where($column, $op, $value)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'where',
-			'args' => array($column, $op, $value),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Creates a new "AND WHERE" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function and_where($column, $op, $value)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'and_where',
-			'args' => array($column, $op, $value),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Creates a new "OR WHERE" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function or_where($column, $op, $value)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'or_where',
-			'args' => array($column, $op, $value),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Alias of and_where_open()
-	 *
-	 * @return  $this
-	 */
-	public function where_open()
-	{
-		return $this->and_where_open();
-	}
-
-	/**
-	 * Opens a new "AND WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_where_open()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'and_where_open',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Opens a new "OR WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_where_open()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'or_where_open',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "AND WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function where_close()
-	{
-		return $this->and_where_close();
-	}
-
-	/**
-	 * Closes an open "AND WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_where_close()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'and_where_close',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "OR WHERE (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_where_close()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'or_where_close',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Applies sorting with "ORDER BY ..."
-	 *
-	 * @param   mixed   $column     column name or array($column, $alias) or object
-	 * @param   string  $direction  direction of sorting
-	 * @return  $this
-	 */
-	public function order_by($column, $direction = NULL)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'order_by',
-			'args' => array($column, $direction),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Return up to "LIMIT ..." results
-	 *
-	 * @param   integer  $number  maximum results to return
-	 * @return  $this
-	 */
-	public function limit($number)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'limit',
-			'args' => array($number),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Enables or disables selecting only unique columns using "SELECT DISTINCT"
-	 *
-	 * @param   boolean  $value  enable or disable distinct columns
-	 * @return  $this
-	 */
-	public function distinct($value)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'distinct',
-			'args' => array($value),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Choose the columns to select from.
-	 *
-	 * @param   mixed  $columns  column name or array($column, $alias) or object
-	 * @param   ...
-	 * @return  $this
-	 */
-	public function select($columns = NULL)
-	{
-		$columns = func_get_args();
-
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'select',
-			'args' => $columns,
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Choose the tables to select "FROM ..."
-	 *
-	 * @param   mixed  $tables  table name or array($table, $alias) or object
-	 * @param   ...
-	 * @return  $this
-	 */
-	public function from($tables)
-	{
-		$tables = func_get_args();
-
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'from',
-			'args' => $tables,
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Adds addition tables to "JOIN ...".
-	 *
-	 * @param   mixed   $table  column name or array($column, $alias) or object
-	 * @param   string  $type   join type (LEFT, RIGHT, INNER, etc)
-	 * @return  $this
-	 */
-	public function join($table, $type = NULL)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'join',
-			'args' => array($table, $type),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Adds "ON ..." conditions for the last created JOIN statement.
-	 *
-	 * @param   mixed   $c1  column name or array($column, $alias) or object
-	 * @param   string  $op  logic operator
-	 * @param   mixed   $c2  column name or array($column, $alias) or object
-	 * @return  $this
-	 */
-	public function on($c1, $op, $c2)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'on',
-			'args' => array($c1, $op, $c2),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Creates a "GROUP BY ..." filter.
-	 *
-	 * @param   mixed   $columns  column name or array($column, $alias) or object
-	 * @param   ...
-	 * @return  $this
-	 */
-	public function group_by($columns)
-	{
-		$columns = func_get_args();
-
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'group_by',
-			'args' => $columns,
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Alias of and_having()
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function having($column, $op, $value = NULL)
-	{
-		return $this->and_having($column, $op, $value);
-	}
-
-	/**
-	 * Creates a new "AND HAVING" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function and_having($column, $op, $value = NULL)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'and_having',
-			'args' => array($column, $op, $value),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Creates a new "OR HAVING" condition for the query.
-	 *
-	 * @param   mixed   $column  column name or array($column, $alias) or object
-	 * @param   string  $op      logic operator
-	 * @param   mixed   $value   column value
-	 * @return  $this
-	 */
-	public function or_having($column, $op, $value = NULL)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'or_having',
-			'args' => array($column, $op, $value),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Alias of and_having_open()
-	 *
-	 * @return  $this
-	 */
-	public function having_open()
-	{
-		return $this->and_having_open();
-	}
-
-	/**
-	 * Opens a new "AND HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_having_open()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'and_having_open',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Opens a new "OR HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_having_open()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'or_having_open',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "AND HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function having_close()
-	{
-		return $this->and_having_close();
-	}
-
-	/**
-	 * Closes an open "AND HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function and_having_close()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'and_having_close',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Closes an open "OR HAVING (...)" grouping.
-	 *
-	 * @return  $this
-	 */
-	public function or_having_close()
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'or_having_close',
-			'args' => array(),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Start returning results after "OFFSET ..."
-	 *
-	 * @param   integer   $number  starting result number
-	 * @return  $this
-	 */
-	public function offset($number)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'offset',
-			'args' => array($number),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Enables the query to be cached for a specified amount of time.
-	 *
-	 * @param   integer  $lifetime  number of seconds to cache
-	 * @return  $this
-	 * @uses    Kohana::$cache_life
-	 */
-	public function cached($lifetime = NULL)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'cached',
-			'args' => array($lifetime),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Set the value of a parameter in the query.
-	 *
-	 * @param   string   $param  parameter key to replace
-	 * @param   mixed    $value  value to use
-	 * @return  $this
-	 */
-	public function param($param, $value)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'param',
-			'args' => array($param, $value),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Adds "USING ..." conditions for the last created JOIN statement.
-	 *
-	 * @param   string  $columns  column name
-	 * @return  $this
-	 */
-	public function using($columns)
-	{
-		// Add pending database call which is executed after query type is determined
-		$this->_db_pending[] = array(
-			'name' => 'using',
-			'args' => array($columns),
-		);
-
-		return $this;
-	}
-
-	/**
-	 * Checks whether a column value is unique.
-	 * Excludes itself if loaded.
-	 *
-	 * @param   string   $field  the field to check for uniqueness
-	 * @param   mixed    $value  the value to check for uniqueness
-	 * @return  bool     whteher the value is unique
-	 */
-	public function unique($field, $value)
-	{
-		$model = ORM::factory($this->object_name())
-			->where($field, '=', $value)
-			->find();
-
-		if ($this->loaded())
-		{
-			return ( ! ($model->loaded() AND $model->pk() != $this->pk()));
-		}
-
-		return ( ! $model->loaded());
-	}
-} // End ORM

+ 0 - 198
frameworks/PHP/php-kohana/modules/orm/classes/Kohana/ORM/Validation/Exception.php

@@ -1,198 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * ORM Validation exceptions.
- *
- * @package    Kohana/ORM
- * @author     Kohana Team
- * @copyright  (c) 2007-2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Kohana_ORM_Validation_Exception extends Kohana_Exception {
-
-	/**
-   * Array of validation objects
-   * @var array
-   */
-	protected $_objects = array();
-
-	/**
-   * The alias of the main ORM model this exception was created for
-   * @var string
-   */
-	protected $_alias = NULL;
-
-	/**
-	 * Constructs a new exception for the specified model
-	 *
-	 * @param  string     $alias       The alias to use when looking for error messages
-	 * @param  Validation $object      The Validation object of the model
-	 * @param  string     $message     The error message
-	 * @param  array      $values      The array of values for the error message
-	 * @param  integer    $code        The error code for the exception
-	 * @return void
-	 */
-	public function __construct($alias, Validation $object, $message = 'Failed to validate array', array $values = NULL, $code = 0, Exception $previous = NULL)
-	{
-		$this->_alias = $alias;
-		$this->_objects['_object'] = $object;
-		$this->_objects['_has_many'] = FALSE;
-
-		parent::__construct($message, $values, $code, $previous);
-	}
-
-	/**
-	 * Adds a Validation object to this exception
-	 *
-	 *     // The following will add a validation object for a profile model
-	 *     // inside the exception for a user model.
-	 *     $e->add_object('profile', $validation);
-	 *     // The errors array will now look something like this
-	 *     // array
-	 *     // (
-	 *     //   'username' => 'This field is required',
-	 *     //   'profile'  => array
-	 *     //   (
-	 *     //     'first_name' => 'This field is required',
-	 *     //   ),
-	 *     // );
-	 *
-	 * @param  string     $alias    The relationship alias from the model
-	 * @param  Validation $object   The Validation object to merge
-	 * @param  mixed      $has_many The array key to use if this exception can be merged multiple times
-	 * @return ORM_Validation_Exception
-	 */
-	public function add_object($alias, Validation $object, $has_many = FALSE)
-	{
-		// We will need this when generating errors
-		$this->_objects[$alias]['_has_many'] = ($has_many !== FALSE);
-
-		if ($has_many === TRUE)
-		{
-			// This is most likely a has_many relationship
-			$this->_objects[$alias][]['_object'] = $object;
-		}
-		elseif ($has_many)
-		{
-			// This is most likely a has_many relationship
-			$this->_objects[$alias][$has_many]['_object'] = $object;
-		}
-		else
-		{
-			$this->_objects[$alias]['_object'] = $object;
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Merges an ORM_Validation_Exception object into the current exception
-	 * Useful when you want to combine errors into one array
-	 *
-	 * @param  ORM_Validation_Exception $object   The exception to merge
-	 * @param  mixed                    $has_many The array key to use if this exception can be merged multiple times
-	 * @return ORM_Validation_Exception
-	 */
-	public function merge(ORM_Validation_Exception $object, $has_many = FALSE)
-	{
-		$alias = $object->alias();
-
-		// We will need this when generating errors
-		$this->_objects[$alias]['_has_many'] = ($has_many !== FALSE);
-
-		if ($has_many === TRUE)
-		{
-			// This is most likely a has_many relationship
-			$this->_objects[$alias][] = $object->objects();
-		}
-		elseif ($has_many)
-		{
-			// This is most likely a has_many relationship
-			$this->_objects[$alias][$has_many] = $object->objects();
-		}
-		else
-		{
-			$this->_objects[$alias] = $object->objects();
-		}
-
-		return $this;
-	}
-
-	/**
-	 * Returns a merged array of the errors from all the Validation objects in this exception
-	 *
-	 *     // Will load Model_User errors from messages/orm-validation/user.php
-	 *     $e->errors('orm-validation');
-	 *
-	 * @param   string  $directory Directory to load error messages from
-	 * @param   mixed   $translate Translate the message
-	 * @return  array
-	 * @see generate_errors()
-	 */
-	public function errors($directory = NULL, $translate = TRUE)
-	{
-		return $this->generate_errors($this->_alias, $this->_objects, $directory, $translate);
-	}
-
-	/**
-	 * Recursive method to fetch all the errors in this exception
-	 *
-	 * @param  string $alias     Alias to use for messages file
-	 * @param  array  $array     Array of Validation objects to get errors from
-	 * @param  string $directory Directory to load error messages from
-	 * @param  mixed  $translate Translate the message
-	 * @return array
-	 */
-	protected function generate_errors($alias, array $array, $directory, $translate)
-	{
-		$errors = array();
-
-		foreach ($array as $key => $object)
-		{
-			if (is_array($object))
-			{
-				$errors[$key] = ($key === '_external')
-					// Search for errors in $alias/_external.php
-					? $this->generate_errors($alias.'/'.$key, $object, $directory, $translate)
-					// Regular models get their own file not nested within $alias
-					: $this->generate_errors($key, $object, $directory, $translate);
-			}
-			elseif ($object instanceof Validation)
-			{
-				if ($directory === NULL)
-				{
-					// Return the raw errors
-					$file = NULL;
-				}
-				else
-				{
-					$file = trim($directory.'/'.$alias, '/');
-				}
-
-				// Merge in this array of errors
-				$errors += $object->errors($file, $translate);
-			}
-		}
-
-		return $errors;
-	}
-
-	/**
-	 * Returns the protected _objects property from this exception
-	 *
-	 * @return array
-	 */
-	public function objects()
-	{
-		return $this->_objects;
-	}
-
-	/**
-	 * Returns the protected _alias property from this exception
-	 *
-	 * @return string
-	 */
-	public function alias()
-	{
-		return $this->_alias;
-	}
-} // End Kohana_ORM_Validation_Exception

+ 0 - 31
frameworks/PHP/php-kohana/modules/orm/classes/Model/Auth/Role.php

@@ -1,31 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-/**
- * Default auth role
- *
- * @package    Kohana/Auth
- * @author     Kohana Team
- * @copyright  (c) 2007-2009 Kohana Team
- * @license    http://kohanaphp.com/license.html
- */
-class Model_Auth_Role extends ORM {
-
-	// Relationships
-	protected $_has_many = array(
-		'users' => array('model' => 'User','through' => 'roles_users'),
-	);
-
-	public function rules()
-	{
-		return array(
-			'name' => array(
-				array('not_empty'),
-				array('min_length', array(':value', 4)),
-				array('max_length', array(':value', 32)),
-			),
-			'description' => array(
-				array('max_length', array(':value', 255)),
-			)
-		);
-	}
-
-} // End Auth Role Model

+ 0 - 204
frameworks/PHP/php-kohana/modules/orm/classes/Model/Auth/User.php

@@ -1,204 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-/**
- * Default auth user
- *
- * @package    Kohana/Auth
- * @author     Kohana Team
- * @copyright  (c) 2007-2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Model_Auth_User extends ORM {
-
-	/**
-	 * A user has many tokens and roles
-	 *
-	 * @var array Relationhips
-	 */
-	protected $_has_many = array(
-		'user_tokens' => array('model' => 'User_Token'),
-		'roles'       => array('model' => 'Role', 'through' => 'roles_users'),
-	);
-
-	/**
-	 * Rules for the user model. Because the password is _always_ a hash
-	 * when it's set,you need to run an additional not_empty rule in your controller
-	 * to make sure you didn't hash an empty string. The password rules
-	 * should be enforced outside the model or with a model helper method.
-	 *
-	 * @return array Rules
-	 */
-	public function rules()
-	{
-		return array(
-			'username' => array(
-				array('not_empty'),
-				array('max_length', array(':value', 32)),
-				array(array($this, 'unique'), array('username', ':value')),
-			),
-			'password' => array(
-				array('not_empty'),
-			),
-			'email' => array(
-				array('not_empty'),
-				array('email'),
-				array(array($this, 'unique'), array('email', ':value')),
-			),
-		);
-	}
-
-	/**
-	 * Filters to run when data is set in this model. The password filter
-	 * automatically hashes the password when it's set in the model.
-	 *
-	 * @return array Filters
-	 */
-	public function filters()
-	{
-		return array(
-			'password' => array(
-				array(array(Auth::instance(), 'hash'))
-			)
-		);
-	}
-
-	/**
-	 * Labels for fields in this model
-	 *
-	 * @return array Labels
-	 */
-	public function labels()
-	{
-		return array(
-			'username'         => 'username',
-			'email'            => 'email address',
-			'password'         => 'password',
-		);
-	}
-
-	/**
-	 * Complete the login for a user by incrementing the logins and saving login timestamp
-	 *
-	 * @return void
-	 */
-	public function complete_login()
-	{
-		if ($this->_loaded)
-		{
-			// Update the number of logins
-			$this->logins = new Database_Expression('logins + 1');
-
-			// Set the last login date
-			$this->last_login = time();
-
-			// Save the user
-			$this->update();
-		}
-	}
-
-	/**
-	 * Tests if a unique key value exists in the database.
-	 *
-	 * @param   mixed    the value to test
-	 * @param   string   field name
-	 * @return  boolean
-	 */
-	public function unique_key_exists($value, $field = NULL)
-	{
-		if ($field === NULL)
-		{
-			// Automatically determine field by looking at the value
-			$field = $this->unique_key($value);
-		}
-
-		return (bool) DB::select(array(DB::expr('COUNT(*)'), 'total_count'))
-			->from($this->_table_name)
-			->where($field, '=', $value)
-			->where($this->_primary_key, '!=', $this->pk())
-			->execute($this->_db)
-			->get('total_count');
-	}
-
-	/**
-	 * Allows a model use both email and username as unique identifiers for login
-	 *
-	 * @param   string  unique value
-	 * @return  string  field name
-	 */
-	public function unique_key($value)
-	{
-		return Valid::email($value) ? 'email' : 'username';
-	}
-
-	/**
-	 * Password validation for plain passwords.
-	 *
-	 * @param array $values
-	 * @return Validation
-	 */
-	public static function get_password_validation($values)
-	{
-		return Validation::factory($values)
-			->rule('password', 'min_length', array(':value', 8))
-			->rule('password_confirm', 'matches', array(':validation', ':field', 'password'));
-	}
-
-	/**
-	 * Create a new user
-	 *
-	 * Example usage:
-	 * ~~~
-	 * $user = ORM::factory('User')->create_user($_POST, array(
-	 *	'username',
-	 *	'password',
-	 *	'email',
-	 * );
-	 * ~~~
-	 *
-	 * @param array $values
-	 * @param array $expected
-	 * @throws ORM_Validation_Exception
-	 */
-	public function create_user($values, $expected)
-	{
-		// Validation for passwords
-		$extra_validation = Model_User::get_password_validation($values)
-			->rule('password', 'not_empty');
-
-		return $this->values($values, $expected)->create($extra_validation);
-	}
-
-	/**
-	 * Update an existing user
-	 *
-	 * [!!] We make the assumption that if a user does not supply a password, that they do not wish to update their password.
-	 *
-	 * Example usage:
-	 * ~~~
-	 * $user = ORM::factory('User')
-	 *	->where('username', '=', 'kiall')
-	 *	->find()
-	 *	->update_user($_POST, array(
-	 *		'username',
-	 *		'password',
-	 *		'email',
-	 *	);
-	 * ~~~
-	 *
-	 * @param array $values
-	 * @param array $expected
-	 * @throws ORM_Validation_Exception
-	 */
-	public function update_user($values, $expected = NULL)
-	{
-		if (empty($values['password']))
-		{
-			unset($values['password'], $values['password_confirm']);
-		}
-
-		// Validation for passwords
-		$extra_validation = Model_User::get_password_validation($values);
-
-		return $this->values($values, $expected)->update($extra_validation);
-	}
-
-} // End Auth User Model

+ 0 - 77
frameworks/PHP/php-kohana/modules/orm/classes/Model/Auth/User/Token.php

@@ -1,77 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-/**
- * Default auth user toke
- *
- * @package    Kohana/Auth
- * @author     Kohana Team
- * @copyright  (c) 2007-2012 Kohana Team
- * @license    http://kohanaframework.org/license
- */
-class Model_Auth_User_Token extends ORM {
-
-	// Relationships
-	protected $_belongs_to = array(
-		'user' => array('model' => 'User'),
-	);
-	
-	protected $_created_column = array(
-		'column' => 'created',
-		'format' => TRUE,
-	);
-
-	/**
-	 * Handles garbage collection and deleting of expired objects.
-	 *
-	 * @return  void
-	 */
-	public function __construct($id = NULL)
-	{
-		parent::__construct($id);
-
-		if (mt_rand(1, 100) === 1)
-		{
-			// Do garbage collection
-			$this->delete_expired();
-		}
-
-		if ($this->expires < time() AND $this->_loaded)
-		{
-			// This object has expired
-			$this->delete();
-		}
-	}
-
-	/**
-	 * Deletes all expired tokens.
-	 *
-	 * @return  ORM
-	 */
-	public function delete_expired()
-	{
-		// Delete all expired tokens
-		DB::delete($this->_table_name)
-			->where('expires', '<', time())
-			->execute($this->_db);
-
-		return $this;
-	}
-
-	public function create(Validation $validation = NULL)
-	{
-		$this->token = $this->create_token();
-
-		return parent::create($validation);
-	}
-
-	protected function create_token()
-	{
-		do
-		{
-			$token = sha1(uniqid(Text::random('alnum', 32), TRUE));
-		}
-		while (ORM::factory('User_Token', array('token' => $token))->loaded());
-
-		return $token;
-	}
-
-} // End Auth User Token Model

+ 0 - 7
frameworks/PHP/php-kohana/modules/orm/classes/Model/Role.php

@@ -1,7 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-
-class Model_Role extends Model_Auth_Role {
-
-	// This class can be replaced or extended
-
-} // End Role Model

+ 0 - 7
frameworks/PHP/php-kohana/modules/orm/classes/Model/User.php

@@ -1,7 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-
-class Model_User extends Model_Auth_User {
-
-	// This class can be replaced or extended
-
-} // End User Model

+ 0 - 7
frameworks/PHP/php-kohana/modules/orm/classes/Model/User/Token.php

@@ -1,7 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct access allowed.');
-
-class Model_User_Token extends Model_Auth_User_Token {
-
-	// This class can be replaced or extended
-
-} // End User Token Model

+ 0 - 3
frameworks/PHP/php-kohana/modules/orm/classes/ORM.php

@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-class ORM extends Kohana_ORM {}

+ 0 - 10
frameworks/PHP/php-kohana/modules/orm/classes/ORM/Validation/Exception.php

@@ -1,10 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-/**
- * ORM Validation exceptions.
- *
- * @package    Kohana/ORM
- * @author     Kohana Team
- * @copyright  (c) 2008-2009 Kohana Team
- * @license    http://kohanaphp.com/license
- */
-class ORM_Validation_Exception extends Kohana_ORM_Validation_Exception {}

+ 0 - 23
frameworks/PHP/php-kohana/modules/orm/config/userguide.php

@@ -1,23 +0,0 @@
-<?php defined('SYSPATH') OR die('No direct script access.');
-
-return array(
-	// Leave this alone
-	'modules' => array(
-
-		// This should be the path to this modules userguide pages, without the 'guide/'. Ex: '/guide/modulename/' would be 'modulename'
-		'orm' => array(
-
-			// Whether this modules userguide pages should be shown
-			'enabled' => TRUE,
-			
-			// The name that should show up on the userguide index page
-			'name' => 'ORM',
-
-			// A short description of this module, shown on the index page
-			'description' => 'Official ORM module, a modeling library for object relational mapping.',
-			
-			// Copyright message, shown in the footer for this module
-			'copyright' => '&copy; 2008–2012 Kohana Team',
-		)	
-	)
-);

+ 0 - 13
frameworks/PHP/php-kohana/modules/orm/guide/orm/examples.md

@@ -1,13 +0,0 @@
-# Examples
-
-- [Simple](examples/simple): Basic, one table model examples.
-- [Validation](examples/validation): Full example of creating a user account and handling validation errors.
-
-## @TODO:
-
-The following is a sample list of examples that might be useful.  Don't feel limited by this list, or consider these required.  Items on the list can be combined, split up, removed or added to.  All contribution are appreciated.
-
-- Examples of changing things like $_table_name, $_labels, with, etc.
-- Example of a one to one relationship.
-- Example of one to many
-- Example of many to many.

+ 0 - 119
frameworks/PHP/php-kohana/modules/orm/guide/orm/examples/simple.md

@@ -1,119 +0,0 @@
-# Simple Examples
-
-This is a simple example of a single ORM model, that has no relationships, but uses validation on the fields. 
-
-## SQL schema
-
-	CREATE TABLE IF NOT EXISTS `members` (
-	  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-	  `username` varchar(32) NOT NULL,
-	  `first_name` varchar(32) NOT NULL,
-	  `last_name` varchar(32) NOT NULL,
-	  `email` varchar(127) DEFAULT NULL,
-	  PRIMARY KEY (`id`)
-	) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-
-## Model
-	
-	<?php defined('SYSPATH') or die('No direct access allowed.');
-
-	class Model_Member extends ORM {
-
-		public function rules()
-		{
-			return array(
-				'username' => array(
-					array('not_empty'),
-					array('min_length', array(':value', 4)),
-					array('max_length', array(':value', 32)),
-					array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')),
-				),
-				'first_name' => array(
-					array('not_empty'),
-					array('min_length', array(':value', 4)),
-					array('max_length', array(':value', 32)),
-					array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')),
-				),
-				'last_name' => array(
-					array('not_empty'),
-					array('min_length', array(':value', 4)),
-					array('max_length', array(':value', 32)),
-					array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')),
-				),
-				'email' => array(
-					array('not_empty'),
-					array('min_length', array(':value', 4)),
-					array('max_length', array(':value', 127)),
-					array('email'),
-				),
-			);
-		}
-	}
-
-[!!] The array returned by `ORM::rules()` will be passed to a [Validation] object and tested when you call `ORM::save()`. 
-
-[!!] Please notice that defining the primary key "id" in the model is not necessary. Also the table name in the database is plural and the model name is singular.
-
-## Controller
-
-	<?php defined('SYSPATH') or die('No direct access allowed.');
-	
-	class Controller_Member extends Controller_Template {
-		
-		public function action_index()
-		{
-			/**
-			 * Example 1
-			 */
-			
-			// Create an instance of a model
-			$members = ORM::factory('Member');
-			
-			// Get all members with the first name "Peter" find_all()
-			// means we get all records matching the query.
-			$members->where('first_name', '=', 'Peter')->find_all();
-
-			// Count records in the $members object
-			$members->count_all();
-			
-			/**
-			 * Example 2
-			 */
-			
-			// Create an instance of a model
-			$member = ORM::factory('Member');
-			
-			// Get a member with the user name "bongo" find() means
-			// we only want the first record matching the query.
-			$member->where('username', '=', 'bongo')->find();
-			
-			/**
-			 * Example 3
-			 */
-			
-			// Create an instance of a model
-			$member = ORM::factory('Member');
-			
-			// Do an INSERT query
-			$member->username = 'bongo';
-			$member->first_name = 'Peter';
-			$member->last_name = 'Smith';
-			$member->save();
-			
-			/**
-			 * Example 4
-			 */
-			
-			// Create an instance of a model where the
-			// table field "id" is "1"
-			$member = ORM::factory('Member', 1);
-			
-			// Do an UPDATE query
-			$member->username = 'bongo';
-			$member->first_name = 'Peter';
-			$member->last_name = 'Smith';
-			$member->save();
-		}
-	}
-
-[!!] $member will be a PHP object where you can access the values from the query e.g. echo $member->first_name

+ 0 - 137
frameworks/PHP/php-kohana/modules/orm/guide/orm/examples/validation.md

@@ -1,137 +0,0 @@
-# Validation Example
-
-This example will create user accounts and demonstrate how to handle model and controller validation. We will create a form, process it, and display any errors to the user. We will be assuming that the Model_User class contains a method called `hash_password` that is used to turn the plaintext passwords into some kind of hash. The implementation of the hashing methods are beyond the scope of this example and should be provided with the Authentication library you decide to use.
-
-## SQL schema
-
-	CREATE TABLE IF NOT EXISTS `members` (
-	  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-	  `username` varchar(32) NOT NULL,
-	  `password` varchar(100) NOT NULL,
-	  PRIMARY KEY (`id`)
-	) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-
-## Model
-	
-	<?php defined('SYSPATH') or die('No direct access allowed.');
-
-	class Model_Member extends ORM {
-
-		public function rules()
-		{
-			return array(
-				'username' => array(
-					array('not_empty'),
-					array('min_length', array(':value', 4)),
-					array('max_length', array(':value', 32)),
-					array(array($this, 'username_available')),
-				),
-				'password' => array(
-					array('not_empty'),
-				),
-			);
-		}
-		
-		public function filters()
-		{
-			return array(
-				'password' => array(
-					array(array($this, 'hash_password')),
-				),
-			);
-		}
-
-		public function username_available($username)
-		{
-			// There are simpler ways to do this, but I will use ORM for the sake of the example
-			return ORM::factory('Member', array('username' => $username))->loaded();
-		}
-
-		public function hash_password($password)
-		{
-			// Do something to hash the password
-		}
-	}
-
-## HTML Form
-
-Please forgive my slightly ugly form. I am trying not to use any modules or unrelated magic. :)
-
-	<form action="<?= URL::site('/members'); ?>" method="post" accept-charset="utf-8">
-		<label for="username">Username:</label>
-		<input id="username" type="text" name="username" value="<?= Arr::get($values, 'username'); ?>" />
-		<label for="username" class="error"><?= Arr::get($errors, 'username'); ?>
-
-		<label for="password">Password:</label>
-		<input id="password" type="password" name="password" value="<?= Arr::get($values, 'password'); ?>" />
-		<label for="password" class="error"><?= Arr::get($errors, 'password'); ?>
-
-		<label for="password_confirm">Repeat Password:</label>
-		<input id="password_confirm" type="password" name="_external[password_confirm]" value="<?= Arr::path($values, '_external.password_confirm'); ?>" />
-		<label for="password_confirm" class="error"><?= Arr::path($errors, '_external.password_confirm'); ?>
-
-		<button type="submit">Create</button>
-	</form>
-
-## Controller
-
-[!!] Remember that the `password` will be hashed as soon as it is set in the model, for this reason, it is impossible to validate it's length or the fact that it matches the `password_confirm` field. The model should not care about validating the `password_confirm` field, so we add that logic to the controller and simply ask the model to bundle the errors into one tidy array. Read the [filters](filters) section to understand how those work.
-
-	public function action_create()
-	{
-		$view = View::factory('members/create')
-			->set('values', $_POST)
-			->bind('errors', $errors);
-
-		if ($_POST)
-		{
-			$member = ORM::factory('Member')
-				// The ORM::values() method is a shortcut to assign many values at once
-				->values($_POST, array('username', 'password'));
-
-			$external_values = array(
-				// The unhashed password is needed for comparing to the password_confirm field
-				'password' => Arr::get($_POST, 'password'),
-			// Add all external values
-			) + Arr::get($_POST, '_external', array());
-			$extra = Validation::factory($external_values)
-				->rule('password_confirm', 'matches', array(':validation', ':field', 'password'));
-
-			try
-			{
-				$member->save($extra);
-				// Redirect the user to his page
-				$this->request->redirect('members/'.$member->id);
-			}
-			catch (ORM_Validation_Exception $e)
-			{
-				$errors = $e->errors('models');
-			}
-		}
-
-		$this->response->body($view);
-	}
-
-## Messages
-
-**application/messages/models/member.php**
-
-	return array(
-		'username' => array(
-			'not_empty' => 'You must provide a username.',
-			'min_length' => 'The username must be at least :param2 characters long.',
-			'max_length' => 'The username must be less than :param2 characters long.',
-			'username_available' => 'This username is not available.',
-		),
-		'password' => array(
-			'not_empty' => 'You must provide a password.',
-		),
-	);
-
-**application/messages/models/member/_external.php**
-
-	return array(
-		'password_confirm' => array(
-			'matches' => 'The password fields did not match.',
-		),
-	);

+ 0 - 41
frameworks/PHP/php-kohana/modules/orm/guide/orm/filters.md

@@ -1,41 +0,0 @@
-# Filters
-
-Filters in ORM work much like they used to when they were part of the Validate class in 3.0.x. However, they have been modified to match the flexible syntax of [Validation] rules in 3.1.x.
-
-Filters run as soon as the field is set in your model and should be used to format the data before it is inserted into the Database. Filters are defined the same way you define [rules](validation), as an array returned by the `ORM::filters()` method, like the following:
-
-	public function filters()
-	{
-		return array(
-			// Field Filters
-			// $field_name => array(mixed $callback[, array $params = array(':value')]),
-			'username' => array(
-				// PHP Function Callback, default implicit param of ':value'
-				array('trim'),
-			),
-			'password' => array(
-				// Callback method with object context and params
-				array(array($this, 'hash_password'), array(':value', Model_User::salt())),
-			),
-			'created_on' => array(
-				// Callback static method with params
-				array('Format::date', array(':value', 'Y-m-d H:i:s')),
-			),
-			'other_field' => array(
-				// Callback static method with implicit param of ':value'
-				array('MyClass::static_method'),
-				// Callback method with object context with implicit param of ':value'
-				array(array($this, 'change_other_field')),
-				// PHP function callback with explicit params
-				array('str_replace', array('luango', 'thomas', ':value'),
-				// Function as the callback (PHP 5.3+)
-				array(function($value) {
-					// Do something to $value and return it.
-					return some_function($value);
-				}),
-			),
-
-		);
-	}
-
-[!!] When defining filters, you may use the parameters `:value`, `:field`, and `:model` to refer to the field value, field name, and the model instance respectively.

+ 0 - 22
frameworks/PHP/php-kohana/modules/orm/guide/orm/index.md

@@ -1,22 +0,0 @@
-# ORM
-
-Kohana 3.x includes a powerful Object Relational Mapping (ORM) module that uses the active record pattern and database introspection to determine a model's column information. ORM is integrated tightly with the [Validation] library.
-
-The ORM allows for manipulation and control of data within a database as though it was a PHP object. Once you define the relationships ORM allows you to pull data from your database, manipulate the data in any way you like, and then save the result back to the database without the use of SQL. By creating relationships between models that follow convention over configuration, much of the repetition of writing queries to create, read, update, and delete information from the database can be reduced or entirely removed. All of the relationships can be handled automatically by the ORM library and you can access related data as standard object properties.
-
-ORM is included with the Kohana 3.x install but needs to be enabled before you can use it. In your `application/bootstrap.php` file modify the call to Kohana::modules and include the ORM modules.
-
-## Getting started
-
-Before we use ORM, we must enable the modules required
-
-	Kohana::modules(array(
-		...
-		'database' => MODPATH.'database',
-		'orm' => MODPATH.'orm',
-		...
-	));
-
-[!!] The database module is requried for the ORM module to work. Of course the database module has to be configured to use an existing database.
-
-You can now create your [models](models) and [use ORM](using).

+ 0 - 10
frameworks/PHP/php-kohana/modules/orm/guide/orm/menu.md

@@ -1,10 +0,0 @@
-## [ORM]()
-- [Creating ORM Models](models)
-- [Basic usage](using)
-- [Relationships](relationships)
-- [Validation](validation)
-- [Filters](filters)
-- [Examples](examples)
-    - [Simple](examples/simple)
-    - [Validation](examples/validation)
-- [Upgrading](upgrading)

+ 0 - 28
frameworks/PHP/php-kohana/modules/orm/guide/orm/models.md

@@ -1,28 +0,0 @@
-# Creating your Model
-
-To create a model for the table `members` in your database, create the file `application/classes/model/member.php` with the following syntax:
-
-	class Model_Member extends ORM
-	{
-		...
-	}
-
-(this should provide more examples)
-
-## Overriding the Table name
-
-If you wish to change the database table that a model uses, just override the `$_table_name` variable like this:
-
-	protected $_table_name = 'strange_tablename';
-
-## Changing the primary key
-
-ORM assumes each model (and database table) has an `id` column that is indexed and unique. If your primary key column isn't named `id`, that's fine - just override the `$_primary_key` variable like this:
-
-	protected $_primary_key = 'strange_pkey';
-
-## Use a non-default database
-
-For each model, you can define which database configuration ORM will run queries on. If you override the `$_db_group` variable in your model, ORM will connect to that database. Example:
-
-	protected $_db_group = 'alternate';

+ 0 - 123
frameworks/PHP/php-kohana/modules/orm/guide/orm/relationships.md

@@ -1,123 +0,0 @@
-# Relationships
-
-Kohana ORM supports four types of object relationships: `belongs_to`, `has_many`, `has_many "through"` and `has_one`. The `has_many "through"` relationship can be used to function like Active Record's `has_many_and_belongs_to` relationship type.
-
-## belongs_to
-
-A `belongs_to` relation should be used when you have one model that belongs to another. For example, a `Child` model belongs_to a `Parent` or a `Flag` model `belongs_to` a `Country`.
-
-This is the base `belongs_to` relationship:
-
-	protected $_belongs_to = array(
-		'[alias name]' => array(
-			'model'       => '[model name]',
-			'foreign_key' => '[column]',
-		),
-	);
-
-You can omit any or all of the keys/values in the array on the right, in which case defaults are used:
-
-	protected $_belongs_to = array('[alias name]' => array());
-
-The **alias name** is what is used to access the related model in your code. If you had a `Post` model that belonged to a `User` model and wished to use the default values of the `belongs_to` configuration then your code would look like this:
-
-	protected $_belongs_to = array('user' => array());
-
-To access the user model, you would use `$post->user`.  Since we're using the defaults above, the alias name will be used for the model name, and the foreign key in the posts table will be the alias name followed by `_id`, in this case it would be `user_id`. (You can change the `_id` suffix by modifying the `$foreign_key_suffix` variable in the model.)
-
-Let's say your `Post` database table schema doesn't have a `user_id` column but instead has an `author_id` column which is a foreign key for a record in the `User` table. You could use code like this:
-
-	protected $_belongs_to = array(
-		'user' => array(
-			'foreign_key' => 'author_id',
-		),
-	);
-
-If you wanted access a post's author by using code like `$post->author` then you would simply need to change the alias and add the `model` index:
-
-	protected $_belongs_to = array(
-		'author' => array(
-			'model'       => 'User',
-		),
-	);
-
-## has_many
-
-The standard `has_many` relationship will likely fall on the other side of a `belongs_to` relationship.  In the above examples, a post belongs to a user.  From the user's perspective, a user has many posts. A has_many relationship is defined below:
-
-	protected $_has_many = array(
-		'[alias name]' => array(
-			'model'       => '[model name]',
-			'foreign_key' => '[column]',
-		),
-	);
-
-Again, you can omit all keys in the right array to use the defaults:
-
-	protected $_has_many = array('[alias name]' => array());
-
-For our user and post example, this would look like the following in the user model:
-
-	protected $_has_many = array('posts' => array());
-
-Using the above, the posts could be access using `$user->posts->find_all()`.  Notice the `find_all()` used in this example. With `belongs_to` and `has_one` relationship types, the model is already loaded with necessary data.  For `has_many` relationships, however, you may want to limit the number of results or add additional conditions to the SQL query; you can do so prior to the `find_all()`.
-
-The model name used by default will be the singular name of the alias using the `inflector` class.  In this case, `posts` uses `post` as the model name.  The foreign key used by default is the owner model's name followed by `_id`.  In this case, the foreign key will be `user_id` and it must exist in the posts table as before.
-
-Let's assume now you want to access the posts using the name `stories` instead, and are still using the `author_id` key as in the `belongs_to` example.  You would define your has_many relationship as:
-
-	protected $_has_many = array(
-		'stories' => array(
-			'model'       => 'Post',
-			'foreign_key' => 'author_id',
-		),
-	);
-
-## has_one
-
-A `has_one` relationship is almost identical to a `has_many` relationship.  In a `has_one` relationship, there can be 1 and only 1 relationship (rather than 1 or more in a has_many). If a user can only have one post or story, rather than many then the code would look like this:
-
-	protected $_has_one = array(
-		'story' => array(
-			'model'       => 'Post',
-			'foreign_key' => 'author_id',
-		),
-	);
-
-## has_many "through"
-
-A `has_many "through"` relationship is used for many-to-many relationships.  For instance, let's assume now we have an additional model, called `Category`.  Posts may belong to more than one category, and each category may have more than one post.  To link them together, an additional table is needed with columns for a `post_id` and a `category_id` (sometimes called a pivot table).  We'll name the model for this `Post_Category` and the corresponding table `categories_posts`.
-
-To define the `has_many` "through" relationship, the same syntax for standard has_many relationships is used with the addition of a 'through' parameter.  Let's assume we're working with the Post model:
-
-	protected $_has_many = array(
-		'categories' => array(
-			'model'   => 'Category',
-			'through' => 'categories_posts',
-		),
-	);
-
-In the Category model:
-
-	protected $_has_many = array(
-		'posts' => array(
-			'model'   => 'Post',
-			'through' => 'categories_posts',
-		),
-	);
-
-To access the categories and posts, you simply use `$post->categories->find_all()` and `$category->posts->find_all()`
-
-Methods are available to check for, add, and remove relationships for many-to-many relationships.  Let's assume you have a $post model loaded, and a $category model loaded as well.  You can check to see if the $post is related to this $category with the following call:
-
-	$post->has('categories', $category);
-
-The first parameter is the alias name to use (in case your post model has more than one relationship to the category model) and the second is the model to check for a relationship with.
-
-Assuming you want to add the relationship (by creating a new record in the categories_posts table), you would simply do:
-
-	$post->add('categories', $category);
-
-To remove:
-
-	$post->remove('categories', $category);

+ 0 - 16
frameworks/PHP/php-kohana/modules/orm/guide/orm/upgrading.md

@@ -1,16 +0,0 @@
-# Upgrading
-
-## Table aliases
-
-ORM [will now alias the main table](http://dev.kohanaframework.org/issues/4066) in a query to the model's singular object name.
-i.e. Prior to 3.2 ORM set the from table like so:
-
-	$this->_db_builder->from($this->_table_name);
-
-As of 3.2 it is now aliased like so:
-
-	$this->_db_builder->from(array($this->_table_name, $this->_object_name));
-
-If you have a model `Model_Order` then when building a query use the alias like so:
-
-	$model->where('order.id', '=', $id);

+ 0 - 94
frameworks/PHP/php-kohana/modules/orm/guide/orm/using.md

@@ -1,94 +0,0 @@
-# Basic Usage
-
-## Load a new model instance
-
-To create a new `Model_User` instance, you can do one of two things:
-
-	$user = ORM::factory('User');
-	// Or
-	$user = new Model_User();
-
-## Inserting
-
-To insert a new record into the database, create a new instance of the model:
-
-	$user = ORM::factory('User');
-
-Then, assign values for each of the properties;
-
-	$user->first_name = 'Trent';
-	$user->last_name = 'Reznor';
-	$user->city = 'Mercer';
-	$user->state = 'PA';
-
-Insert the new record into the database by running [ORM::save]:
-
-	$user->save();
-
-[ORM::save] checks to see if a value is set for the primary key (`id` by default). If the primary key is set, then ORM will execute an `UPDATE` otherwise it will execute an `INSERT`.
-
-
-## Finding an object
-
-To find an object you can call the [ORM::find] method or pass the id into the ORM constructor:
-
-	// Find user with ID 20
-	$user = ORM::factory('User')
-		->where('id', '=', 20)
-		->find();
-	// Or
-	$user = ORM::factory('User', 20);
-
-## Check that ORM loaded a record
-
-Use the [ORM::loaded] method to check that ORM successfully loaded a record.
-
-	if ($user->loaded())
-	{
-		// Load was successful
-	}
-	else
-	{
-		// Error
-	}
-
-## Updating and Saving
-
-Once an ORM model has been loaded, you can modify a model's properties like this:
-
-	$user->first_name = "Trent";
-	$user->last_name = "Reznor";
-
-And if you want to save the changes you just made back to the database, just run a `save()` call like this:
-
-	$user->save();
-
-
-
-## Deleting
-
-
-To delete an object, you can call the [ORM::delete] method on a loaded ORM model.
-
-	$user = ORM::factory('User', 20);
-	$user->delete();
-
-	
-## Mass assignment
-	
-
-To set multiple values at once, use [ORM::values]
-	
-	try
-	{
-		$user = ORM::factory('user')
-			->values($this->request->post(), array('username','password'))
-			->create();
-	}
-	catch (ORM_Validation_Exception $e)
-	{
-		// Handle validation errors ...
-	}
-	
-[!!] Although the second argument is optional, it is *highly recommended* to specify the list of columns you expect to change. Not doing so will leave your code _vulnerable_ in case the attacker adds fields you didn't expect.
-

+ 0 - 111
frameworks/PHP/php-kohana/modules/orm/guide/orm/validation.md

@@ -1,111 +0,0 @@
-# Validation
-
-ORM models are tightly integrated with the [Validation] library and the module comes with a very flexible [ORM_Validation_Exception] that helps you quickly handle validation errors from basic CRUD operations.
-
-## Defining Rules
-
-Validation rules are defined in the `ORM::rules()` method. This method returns the array of rules to be added to the [Validation] object like so:
-
-	public function rules()
-	{
-		return array(
-			'username' => array(
-				// Uses Valid::not_empty($value);
-				array('not_empty'),
-				// Calls Some_Class::some_method('param1', 'param2');
-				array('Some_Class::some_method', array('param1', 'param2')),
-				// Calls A_Class::a_method($value);
-				array(array('A_Class', 'a_method')),
-				// Calls the lambda function and passes the field value and the validation object
-				array(function($value, Validation $object)
-				{
-					$object->error('some_field', 'some_error');
-				}, array(':value', ':validation')),
-			),
-		);
-	}
-
-### Bound Values
-
-ORM will automatically bind the following values with `Validation::bind()`:
-
-- **:field** - The name of the field the rule is being applied to.
-- **:value** - The value of the field the rule is being applied to.
-- **:model** - The instance of the model that is being validated.
-
-## Automatic Validation
-
-All models automatically validate their own data when `ORM::save()`, `ORM::update()`, or `ORM::create()` is called. Because of this, you should always expect these methods to throw an [ORM_Validation_Exception] when the model's data is invalid.
-
-	public function action_create()
-	{
-		try
-		{
-			$user = ORM::factory('User');
-			$user->username = 'invalid username';
-			$user->save();
-		}
-		catch (ORM_Validation_Exception $e)
-		{
-			$errors = $e->errors();
-		}
-	}
-
-## Handling Validation Exceptions
-
-The [ORM_Validation_Exception] will give you access to the validation errors that were encountered while trying to save a model's information. The `ORM_Validation_Exception::errors()` method works very similarly to `Validation::errors()`. Not passing a first parameter will return the name of the rules that failed. But unlike `Validate::errors()`, the first parameter of `ORM_Validation_Exception::errors()` is a directory path. The model's ORM::$_object_name will be appended to the directory in order to form the message file for `Validation::errors()` to use. The second parameter is identical to that of `Validation::errors()`.
-
-In the below example, the error messages will be defined in `application/messages/models/user.php`
-
-	public function action_create()
-	{
-		try
-		{
-			$user = ORM::factory('User');
-			$user->username = 'invalid username';
-			$user->save();
-		}
-		catch (ORM_Validation_Exception $e)
-		{
-			$errors = $e->errors('models');
-		}
-	}
-
-## External Validation
-
-Certain forms contain information that should not be validated by the model, but by the controller. Information such as a [CSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) token, password verification, or a [CAPTCHA](http://en.wikipedia.org/wiki/CAPTCHA) should never be validated by a model. However, validating information in multiple places and combining the errors to provide the user with a good experience is often quite tedius. For this reason, the [ORM_Validation_Exception] is built to handle multiple Validation objects and namespaces the array of errors automatically for you. `ORM::save()`, `ORM::update()`, and `ORM::create()` all take an optional first parameter which is a [Validation] object to validate along with the model.
-
-	public function action_create()
-	{
-		try
-		{
-			$user = ORM::factory('User');
-			$user->username = $_POST['username'];
-			$user->password = $_POST['password'];
-
-			$extra_rules = Validation::factory($_POST)
-				->rule('password_confirm', 'matches', array(
-					':validation', ':field', 'password'
-				));
-
-			// Pass the extra rules to be validated with the model
-			$user->save($extra_rules);
-		}
-		catch (ORM_Validation_Exception $e)
-		{
-			$errors = $e->errors('models');
-		}
-	}
-
-Because the validation object was passed as a parameter to the model, any errors found in that check will be namespaced into a sub-array called `_external`. The array of errors would look something like this:
-
-	array(
-		'username'  => 'This field cannot be empty.',
-		'_external' => array(
-			'password_confirm' => 'The values you entered in the password fields did not match.',
-		),
-	);
-
-This ensures that errors from multiple validation objects and models will never overwrite each other.
-
-[!!] The power of the [ORM_Validation_Exception] can be leveraged in many different ways to merge errors from related models. Take a look at the list of [Examples](examples) for some great use cases.