cvs: pear /MDB2_Schema/MDB2 Schema.php
| From: | Igor Feghali | Date: | Fri, 18 Aug 2006 21:03:26 +0000 |
| Subject: | cvs: pear /MDB2_Schema/MDB2 Schema.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-41780@lists.php.net to get a copy of this message | ||
ifeghali Fri Aug 18 21:03:26 2006 UTC
Modified files:
/pear/MDB2_Schema/MDB2 Schema.php
Log:
- Passing the right field type to getExpression()
- Todo: passing null to getExpression() on expression's operants and function's
arguments because we don't know the type of them yet
http://cvs.php.net/viewvc.cgi/pear/MDB2_Schema/MDB2/Schema.php?r1=1.85&r2=1.86&diff_format=u
Index: pear/MDB2_Schema/MDB2/Schema.php
diff -u pear/MDB2_Schema/MDB2/Schema.php:1.85 pear/MDB2_Schema/MDB2/Schema.php:1.86
--- pear/MDB2_Schema/MDB2/Schema.php:1.85 Fri Aug 18 00:39:05 2006
+++ pear/MDB2_Schema/MDB2/Schema.php Fri Aug 18 21:03:25 2006
@@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: Schema.php,v 1.85 2006/08/18 00:39:05 ifeghali Exp $
+// $Id: Schema.php,v 1.86 2006/08/18 21:03:25 ifeghali Exp $
//
require_once 'MDB2.php';
@@ -702,7 +702,7 @@
$query = '';
switch ($instruction['type']) {
case 'insert':
- $data = $this->getInstructionFields($instruction);
+ $data = $this->getInstructionFields($instruction, $table['fields']);
if (!empty($data)) {
$fields = implode(', ', array_keys($data));
$values = implode(', ', array_values($data));
@@ -711,8 +711,8 @@
}
break;
case 'update':
- $data = $this->getInstructionFields($instruction);
- $where = $this->getInstructionWhere($instruction);
+ $data = $this->getInstructionFields($instruction, $table['fields']);
+ $where = $this->getInstructionWhere($instruction, $table['fields']);
if (!empty($data)) {
array_walk($data, array($this, 'buildFieldValue'));
$fields_values = implode(', ', $data);
@@ -721,7 +721,7 @@
}
break;
case 'delete':
- $where = $this->getInstructionWhere($instruction);
+ $where = $this->getInstructionWhere($instruction, $table['fields']);
$query = sprintf($query_delete, $table_name, $where);
break;
}
@@ -761,7 +761,7 @@
* Generates a string that represents a value that should be associated
* with a column in a SQL query.
*
- * @param mixed multi dimensional array that represents the parsed field
+ * @param array multi dimensional array that represents the parsed field
* of an initialization instruction.
* @param string type of column
*
@@ -787,7 +787,7 @@
&& is_array($element['data']['arguments'])
) {
foreach ($element['data']['arguments'] as $v) {
- $arguments[] = $this->getExpression($v);
+ $arguments[] = $this->getExpression($v, null);
}
}
if (method_exists($this->db->function,
$element['data']['name'])) {
@@ -803,9 +803,9 @@
break;
case 'expression':
$str.= '(';
- $str.=
$this->getExpression($element['data']['operants'][0]);
+ $str.= $this->getExpression($element['data']['operants'][0],
null);
$str.= $this->getOperator($element['data']['operator']);
- $str.=
$this->getExpression($element['data']['operants'][1]);
+ $str.= $this->getExpression($element['data']['operants'][1],
null);
$str.= ')';
break;
}
@@ -859,8 +859,10 @@
* Walks the parsed initialization instruction array, field by field,
* storing them and their processed values inside an array.
*
- * @param mixed multi dimensional array that contains the parsed
+ * @param array multi dimensional array that contains the parsed
* initialization instruction to be processed.
+ * @param array multi dimensional array that contains the definition
+ * of the fields of the table.
*
* @return array array of strings in the form 'field_name' => 'value'
*
@@ -868,12 +870,12 @@
* @static
* @see MDB2_Schema::initializeTable()
*/
- function getInstructionFields($instruction)
+ function getInstructionFields($instruction, $fields_definition = array())
{
$fields = array();
if (!empty($instruction['data']['field']) &&
is_array($instruction['data']['field'])) {
foreach ($instruction['data']['field'] as $field) {
- $fields[$field['name']] =
$this->getExpression($field['group']);
+ $fields[$field['name']] =
$this->getExpression($field['group'],
$fields_definition[$field['name']]['type']);
}
}
return $fields;
@@ -887,8 +889,10 @@
* array, field by field, storing them and their processed values
* inside an array.
*
- * @param mixed multi dimensional array that contains the parsed
+ * @param array multi dimensional array that contains the parsed
* initialization instruction to be processed.
+ * @param array multi dimensional array that contains the definition
+ * of the fields of the table.
*
* @return array array of strings in the form 'field_name' => 'value'
*
@@ -896,11 +900,11 @@
* @static
* @see MDB2_Schema::initializeTable()
*/
- function getInstructionWhere($instruction)
+ function getInstructionWhere($instruction, $fields_definition = array())
{
$where = '';
if (!empty($instruction['data']['where'])) {
- $where = 'WHERE
'.$this->getExpression($instruction['data']['where']);
+ $where = 'WHERE
'.$this->getExpression($instruction['data']['where'],
$fields_definition[$field['name']]['type']);
}
return $where;
}