From e4320cab263a45f8920599d5c919230309e7284c Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 6 Oct 2007 21:48:38 +0000 Subject: Added TDbCommand.queryColumn() --- HISTORY | 1 + framework/Data/TDbCommand.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/HISTORY b/HISTORY index fd1462ff..38bdd3f8 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ Version 3.1.2 To be released ============================ CHG: Changed TConditional so that the controls in its template behave like they are in its parent (Qiang) +ENH: Added TDbCommand.queryColumn() (Qiang) NEW: Added TDbLogRoute (Qiang) NEW: Added TDataRenderer and TItemDataRenderer (Qiang) diff --git a/framework/Data/TDbCommand.php b/framework/Data/TDbCommand.php index f5d7d647..b4bd9dd4 100644 --- a/framework/Data/TDbCommand.php +++ b/framework/Data/TDbCommand.php @@ -283,6 +283,23 @@ class TDbCommand extends TComponent throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); } } + + /** + * Executes the SQL statement and returns the first column of the result. + * This is a convenient method of {@link query} when only the first column of data is needed. + * Note, the column returned will contain the first element in each row of result. + * @return array the first column of the query result. Empty array if no result. + * @throws TDbException execution failed + * @since 3.1.2 + */ + public function queryColumn() + { + $rows=$this->query()->readAll(); + $column=array(); + foreach($rows as $row) + $column[]=current($row); + return $column; + } } ?> \ No newline at end of file -- cgit v1.2.3