1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Eav
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Eav Mysql resource helper model
30: *
31: * @category Mage
32: * @package Mage_Eav
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Eav_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_Helper_Mysql4
36: {
37: /**
38: * Mysql column - Table DDL type pairs
39: *
40: * @var array
41: */
42: protected $_ddlColumnTypes = array(
43: Varien_Db_Ddl_Table::TYPE_BOOLEAN => 'bool',
44: Varien_Db_Ddl_Table::TYPE_SMALLINT => 'smallint',
45: Varien_Db_Ddl_Table::TYPE_INTEGER => 'int',
46: Varien_Db_Ddl_Table::TYPE_BIGINT => 'bigint',
47: Varien_Db_Ddl_Table::TYPE_FLOAT => 'float',
48: Varien_Db_Ddl_Table::TYPE_DECIMAL => 'decimal',
49: Varien_Db_Ddl_Table::TYPE_NUMERIC => 'decimal',
50: Varien_Db_Ddl_Table::TYPE_DATE => 'date',
51: Varien_Db_Ddl_Table::TYPE_TIMESTAMP => 'timestamp',
52: Varien_Db_Ddl_Table::TYPE_DATETIME => 'datetime',
53: Varien_Db_Ddl_Table::TYPE_TEXT => 'text',
54: Varien_Db_Ddl_Table::TYPE_BLOB => 'blob',
55: Varien_Db_Ddl_Table::TYPE_VARBINARY => 'blob'
56: );
57:
58: /**
59: * Returns columns for select
60: *
61: * @param string $tableAlias
62: * @param string $eavType
63: * @return string|array
64: */
65: public function attributeSelectFields($tableAlias, $eavType)
66: {
67: return '*';
68: }
69:
70: /**
71: * Returns DDL type by column type in database
72: *
73: * @param string $columnType
74: * @return string
75: */
76: public function getDdlTypeByColumnType($columnType)
77: {
78: switch ($columnType) {
79: case 'char':
80: case 'varchar':
81: $columnType = 'text';
82: break;
83: case 'tinyint':
84: $columnType = 'smallint';
85: break;
86: }
87:
88: return array_search($columnType, $this->_ddlColumnTypes);
89: }
90:
91: /**
92: * Prepares value fields for unions depend on type
93: *
94: * @param string $value
95: * @param string $eavType
96: * @return Zend_Db_Expr
97: */
98: public function prepareEavAttributeValue($value, $eavType)
99: {
100: return $value;
101: }
102:
103: /**
104: * Groups selects to separate unions depend on type
105: *
106: * @param array $selects
107: * @return array
108: */
109: public function getLoadAttributesSelectGroups($selects)
110: {
111: $mainGroup = array();
112: foreach ($selects as $eavType => $selectGroup) {
113: $mainGroup = array_merge($mainGroup, $selectGroup);
114: }
115: return array($mainGroup);
116: }
117:
118: /**
119: * Retrieve 'cast to int' expression
120: *
121: * @param string|Zend_Db_Expr $expression
122: * @return Zend_Db_Expr
123: */
124: public function getCastToIntExpression($expression)
125: {
126: return new Zend_Db_Expr("CAST($expression AS SIGNED)");
127: }
128: }
129: