We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define Primary Key from dbMetadata
Define is Primary Key generated
After executing Insert query: 3.1. If the table contains PrimaryKey:
Primary Key Value
execute query Select By Primary Key and return selected row 3.2. If the table doesn't contain PrimaryKey - return input body
Select By Primary Key
The text was updated successfully, but these errors were encountered:
As example:
public JsonObject executeInsertGeneral(Connection connection, String tableName, JsonObject body, String primaryKeyName) throws SQLException { validateQuery(); JsonObject keysValues = getKeyValue(body); String keys = keysValues.getString("keys"); String values = keysValues.getString("values"); String sql = "INSERT INTO " + tableName + " (" + keys + ")" + " VALUES (" + values + ")"; try (PreparedStatement stmt = connection .prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { int i = 1; for (String key : body.keySet()) { Utils.setStatementParam(stmt, i, key, body); i++; } int affectedRows = stmt.executeUpdate(); if (affectedRows != 1) { throw new SQLException("Inserting failed, no rows affected."); } if (primaryKeyName != null) { JsonObjectBuilder primaryKeyBody = Json.createObjectBuilder(); int generatedKeysCount = 0; try (ResultSet generatedKeys = stmt.getGeneratedKeys()) { while (generatedKeys.next()) { primaryKeyBody.add(primaryKeyName, generatedKeys.getLong(1)); generatedKeysCount++; if (generatedKeysCount > 1) { throw new SQLException("More than one generated key!"); } } } if (generatedKeysCount == 0) { return getRowByPrimaryKey(connection, primaryKeyName, body); } return getRowByPrimaryKey(connection, primaryKeyName, primaryKeyBody.build()); } else { return body; } } }
Sorry, something went wrong.
No branches or pull requests
Define Primary Key from dbMetadata
Define is Primary Key generated
After executing Insert query:
3.1. If the table contains PrimaryKey:
Primary Key Value
from the statementPrimary Key Value
from bodyexecute query
Select By Primary Key
and return selected row3.2. If the table doesn't contain PrimaryKey - return input body
The text was updated successfully, but these errors were encountered: