thekid/rfc — Issue #107: RFC 0107: Generic acccess to rdbms.Peer/rdbms.DataSet
Author: thekid
Created: 2011-10-09 15:08:30+00:00
State: open

Scope of Change
====
The Peer / DataSet classes will be changed to be able to access them in
a generic way.

Rationale
====
Required for xp-framework/rfc #78

Functionality
====

Field information
----
Some type information is lost after classes are generated, i.e. the exact
type in the database (the Peer object only knows the SQL token, %s, %d,
etc.). Thus, the rdbms.Peer's "types" field will be changed from
array to array in order to be able to
contain more information.

Comparison: Excerpt from net.xp_framework.unittest.rdbms.dataset.Job

```php
setTypes(array(
'job_id' => '%d',
'title' => '%s',
'valid_from' => '%s',
'expire_at' => '%s'
));

// New
$peer->setTypes(array(
'job_id' => array('%d', FieldType::NUMERIC, FALSE),
'title' => array('%s', FieldType::VARCHAR, FALSE),
'valid_from' => array('%s', FieldType::VARCHAR, TRUE),
'expire_at' => array('%s', FieldType::DATETIME, FALSE),
));
?>
```

The array contains the following fields:

```
Offset Contents
------ ---------------------------------------------------------------
0 SQL token (one of %d, %s, %f)
1 Field type (one of the rdbms.FieldType enumeration's constants)
2 Whether the field is nullable (boolean)

```

Fieldtype constants
----

```php

```

Generic set/get methods
----
The following two methods will be added to the DataSet class:

```php

```

This will make dynamic method calls (whether by evaluation brackets or
reflection) obsolete:

```php
{'get'.$peer->identity}();
$dataset->{'set'.$field}($value);

// Old #2
$id= $dataset->getClass()->getMethod('get'.$peer->identity)->invoke($dataset);
$dataset->getClass()->getMethod('set'.$field)->invoke($dataset, array($value));

// New
$id= $dataset->get($peer->identity);
?>
```

New DataSet instance creation
----
A new method rdbms.Peer class will be added to the rdbms.Peer class to
complement the objectFor(array) method:

```php

```

This is a shorthand for the following:

```php
identifier)->newInstance();

// New
$ds= $peer->newObject();
?>
```

Security considerations
====
n/a

Speed impact
====
Slightly slower.

Dependencies
====
New FieldType class for the field type enumeration.

Related documents
====
- http://xp-framework.net/rfc/contrib/rfc0107.diff
Implementing patch

- http://xp-framework.net/rfc/contrib/rfc0107-dbgenerator.diff
DB Generator patch (generates PHP5 source including the new functionality)

Comments
====
- friebe, Fri Jan 12 15:42:38 CET 2007
By choosing an array for field information, we can extend field
information easily by adding new elements.