| New Proposal Template This page has been created from a template that uses "zones." To proceed:
|
Zend Framework: Zend_Db_Cursor Component Proposal
| Proposed Component Name | Zend_Db_Cursor |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Db_Cursor |
| Proposers | Bruno Piraja Moyle |
| Zend Liaison | TBD |
| Revision | 1.0 - 24 june 2009: Initial Draft. (wiki revision: 16) |
Table of Contents
1. Overview
Zend_Db_Cursor goal is to allow using database ref cursors in a row set flavor. Most of Oracle stored procedures makes use of ref cursors and usually returns it as an 'in out' parameter. oci8 extension allow the creation and access of these cursors.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
These components depends that PHP specific database extension provides interfaces to create these kind of cursors, as oci8 does.
4. Dependencies on Other Framework Components
- Zend_Exception
- Zend_Db_Adapter
- Zend_Db_Statement
5. Theory of Operation
The component should be used as a wrapper for cursors, by instantiating an object using the new operator:
In the 'index' view script
To test the component, you can use the following stored procedure - in Oracle(r) database:
This stored procedure receives an 'in out' ref cursor as a parameter and open it. By opening a ref cursor, it is populated and is ready to fetch.
6. Milestones / Tasks
- Milestone 1: [Done] Component development;
- Milestone 2: Tests;
- Milestone 3: Documentation;
- Milestone 4: Approval.
7. Class Index
- Zend_Db_Cursor_CursorAbstract
- Zend_Db_Cursor_Oracle
- Zend_Db_Cursor_Row
- Zend_Db_Cursor_Exception
- Zend_Db_Statement (this class needs to be updated in order to be aware of ref cursors binding)
8. Use Cases
| UC-01 |
|---|
13 Comments
comments.show.hideSep 18, 2009
Bruno Pirajá Moyle
By design, a cursor is a in memory result set. As a result set, it contains many records - or rows - and each row contains columns with values.
I think that is a good idea to define a class to abstract these rows - Zend_Db_Cursor_Row - as well, or make cursors behave as Zend_Db_Table_Rowset - as they share common behavior.
Any opinions?
Sep 18, 2009
Bruno Pirajá Moyle
Added the class skeleton. This code is not tested yet.
Sep 21, 2009
Brian Tipton
I am in 100% agreement that this is the proper approach to take. My first pass was really just to flesh out the ideas, and get some workable code to test. I would like to also modify Zend_Db_Statment_Oracle to be "cursor aware" so that in addition to your use case (Theory of Operation) above, you could do the following:
As you said, by design a cursor is an in memory result set. It's that point which makes me feel that you shouldn't be calling execute() on a cursor, that should be done on the Statement. If we make the Statement "cursor aware" it becomes much more fluid for the program to do the above, while still allowing the use case you have proposed for those that prefer modeling the PHP/OCI8 coding style.
What I'm currently working on looks similar to what you have proposed, though slightly different. Let me see if I can make this look right...
Zend/ Db/ Cursor/ Oracle/ Exception.php Exception.php Interface.php Oracle.php Cursor.phpWhere Zend_Db_Cursor is an abstract class that implements Zend_Db_Cursor_Interface and Zend_Db_Oracle_Cursor extends Zend_Db_Cursor. I have skeleton code to complete all the above classes, but haven't gotten around to testing them yet. I'm hoping to have time today (after meetings) to start working on that.
Sep 22, 2009
Bruno Pirajá Moyle
I agree with you that executing a cursor looks odd. My initial intention was to not create dependencies between it and the Zend_Db_* components, but after some tests, it looks like that the dependency with Zend_Db_Statement will be inevitable.
My files structure is like this:
Some considerations:
I found a annoying problem: The oci extension only knows how to work with cursors created with the oci_new_cursor function. The component will have to integrate with Zend_Db_Statement to turn on the cursor 'awareness'.
Looking at class code, there is a $_cursor property that holds a oci 'flavor' cursor. Maybe its necessary to create some methods to access it (getRawCursor() and setRawCursor($cursor)).
I am updating the theory of operation.
Dec 01, 2009
Bruno Pirajá Moyle
Re-assuming the proposal after a long break.
Jan 11, 2010
Bruno Pirajá Moyle
Just finished a new component draft, updating within a week.
Jan 29, 2010
Jean-Paul Aydin
I tried the alpha component and it seems that Statement is not well created, i get this error :
Warning: oci_bind_by_name(): supplied argument is not a valid oci8 statement resource
Jan 29, 2010
Bruno Pirajá Moyle
Just updated this proposal. Uploaded the working class skeletons - see the Theory of Operation section.
The alpha version allow to bind a ref cursor in an Oracle statement and to fetch data from it as a rowset.
Next improvement is to allow object flavor access to the Zend_Db_Cursor_Row objects.
If you can, test it and give some feedback.
Thanks
Jan 29, 2010
Bruno Pirajá Moyle
Zend_Db_Row can be accessed as an array ($row['column']) and as an object ($row->column)
Feb 11, 2010
Bruno Pirajá Moyle
Just pushed the package draft in github, the link is http://github.com/brunitto/zend-db-cursor.git
May 13, 2010
Webysther Nunes Vilela de Faria
Hello, good work. But in my opinion I believe there should be simpler, as previously stated by Brian, because the cursor in Oracle is a statement and this should be so treated for compatibility as other classes of stock are. If you create an abstract class for cursor depending on the interpretation can be confusing because its definition is sometimes a little differently in each bank, as being fit for a bank but not as a cursor.
How do I put this link: http://framework.zend.com/issues/browse/ZFINC-13 would leave here the implementation I made that solves this problem as yet have no knowledge of how to create a proposal I have just the patch same link above.
Following example of using already testing in Oracle 9i Release 2 (9.2):
SampleModel.php
SampleController.php
May 13, 2010
Webysther Nunes Vilela de Faria
Patch:
Feb 05, 2011
Dolf Schimmel (Freeaqingme)
Archiving this proposal, feel free to recover it when you want to work on it again. For more details see this email.