From ae491aae7f2fd468f2c525303afdd0f24a1ddab2 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 13 Oct 2015 13:17:16 +1100 Subject: [PATCH] Enabled list_columns to handle like queries --- classes/Kohana/Database/DB2.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/classes/Kohana/Database/DB2.php b/classes/Kohana/Database/DB2.php index cdf5a93..d235b5b 100644 --- a/classes/Kohana/Database/DB2.php +++ b/classes/Kohana/Database/DB2.php @@ -166,29 +166,22 @@ class Kohana_Database_DB2 extends Database { // Make sure the database is connected $this->_connection or $this->connect(); + $table = strtoupper($table); + // Quote the table name $table = ($add_prefix === TRUE) ? $this->quote_table($table) : $table; - if (is_string($like)) - { - // Search for column names - throw new Kohana_Exception('Like queries not implemented'); - } - else - { - // Find all column names - try { - $result = db2_columns($this->_connection,NULL,$this->_config['connection']['schema'] ? $this->_config['connection']['schema'] : '%',$table); + // Find all column names + try { + $result = db2_columns($this->_connection,NULL,$this->_config['connection']['schema'] ? $this->_config['connection']['schema'] : '%',$table,$like); - } catch (Exception $e) { - throw new Database_Exception('Unable to obtain Columns for :table [:error]',array(':table'=>$table,':error' => db2_stmt_errormsg()),db2_stmt_error()); - } + } catch (Exception $e) { + throw new Database_Exception('Unable to obtain Columns for :table [:error] (:like)',array(':like'=>$like,':table'=>$table,':error' => db2_stmt_errormsg()),db2_stmt_error()); } $count = 0; $columns = array(); - while ($row = db2_fetch_assoc($result)) - { + while ($row = db2_fetch_assoc($result)) { list($type, $length) = $this->_parse_type($row['TYPE_NAME']); $column = $this->datatype($type); @@ -240,6 +233,10 @@ class Kohana_Database_DB2 extends Database { $columns[$row['COLUMN_NAME']] = $column; } + if (! $columns) + throw new Database_Exception('Unable to obtain Columns for :table [:error] (:like)', + array(':like'=>$like,':table'=>$table,':error' => db2_conn_errormsg()),db2_conn_error()); + // Save our cache data for next call if ($this->_config['caching']) { Kohana::cache($cache_key,$columns);