Commit daf05777 authored by Dave Cridland's avatar Dave Cridland Committed by GitHub

Merge pull request #667 from Hammington/adjust-limit-expression-for-oracle-12.0-and-below

adjust limit expression for oracle 12.0 and below
parents 4ce9fc68 09d01875
...@@ -4,6 +4,7 @@ import java.sql.Connection; ...@@ -4,6 +4,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
...@@ -498,6 +499,36 @@ public class JdbcPersistenceManager implements PersistenceManager { ...@@ -498,6 +499,36 @@ public class JdbcPersistenceManager implements PersistenceManager {
limitSB.append(" BETWEEN ").append(firstIndex+1); limitSB.append(" BETWEEN ").append(firstIndex+1);
limitSB.append(" AND ").append(firstIndex+max); limitSB.append(" AND ").append(firstIndex+max);
} }
else if( isOracleDB() ) {
try {
final Statement statement = DbConnectionManager.getConnection().createStatement();
final ResultSet resultSet = statement.executeQuery( "select VERSION from PRODUCT_COMPONENT_VERSION P where P.PRODUCT like 'Oracle Database%'" );
resultSet.next();
final String versionString = resultSet.getString( "VERSION" );
final String[] versionParts = versionString.split( "\\." );
final int majorVersion = Integer.parseInt( versionParts[ 0 ] );
final int minorVersion = Integer.parseInt( versionParts[ 1 ] );
if( ( majorVersion == 12 && minorVersion >= 1 ) || majorVersion > 12 ) {
limitSB.append(" LIMIT ").append(max);
limitSB.append(" OFFSET ").append(firstIndex);
}
else {
querySB.insert( 0, "SELECT * FROM ( " );
limitSB.append( " ) WHERE rownum BETWEEN " )
.append( firstIndex + 1 )
.append( " AND " )
.append( firstIndex + max );
}
} catch( SQLException e ) {
Log.warn( "Unable to determine oracle database version using fallback", e );
querySB.insert( 0, "SELECT * FROM ( " );
limitSB.append( " ) WHERE rownum BETWEEN " )
.append( firstIndex + 1 )
.append( " AND " )
.append( firstIndex + max );
}
}
else { else {
limitSB.append(" LIMIT ").append(max); limitSB.append(" LIMIT ").append(max);
limitSB.append(" OFFSET ").append(firstIndex); limitSB.append(" OFFSET ").append(firstIndex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment