Skip to content

Commit

Permalink
TEIID-4245: Add support for fetch syntax "FETCH cursorname" (supporin…
Browse files Browse the repository at this point in the history
…g just fetch cursor name)
  • Loading branch information
shawkins authored and jolee committed Jul 6, 2016
1 parent a5d8d6f commit da40406
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
2 changes: 2 additions & 0 deletions build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ <h4>from ${project.version}</h4>
</li>
<li>[<a href='https://issues.jboss.org/browse/TEIID-3866'>TEIID-3866</a>] - with clause used by subquery repeated in the subquery (removing duplicate with clauses, correcting the check to remove the with clause)
</li>
<li>[<a href='https://issues.jboss.org/browse/TEIID-4245'>TEIID-4245</a>] - Add support for fetch syntax "FETCH cursorname" (supporing just fetch cursor name)
</li>
<li>[<a href='https://issues.jboss.org/browse/TEIID-4304'>TEIID-4304</a>] - Correct handling with subquery in on clause
</li>
</ul>
Expand Down
17 changes: 13 additions & 4 deletions runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.teiid.jdbc.ResultSetImpl;
import org.teiid.jdbc.StatementImpl;
import org.teiid.jdbc.TeiidDriver;
import org.teiid.jdbc.TeiidSQLException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.net.TeiidURL;
Expand Down Expand Up @@ -158,10 +159,9 @@ public class ODBCServerRemoteImpl implements ODBCServerRemote {
"\\s+order by ref.oid, ref.i", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$

private static Pattern cursorSelectPattern = Pattern.compile("DECLARE\\s+\"(\\w+)\"(?:\\s+INSENSITIVE)?(\\s+(NO\\s+)?SCROLL)?\\s+CURSOR\\s+(?:WITH(?:OUT)? HOLD\\s+)?FOR\\s+(.*)", Pattern.CASE_INSENSITIVE|Pattern.DOTALL); //$NON-NLS-1$
private static Pattern fetchPattern = Pattern.compile("FETCH (\\d+) IN \"(\\w+)\".*", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Pattern fetchPattern = Pattern.compile("FETCH(?:(?:\\s+FORWARD)?\\s+(\\d+)\\s+(?:IN|FROM))?\\s+\"(\\w+)\"\\s*", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Pattern movePattern = Pattern.compile("MOVE (\\d+) IN \"(\\w+)\".*", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Pattern closePattern = Pattern.compile("CLOSE \"(\\w+)\"", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$

private static Pattern deallocatePattern = Pattern.compile("DEALLOCATE(?:\\s+PREPARE)?\\s+(.*)", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Pattern releasePattern = Pattern.compile("RELEASE (\\w+\\d?_*)", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Pattern savepointPattern = Pattern.compile("SAVEPOINT (\\w+\\d?_*)", Pattern.DOTALL|Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
Expand Down Expand Up @@ -1033,7 +1033,12 @@ public void onCompletion(ResultsFuture<Integer> future) {
cursorExecute(m.group(1), fixSQL(m.group(4)), results, scroll);
}
else if ((m = fetchPattern.matcher(sql)).matches()){
cursorFetch(m.group(2), Integer.parseInt(m.group(1)), results);
String rows = m.group(1);
int rowCount = 1;
if (rows != null) {
rowCount = Integer.parseInt(rows);
}
cursorFetch(m.group(2), rowCount, results);
}
else if ((m = movePattern.matcher(sql)).matches()){
cursorMove(m.group(2), Integer.parseInt(m.group(1)), results);
Expand All @@ -1058,7 +1063,11 @@ else if ((m = deallocatePattern.matcher(sql)).matches()) {
return;
}
}
} catch(IOException e) {
} catch (NumberFormatException e) {
//create a sqlexception so that the logic doesn't over log this
done(TeiidSQLException.create(e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40147, e.getMessage())));
return;
} catch(Exception e) {
done(e);
return;
}
Expand Down
18 changes: 18 additions & 0 deletions runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,23 @@ public static enum Event implements BundleUtil.Event{
TEIID40123,
TEIID40124,
TEIID40125,
TEIID40130,
TEIID40131,
TEIID40132,
TEIID40133,
TEIID40134,
TEIID40135,
TEIID40136,
TEIID40137,
TEIID40138,
TEIID40139,
TEIID40140,
TEIID40141,
TEIID40142,
TEIID40143, //data roles required
TEIID40144,
TEIID40145,
TEIID40146,
TEIID40147
}
}
21 changes: 21 additions & 0 deletions runtime/src/main/resources/org/teiid/runtime/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,24 @@ TEIID40122=Could not initialize ODBC SSL. No connections will be allowed since
TEIID40123=SSL is required.
TEIID40124=SSL is required, but not configured properly on the server.
TEIID40125=A secure authentication is required, such as a GSS authentication.


TEIID40130=Method {0} is Deprecated
TEIID40131=VDB {0} {1} does not exist.
TEIID40132=VDB {0}.{1} is {2} and not ACTIVE.
TEIID40133={0} deploy failed {1}
TEIID40134=VDB {0} does not exist, use VDB name to execute undeploy in Embedded
TEIID40135=Restart VDB {0}.{1} with Model {2} failed
TEIID40136=Get Translator {0} failed {1}
TEIID40137={0} not supported in Embedded
TEIID40138=Get Translator {0} - {1} Property Definitions failed {2}
TEIID40139=Cache Type {0} not found in the configuration, available Cache Type: {1}, {2}
TEIID40140={0} execute failed {1}
TEIID40141=Cancel request via sessionId {0} executionId {1} failed {2}
TEIID40142={0} deploy failed only *-vdb.xml artifacts are expected. Use other EmbeddedServer deploy methods for other artifacts.
TEIID40143={0} deploy failed - data roles are required, but none are defined.

TEIID40144={0} deploy failed - imported vdb {1} is not properly specified. The version must be fully specified
TEIID40145={0} deploy failed - the version must be fully specified

TEIID40147=Invalid integer {0}
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,26 @@ private void connect(String database) throws SQLException {
ExtendedQueryExectutorImpl.simplePortal = "foo";
try {
assertFalse(stmt.execute("declare \"foo\" cursor for select * from pg_proc;"));
stmt.execute("fetch \"foo\"");
assertFalse(stmt.execute("move 5 in \"foo\""));
stmt.execute("fetch 10 in \"foo\"");
ResultSet rs = stmt.getResultSet();
int rowCount = 0;
while (rs.next()) {
rowCount++;
}
assertEquals(6, rowCount);

assertEquals(5, rowCount);
stmt.execute("close \"foo\"");

//start a new cursor and check failure
assertFalse(stmt.execute("declare \"foo\" cursor for select * from pg_proc;"));
try {
stmt.execute("fetch 9999999999 in \"foo\"");
fail();
} catch (SQLException e) {

}
} finally {
ExtendedQueryExectutorImpl.simplePortal = null;
}
Expand Down

0 comments on commit da40406

Please sign in to comment.