[floe] r416 committed - convertatronic filenames

0 views
Skip to first unread message

fl...@googlecode.com

unread,
May 23, 2010, 3:22:03 PM5/23/10
to floe-c...@googlegroups.com
Revision: 416
Author: coretxt
Date: Sun May 23 12:21:14 2010
Log: convertatronic filenames
http://code.google.com/p/floe/source/detail?r=416

Modified:
/trunk/src/repository/Query.class.php
/trunk/src/repository/services/mysql/MysqlAdaptor.class.php
/trunk/src/repository/services/mysql/MysqlConnection.class.php
/trunk/src/repository/services/mysql/MysqlIterator.class.php
/trunk/src/repository/services/mysql/MysqlQuery.class.php

=======================================
--- /trunk/src/repository/Query.class.php Thu May 20 13:33:53 2010
+++ /trunk/src/repository/Query.class.php Sun May 23 12:21:14 2010
@@ -11,9 +11,8 @@
*/

require_once dirname(__FILE__).'/../language/en/Inflect.class.php';
-require_once 'store/mysql/MysqlQuery.class.php';
-
-if (!defined('StorageAdaptor_DefaultInstance'))
define('StorageAdaptor_DefaultInstance', 'Mysql');
+
+if (!defined('Storage_DefaultInstance'))
define('Storage_DefaultInstance', 'Mysql');

/**
* Criteria based select query interface.
@@ -35,10 +34,10 @@
/**
* Factory method for returning a Query object supporting the default
storage adaptor.
*/
- static function instance($adaptor=false) {
- $adaptor = (($adaptor) ? $adaptor : StorageAdaptor_DefaultInstance);
+ static function init($adaptor=false) {
+ $adaptor = (($adaptor) ? $adaptor : Storage_DefaultInstance);
$queryAdaptor = $adaptor."Query";
- require_once 'store/'. strtolower($adaptor) .'/'.
$queryAdaptor .'.class.php';
+ require_once 'services/'. strtolower($adaptor) .'/'.
$queryAdaptor .'.class.php';
return new $queryAdaptor();
}

=======================================
--- /trunk/src/repository/services/mysql/MysqlAdaptor.class.php Sun May 23
12:12:02 2010
+++ /trunk/src/repository/services/mysql/MysqlAdaptor.class.php Sun May 23
12:21:14 2010
@@ -8,29 +8,31 @@
*
* $Id$
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/

+require_once 'MysqlConnection.class.php';
+require_once 'MysqlQuery.class.php';
require_once 'MysqlIterator.class.php';

/**
* Gateway for managing common database operations.
*
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/
-class MysqlGateway {
-
- var $_connection;
- var $_result;
- var $_currentTable;
+class MysqlAdaptor {
+
+ var $connection;
+ var $result;
+ var $currentTable;

function __construct($connection) {
- $this->_connection = $connection;
+ $this->connection = $connection;
}

function affectedRows() {
- return mysql_affected_rows($this->_result);
+ return mysql_affected_rows($this->result);
}

/**
@@ -46,7 +48,7 @@
* @return stdClass
*/
function getObject() {
- return mysql_fetch_object($this->_result);
+ return mysql_fetch_object($this->result);
}

/**
@@ -55,7 +57,7 @@
* @return mixed value
*/
function getValue() {
- $result = mysql_fetch_array($this->_result);
+ $result = mysql_fetch_array($this->result);
return $result[0];
}

@@ -66,7 +68,7 @@
*/
function getObjects() {
$i=0; $objects = array();
- while ($row = mysql_fetch_object($this->_result)) {
+ while ($row = mysql_fetch_object($this->result)) {
$objects[$i] = $row; $i++;
}
return $objects;
@@ -78,34 +80,34 @@
* @return Iterator<stdClass>
*/
function getIterator() {
- return new MysqlIterator($this->_result);
+ return new MysqlIterator($this->result);
}

/**
*
*/
function selectById($table, $id, $target=false) {
- $this->_currentTable = $table;
+ $this->currentTable = $table;
$fields = (!$target) ? '*' : implode(',', array_keys($target));
$sql = 'SELECT '.$fields.' FROM `'.$table.'` WHERE id="'.$id.'"';
- $this->_result = $this->_connection->execute($sql);
+ $this->result = $this->connection->execute($sql);
}

/**
*
*/
function selectAll($table) {
- $this->_currentTable = $table;
+ $this->currentTable = $table;
$sql = 'SELECT * FROM `'.$table.'`';
- $this->_result = $this->_connection->execute($sql);
+ $this->result = $this->connection->execute($sql);
}

/**
*
*/
function selectByKey($table, $target) {
- $this->_connection->connect();
- $this->_currentTable = $table;
+ $this->connection->connect();
+ $this->currentTable = $table;
$sql = 'SELECT * FROM `'.$table.'` WHERE ';
$where = '';
foreach ($target as $key => $value) {
@@ -115,18 +117,18 @@
$where .= mysql_real_escape_string($key) .'="'.
mysql_real_escape_string($value) .'" ';
}
$sql .= $where;
- $this->_result = $this->_connection->execute($sql);
+ $this->result = $this->connection->execute($sql);
}

/**
*
*/
function selectByAssociation($table, $join_table, $target=false) {
- $this->_currentTable = $table;
+ $this->currentTable = $table;
$sql = "SELECT * FROM `$table`,`$join_table` ";
$sql .= "WHERE
$table.id=$join_table.".Inflect::toSingular($table)."_id";
if ($target) $sql .= " AND
$join_table.".key($target)."='".current($target)."'";
- $this->_result = $this->_connection->execute($sql);
+ $this->result = $this->connection->execute($sql);
}

/**
@@ -136,8 +138,8 @@
* @param $columns associative array of column=>value pairs to create
*/
function insert($table, $columns) {
- $this->_connection->connect();
- $this->_currentTable = $table;
+ $this->connection->connect();
+ $this->currentTable = $table;
$keys = array_keys($columns);
$values = array_values($columns);
$colnum = count($columns);
@@ -151,7 +153,7 @@
$sql .= '"'.mysql_real_escape_string((string)$values[$i]).'"';
$i==($colnum-1) ? $sql .= ')' : $sql .= ',';
}
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
@@ -165,7 +167,7 @@
* Updates a row in specified table
*/
function update($table, $target, $columns) {
- $this->_connection->connect();
+ $this->connection->connect();
$colnum = count($columns);
$i = 1;
$sql = 'UPDATE `'.mysql_real_escape_string($table).'` SET ';
@@ -175,7 +177,7 @@
$i++;
}

$sql .= 'WHERE '.mysql_real_escape_string(key($target)).'="'.mysql_real_escape_string(current($target)).'"';
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
@@ -192,23 +194,23 @@
}
$where .= mysql_real_escape_string($key) .'="'.
mysql_real_escape_string($value) .'" ';
}
- $this->_connection->execute($sql . $where);
+ $this->connection->execute($sql . $where);
}

/**
* Executes an arbitrary SQL query on the connection.
*/
function query($sql) {
- $this->_result = $this->_connection->execute($sql);
+ $this->result = $this->connection->execute($sql);
}

/**
* Executes an arbitrary SELECT query on the connection.
*/
function select($table, $clauses) {
- $this->_currentTable = $table;
+ $this->currentTable = $table;
$sql = "SELECT * FROM `$table` $clauses";
- $this->_result = $this->_connection->execute($sql);
+ $this->result = $this->connection->execute($sql);
}

/**
@@ -225,28 +227,28 @@
}
$sql .= "\nPRIMARY KEY (`id`)\n";
$sql .= ") TYPE=$type AUTO_INCREMENT=1 ;";
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
* Destroys an existing table and all its data
*/
function dropTable($table) {
- $this->_connection->execute("DROP TABLE `$table`");
+ $this->connection->execute("DROP TABLE `$table`");
}

/**
* Renames a table
*/
function renameTable($tableFrom, $tableTo) {
- $this->_connection->execute("RENAME TABLE `$tableFrom` TO `$tableTo`");
+ $this->connection->execute("RENAME TABLE `$tableFrom` TO `$tableTo`");
}

/**
* Checks if a table exists
*/
function tableExists($table) {
- $this->_connection->execute("DROP TABLE IF EXISTS `$table``");
+ $this->connection->execute("DROP TABLE IF EXISTS `$table``");
}

/**
@@ -255,14 +257,14 @@
function changeColumn($table, $oldCol, $newCol, $type=false) {
if (!$type) {
$sql = "SHOW FIELDS FROM `$table` LIKE '$oldCol'";
- $this->_result = $this->_connection->execute($sql);
+ $this->result = $this->connection->execute($sql);
$field = $this->getObject();
$definition = $field->Type;
} else {
$definition = $this->defineType($type);
}
$sql = "ALTER TABLE `$table` CHANGE COLUMN $oldCol $newCol ".
$definition;
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
@@ -271,7 +273,7 @@
function addColumn($table, $name, $type) {
$name = Inflect::propertyToColumn($name);
$sql = "ALTER TABLE `$table` ADD COLUMN $name " .
$this->defineType($type);
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
@@ -280,7 +282,7 @@
function dropColumn($table, $name) {
$name = Inflect::propertyToColumn($name);
$sql = "ALTER TABLE `$table` DROP COLUMN $name";
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
@@ -289,7 +291,7 @@
function addIndex($table, $name, $columns) {
$name = strtoupper($name);
$sql = "ALTER TABLE `$table` ADD INDEX `$name` (".
array_reduce($columns, array($this,'reduceIndexColumns')) .")";
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
@@ -311,7 +313,7 @@
function dropIndex($table, $name) {
$name = strtoupper($name);
$sql = "DROP INDEX `$name` ON `$table`";
- $this->_connection->execute($sql);
+ $this->connection->execute($sql);
}

/**
@@ -321,7 +323,7 @@
*/
function hasTable($table) {
$sql = "SHOW TABLES LIKE '$table'";
- return (boolean)mysql_num_rows($this->_connection->execute($sql));
+ return (boolean)mysql_num_rows($this->connection->execute($sql));
}

/**
=======================================
--- /trunk/src/repository/services/mysql/MysqlConnection.class.php Wed May
19 05:55:56 2010
+++ /trunk/src/repository/services/mysql/MysqlConnection.class.php Sun May
23 12:21:14 2010
@@ -8,7 +8,7 @@
*
* $Id$
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/

require_once dirname(__FILE__) .'/../../../framework/EventLog.class.php';
@@ -16,65 +16,65 @@

/**
* If a UTF8 connection is needed, this constant should be set to true.
- * Should only be used if the database is not correctly configured for
UTF8 connections.
+ * Should only be used if the name is not correctly configured for UTF8
connections.
*/
if (!defined('MysqlConnection_ForceUTF8'))
define('MysqlConnection_ForceUTF8', false);

/**
- * An active connection to a MySql database server.
+ * An active connection to a MySql name server.
*
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/
class MysqlConnection {

private $connection;
- private $_db_host;
- private $_db_name;
- private $_db_user;
- private $_db_pass;
+ private $host;
+ private $name;
+ private $user;
+ private $pass;

/**
* Constructs a Mysql connection that can be obtained upon invocation of
the connect method.
*
- * @param $host Address of database server
- * @param $name Name of database to connect to
- * @param $user Authorized user name on database
- * @param $pass Authorized password for user
+ * @param $host Address of name server
+ * @param $name Name of name to connect to
+ * @param $user Authorized user name on name
+ * @param $pass Authorized pass for user
*/
function __construct($environment = false) {
if ($environment) {
- $this->_db_host = $environment->DB_HOST;
- $this->_db_name = $environment->DB_NAME;
- $this->_db_user = $environment->DB_USER;
- $this->_db_pass = $environment->DB_PASS;
+ $this->host = $environment->DB_HOST;
+ $this->name = $environment->DB_NAME;
+ $this->user = $environment->DB_USER;
+ $this->pass = $environment->DB_PASS;
} else {
- $this->_db_host = DB_HOST;
- $this->_db_name = DB_NAME;
- $this->_db_user = DB_USER;
- $this->_db_pass = DB_PASS;
+ $this->host = DB_HOST;
+ $this->name = DB_NAME;
+ $this->user = DB_USER;
+ $this->pass = DB_PASS;
}
}

/**
- * Idempotent method creates the low level connection to the database.
+ * Idempotent method creates the low level connection to the name.
*
* @public
* @return boolean true on success
*/
function connect() {
if (!is_resource($this->connection)) {
- $this->connection = @mysql_connect($this->_db_host, $this->_db_user,
$this->_db_pass);
+ $this->connection = @mysql_connect($this->host, $this->user,
$this->pass);
if (!is_resource($this->connection)) {
$this->raiseError();
return false;
}
- EventLog::info("Connected to [{$this->_db_host}]");
- if (!@mysql_select_db($this->_db_name, $this->connection)) {
+ EventLog::info("Connected to [{$this->host}]");
+ if (!@mysql_select_db($this->name, $this->connection)) {
$this->raiseError();
return false;
}
- EventLog::info("Selected [{$this->_db_name}]");
+ EventLog::info("Selected [{$this->name}]");
if (MysqlConnection_ForceUTF8) mysql_set_charset('utf8',
$this->connection);
}
return true;
@@ -89,7 +89,7 @@
}

/**
- * Issue an SQL query against the database
+ * Issue an SQL query against the name
*/
function execute($sql) {
$this->connect();
=======================================
--- /trunk/src/repository/services/mysql/MysqlIterator.class.php Tue May 18
08:02:36 2010
+++ /trunk/src/repository/services/mysql/MysqlIterator.class.php Sun May 23
12:21:14 2010
@@ -8,7 +8,7 @@
*
* $Id$
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/
require_once dirname(__FILE__).'/../StorageIterator.class.php';

@@ -16,7 +16,7 @@
* Iterator over a Mysql result set.
*
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/
class MysqlIterator implements Iterator {

=======================================
--- /trunk/src/repository/services/mysql/MysqlQuery.class.php Thu May 20
05:26:59 2010
+++ /trunk/src/repository/services/mysql/MysqlQuery.class.php Sun May 23
12:21:14 2010
@@ -8,15 +8,16 @@
*
* $Id$
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/
+
require_once dirname(__FILE__).'/../../Query.class.php';

/**
* Query criteria builder representing a Mysql query
*
* @package repository
- * @subpackage store.mysql
+ * @subpackage services.mysql
*/
class MysqlQuery extends Query {

--
You received this message because you are subscribed to the Google Groups "Floe Commits" group.
To post to this group, send email to floe-c...@googlegroups.com.
To unsubscribe from this group, send email to floe-commits...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/floe-commits?hl=en.

Reply all
Reply to author
Forward
0 new messages