[Solar-talk] Re: Solar_Sql function _getTypeSizeScope returns
incorrect type
Pierre Oztel
pierre.oztel at gmail.com
Thu Jul 5 10:28:15 CDT 2007
Alright the default problem is solved the Solar_Sql_Table class.
I was wondering also why do we use the Solar_Sql::quote() methods. I cannot
see a reason for that, therefore i modified some
function such as:
//where array
//throws exception if the where clause does not contain a named
placeholder
//disallow updates without a where clause
public function update($data, $where = array())
{
$this->_autoValid($data);
if(empty($where)) {
throw new Exception('Invalid where clause: empty');
}
$where_clause = 'WHERE ';
foreach($where as $key) {
if(!array_key_exists($key, $data)) {
throw new Exception("Invalid where clause: '$key' not set");
} else {
$where_clause .= "$key = :$key AND ";
}
}
$where_clause = substr($where_clause,0,-5);
//force the update date
$data['updated'] = date('Y-m-d\TH:i:s');
$tmp = array();
foreach($data as $col => $val) {
$tmp[] = "$col = :$col";
}
$stmt = "UPDATE $this->_name SET "
. implode(', ', $tmp)
. ' '
. $where_clause;
$this->_connect();
$this->_sql->begin()
try {
$this->_sql->query($stmt, $data);
} catch (Exception $e) {
$this->_sql->rollback();
}
return $data;
}
Here's a list of suggestion that i'd like Solar to implement:
- 100% of the queries are prepared statement, no quote
- Insert, Update methods in Sql_Table should natively support rollback
mecanism since this class is already casting, validating
- Solar_Valid should be stored in the registry
- Foreign key constraints should be available
Suggestions ?
2007/7/2, Pierre Oztel <pierre.oztel at gmail.com>:
>
> I am also wondering how to use the Solar_Sql $_cols property.
>
> Actually, any values affected to $_cols['colname']['default'] are ignored
> by the old _buildColDef() or the new _sqlColDef () method.
>
> On line 1856 from file Adapter.php, we have :
>
> $coldef .= ($require) ? ' NOT NULL' : ' NULL';
> //added lines
> $default = $this->quote($default);
> $coldef .= ($this->notEmpty()) ? " DEFAULT '$default" : '';
>
> Some help with this problem ?
>
>
>
> 2007/7/2, Pierre Oztel <pierre.oztel at gmail.com>:
> >
> > The function Solar_Sql::_getSolarType returns incorrect types for PDO
> > mysql driver.
> >
> > I tested it with this schema:
> >
> > CREATE TABLE `bookmark` (
> > `id` int(11) NOT NULL auto_increment,
> > `url` varchar(255) NOT NULL,
> > `name` varchar(255) NOT NULL,
> > `description` mediumtext,
> > `tag` varchar(255) default NULL,
> > `created` datetime NOT NULL,
> > `updated` datetime NOT NULL,
> > PRIMARY KEY (`id`),
> > KEY `name` (`name`)
> > ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
> >
> > --
> > -- Dumping data for table `bookmark`
> > --
> >
> > INSERT INTO `bookmark` (`id`, `url`, `name`, `description`, `tag`,
> > `created`, `updated`) VALUES
> > (1, 'http1', 'name1', 'descr1', 'tag1', '2007-06-23 17:28:52',
> > '2007-06-23 17:28:52'),
> > (2, 'http2', 'name2', 'descr2', 'tag2', '2007-06-23 17:28:52',
> > '2007-06-23 17:28:52'),
> > (3, 'http3', 'name3', 'descr3', 'tag3', '2007-06-23 17:28:52',
> > '2007-06-23 17:28:52'),
> > (4, 'http4', 'name4', 'descr4', 'tag4', '2007-06-23 17:28:52',
> > '2007-06-23 17:28:52'),
> > (5, 'http5', 'name5', 'descr5', 'tag5', '2007-06-23 17:28:52',
> > '2007-06-23 17:28:52');
> >
> >
> > Solar_Sql::fetchTableCols() return the following:
> >
> >
> > *array
> >
> > *
> > 'id' =>
> > *array*
> > 'name' => string 'id' *(length=2)*
> >
> > 'type' => string 'int' *(length=3)*
> > 'size' => string
> >
> > '11' *(length=2)*
> > 'scope' => null
> > 'default' => null
> >
> > 'require' => boolean true
> > 'primary' => boolean
> >
> > true
> > 'autoinc' => boolean true
> > 'url' =>
> > *array*
> > 'name'
> >
> > => string 'url' *(length=3)*
> > 'type' => string
> >
> > 'varchar' *(length=7)*
> > 'size' => string '255' *(length=3)*
> > 'scope'
> >
> > => null
> > 'default' => string '' *(length=0)*
> > 'require'
> >
> > => boolean true
> > 'primary' => boolean false
> > 'autoinc'
> >
> > => boolean false
> > 'name' =>
> > *array*
> > 'name' => string
> >
> > 'name' *(length=4)*
> > 'type' => string 'varchar' *(length=7)*
> > 'size'
> >
> > => string '255' *(length=3)*
> > 'scope' => null
> > 'default'
> >
> > => string '' *(length=0)*
> > 'require' => boolean
> >
> > true
> > 'primary' => boolean false
> > 'autoinc' => boolean
> >
> > false
> > 'description' =>
> > *array*
> > 'name' => string 'description'
> >
> > *(length=11)*
> > 'type' => string 'mediumtext' *(length=10)*
> > 'size' =>
> >
> > null
> > 'scope' => null
> > 'default' =>
> > null
> >
> > 'require' => boolean false
> > 'primary' => boolean
> >
> > false
> > 'autoinc' => boolean false
> > 'tag' =>
> > *array*
> > 'name'
> >
> > => string 'tag' *(length=3)*
> > 'type' => string
> >
> > 'varchar' *(length=7)*
> > 'size' => string '255' *(length=3)*
> > 'scope'
> >
> > => null
> > 'default' => null
> > 'require' => boolean
> >
> > false
> > 'primary' => boolean false
> > 'autoinc' =>
> >
> > boolean false
> > 'created' =>
> > *array*
> > 'name' => string
> >
> > 'created' *(length=7)*
> > 'type' => string 'integer' *(length=7)*
> > 'size'
> >
> > => null
> > 'scope' => null
> > 'default' => string
> >
> > '' *(length=0)*
> > 'require' => boolean true
> > 'primary'
> >
> > => boolean false
> > 'autoinc' => boolean false
> > 'updated'
> >
> > =>
> > *array*
> > 'name' => string 'updated' *(length=7)*
> > 'type'
> >
> > => string 'integer' *(length=7)*
> > 'size' => null
> > 'scope'
> >
> > => null
> > 'default' => string '' *(length=0)*
> > 'require'
> >
> > => boolean true
> > 'primary' => boolean false
> > 'autoinc'
> >
> > => boolean false
> >
> >
> >
> > As such declared 'datetime' fields are recognized as 'integer';
> >
> >
> > A little modification in the getSolarType makes it works:
> >
> > ---
> > function _getSolarType() {
> > if(array_key_exists($type, $this->_describe)) {
> > $type = $this->_describe[$type];
> > }
> > return $type;
> > }
> > ---
> >
> >
> >
> >
> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman-mail3.webfaction.com/pipermail/solar-talk/attachments/20070705/6fab745f/attachment-0001.html
More information about the Solar-talk
mailing list