Author: Frederik Holljen
Date: 2006-01-14 13:07:43 +0100 (Sat, 14 Jan 2006)
New Revision: 1848

Log:
- Final exceptions conversion

Added:
   packages/Database/trunk/src/exceptions/query/
   packages/Database/trunk/src/exceptions/query/invalid.php
   packages/Database/trunk/src/exceptions/query/variable_parameter.php
Modified:
   packages/Database/trunk/src/exceptions/exception.php
   packages/Database/trunk/src/handlers/mysql.php
   packages/Database/trunk/src/handlers/oracle.php
   packages/Database/trunk/src/handlers/pgsql.php
   packages/Database/trunk/src/handlers/sqlite.php
   packages/Database/trunk/src/query_autoload.php
   packages/Database/trunk/src/sqlabstraction/expression.php
   
packages/Database/trunk/src/sqlabstraction/implementations/expression_oracle.php
   
packages/Database/trunk/src/sqlabstraction/implementations/expression_pgsql.php
   
packages/Database/trunk/src/sqlabstraction/implementations/query_select_oracle.php
   packages/Database/trunk/src/sqlabstraction/query.php
   packages/Database/trunk/src/sqlabstraction/query_delete.php
   packages/Database/trunk/src/sqlabstraction/query_insert.php
   packages/Database/trunk/src/sqlabstraction/query_select.php
   packages/Database/trunk/src/sqlabstraction/query_update.php
   packages/Database/trunk/src/sqlabstraction/utilities.php
   packages/Database/trunk/tests/sqlabstraction/expression_test.php
   packages/Database/trunk/tests/sqlabstraction/query_select_test_impl.php

Modified: packages/Database/trunk/src/exceptions/exception.php
===================================================================
--- packages/Database/trunk/src/exceptions/exception.php        2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/exceptions/exception.php        2006-01-14 
12:07:43 UTC (rev 1848)
@@ -26,51 +26,6 @@
      */
     public function __construct( $message )
     {
-        if ( $message === null )
-        {
-            // If message is not specified, let's set the default one.
-            switch ( $code )
-            {
-                case self::MISSING_DATABASE_NAME:
-                    $message = 'No database name specified.';
-                    break;
-
-                case self::MISSING_USER_NAME:
-                    $message = 'No user name specified.';
-                    break;
-
-                case self::MISSING_PASSWORD:
-                    $message = 'No password specified.';
-                    break;
-
-                case self::UNKNOWN_IMPL:
-                    $message = 'Specified database implementation not found.';
-                    break;
-
-                case self::INSTANCE_NOT_FOUND:
-                    $message = 'Specified instance not found.';
-                    break;
-
-                case self::NOT_IMPLEMENTED:
-                    $message = 'Functionality is not implemented. This 
probably means that you should override the method that threw the exception.';
-                    break;
-
-                case self::INVALID_ARGUMENT:
-                    $message = 'Invalid argument.';
-                    break;
-
-                case self::GENERIC_ERROR:
-                    $message = 'Unknown error occured.';
-                    break;
-
-                case self::TRANSACTION_ERROR:
-                    $message = 'Transaction inconsistency. Check that you 
issued COMMIT/ROLLBACK exactly as many times as BEGIN.';
-                    break;
-                default:
-                    $message = '';
-            }
-        }
-
         parent::__construct( $message  );
     }
 }

Added: packages/Database/trunk/src/exceptions/query/invalid.php
===================================================================
--- packages/Database/trunk/src/exceptions/query/invalid.php    2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/exceptions/query/invalid.php    2006-01-14 
12:07:43 UTC (rev 1848)
@@ -0,0 +1,36 @@
+<?php
+/**
+ * File containing the ezcQueryException class.
+ *
+ * @package Database
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Base class for exceptions related to the SQL abstraction.
+ *
+ * @package Database
+ */
+class ezcQueryInvalidException extends ezcQueryException
+{
+    /**
+     * Constructs a QueryInvalid exception with the type $type and the
+     * additional information $message.
+     *
+     * $type should be used to specify the type of the query that failed.
+     * Possible values are SELECT, INSERT, UPDATE and DELETE.
+     *
+     * Use $message to specify exactly what went wrong.
+     *
+     * @param string $type
+     * @param string $additionalInfo
+     */
+    public function __construct( $type, $message )
+    {
+        $info = "The {$type} query could not be built. {$message}";
+        parent::__construct( $message );
+    }
+}
+?>


Property changes on: packages/Database/trunk/src/exceptions/query/invalid.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: packages/Database/trunk/src/exceptions/query/variable_parameter.php
===================================================================
--- packages/Database/trunk/src/exceptions/query/variable_parameter.php 
2006-01-13 18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/exceptions/query/variable_parameter.php 
2006-01-14 12:07:43 UTC (rev 1848)
@@ -0,0 +1,46 @@
+<?php
+/**
+ * File containing the ezcQueryException class.
+ *
+ * @package Database
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Base class for exceptions related to the SQL abstraction.
+ *
+ * @package Database
+ */
+class ezcQueryVariableParameterException extends ezcQueryException
+{
+    /**
+     * Constructs a QueryInvalid exception with the type $type and the
+     * additional information $message.
+     *
+     * @param string $type
+     * @param string $additionalInfo
+     */
+    public function __construct( $method, $numProvided, $numExpected )
+    {
+        $expectedString ="$numExpected parameter";
+        if( $numExpected > 1 )
+        {
+            $expectedString .= 's';
+        }
+
+        $providedString = "none were provided";
+        if( $numProvided == 1 )
+        {
+            $providedString = "only one was provided";
+        }
+        else if( $numProvided > 1 )
+        {
+            $providedString = "only $numProvided was provided";
+        }
+        $info = "The method $method expected at least {$expectedString} but 
{$providedString}.";
+        parent::__construct( $info );
+    }
+}
+?>


Property changes on: 
packages/Database/trunk/src/exceptions/query/variable_parameter.php
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: packages/Database/trunk/src/handlers/mysql.php
===================================================================
--- packages/Database/trunk/src/handlers/mysql.php      2006-01-13 18:06:00 UTC 
(rev 1847)
+++ packages/Database/trunk/src/handlers/mysql.php      2006-01-14 12:07:43 UTC 
(rev 1848)
@@ -28,7 +28,7 @@
      * - charset:         Client character set
      * - socket:          UNIX socket path
      *
-     * @throws ezcDbException::MISSING_DATABASE_NAME if database name is not 
specified in $params
+     * @throws ezcDbMissingParameterException if the database name was not 
specified.
      * @param array $dbparams Database connection parameters (key=>value 
pairs).
      */
     public function __construct( $dbParams )

Modified: packages/Database/trunk/src/handlers/oracle.php
===================================================================
--- packages/Database/trunk/src/handlers/oracle.php     2006-01-13 18:06:00 UTC 
(rev 1847)
+++ packages/Database/trunk/src/handlers/oracle.php     2006-01-14 12:07:43 UTC 
(rev 1848)
@@ -27,7 +27,7 @@
      * - charset:         Client character set
      *
      * @param array $dbparams Database connection parameters (key=>value 
pairs).
-     * @throws ezcDbException::MISSING_DATABASE_NAME if database name is not 
specified in $params
+     * @throws ezcDbMissingParameterException if the database name was not 
specified.
      */
     public function __construct( $dbParams )
     {
@@ -50,7 +50,7 @@
 
         if ( !isset( $database ) )
         {
-            throw new ezcDbException( ezcDbException::MISSING_DATABASE_NAME );
+            throw new ezcDbMissingParameterException( 'database', 'dbParams' );
         }
 
         $dsn = "oci:dbname=$database";

Modified: packages/Database/trunk/src/handlers/pgsql.php
===================================================================
--- packages/Database/trunk/src/handlers/pgsql.php      2006-01-13 18:06:00 UTC 
(rev 1847)
+++ packages/Database/trunk/src/handlers/pgsql.php      2006-01-14 12:07:43 UTC 
(rev 1848)
@@ -26,7 +26,7 @@
      * - host|hostspec:   Name of the host database is running on
      * - port:            TCP port
      *
-     * @throws ezcDbException::MISSING_DATABASE_NAME if database name is not 
specified in $params
+     * @throws ezcDbMissingParameterException if the database name was not 
specified.
      * @param array $dbparams Database connection parameters (key=>value 
pairs).
      */
     public function __construct( $dbParams )
@@ -59,7 +59,7 @@
 
         if ( !isset( $database ) )
         {
-            throw new ezcDbException( ezcDbException::MISSING_DATABASE_NAME );
+            throw new ezcDbMissingParameterException( 'database', 'dbParams' );
         }
 
         $dsn = "pgsql:dbname=$database";

Modified: packages/Database/trunk/src/handlers/sqlite.php
===================================================================
--- packages/Database/trunk/src/handlers/sqlite.php     2006-01-13 18:06:00 UTC 
(rev 1847)
+++ packages/Database/trunk/src/handlers/sqlite.php     2006-01-14 12:07:43 UTC 
(rev 1848)
@@ -23,7 +23,7 @@
      * Supported database parameters are:
      * - dbname|database: Database name
      *
-     * @throws ezcDbException::MISSING_DATABASE_NAME if database name is not 
specified in $params
+     * @throws ezcDbMissingParameterException if the database name was not 
specified.
      * @param array $dbparams Database connection parameters (key=>value 
pairs).
      */
     public function __construct( $dbParams )
@@ -47,7 +47,7 @@
 
         if ( !isset( $database ) )
         {
-            throw new ezcDbException( ezcDbException::MISSING_DATABASE_NAME );
+            throw new ezcDbMissingParameterException( 'database', 'dbParams' );
         }
 
         $dsn = "sqlite:$database";

Modified: packages/Database/trunk/src/query_autoload.php
===================================================================
--- packages/Database/trunk/src/query_autoload.php      2006-01-13 18:06:00 UTC 
(rev 1847)
+++ packages/Database/trunk/src/query_autoload.php      2006-01-14 12:07:43 UTC 
(rev 1848)
@@ -12,6 +12,8 @@
 return array(
     'ezcQuery' => 'Database/sqlabstraction/query.php',
     'ezcQueryException' => 'Database/exceptions/query_exception.php',
+    'ezcQueryInvalidException' => 'Database/exceptions/query/invalid.php',
+    'ezcQueryVariableParameterException' => 
'Database/exceptions/query/variable_parameter.php',
     'ezcQuerySelect' => 'Database/sqlabstraction/query_select.php',
     'ezcQuerySelectOracle' => 
'Database/sqlabstraction/implementations/query_select_oracle.php',
     'ezcQuerySelectSqlite' => 
'Database/sqlabstraction/implementations/query_select_sqlite.php',

Modified: packages/Database/trunk/src/sqlabstraction/expression.php
===================================================================
--- packages/Database/trunk/src/sqlabstraction/expression.php   2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/sqlabstraction/expression.php   2006-01-14 
12:07:43 UTC (rev 1848)
@@ -127,7 +127,7 @@
         $args = func_get_args();
         if ( count( $args ) < 1 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'lOr', count( $args 
), 1 );
         }
 
         $elements = ezcQuerySelect::arrayFlatten( $args );
@@ -164,7 +164,7 @@
         $args = func_get_args();
         if ( count( $args ) < 1 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'lAnd', count( $args 
), 1 );
         }
 
         $elements = ezcQuerySelect::arrayFlatten( $args );
@@ -219,7 +219,7 @@
         $elements = $this->getIdentifiers( $elements );
         if ( count( $elements ) < 1 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( $type, count( $args 
), 1 );
         }
         if ( count( $elements ) == 1 )
         {
@@ -480,7 +480,7 @@
         $args = func_get_args();
         if ( count( $args ) < 2 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'in', count( $args 
), 2 );
         }
 
         $values = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) );
@@ -489,7 +489,7 @@
 
         if( count( $values ) == 0 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'in', count( $args 
), 2 );
         }
         return "{$value} IN ( " . join( ', ', $values ) . ' )';
     }
@@ -729,7 +729,7 @@
 
         if ( count( $cols ) < 1 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'concat', count( 
$args ), 1 );
         }
 
         $cols = $this->getIdentifiers( $cols );

Modified: 
packages/Database/trunk/src/sqlabstraction/implementations/expression_oracle.php
===================================================================
--- 
packages/Database/trunk/src/sqlabstraction/implementations/expression_oracle.php
    2006-01-13 18:06:00 UTC (rev 1847)
+++ 
packages/Database/trunk/src/sqlabstraction/implementations/expression_oracle.php
    2006-01-14 12:07:43 UTC (rev 1848)
@@ -31,7 +31,9 @@
      * concat() accepts an arbitrary number of parameters. Each parameter
      * must contain an expression or an array with expressions.
      *
+     * @throw ezcQueryVariableException if no parameters are provided
      * @param string|array(string) strings that will be concatinated.
+     * @return string
      */
     public function concat()
     {
@@ -39,7 +41,7 @@
         $cols = self::arrayFlatten( $args );
         if ( count( $cols ) < 1 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'concat', count( 
$args ), 1 );
         }
 
         $cols = $this->getIdentifiers( $cols );

Modified: 
packages/Database/trunk/src/sqlabstraction/implementations/expression_pgsql.php
===================================================================
--- 
packages/Database/trunk/src/sqlabstraction/implementations/expression_pgsql.php 
    2006-01-13 18:06:00 UTC (rev 1847)
+++ 
packages/Database/trunk/src/sqlabstraction/implementations/expression_pgsql.php 
    2006-01-14 12:07:43 UTC (rev 1848)
@@ -97,7 +97,9 @@
      * concat() accepts an arbitrary number of parameters. Each parameter
      * must contain an expression or an array with expressions.
      *
+     * @throws ezcQueryVariableParameterException if no parameters are 
provided.
      * @param string|array(string) strings that will be concatinated.
+     * @return string
      */
     public function concat()
     {
@@ -105,7 +107,7 @@
         $cols = ezcQuery::arrayFlatten( $args );
         if ( count( $cols ) < 1 )
         {
-            throw new ezcDbAbstractionException( 
ezcDbAbstractoinException::INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'select', count( 
$args ), 1 );
         }
 
         $cols = $this->getIdentifiers( $cols );

Modified: 
packages/Database/trunk/src/sqlabstraction/implementations/query_select_oracle.php
===================================================================
--- 
packages/Database/trunk/src/sqlabstraction/implementations/query_select_oracle.php
  2006-01-13 18:06:00 UTC (rev 1847)
+++ 
packages/Database/trunk/src/sqlabstraction/implementations/query_select_oracle.php
  2006-01-14 12:07:43 UTC (rev 1848)
@@ -117,6 +117,9 @@
         return 'dual';
     }
 
+    /**
+     * Transforms the query from the parent to provide LIMIT functionality.
+     */
     public function getQuery()
     {
         $query = parent::build();
@@ -128,13 +131,6 @@
         }
         return $query;
     }
-
-    // not possible
-    public function buildLimit()
-    {
-        throw new exception();
-    }
-
 }
 
 ?>

Modified: packages/Database/trunk/src/sqlabstraction/query.php
===================================================================
--- packages/Database/trunk/src/sqlabstraction/query.php        2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/sqlabstraction/query.php        2006-01-14 
12:07:43 UTC (rev 1848)
@@ -320,7 +320,7 @@
     /**
      * Returns the query string for this query object.
      *
-     * @throws ezcQueryException if it was not possible to build a valid query.
+     * @throws ezcQueryInvalidException if it was not possible to build a 
valid query.
      * @return string
      */
     abstract public function getQuery();

Modified: packages/Database/trunk/src/sqlabstraction/query_delete.php
===================================================================
--- packages/Database/trunk/src/sqlabstraction/query_delete.php 2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/sqlabstraction/query_delete.php 2006-01-14 
12:07:43 UTC (rev 1848)
@@ -89,8 +89,8 @@
      * $q->deleteFrom( 'MyTable' )->where( $q->eq( 'id', 1 ) );
      * </code>
      *
-     * @throws ezcDbAbstractionException if called more than once.
-     * @throws ezcDbAbstractionException if called with no parameters.
+     * @throws ezcQueryException if called more than once.
+     * @throws ezcQueryVaraibleParameterException if called with no parameters.
      * @param string|array(string) Either a string with a logical expression 
name
      * or an array with logical expressions.
      * @return ezcQueryDelete
@@ -106,7 +106,7 @@
         $expressions = self::arrayFlatten( $args );
         if ( count( $expressions ) < 1 )
         {
-            throw new ezcQueryException( "where called without arguments" );
+            throw new ezcQueryVariableParameterException( 'where', count( 
$args ), 1 );
         }
 
         $this->whereString = 'WHERE ' . join( ' AND ', $expressions );
@@ -118,14 +118,14 @@
      * Returns the query string for this query object.
      *
      * @todo wrong exception
-     * @throws ezcQueryException if no table or no values have been set.
+     * @throws ezcQueryInvalidException if no table or no values have been set.
      * @return string
      */
     public function getQuery()
     {
         if ( $this->table == null )
         {
-            throw new ezcQueryException( "You must call deleteFrom() when 
executing a delete query." );
+            throw new ezcQueryInvalidException( "DELETE", "deleteFrom() was 
not called before getQuery()." );
         }
         $query = "DELETE FROM {$this->table}";
 

Modified: packages/Database/trunk/src/sqlabstraction/query_insert.php
===================================================================
--- packages/Database/trunk/src/sqlabstraction/query_insert.php 2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/sqlabstraction/query_insert.php 2006-01-14 
12:07:43 UTC (rev 1848)
@@ -99,7 +99,7 @@
     /**
      * Returns the query string for this query object.
      *
-     * @throws ezcQueryException if no table or no values have been set.
+     * @throws ezcQueryInvalidException if no table or no values have been set.
      * @return string
      */
     public function getQuery()
@@ -107,7 +107,7 @@
         if ( $this->table == null || empty( $this->values ) )
         {
             $problem = $this->table == null ? 'table' : 'values';
-            throw new ezcQueryException( "No " . $problem . " set." );
+            throw new ezcQueryInvalidException( "INSERT", "No " . $problem . " 
set." );
         }
         $query = "INSERT INTO {$this->table}";
         $columns = implode( ', ', array_keys( $this->values ) );

Modified: packages/Database/trunk/src/sqlabstraction/query_select.php
===================================================================
--- packages/Database/trunk/src/sqlabstraction/query_select.php 2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/sqlabstraction/query_select.php 2006-01-14 
12:07:43 UTC (rev 1848)
@@ -146,8 +146,8 @@
      * $q->select( $columns );
      * </code>
      *
-     * @throws ezcDbAbstractionException if called more than once.
-     * @throws ezcDbAbstractionException if called with no parameters..
+     * @throws ezcQueryException if called more than once.
+     * @throws ezcQueryVariableParameterException if called with no 
parameters..
      * @param string|array(string) Either a string with a column name or an 
array of column names.
      * @return ezcQuery returns a pointer to $this.
      */
@@ -163,7 +163,7 @@
 
         if ( count( $cols ) < 1 )
         {
-            throw new ezcQueryException( "Must select from at least one 
column" );
+            throw new ezcQueryVariableParameterException( 'select', count( 
$args ), 1 );
         }
 
         $cols = $this->getIdentifiers( $cols );
@@ -207,8 +207,8 @@
      * $q->select( 'id' )->from( 'table_name' );
      * </code>
      *
-     * @throws ezcDbAbstractionException if called more than once.
-     * @throws ezcDbAbstractionException if called with no parameters.
+     * @throws ezcQueryException if called more than once.
+     * @throws ezcQueryVariableParameterException if called with no parameters.
      * @param string|array(string) Either a string with a table name or an 
array of table names.
      * @return a pointer to $this
      */
@@ -223,7 +223,7 @@
         $tables = self::arrayFlatten( $args );
         if ( count( $tables ) < 1 )
         {
-            throw new ezcQueryException( "Must select from at least one table" 
);
+            throw new ezcQueryVariableParameterException( 'from', count( $args 
), 1 );
         }
         $tables = $this->getIdentifiers( $tables );
 
@@ -319,8 +319,8 @@
      * $q->select( '*' )->from( 'table' )->where( $q->expr->eq( 'id', 1 ) );
      * </code>
      *
-     * @throws ezcDbAbstractionException if called more than once.
-     * @throws ezcDbAbstractionException if called with no parameters.
+     * @throws ezcQueryException if called more than once.
+     * @throws ezcQueryVariableParameterException if called with no parameters.
      * @param string|array(string) Either a string with a logical expression 
name
      * or an array with logical expressions.
      * @return ezcQuerySelect
@@ -336,7 +336,7 @@
         $expressions = self::arrayFlatten( $args );
         if ( count( $expressions ) < 1 )
         {
-            throw new ezcQueryException( 
ezcQueryException::SELECT_INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'where', count( 
$args ), 1 );
         }
 
         $this->whereString = 'WHERE ' . join( ' AND ', $expressions );
@@ -427,7 +427,7 @@
      *                  ->groupBy( 'id' );
      * </code>
      *
-     * @throws ezcDbAbstractionException if called with no parameters.
+     * @throws ezcQueryVariableParameterException if called with no parameters.
      * @param string $column a column name in the result set
      * @return ezcQuery a pointer to $this
      */
@@ -437,7 +437,7 @@
         $columns = self::arrayFlatten( $args );
         if ( count( $columns ) < 1 )
         {
-            throw new ezcQueryException( 
ezcQueryException::SELECT_INVALID_ARGUMENT_NUM );
+            throw new ezcQueryVariableParameterException( 'groupBy', count( 
$args ), 1 );
         }
         $columns = $this->getIdentifiers( $columns );
 
@@ -479,15 +479,14 @@
      * various parts of the select query.
      *
      * @todo add newlines? easier for debugging
-     * @throws ezcQueryException if it was not possible to build a valid query.
+     * @throws ezcQueryInvalidException if it was not possible to build a 
valid query.
      * @return string
      */
     public function getQuery()
     {
         if ( $this->selectString == null )
         {
-            throw new ezcQueryException( 
ezcQueryException::BUILD_SELECT_FAILED,
-                                         "select() as not called before 
getQuery()." );
+            throw new ezcQueryInvalidException( "SELECT", "select() was not 
called before getQuery()." );
         }
 
         $query = "{$this->selectString}";

Modified: packages/Database/trunk/src/sqlabstraction/query_update.php
===================================================================
--- packages/Database/trunk/src/sqlabstraction/query_update.php 2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/sqlabstraction/query_update.php 2006-01-14 
12:07:43 UTC (rev 1848)
@@ -117,8 +117,8 @@
      * $q->update( 'MyTable' )->where( $q->eq( 'id', 1 ) );
      * </code>
      *
-     * @throws ezcDbAbstractionException if called more than once.
-     * @throws ezcDbAbstractionException if called with no parameters.
+     * @throws ezcQueryException if called more than once.
+     * @throws ezcQueryVariableParameterException if called with no parameters.
      * @param string|array(string) Either a string with a logical expression 
name
      * or an array with logical expressions.
      * @return ezcQueryUpdate
@@ -134,7 +134,7 @@
         $expressions = self::arrayFlatten( $args );
         if ( count( $expressions ) < 1 )
         {
-            throw new ezcQueryException( "Need at least one parameter" );
+            throw new ezcQueryVariableParameterException( 'where', count( 
$args ), 1 );
         }
 
         $this->whereString = 'WHERE ' . join( ' AND ', $expressions );
@@ -146,7 +146,7 @@
      * Returns the query string for this query object.
      *
      * @todo wrong exception
-     * @throws ezcQueryException if no table or no values have been set.
+     * @throws ezcQueryInvalidException if no table or no values have been set.
      * @return string
      */
     public function getQuery()
@@ -154,7 +154,7 @@
         if ( $this->table == null || empty( $this->values ) )
         {
             $problem = $this->table == null ? 'table' : 'values';
-            throw new ezcQueryException( "No " . $problem . " set." );
+            throw new ezcQueryInvalidException( "UPDATE", "No " . $problem . " 
set." );
         }
         $query = "UPDATE {$this->table} SET ";
 

Modified: packages/Database/trunk/src/sqlabstraction/utilities.php
===================================================================
--- packages/Database/trunk/src/sqlabstraction/utilities.php    2006-01-13 
18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/src/sqlabstraction/utilities.php    2006-01-14 
12:07:43 UTC (rev 1848)
@@ -103,7 +103,7 @@
      */
     public function cleanup()
     {
-        throw new ezcDbException( ezcDbException::NOT_IMPLEMENTED );
+        throw new ezcDbException( "Not implemented" );
     }
 }
 

Modified: packages/Database/trunk/tests/sqlabstraction/expression_test.php
===================================================================
--- packages/Database/trunk/tests/sqlabstraction/expression_test.php    
2006-01-13 18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/tests/sqlabstraction/expression_test.php    
2006-01-14 12:07:43 UTC (rev 1848)
@@ -52,6 +52,15 @@
         return new ezcTestSuite( 'ezcQueryExpressionTest' );
     }
 
+    public function testLorNone()
+    {
+        try
+        {
+            $this->e->lOr();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testlOrSingle()
     {
         $reference = 'true';
@@ -64,6 +73,15 @@
         $this->assertEquals( $reference, $this->e->lOr( 'true', 'false' ) );
     }
 
+    public function testlAndNone()
+    {
+        try
+        {
+            $this->e->lAnd();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testlAndSingle()
     {
         $reference = 'true';
@@ -82,6 +100,15 @@
         $this->assertEquals( $reference, $this->e->not( 'true' ) );
     }
 
+    public function testAddNone()
+    {
+        try
+        {
+            $this->e->add();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testAddSingle()
     {
         $reference = '1';
@@ -94,6 +121,15 @@
         $this->assertEquals( $reference, $this->e->add( 1, 1 ) );
     }
 
+    public function testSubtractNone()
+    {
+        try
+        {
+            $this->e->sub();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testSubtractSingle()
     {
         $reference = '1';
@@ -106,6 +142,15 @@
         $this->assertEquals( $reference, $this->e->sub( 1, 1 ) );
     }
 
+    public function testMultiplyNone()
+    {
+        try
+        {
+            $this->e->mul();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testMultiplySingle()
     {
         $reference = '1';
@@ -118,6 +163,15 @@
         $this->assertEquals( $reference, $this->e->mul( 1, 1 ) );
     }
 
+    public function testDivideNone()
+    {
+        try
+        {
+            $this->e->div();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testDivideSingle()
     {
         $reference = '1';
@@ -166,6 +220,15 @@
         $this->assertEquals( $reference, $this->e->lte( 'field1', 'field2' ) );
     }
 
+    public function testInNone()
+    {
+        try
+        {
+            $this->e->in( 'id' );
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testInSingle()
     {
         $reference = 'id IN ( 1 )';
@@ -256,60 +319,15 @@
         $this->assertEquals( $reference, $this->e->now() );
     }
 
-    public function testSubStringNoLen()
+    public function testConcatNone()
     {
-        if ( $this->db->getName() != 'sqlite' )
+        try
         {
-            $reference = 'substring( field from 10 )';
-            $this->assertEquals( $reference, $this->e->subString( 'field', 10 
) );
-        }
+            $this->e->concat();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
     }
 
-    public function testSubStringWithLen()
-    {
-        if ( $this->db->getName() != 'sqlite' )
-        {
-            $reference = 'substring( field from 10 for 5 )';
-            $this->assertEquals( $reference, $this->e->subString( 'field', 10, 
5 ) );
-        }
-    }
-
-    public function testSubStringNoLenSqlite()
-    {
-        if ( $this->db->getName() == 'sqlite' )
-        {
-            $reference = 'substr( field, 10, 1073741823 )';
-            $this->assertEquals( $reference, $this->e->subString( 'field', 10 
) );
-        }
-    }
-
-    public function testSubStringWithLenSqlite()
-    {
-        if ( $this->db->getName() == 'sqlite' )
-        {
-            $reference = 'substr( field, 10, 5 )';
-            $this->assertEquals( $reference, $this->e->subString( 'field', 10, 
5 ) );
-        }
-    }
-
-    public function testConcatSingle()
-    {
-        $reference = 'CONCAT( field )';
-        $this->assertEquals( $reference, $this->e->concat( 'field' ) );
-    }
-
-    public function testConcatMulti()
-    {
-        $reference = 'CONCAT( field, field2 )';
-        $this->assertEquals( $reference, $this->e->concat( 'field', 'field2' ) 
);
-    }
-
-    public function testConcatMulti3()
-    {
-        $reference = 'CONCAT( field, field2, field3 )';
-        $this->assertEquals( $reference, $this->e->concat( 'field', 'field2', 
'field3' ) );
-    }
-
     /**
      * Implementation tests, these are run on a selectQuery object so we know
      * we have the correct expression type.

Modified: 
packages/Database/trunk/tests/sqlabstraction/query_select_test_impl.php
===================================================================
--- packages/Database/trunk/tests/sqlabstraction/query_select_test_impl.php     
2006-01-13 18:06:00 UTC (rev 1847)
+++ packages/Database/trunk/tests/sqlabstraction/query_select_test_impl.php     
2006-01-14 12:07:43 UTC (rev 1848)
@@ -178,6 +178,15 @@
     }
 
     // LOGIC TESTS
+    public function testSelectNone()
+    {
+        try
+        {
+            $this->q->select( );
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testSelectMulti()
     {
         $this->q->select( 'id', 'company' )->from( 'query_test' );
@@ -234,6 +243,15 @@
         $this->fail( "Two calls to select() did not fail" );
     }
 
+    public function testEmptyFrom()
+    {
+        try
+        {
+            $this->q->select( 'd' )->from();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testMultipleFrom()
     {
         try
@@ -243,6 +261,15 @@
         $this->fail( "Two calls to from() did not fail" );
     }
 
+    public function testEmptyWhere()
+    {
+        try
+        {
+            $this->q->select( 'd' )->from('d')->where();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
+
     public function testMultipleWhere()
     {
         try
@@ -252,7 +279,16 @@
         $this->fail( "Two calls to where() did not fail" );
     }
 
+    public function testEmptyGroupBy()
+    {
+        try
+        {
+            $this->q->select( 'd' )->from('d')->groupBy();
+            $this->fail( "Expected exception" );
+        }catch( ezcQueryVariableParameterException $e ) {}
+    }
 
+
     public static function suite()
     {
         return new ezcTestSuite( 'ezcQuerySelectTestImpl' );

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to