X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FTable.php;fp=lib%2Fpq%2FGateway%2FTable.php;h=e4adbb7a532642e23005871f27c6e16ea100f436;hp=a25b2ad3fd6e07008bf59f27caa56239293756ac;hb=409fca54acfee2db6c62540a8f67b1adfa695a38;hpb=0b0830c9c6254d596808d461755309200582825a diff --git a/lib/pq/Gateway/Table.php b/lib/pq/Gateway/Table.php index a25b2ad..e4adbb7 100644 --- a/lib/pq/Gateway/Table.php +++ b/lib/pq/Gateway/Table.php @@ -53,6 +53,11 @@ class Table */ protected $identity; + /** + * @var \pq\Gateway\Table\Attributes + */ + protected $attributes; + /** * @var \pq\Gateway\Table\Relations */ @@ -205,6 +210,13 @@ class Table return $this->identity; } + function getAttributes() { + if (!isset($this->attributes)) { + $this->attributes = new Table\Attributes($this); + } + return $this->attributes; + } + /** * Get foreign key relations * @param string $to fkey @@ -430,7 +442,7 @@ class Table $params = array(); foreach ($data as $key => $val) { $query->write($first ? "(" : ",", $key); - $params[] = $query->param($val); + $params[] = $query->param($val, $this->getAttributes()->getColumn($key)->type); $first and $first = false; } $query->write(") VALUES (", $params, ")"); @@ -456,7 +468,8 @@ class Table $query->write("UPDATE", $this->conn->quoteName($this->name)); $first = true; foreach ($data as $key => $val) { - $query->write($first ? "SET" : ",", $key, "=", $query->param($val)); + $query->write($first ? "SET" : ",", $key, "=", + $query->param($val, $this->getAttributes()->getColumn($key)->type)); $first and $first = false; } $query->write("WHERE")->criteria($where);