1 # interface pq\Converter
3 Interface for type conversions.
10 * Naive geometric point
15 function __construct($x, $y) {
27 function __construct(Point $p1, Point $p2) {
34 * Our converter handles only objects of type box
36 class BoxConverter implements pq\Converter {
38 function __construct(pq\Types $types) {
39 $this->oid = $types["box"]->oid;
44 * @see pq\Converter::convertTypes()
46 function convertTypes() {
53 * @see pq\Converter::convertToString()
55 function convertToString($box, $type = NULL) {
56 return sprintf("(%F,%F),(%F,%F)",
57 $box->p1->x, $box->p1->y,
58 $box->p2->x, $box->p2->y
65 * @see pq\Converter::convertFromString()
67 function convertFromString($data, $type = NULL) {
68 list($p1x, $p1y, $p2x, $p2y) = sscanf($data, "(%f,%f),(%f,%f)");
69 return new Box(new Point($p1x, $p1y), new Point($p2x, $p2y));
73 $conn = new pq\Connection;
74 $types = new pq\Types($conn);
75 $conv = new BoxConverter($types);
76 $inbox = new Box(new Point(1.1, 2.2), new Point(3.3, 4.4));
78 $conn->setConverter($conv);
79 $result = $conn->execParams("SELECT \$1", [$inbox], [$types["box"]->oid]);
80 $result->fetchCol($outbox);
90 object(Point)#164 (2) {
97 object(Point)#165 (2) {