partial QueryWriter
authorMichael Wallner <mike@php.net>
Wed, 15 Oct 2014 05:40:56 +0000 (07:40 +0200)
committerMichael Wallner <mike@php.net>
Wed, 15 Oct 2014 05:40:56 +0000 (07:40 +0200)
17 files changed:
pq-gateway/pq/Query.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer/__toString.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer/criteria.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer/getParams.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer/getTypes.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer/param.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer/reset.md [new file with mode: 0644]
pq-gateway/pq/Query/Writer/write.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface/__toString.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface/criteria.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface/getParams.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface/getTypes.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface/param.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface/reset.md [new file with mode: 0644]
pq-gateway/pq/Query/WriterInterface/write.md [new file with mode: 0644]

diff --git a/pq-gateway/pq/Query.md b/pq-gateway/pq/Query.md
new file mode 100644 (file)
index 0000000..e2fd8e0
--- /dev/null
@@ -0,0 +1,3 @@
+# namespace pq\Query
+
+The pq\Query namespace holds implementations and interfaces related to assembling, expressing and executing queries on behalf of the gateway.
diff --git a/pq-gateway/pq/Query/Writer.md b/pq-gateway/pq/Query/Writer.md
new file mode 100644 (file)
index 0000000..2203f61
--- /dev/null
@@ -0,0 +1,13 @@
+# class pq\Query\Writer implements pq\Query\WriterInterface
+
+A query writer implementation.
+
+## Properties:
+
+* protected string $query  
+  The assembled query.
+* protected array $params  
+  The query parameters.
+* protected array $types  
+  The query parameters' types.
+
diff --git a/pq-gateway/pq/Query/Writer/__toString.md b/pq-gateway/pq/Query/Writer/__toString.md
new file mode 100644 (file)
index 0000000..ae0f1df
--- /dev/null
@@ -0,0 +1,11 @@
+# string pq\Query\Writer::__toString()
+
+Retrieve the assembled query.
+
+## Params:
+
+None.
+
+## Returns:
+
+* string, the plainy query string.
diff --git a/pq-gateway/pq/Query/Writer/criteria.md b/pq-gateway/pq/Query/Writer/criteria.md
new file mode 100644 (file)
index 0000000..0f27ae5
--- /dev/null
@@ -0,0 +1,41 @@
+# pq\Query\Writer pq\Query\Writer::criteria(array $criteria)
+
+Write nested AND/OR criteria to the query string.
+
+## Params:
+
+* array $criteria  
+  Nested AND/OR criteria.
+
+## Returns:
+
+* pq\Query\Writer, self.
+
+## Example:
+
+       <?php
+       
+       use pq\Query;
+       
+       $q = new Query\Writer;
+       $q->write("select * from account where")
+         ->criteria([
+           ["id >" => 1, "id <" => 5],
+           ["name =" => "mike"]
+         ]);
+       
+       var_dump((string) $q, $q->getParams());
+       
+       ?>
+
+Yields:
+
+       string(84) "select * from account where ( ( ( id > $1 ) AND ( id < $2 ) ) OR ( ( name = $3 ) ) )"
+       array(3) {
+         [0]=>
+         int(1)
+         [1]=>
+         int(5)
+         [2]=>
+         string(4) "mike"
+       }
diff --git a/pq-gateway/pq/Query/Writer/getParams.md b/pq-gateway/pq/Query/Writer/getParams.md
new file mode 100644 (file)
index 0000000..719eb95
--- /dev/null
@@ -0,0 +1,11 @@
+# array pq\Query\Writer::getParams()
+
+Retrieve the query parameters.
+
+## Params:
+
+None.
+
+## Returns:
+
+* array, list of query parameters.
diff --git a/pq-gateway/pq/Query/Writer/getTypes.md b/pq-gateway/pq/Query/Writer/getTypes.md
new file mode 100644 (file)
index 0000000..277f0c9
--- /dev/null
@@ -0,0 +1,11 @@
+# array pq\Query\Writer::getTypes()
+
+Get the query parameters' types.
+
+## Params:
+
+None.
+
+## Returns:
+
+* array, list of type OIDs.
diff --git a/pq-gateway/pq/Query/Writer/param.md b/pq-gateway/pq/Query/Writer/param.md
new file mode 100644 (file)
index 0000000..9a7e9a7
--- /dev/null
@@ -0,0 +1,35 @@
+# string pq\Query\Writer::param(mixed $param[, int $type = NULL])
+
+Remember the parameter with any associated type and return $N to be written to the query string.
+
+## Params:
+
+* mixed $param  
+  Query parameter value.
+* Optional int $type = NULL  
+  The type OID of the parameter.
+
+## Returns:
+
+* string, '$N', to be used with pq\Query\Writer::write(), where N is tne number of this parameter.
+
+## Example:
+
+       <?php
+       
+       use pq\Query;
+       
+       $writer = new Query\Writer;
+       $writer->write("SELECT", $writer->param(1));
+       
+       var_dump((string) $writer, $writer->getParams());
+       
+       ?>
+
+Yields:
+
+       string(9) "SELECT $1"
+       array(1) {
+         [0]=>
+         int(1)
+       }
diff --git a/pq-gateway/pq/Query/Writer/reset.md b/pq-gateway/pq/Query/Writer/reset.md
new file mode 100644 (file)
index 0000000..c29d5cb
--- /dev/null
@@ -0,0 +1,11 @@
+# pq\Query\Writer pq\Query\Writer::reset()
+
+Reset the query writer to initial state.
+
+## Params:
+
+None.
+
+## Returns:
+
+* pq\Query\Writer, self.
diff --git a/pq-gateway/pq/Query/Writer/write.md b/pq-gateway/pq/Query/Writer/write.md
new file mode 100644 (file)
index 0000000..ba03b7b
--- /dev/null
@@ -0,0 +1,11 @@
+# pq\Query\Writer pq\Query\Writer::write()
+
+Write a part of the query string.
+
+## Params:
+
+* Variable list of query parts.
+
+## Returns:
+
+* pq\Query\Writer, self.
diff --git a/pq-gateway/pq/Query/WriterInterface.md b/pq-gateway/pq/Query/WriterInterface.md
new file mode 100644 (file)
index 0000000..3d3718f
--- /dev/null
@@ -0,0 +1,4 @@
+# interface pq\Query\WriterInterface
+
+API for assembling unnamed statements with safe parameter substitution.
+See pq\Gateway\Table::setQueryWriter().
diff --git a/pq-gateway/pq/Query/WriterInterface/__toString.md b/pq-gateway/pq/Query/WriterInterface/__toString.md
new file mode 100644 (file)
index 0000000..46fa92b
--- /dev/null
@@ -0,0 +1,11 @@
+# string pq\Query\WriterInterface::__toString()
+
+Retrieve the assembled query.
+
+## Params:
+
+None.
+
+## Returns:
+
+* string, the plainy query string.
diff --git a/pq-gateway/pq/Query/WriterInterface/criteria.md b/pq-gateway/pq/Query/WriterInterface/criteria.md
new file mode 100644 (file)
index 0000000..374e1d1
--- /dev/null
@@ -0,0 +1,41 @@
+# pq\Query\WriterInterface pq\Query\WriterInterface::criteria(array $criteria)
+
+Write nested AND/OR criteria to the query string.
+
+## Params:
+
+* array $criteria  
+  Nested AND/OR criteria.
+
+## Returns:
+
+* pq\Query\WriterInterface, self.
+
+## Example:
+
+       <?php
+       
+       use pq\Query;
+       
+       $q = new Query\Writer;
+       $q->write("select * from account where")
+         ->criteria([
+           ["id >" => 1, "id <" => 5],
+           ["name =" => "mike"]
+         ]);
+       
+       var_dump((string) $q, $q->getParams());
+       
+       ?>
+
+Yields:
+
+       string(84) "select * from account where ( ( ( id > $1 ) AND ( id < $2 ) ) OR ( ( name = $3 ) ) )"
+       array(3) {
+         [0]=>
+         int(1)
+         [1]=>
+         int(5)
+         [2]=>
+         string(4) "mike"
+       }
diff --git a/pq-gateway/pq/Query/WriterInterface/getParams.md b/pq-gateway/pq/Query/WriterInterface/getParams.md
new file mode 100644 (file)
index 0000000..7839a60
--- /dev/null
@@ -0,0 +1,11 @@
+# array pq\Query\WriterInterface::getParams()
+
+Retrieve the query parameters.
+
+## Params:
+
+None.
+
+## Returns:
+
+* array, list of query parameters.
diff --git a/pq-gateway/pq/Query/WriterInterface/getTypes.md b/pq-gateway/pq/Query/WriterInterface/getTypes.md
new file mode 100644 (file)
index 0000000..f518c52
--- /dev/null
@@ -0,0 +1,11 @@
+# array pq\Query\WriterInterface::getTypes()
+
+Get the query parameters' types.
+
+## Params:
+
+None.
+
+## Returns:
+
+* array, list of type OIDs.
diff --git a/pq-gateway/pq/Query/WriterInterface/param.md b/pq-gateway/pq/Query/WriterInterface/param.md
new file mode 100644 (file)
index 0000000..f674fba
--- /dev/null
@@ -0,0 +1,35 @@
+# string pq\Query\WriterInterface::param(mixed $param[, int $type = NULL])
+
+Remember the parameter with any associated type and return $N to be written to the query string.
+
+## Params:
+
+* mixed $param  
+  Query parameter value.
+* Optional int $type = NULL  
+  The type OID of the parameter.
+
+## Returns:
+
+* string, '$N', to be used with pq\Query\WriterInterface::write(), where N is tne number of this parameter.
+
+## Example:
+
+       <?php
+       
+       use pq\Query;
+       
+       $writer = new Query\Writer;
+       $writer->write("SELECT", $writer->param(1));
+       
+       var_dump((string) $writer, $writer->getParams());
+       
+       ?>
+
+Yields:
+
+       string(9) "SELECT $1"
+       array(1) {
+         [0]=>
+         int(1)
+       }
diff --git a/pq-gateway/pq/Query/WriterInterface/reset.md b/pq-gateway/pq/Query/WriterInterface/reset.md
new file mode 100644 (file)
index 0000000..31f9005
--- /dev/null
@@ -0,0 +1,11 @@
+# pq\Query\WriterInterface pq\Query\WriterInterface::reset()
+
+Reset the query writer to initial state.
+
+## Params:
+
+None.
+
+## Returns:
+
+* pq\Query\WriterInterface, self.
diff --git a/pq-gateway/pq/Query/WriterInterface/write.md b/pq-gateway/pq/Query/WriterInterface/write.md
new file mode 100644 (file)
index 0000000..18f44a5
--- /dev/null
@@ -0,0 +1,11 @@
+# pq\Query\WriterInterface pq\Query\WriterInterface::write()
+
+Write a part of the query string.
+
+## Params:
+
+* Variable list of query parts.
+
+## Returns:
+
+* pq\Query\WriterInterface, self.