use of com.mysql.cj.jdbc.exceptions.MysqlDataTruncation in project ABC by RuiPinto96274.
the class NativeProtocol method convertShowWarningsToSQLWarnings.
/**
* Turns output of 'SHOW WARNINGS' into JDBC SQLWarning instances.
*
* If 'forTruncationOnly' is true, only looks for truncation warnings, and
* actually throws DataTruncation as an exception.
*
* @param warningCountIfKnown
* the warning count (if known), otherwise set it to 0.
* @param forTruncationOnly
* if this method should only scan for data truncation warnings
*
* @return the SQLWarning chain (or null if no warnings)
*/
public SQLWarning convertShowWarningsToSQLWarnings(int warningCountIfKnown, boolean forTruncationOnly) {
SQLWarning currentWarning = null;
ResultsetRows rows = null;
try {
/*
* +---------+------+---------------------------------------------+
* | Level ..| Code | Message ....................................|
* +---------+------+---------------------------------------------+
* | Warning | 1265 | Data truncated for column 'field1' at row 1 |
* +---------+------+---------------------------------------------+
*/
NativePacketPayload resultPacket = sendCommand(getCommandBuilder().buildComQuery(getSharedSendPacket(), "SHOW WARNINGS"), false, 0);
Resultset warnRs = readAllResults(-1, warningCountIfKnown > 99, /* stream large warning counts */
resultPacket, false, null, new ResultsetFactory(Type.FORWARD_ONLY, Concurrency.READ_ONLY));
int codeFieldIndex = warnRs.getColumnDefinition().findColumn("Code", false, 1) - 1;
int messageFieldIndex = warnRs.getColumnDefinition().findColumn("Message", false, 1) - 1;
ValueFactory<String> svf = new StringValueFactory(this.propertySet);
ValueFactory<Integer> ivf = new IntegerValueFactory(this.propertySet);
rows = warnRs.getRows();
Row r;
while ((r = rows.next()) != null) {
int code = r.getValue(codeFieldIndex, ivf);
if (forTruncationOnly) {
if (code == MysqlErrorNumbers.ER_WARN_DATA_TRUNCATED || code == MysqlErrorNumbers.ER_WARN_DATA_OUT_OF_RANGE) {
DataTruncation newTruncation = new MysqlDataTruncation(r.getValue(messageFieldIndex, svf), 0, false, false, 0, 0, code);
if (currentWarning == null) {
currentWarning = newTruncation;
} else {
currentWarning.setNextWarning(newTruncation);
}
}
} else {
// String level = warnRs.getString("Level");
String message = r.getValue(messageFieldIndex, svf);
SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlState(code), code);
if (currentWarning == null) {
currentWarning = newWarning;
} else {
currentWarning.setNextWarning(newWarning);
}
}
}
if (forTruncationOnly && (currentWarning != null)) {
throw ExceptionFactory.createException(currentWarning.getMessage(), currentWarning);
}
return currentWarning;
} catch (IOException ex) {
throw ExceptionFactory.createException(ex.getMessage(), ex);
} finally {
if (rows != null) {
rows.close();
}
}
}
use of com.mysql.cj.jdbc.exceptions.MysqlDataTruncation in project JavaSegundasQuintas by ecteruel.
the class NativeProtocol method convertShowWarningsToSQLWarnings.
/**
* Turns output of 'SHOW WARNINGS' into JDBC SQLWarning instances.
*
* If 'forTruncationOnly' is true, only looks for truncation warnings, and
* actually throws DataTruncation as an exception.
*
* @param warningCountIfKnown
* the warning count (if known), otherwise set it to 0.
* @param forTruncationOnly
* if this method should only scan for data truncation warnings
*
* @return the SQLWarning chain (or null if no warnings)
*/
public SQLWarning convertShowWarningsToSQLWarnings(int warningCountIfKnown, boolean forTruncationOnly) {
SQLWarning currentWarning = null;
ResultsetRows rows = null;
try {
/*
* +---------+------+---------------------------------------------+
* | Level ..| Code | Message ....................................|
* +---------+------+---------------------------------------------+
* | Warning | 1265 | Data truncated for column 'field1' at row 1 |
* +---------+------+---------------------------------------------+
*/
NativePacketPayload resultPacket = sendCommand(getCommandBuilder().buildComQuery(getSharedSendPacket(), "SHOW WARNINGS"), false, 0);
Resultset warnRs = readAllResults(-1, warningCountIfKnown > 99, /* stream large warning counts */
resultPacket, false, null, new ResultsetFactory(Type.FORWARD_ONLY, Concurrency.READ_ONLY));
int codeFieldIndex = warnRs.getColumnDefinition().findColumn("Code", false, 1) - 1;
int messageFieldIndex = warnRs.getColumnDefinition().findColumn("Message", false, 1) - 1;
ValueFactory<String> svf = new StringValueFactory(this.propertySet);
ValueFactory<Integer> ivf = new IntegerValueFactory(this.propertySet);
rows = warnRs.getRows();
Row r;
while ((r = rows.next()) != null) {
int code = r.getValue(codeFieldIndex, ivf);
if (forTruncationOnly) {
if (code == MysqlErrorNumbers.ER_WARN_DATA_TRUNCATED || code == MysqlErrorNumbers.ER_WARN_DATA_OUT_OF_RANGE) {
DataTruncation newTruncation = new MysqlDataTruncation(r.getValue(messageFieldIndex, svf), 0, false, false, 0, 0, code);
if (currentWarning == null) {
currentWarning = newTruncation;
} else {
currentWarning.setNextWarning(newTruncation);
}
}
} else {
// String level = warnRs.getString("Level");
String message = r.getValue(messageFieldIndex, svf);
SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlState(code), code);
if (currentWarning == null) {
currentWarning = newWarning;
} else {
currentWarning.setNextWarning(newWarning);
}
}
}
if (forTruncationOnly && (currentWarning != null)) {
throw ExceptionFactory.createException(currentWarning.getMessage(), currentWarning);
}
return currentWarning;
} catch (IOException ex) {
throw ExceptionFactory.createException(ex.getMessage(), ex);
} finally {
if (rows != null) {
rows.close();
}
}
}
use of com.mysql.cj.jdbc.exceptions.MysqlDataTruncation in project aws-mysql-jdbc by awslabs.
the class NativeProtocol method convertShowWarningsToSQLWarnings.
/**
* Turns output of 'SHOW WARNINGS' into JDBC SQLWarning instances.
*
* If 'forTruncationOnly' is true, only looks for truncation warnings, and
* actually throws DataTruncation as an exception.
*
* @param forTruncationOnly
* if this method should only scan for data truncation warnings
*
* @return the SQLWarning chain (or null if no warnings)
*/
public SQLWarning convertShowWarningsToSQLWarnings(boolean forTruncationOnly) {
if (this.warningCount == 0) {
return null;
}
SQLWarning currentWarning = null;
ResultsetRows rows = null;
try {
/*
* +---------+------+---------------------------------------------+
* | Level ..| Code | Message ....................................|
* +---------+------+---------------------------------------------+
* | Warning | 1265 | Data truncated for column 'field1' at row 1 |
* +---------+------+---------------------------------------------+
*/
NativePacketPayload resultPacket = sendCommand(getCommandBuilder().buildComQuery(getSharedSendPacket(), "SHOW WARNINGS"), false, 0);
Resultset warnRs = readAllResults(-1, this.warningCount > 99, /* stream large warning counts */
resultPacket, false, null, new ResultsetFactory(Type.FORWARD_ONLY, Concurrency.READ_ONLY));
int codeFieldIndex = warnRs.getColumnDefinition().findColumn("Code", false, 1) - 1;
int messageFieldIndex = warnRs.getColumnDefinition().findColumn("Message", false, 1) - 1;
ValueFactory<String> svf = new StringValueFactory(this.propertySet);
ValueFactory<Integer> ivf = new IntegerValueFactory(this.propertySet);
rows = warnRs.getRows();
Row r;
while ((r = rows.next()) != null) {
int code = r.getValue(codeFieldIndex, ivf);
if (forTruncationOnly) {
if (code == MysqlErrorNumbers.ER_WARN_DATA_TRUNCATED || code == MysqlErrorNumbers.ER_WARN_DATA_OUT_OF_RANGE) {
DataTruncation newTruncation = new MysqlDataTruncation(r.getValue(messageFieldIndex, svf), 0, false, false, 0, 0, code);
if (currentWarning == null) {
currentWarning = newTruncation;
} else {
currentWarning.setNextWarning(newTruncation);
}
}
} else {
// String level = warnRs.getString("Level");
String message = r.getValue(messageFieldIndex, svf);
SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlState(code), code);
if (currentWarning == null) {
currentWarning = newWarning;
} else {
currentWarning.setNextWarning(newWarning);
}
}
}
if (forTruncationOnly && (currentWarning != null)) {
throw ExceptionFactory.createException(currentWarning.getMessage(), currentWarning);
}
return currentWarning;
} catch (IOException ex) {
throw ExceptionFactory.createException(ex.getMessage(), ex);
} finally {
if (rows != null) {
rows.close();
}
}
}
use of com.mysql.cj.jdbc.exceptions.MysqlDataTruncation in project aws-mysql-jdbc by awslabs.
the class ExceptionsTest method testConstructors.
@Test
public void testConstructors() {
new CommunicationsException(TEST_MESSAGE, new Throwable());
new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new PacketReceivedTimeHolder() {
}, new Exception());
new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new Exception());
new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
new MySQLQueryInterruptedException();
new MySQLQueryInterruptedException(TEST_MESSAGE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLStatementCancelledException();
new MySQLStatementCancelledException(TEST_MESSAGE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTimeoutException();
new MySQLTimeoutException(TEST_MESSAGE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTransactionRollbackException();
new MySQLTransactionRollbackException(TEST_MESSAGE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new NotUpdatable(TEST_MESSAGE);
new OperationNotSupportedException();
new OperationNotSupportedException(TEST_MESSAGE);
new PacketTooBigException(TEST_MESSAGE);
new PacketTooBigException(0, 100);
new SQLError();
}
use of com.mysql.cj.jdbc.exceptions.MysqlDataTruncation in project ABC by RuiPinto96274.
the class ExceptionsTest method testConstructors.
@Test
public void testConstructors() {
new CommunicationsException(TEST_MESSAGE, new Throwable());
new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new PacketReceivedTimeHolder() {
}, new Exception());
new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new Exception());
new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
new MySQLQueryInterruptedException();
new MySQLQueryInterruptedException(TEST_MESSAGE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLStatementCancelledException();
new MySQLStatementCancelledException(TEST_MESSAGE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTimeoutException();
new MySQLTimeoutException(TEST_MESSAGE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTransactionRollbackException();
new MySQLTransactionRollbackException(TEST_MESSAGE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new NotUpdatable(TEST_MESSAGE);
new OperationNotSupportedException();
new OperationNotSupportedException(TEST_MESSAGE);
new PacketTooBigException(TEST_MESSAGE);
new PacketTooBigException(0, 100);
new SQLError();
}
Aggregations