Skip to content

Commit 60f89dd

Browse files
committed
Handle format table name - 1402 changes
1 parent f6315af commit 60f89dd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,4 +717,30 @@ private ExecuteResult execute(String sql, Integer offset, Integer count) {
717717
}
718718
return executeResult;
719719
}
720+
721+
/**
722+
* Formats the given table name by stripping off any schema or catalog prefixes.
723+
* If the table name contains a dot ('.'), it splits the string by the dot
724+
* and returns the last part, which is generally the actual table name.
725+
* If the table name is blank (null, empty, or only whitespace), it returns the original table name.
726+
*
727+
* @param tableName the original table name, potentially including schema or catalog prefixes.
728+
* @return the formatted table name, or the original table name if it's blank or contains no dot.
729+
*/
730+
public static String formatTableName(String tableName) {
731+
// Check if the table name is blank (null, empty, or only whitespace)
732+
if (StringUtils.isBlank(tableName)) {
733+
return tableName;
734+
}
735+
736+
// Check if the table name contains a dot ('.')
737+
if (tableName.contains(".")) {
738+
// Split the table name by the dot and return the last part
739+
String[] split = tableName.split("\\.");
740+
return split[split.length - 1];
741+
}
742+
743+
// Return the original table name if it contains no dot
744+
return tableName;
745+
}
720746
}

0 commit comments

Comments
 (0)