use of java.sql.SQLWarning in project jOOQ by jOOQ.
the class Fields method field.
@Override
@SuppressWarnings("unchecked")
public final <T> Field<T> field(Field<T> field) {
if (field == null)
return null;
// [#4540] Try finding a match by identity
for (Field<?> f : fields) if (f == field)
return (Field<T>) f;
// [#1802] Try finding an exact match (e.g. exact matching qualified name)
for (Field<?> f : fields) if (f.equals(field))
return (Field<T>) f;
// [#4283] table / column matches are better than only column matches
Field<?> columnMatch = null;
Field<?> columnMatch2 = null;
String tableName = tableName(field);
String fieldName = field.getName();
for (Field<?> f : fields) {
String fName = f.getName();
if (tableName != null) {
String tName = tableName(f);
if (tName != null && tableName.equals(tName) && fName.equals(fieldName))
return (Field<T>) f;
}
// In case no exact match was found, return the first field with matching name
if (fName.equals(fieldName)) {
if (columnMatch == null)
columnMatch = f;
else
// [#4476] [#4477] This might be unintentional from a user
// perspective, e.g. when ambiguous ID columns are present.
// [#5578] Finish the loop, though, as we might have an exact match
// despite some ambiguity
columnMatch2 = f;
}
}
if (columnMatch2 != null)
if (log.isInfoEnabled())
log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + columnMatch2 + " match.", new SQLWarning());
return (Field<T>) columnMatch;
}
use of java.sql.SQLWarning in project voltdb by VoltDB.
the class TestJDBC method testVarbinary.
/*public void testSimpleStuff() {
String ddl = "create table test (cash integer default 23);";
String dml = "insert into test values (123);";
String query = "select * from test;";
Connection dbconn;
try {
Class.forName("org.hsqldb_voltpatches.jdbcDriver" );
dbconn = DriverManager.getConnection("jdbc:hsqldb:mem:x1", "sa", "");
dbconn.setAutoCommit(true);
dbconn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
Statement stmt = dbconn.createStatement();
stmt.execute(ddl);
SQLWarning warn = stmt.getWarnings();
if (warn != null)
System.out.println("warn: " + warn.getMessage());
assertTrue(warn == null);
long ucount = stmt.executeUpdate(dml);
assertTrue(ucount == 1);
ResultSet rs = stmt.executeQuery(query);
assertTrue(rs != null);
ResultSetMetaData rsmd = rs.getMetaData();
assertTrue(rsmd != null);
assertTrue(rsmd.getColumnCount() == 1);
boolean success = rs.next();
assertTrue(success);
int x = rs.getInt(1);
assertTrue(x == 123);
try {
stmt.execute("SHUTDOWN;");
} catch (Exception e) {};
dbconn.close();
System.gc();
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}*/
public void testVarbinary() {
String ddl = "create table testvb (cash integer default 23, b varbinary(1024) default NULL);";
String dml = "insert into testvb values (123, 'AAAA');";
String query = "select * from testvb;";
Connection dbconn;
try {
Class.forName("org.hsqldb_voltpatches.jdbcDriver");
dbconn = DriverManager.getConnection("jdbc:hsqldb:mem:x1", "sa", "");
dbconn.setAutoCommit(true);
dbconn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
Statement stmt = dbconn.createStatement();
stmt.execute(ddl);
SQLWarning warn = stmt.getWarnings();
if (warn != null)
System.out.println("warn: " + warn.getMessage());
assertTrue(warn == null);
long ucount = stmt.executeUpdate(dml);
assertTrue(ucount == 1);
ResultSet rs = stmt.executeQuery(query);
assertTrue(rs != null);
ResultSetMetaData rsmd = rs.getMetaData();
assertTrue(rsmd != null);
assertTrue(rsmd.getColumnCount() == 2);
boolean success = rs.next();
assertTrue(success);
int x = rs.getInt(1);
assertTrue(x == 123);
try {
stmt.execute("SHUTDOWN;");
} catch (Exception e) {
}
;
dbconn.close();
System.gc();
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
use of java.sql.SQLWarning in project voltdb by VoltDB.
the class TestJDBC method testDecimal.
public void testDecimal() {
String ddl = "create table test (cash decimal default 23.587);";
String dml = "insert into test values (123.45678911111);";
String query = "select * from test;";
Connection dbconn;
try {
Class.forName("org.hsqldb_voltpatches.jdbcDriver");
dbconn = DriverManager.getConnection("jdbc:hsqldb:mem:x1", "sa", "");
dbconn.setAutoCommit(true);
dbconn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
Statement stmt = dbconn.createStatement();
stmt.execute(ddl);
SQLWarning warn = stmt.getWarnings();
if (warn != null)
System.out.println("warn: " + warn.getMessage());
assertTrue(warn == null);
long ucount = stmt.executeUpdate(dml);
assertTrue(ucount == 1);
ResultSet rs = stmt.executeQuery(query);
assertTrue(rs != null);
ResultSetMetaData rsmd = rs.getMetaData();
assertTrue(rsmd != null);
assertTrue(rsmd.getColumnCount() == 1);
/*System.out.printf("Typename %s, Type %d, Precision %s, Scale %d, Classname %s\n",
rsmd.getColumnTypeName(1),
rsmd.getColumnType(1),
rsmd.getPrecision(1),
rsmd.getScale(1),
rsmd.getColumnClassName(1));*/
boolean success = rs.next();
assertTrue(success);
BigDecimal x = rs.getBigDecimal(1);
assertNotNull(x);
//System.out.printf("Value: %.10f\n", x.doubleValue());
BigDecimal expected = new BigDecimal(123.4567);
assertTrue(x.subtract(expected).abs().doubleValue() < .01);
try {
stmt.execute("SHUTDOWN;");
} catch (Exception e) {
}
;
dbconn.close();
System.gc();
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
use of java.sql.SQLWarning in project voltdb by VoltDB.
the class TestJDBC method testTinyInt.
public void testTinyInt() {
String ddl = "create table test (cash tinyint default 0);";
String dml = "insert into test values (123);";
String query = "select * from test;";
Connection dbconn;
try {
Class.forName("org.hsqldb_voltpatches.jdbcDriver");
dbconn = DriverManager.getConnection("jdbc:hsqldb:mem:x1", "sa", "");
dbconn.setAutoCommit(true);
dbconn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
Statement stmt = dbconn.createStatement();
stmt.execute(ddl);
SQLWarning warn = stmt.getWarnings();
if (warn != null)
System.out.println("warn: " + warn.getMessage());
assertTrue(warn == null);
long ucount = stmt.executeUpdate(dml);
assertTrue(ucount == 1);
ResultSet rs = stmt.executeQuery(query);
assertTrue(rs != null);
ResultSetMetaData rsmd = rs.getMetaData();
assertTrue(rsmd != null);
assertTrue(rsmd.getColumnCount() == 1);
/*System.out.printf("Typename %s, Type %d, Precision %s, Scale %d, Classname %s\n",
rsmd.getColumnTypeName(1),
rsmd.getColumnType(1),
rsmd.getPrecision(1),
rsmd.getScale(1),
rsmd.getColumnClassName(1));*/
boolean success = rs.next();
assertTrue(success);
int x = rs.getInt(1);
assertTrue(x == 123);
try {
stmt.execute("SHUTDOWN;");
} catch (Exception e) {
}
;
dbconn.close();
System.gc();
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
use of java.sql.SQLWarning in project voltdb by VoltDB.
the class JDBCConnection method xlateRSConcurrency.
/**
* Translates <code>ResultSet</code> concurrency, adding to the warning
* chain if the requested concurrency is downgraded. <p>
*
* Starting with HSQLDB 1.7.2, <code>CONCUR_READ_ONLY</code> is
* passed through while <code>CONCUR_UPDATABLE</code> is downgraded
* to <code>CONCUR_READ_ONLY</code> and an SQLWarning is issued.
*
* @param concurrency of <code>ResultSet</code>; one of
* <code>JDBCResultSet.CONCUR_XXX</code>
* @return the actual concurrency that will be used
* @throws SQLException if concurrency is not one of the defined values
*/
int xlateRSConcurrency(int concurrency) throws SQLException {
SQLWarning w;
String msg;
switch(concurrency) {
case JDBCResultSet.CONCUR_READ_ONLY:
{
return concurrency;
}
case JDBCResultSet.CONCUR_UPDATABLE:
{
msg = "CONCUR_UPDATABLE => CONCUR_READ_ONLY";
w = new SQLWarning(msg, "SOO10", ErrorCode.JDBC_INVALID_ARGUMENT);
addWarning(w);
return JDBCResultSet.CONCUR_READ_ONLY;
}
default:
{
msg = "ResultSet concurrency: " + concurrency;
throw Util.invalidArgument(msg);
}
}
}
Aggregations