Index: java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java	(revision 614946)
+++ java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java	(working copy)
@@ -1435,14 +1435,16 @@
 		** return VARIANT.  Otherwise, we return
 		** CONSTANT. For result columns that are 
 		** generating autoincrement values, the result
-		** is variant-- note that there is no expression
-		** associated with an autoincrement column in 
-		** an insert statement.
+		** is variant.
 		*/
-		int expType = ((expression != null) ?
-					   expression.getOrderableVariantType() : 
-					   ((isAutoincrementGenerated()) ? 
-						Qualifier.VARIANT : Qualifier.CONSTANT));
+        int expType;
+        if (isAutoincrementGenerated()) {
+            expType = Qualifier.VARIANT;
+        } else if (expression != null) {
+            expType = expression.getOrderableVariantType();
+        } else {
+            expType = Qualifier.CONSTANT;
+        }
 
 		switch (expType)
 		{
Index: java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java	(revision 614946)
+++ java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java	(working copy)
@@ -21,9 +21,6 @@
 
 package org.apache.derbyTesting.functionTests.tests.lang;
 
-import java.util.HashMap;
-import java.util.Iterator;
-
 import java.sql.Connection;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
@@ -2050,4 +2047,59 @@
         }
         tst.close();
     }
+
+
+    // Regression tests for DERBY-3343 (regression from the fix for DERBY-827)
+    /**
+     * Private helper method. Runs the same test for different
+     * generated identity columns.
+     * @param dataType SMALLINT, INT, or BIGINT
+     * @param generatedType BY DEFAULT or ALWAYS
+     * @throws Exception all errors passed on to JUnit
+     */
+    private void testGeneratedIdentity(String dataType, String generateType) 
+        throws Exception {
+        Statement s = createStatement();
+        try {
+            s.execute("CREATE TABLE T(GI "+dataType+" PRIMARY KEY GENERATED "+
+                      generateType+
+                      " AS IDENTITY (START WITH 5, INCREMENT BY 10), "+
+                      "L VARCHAR(8))");
+            PreparedStatement implicit = 
+                prepareStatement("INSERT INTO T(L) VALUES('implicit')"); 
+            implicit.executeUpdate();
+            implicit.executeUpdate();
+            implicit.executeUpdate();
+
+            PreparedStatement explicit = 
+                prepareStatement("INSERT INTO T(GI, L) "+
+                                 "VALUES(DEFAULT, 'explicit')"); 
+            explicit.executeUpdate();
+            explicit.executeUpdate();
+            explicit.executeUpdate();
+        }
+        finally {
+            try { s.executeUpdate("DROP TABLE T"); } 
+            catch (SQLException e) {}
+        }
+    } 
+    public void testIntGeneratedByDefaultAsIdentity() throws Exception {
+        testGeneratedIdentity("INT","BY DEFAULT");
+    }
+    public void testSmallintGeneratedByDefaultAsIdentity() throws Exception {
+        testGeneratedIdentity("SMALLINT","BY DEFAULT");
+    }
+    public void testBigintGeneratedByDefaultAsIdentity() throws Exception {
+        testGeneratedIdentity("BIGINT","BY DEFAULT");
+    }
+
+    public void testIntGeneratedAlwaysAsIdentity() throws Exception {
+        testGeneratedIdentity("INT","ALWAYS");
+    }
+    public void testSmallintGeneratedAlwaysAsIdentity() throws Exception {
+        testGeneratedIdentity("SMALLINT","ALWAYS");
+    }
+    public void testBigintGeneratedAlwaysAsIdentity() throws Exception {
+        testGeneratedIdentity("BIGINT","ALWAYS");
+    }
 }
