|
|
Subject: Re: quoteInto improvment - msg#00007
List: php.zend.framework.db
There are deep problems with quoting in Zend_Db* components:
http://framework.zend.com/wiki/x/RB8
Cheers,
Gavin
David Koblas wrote:
The quoteInto() method is a little limiting...
public function quoteInto($text, $value)
{
return str_replace('?', $this->quote($value), $text);
}
Really should be able to handle an array as a second argument, on top
of it it would be nice if then could handle key => value arrays.
Maybe something like:
class Db_Quote_Closure {
public $value;
public $db;
private $idx = 0;
public function __construct($db, $v) {
$this->db = $db;
$this->value = $v;
}
public function doAssoc($matches) {
return $this->db->quote($this->value[$matches[1]]);
}
public function doIndex($matches) {
if (isset($this->value[$this->idx]))
return $this->db->quote($this->value[$this->idx++]);
return '';
}
}
static function quoteInto($str, $value) {
if (is_array($value)) {
$allNumbers = true;
foreach (array_keys($value) as $k) {
$allNumbers &= is_numeric($k);
}
$obj = new Db_Quote_Closure($db, $value);
if ($allNumbers) {
return preg_replace_callback('/\?/', array($obj,
'doIndex'), $str);
} else {
return preg_replace_callback('/:(\w+)/', array($obj,
'doAssoc'), $str);
}
} else {
return str_replace('?', $db->quote($value), $str);
}
}
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
quoteInto improvment
The quoteInto() method is a little limiting...
public function quoteInto($text, $value)
{
return str_replace('?', $this->quote($value), $text);
}
Really should be able to handle an array as a second argument, on top of
it it would be nice if then could handle key => value arrays. Maybe
something like:
class Db_Quote_Closure {
public $value;
public $db;
private $idx = 0;
public function __construct($db, $v) {
$this->db = $db;
$this->value = $v;
}
public function doAssoc($matches) {
return $this->db->quote($this->value[$matches[1]]);
}
public function doIndex($matches) {
if (isset($this->value[$this->idx]))
return $this->db->quote($this->value[$this->idx++]);
return '';
}
}
static function quoteInto($str, $value) {
if (is_array($value)) {
$allNumbers = true;
foreach (array_keys($value) as $k) {
$allNumbers &= is_numeric($k);
}
$obj = new Db_Quote_Closure($db, $value);
if ($allNumbers) {
return preg_replace_callback('/\?/', array($obj,
'doIndex'), $str);
} else {
return preg_replace_callback('/:(\w+)/', array($obj,
'doAssoc'), $str);
}
} else {
return str_replace('?', $db->quote($value), $str);
}
}
Next Message by Date:
click to view message preview
Re: Zend_Db_Table
Gavin Vess wrote:
> I am pleased to announce the continuing interest by many in the "KISS"
> ORM flavors discussed for months in the ZF mail lists. The community
> proposal below shows excellent potential, has been approved for the ZF Lab.
>
> We look forward to its evolution and testing in the ZF Laboratory, and
> increasing potential for moving to ZF core. When the code is committed,
> please consider giving this a trial run, and post your feedback to this
> list :)
>
> Speaking only for myself, I suspect we need an ultralight-weight ORM and
> a "heavy" lifter, such as Qcodo, in order to satisfy the diverse needs
> of the majority.
>
> http://framework.zend.com/wiki/x/bx0
>
> http://framework.zend.com/wiki/x/Mw4
>
> http://www.nabble.com/-need-advices--An-idea-to-build-a-KISS-ORM-system-upon-Zend_Db_Table-tf1926214.html#a5274924
>
>
> Cheers,
> Gavin
>
> P.S. For information on the ZF Lab, see
> http://framework.zend.com/wiki/display/ZFPROP/Home
>
> svn checkout http://framework.zend.com/svn/laboratory/
Excellent - looks interesting.
Regards,
Rob...
Previous Message by Thread:
click to view message preview
quoteInto improvment
The quoteInto() method is a little limiting...
public function quoteInto($text, $value)
{
return str_replace('?', $this->quote($value), $text);
}
Really should be able to handle an array as a second argument, on top of
it it would be nice if then could handle key => value arrays. Maybe
something like:
class Db_Quote_Closure {
public $value;
public $db;
private $idx = 0;
public function __construct($db, $v) {
$this->db = $db;
$this->value = $v;
}
public function doAssoc($matches) {
return $this->db->quote($this->value[$matches[1]]);
}
public function doIndex($matches) {
if (isset($this->value[$this->idx]))
return $this->db->quote($this->value[$this->idx++]);
return '';
}
}
static function quoteInto($str, $value) {
if (is_array($value)) {
$allNumbers = true;
foreach (array_keys($value) as $k) {
$allNumbers &= is_numeric($k);
}
$obj = new Db_Quote_Closure($db, $value);
if ($allNumbers) {
return preg_replace_callback('/\?/', array($obj,
'doIndex'), $str);
} else {
return preg_replace_callback('/:(\w+)/', array($obj,
'doAssoc'), $str);
}
} else {
return str_replace('?', $db->quote($value), $str);
}
}
Next Message by Thread:
click to view message preview
Table manipulation in Zend_Db_Adaptor
Hi,
I really like the
Zend_Db_Schema_Manager(http://framework.zend.com/wiki/display/ZFPROP/Zend_Db_Schema_Manager+-+Rob+Allen)
proposal. It is especially the possibility of having the db schema in
versioncontrol in a backend neutral way. But as mentioned in the proposal
this requires some adapter functionality for each supported engine.
Stealing from rails; the following methods would properbly be needed:
createTable($name, $options);
dropTable($name);
renameTable($oldName, $newName);
addColumn($tableName, $columName, $type, $options);
renameColumn($tableName, $columnName, $newColumnName);
changeColumn($tableName, $columnName, $type, $options);
removeColumn($tableName, $columnName);
This would also require some cross-db datatypes like:
string, text, integer, float, datetime, timestamp, time, date, binary,
boolean
I think these methods would be a nice adition to the db adapters. The
describeTable method of the adapters already does some abstraction of schema
information, why not go all the way?
What do you think?
/Jacob
--
View this message in context:
http://www.nabble.com/Table-manipulation-in-Zend_Db_Adaptor-tf2823225s16154.html#a7880343
Sent from the Zend DB mailing list archive at Nabble.com.
|
|