File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
src/main/java/net/sf/jsqlparser/schema Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -425,4 +425,44 @@ public Table setResolvedTable(Table resolvedTable) {
425
425
this .resolvedTable = new Table (resolvedTable .getFullyQualifiedName ());
426
426
return this ;
427
427
}
428
+
429
+ /**
430
+ * Sets a table's catalog and schema only when not set. Useful for setting CURRENT_SCHEMA() and
431
+ * CURRENT_DATABASE()
432
+ *
433
+ * @param currentCatalogName the catalog name
434
+ * @param currentSchemaName the schema name
435
+ * @return the provided table
436
+ */
437
+ public Table setUnsetCatalogAndSchema (String currentCatalogName , String currentSchemaName ) {
438
+ String databaseName = getDatabaseName ();
439
+ if (databaseName == null || databaseName .isEmpty ()) {
440
+ setDatabaseName (currentCatalogName );
441
+ }
442
+
443
+ String schemaName = getSchemaName ();
444
+ if (schemaName == null || schemaName .isEmpty ()) {
445
+ setSchemaName (currentSchemaName );
446
+ }
447
+ return this ;
448
+ }
449
+
450
+ /**
451
+ * Sets a tables' catalog and schema only when not set. Useful for setting CURRENT_SCHEMA() and
452
+ * CURRENT_DATABASE()
453
+ *
454
+ * @param currentCatalogName the current catalog name
455
+ * @param currentSchemaName the current schema name
456
+ * @param tables the tables
457
+ * @return the tables
458
+ */
459
+ public static Table [] setUnsetCatalogAndSchema (String currentCatalogName ,
460
+ String currentSchemaName , Table ... tables ) {
461
+ for (Table t : tables ) {
462
+ if (t != null ) {
463
+ t .setUnsetCatalogAndSchema (currentCatalogName , currentSchemaName );
464
+ }
465
+ }
466
+ return tables ;
467
+ }
428
468
}
You can’t perform that action at this time.
0 commit comments