[Solar-talk] New Sql Adapter and Select Code in SVN
Paul M Jones
pmjones at solarphp.com
Tue Mar 13 10:04:47 PDT 2007
Hi everyone,
As I've talked about earlier, the new SQL_Adapter code is in place.
I noted before that the combined select() method has been removed in
favor of separate fetch*() methods.
Transitioning from the older Adapter and Select code to the new code
should be as easy as a search-and-replace on your code base (in most
common cases, anyway). I've done the search-and-replace for the
Solar distribution, and didn't have to change anything in the
Bookmarks application code, only the underlying table-based Model and
Content classes (and even those didn't change much).
Using The New Solar_Sql_Adapter
-------------------------------
You will want to search-and-replace from these old calls to these new
calls:
| Old Solar_Sql_Adapter Call | New Call |
| -------------------------------- | ------------------- |
| $sql->select('all' ...) | $sql->fetchRowset() |
| $sql->select('array' ...) | $sql->fetchAll() |
| $sql->select('assoc' ...) | $sql->fetchAssoc() |
| $sql->select('col' ...) | $sql->fetchCol() |
| $sql->select('one' ...) | $sql->fetchValue() |
| $sql->select('pair' ...) | $sql->fetchPairs() |
| $sql->select('pairs' ...) | $sql->fetchPairs() |
| $sql->select('pdo' ...) | $sql->fetchPdo() |
| $sql->select('pdostatement' ...) | $sql->fetchPdo() |
| $sql->select('result' ...) | **not supported** |
| $sql->select('row' ...) | $sql->fetchRow() |
| $sql->select('statement' ...) | $sql->fetchPdo() |
| $sql->select('string' ...) | $sql->fetchSql() |
{{Note:
The fetchRow() and fetchRowset() methods are deprecated as of
their introduction. They are available only for transition
purposes as we move from Table/Row/Rowset to Model.
Also, the new fetchOne() method is the equivalent of fetching a
single row as an array.
}}
Using The New Solar_Sql_Select
------------------------------
While the Select class has not changed much internally, you still need
to search-and-replace from old calls to new ones, because of the
changes in the Adapter code.
| Old Solar_Sql_Select Call | New Call |
| ------------------------------- | ------------------------ |
| $select->fetch('all') | $select->fetch('rowset') |
| $select->fetch('array') | $select->fetch('all') |
| $select->fetch('assoc') | $select->fetch('assoc') |
| $select->fetch('col') | $select->fetch('col') |
| $select->fetch('one') | $select->fetch('value') |
| $select->fetch('pair') | $select->fetch('pairs') |
| $select->fetch('pairs') | $select->fetch('pairs') |
| $select->fetch('pdo') | $select->fetch('pdo') |
| $select->fetch('pdostatement') | $select->fetch('pdo') |
| $select->fetch('result') | **not supported** |
| $select->fetch('row') | $select->fetch('row') |
| $select->fetch('statement') | $select->fetch('sql') |
| $select->fetch('string') | $select->fetch('sql') |
{{Note:
The fetch('row') and fetch('rowset') methods are deprecated as of
their introduction. They are available only for transition
purposes as we move from Table/Row/Rowset to Model.
Also, the new fetch('one') method is the equivalent of fetching a
single row as an array.
}}
Deprecating Table/Row/Rowset
----------------------------
Solar_Sql_Table, Row, and Rowset will be deprecated in favor of the
new Model class, and will be removed at some time in the future.
Even so, I have already converted them to use the new Adapter and
Select code, so you should not have much (if any) trouble with your
existing Table-based classes.
Because the Model class is not complete, Table/Row/Rowset will be
sticking around for at least the next two monthly releases, and
perhaps for even longer. That should give us all time to to work
with the new Model classes and prepare a transition away from Table.
(I promise I won't remove Table/Row/Rowset without bringing it up on
the mailing list at least one more time.)
If anyone has problems with this timeline or approach, I'm open to
hearing other ideas. Not trying to force anything on you guys, just
trying to provide a clear migration path.
I'll talk more about the new Model class in a separate email.
As always, if you guys have questions, comments, or concerns, please
let me know ... and thank you for your patience with these big
changes in the SQL/ORM package.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list