From bc628435b486a03137b318efc416730fcee04538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Mon, 26 Jun 2023 12:03:32 +0200 Subject: [PATCH] CR --- .../0.0.0-dev/src/Connection/Connection.enso | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Connection.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Connection.enso index b0c8881278208..ff014b5d46e04 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Connection.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Connection/Connection.enso @@ -404,16 +404,22 @@ type Connection registry - but that means it was created by Enso as a hidden table. generate_dry_run_table_name : Text -> Text generate_dry_run_table_name self table_name = + max_length = (self.max_table_name_length.if_nothing 60) - 1 go ix = prefix = "enso-dry-run-" + if ix == 0 then "" else ix.to_text + "-" - max_length = (self.max_table_name_length.if_nothing 60) - 1 - name = prefix + table_name.take (max_length - prefix.length) - ## The dry run name is ok if it is already registered (that means it - may exist in the Database, but it was created by other dry runs - and is safe to overwrite) or if it does not exist in the database. - name_ok = (self.hidden_table_registry.is_registered name) || (self.table_exists name . not) - if name_ok then name else - @Tail_Call go (ix + 1) + ## This check ensures that if all possible names are taken, the + method will not loop forever but report an error. It should never + occur in practice - it would mean that the Database contains + unimaginable amounts of dry run tables or has impractically small + table name length limit. + if prefix.length > max_length then Error.throw (Illegal_State.Error "Reached the table name length limit ("+max_length.to_text+") while trying to find a unused table name. It seems that all possible names are already taken. The Database may need to be cleaned up for dry run to work." else + name = (prefix + table_name) . take max_length + ## The dry run name is ok if it is already registered (that means it + may exist in the Database, but it was created by other dry runs + and is safe to overwrite) or if it does not exist in the database. + name_ok = (self.hidden_table_registry.is_registered name) || (self.table_exists name . not) + if name_ok then name else + @Tail_Call go (ix + 1) go 0 ## PRIVATE