use of com.mysql.cj.jdbc.exceptions.NotUpdatable in project aws-mysql-jdbc by awslabs.
the class UpdatableResultSet method moveToInsertRow.
@Override
public void moveToInsertRow() throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
if (!this.isUpdatable) {
throw new NotUpdatable(this.notUpdatableReason);
}
if (this.inserter == null) {
if (this.insertSQL == null) {
generateStatements();
}
this.inserter = (ClientPreparedStatement) this.getConnection().clientPrepareStatement(this.insertSQL);
this.inserter.getQueryBindings().setColumnDefinition(this.getMetadata());
if (this.populateInserterWithDefaultValues) {
extractDefaultValues();
}
}
resetInserter();
Field[] fields = this.getMetadata().getFields();
int numFields = fields.length;
this.onInsertRow = true;
this.doingUpdates = false;
this.savedCurrentRow = this.thisRow;
byte[][] newRowData = new byte[numFields][];
this.thisRow = new ByteArrayRow(newRowData, getExceptionInterceptor());
this.thisRow.setMetadata(this.getMetadata());
for (int i = 0; i < numFields; i++) {
if (!this.populateInserterWithDefaultValues) {
this.inserter.setBytesNoEscapeNoQuotes(i + 1, StringUtils.getBytes("DEFAULT"));
newRowData = null;
} else {
if (this.defaultColumnValue[i] != null) {
Field f = fields[i];
switch(f.getMysqlTypeId()) {
case MysqlType.FIELD_TYPE_DATE:
case MysqlType.FIELD_TYPE_DATETIME:
case MysqlType.FIELD_TYPE_TIME:
case MysqlType.FIELD_TYPE_TIMESTAMP:
if (this.defaultColumnValue[i].length > 7 && this.defaultColumnValue[i][0] == (byte) 'C' && this.defaultColumnValue[i][1] == (byte) 'U' && this.defaultColumnValue[i][2] == (byte) 'R' && this.defaultColumnValue[i][3] == (byte) 'R' && this.defaultColumnValue[i][4] == (byte) 'E' && this.defaultColumnValue[i][5] == (byte) 'N' && this.defaultColumnValue[i][6] == (byte) 'T' && this.defaultColumnValue[i][7] == (byte) '_') {
this.inserter.setBytesNoEscapeNoQuotes(i + 1, this.defaultColumnValue[i]);
} else {
this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
}
break;
default:
this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
}
// This value _could_ be changed from a getBytes(), so we need a copy....
byte[] defaultValueCopy = new byte[this.defaultColumnValue[i].length];
System.arraycopy(this.defaultColumnValue[i], 0, defaultValueCopy, 0, defaultValueCopy.length);
newRowData[i] = defaultValueCopy;
} else {
this.inserter.setNull(i + 1, MysqlType.NULL);
newRowData[i] = null;
}
}
}
}
}
use of com.mysql.cj.jdbc.exceptions.NotUpdatable 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.NotUpdatable 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();
}
use of com.mysql.cj.jdbc.exceptions.NotUpdatable in project JavaSegundasQuintas by ecteruel.
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.NotUpdatable in project JavaSegundasQuintas by ecteruel.
the class UpdatableResultSet method moveToInsertRow.
@Override
public void moveToInsertRow() throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
if (!this.isUpdatable) {
throw new NotUpdatable(this.notUpdatableReason);
}
if (this.inserter == null) {
if (this.insertSQL == null) {
generateStatements();
}
this.inserter = (ClientPreparedStatement) this.getConnection().clientPrepareStatement(this.insertSQL);
this.inserter.getQueryBindings().setColumnDefinition(this.getMetadata());
if (this.populateInserterWithDefaultValues) {
extractDefaultValues();
}
}
resetInserter();
Field[] fields = this.getMetadata().getFields();
int numFields = fields.length;
this.onInsertRow = true;
this.doingUpdates = false;
this.savedCurrentRow = this.thisRow;
byte[][] newRowData = new byte[numFields][];
this.thisRow = new ByteArrayRow(newRowData, getExceptionInterceptor());
this.thisRow.setMetadata(this.getMetadata());
for (int i = 0; i < numFields; i++) {
if (!this.populateInserterWithDefaultValues) {
this.inserter.setBytesNoEscapeNoQuotes(i + 1, StringUtils.getBytes("DEFAULT"));
newRowData = null;
} else {
if (this.defaultColumnValue[i] != null) {
Field f = fields[i];
switch(f.getMysqlTypeId()) {
case MysqlType.FIELD_TYPE_DATE:
case MysqlType.FIELD_TYPE_DATETIME:
case MysqlType.FIELD_TYPE_TIME:
case MysqlType.FIELD_TYPE_TIMESTAMP:
if (this.defaultColumnValue[i].length > 7 && this.defaultColumnValue[i][0] == (byte) 'C' && this.defaultColumnValue[i][1] == (byte) 'U' && this.defaultColumnValue[i][2] == (byte) 'R' && this.defaultColumnValue[i][3] == (byte) 'R' && this.defaultColumnValue[i][4] == (byte) 'E' && this.defaultColumnValue[i][5] == (byte) 'N' && this.defaultColumnValue[i][6] == (byte) 'T' && this.defaultColumnValue[i][7] == (byte) '_') {
this.inserter.setBytesNoEscapeNoQuotes(i + 1, this.defaultColumnValue[i]);
} else {
this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
}
break;
default:
this.inserter.setBytes(i + 1, this.defaultColumnValue[i], false, false);
}
// This value _could_ be changed from a getBytes(), so we need a copy....
byte[] defaultValueCopy = new byte[this.defaultColumnValue[i].length];
System.arraycopy(this.defaultColumnValue[i], 0, defaultValueCopy, 0, defaultValueCopy.length);
newRowData[i] = defaultValueCopy;
} else {
this.inserter.setNull(i + 1, MysqlType.NULL);
newRowData[i] = null;
}
}
}
}
}
Aggregations