MCPcopy Create free account
hub / github.com/cmu-db/benchbase / getSequenceName

Method getSequenceName

src/main/java/com/oltpbenchmark/util/SQLUtil.java:204–247  ·  view source on GitHub ↗

Return the internal sequence name for the given Column @param conn @param dbType @param catalog_col @return

(Connection conn, DatabaseType dbType, Column catalog_col)

Source from the content-addressed store, hash-verified

202 * @return
203 */
204 public static String getSequenceName(Connection conn, DatabaseType dbType, Column catalog_col)
205 throws SQLException {
206 Table catalog_tbl = catalog_col.getTable();
207
208 String seqName = null;
209 String sql = null;
210 if (dbType == DatabaseType.POSTGRES) {
211 sql =
212 String.format(
213 "SELECT pg_get_serial_sequence('%s', '%s')",
214 catalog_tbl.getName(), catalog_col.getName());
215 } else if (dbType == DatabaseType.SQLSERVER || dbType == DatabaseType.SQLAZURE) {
216 // NOTE: This likely only handles certain syntaxes for defaults.
217 sql =
218 String.format(
219 """
220SELECT REPLACE(REPLACE([definition], '(NEXT VALUE FOR [', ''), '])', '') AS seq
221FROM sys.default_constraints dc
222JOIN sys.columns c ON c.default_object_id=dc.object_id
223JOIN sys.tables t ON c.object_id=t.object_id
224WHERE t.name='%s' AND c.name='%s'
225""",
226 catalog_tbl.getName(), catalog_col.getName());
227 } else {
228 if (LOG.isDebugEnabled()) {
229 LOG.debug("Unexpected request for sequence name on {} using {}", catalog_col, dbType);
230 }
231 }
232
233 if (sql != null) {
234 try (Statement stmt = conn.createStatement()) {
235 try (ResultSet result = stmt.executeQuery(sql)) {
236 if (result.next()) {
237 seqName = result.getString(1);
238 }
239 }
240 if (LOG.isDebugEnabled()) {
241 LOG.debug(String.format("%s => [%s]", sql, seqName));
242 }
243 }
244 }
245
246 return seqName;
247 }
248
249 /**
250 * Mark the given table which has an identity column to be able to be inserted into with explicit

Callers 1

updateAutoIncrementMethod · 0.95

Calls 6

formatMethod · 0.80
executeQueryMethod · 0.80
getStringMethod · 0.80
getTableMethod · 0.65
getNameMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected