From 15075ee7d804d5ddfd9a36ebc7cddebeaf1ffc96 Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Wed, 16 Oct 2024 19:41:37 +0800 Subject: [PATCH] Fix embedded Signed-off-by: Jin Hai --- python/infinity_embedded/infinity.py | 2 +- python/infinity_embedded/local_infinity/client.py | 9 +++++++-- python/infinity_embedded/local_infinity/db.py | 3 ++- python/infinity_embedded/local_infinity/infinity.py | 4 ++-- src/embedded_infinity/wrap_infinity.cpp | 6 +++++- src/embedded_infinity/wrap_infinity.cppm | 5 +++-- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/python/infinity_embedded/infinity.py b/python/infinity_embedded/infinity.py index d6fc31d9c8..1251925629 100644 --- a/python/infinity_embedded/infinity.py +++ b/python/infinity_embedded/infinity.py @@ -19,7 +19,7 @@ def __init__(self, uri): self.uri = uri @abstractmethod - def create_database(self, db_name, options=None): + def create_database(self, db_name, options=None, comment: str = None): pass @abstractmethod diff --git a/python/infinity_embedded/local_infinity/client.py b/python/infinity_embedded/local_infinity/client.py index bf78ec84e7..2cd5c57d7a 100644 --- a/python/infinity_embedded/local_infinity/client.py +++ b/python/infinity_embedded/local_infinity/client.py @@ -69,10 +69,15 @@ def convert_res(self, res, has_db_names=False, has_table_names=False, has_result return LocalQueryResult(PyErrorCode(res.error_code.value), res.error_msg, index_names=res.names) return LocalQueryResult(PyErrorCode(res.error_code.value), res.error_msg) - def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError): + def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError, comment: str = None): create_database_options = CreateDatabaseOptions() create_database_options.conflict_type = conflict_type - return self.convert_res(self.client.CreateDatabase(db_name, create_database_options)) + db_comment: str = None + if comment is None: + db_comment = "" + else: + db_comment = comment + return self.convert_res(self.client.CreateDatabase(db_name, create_database_options, db_comment)) def drop_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError): drop_database_options = DropDatabaseOptions() diff --git a/python/infinity_embedded/local_infinity/db.py b/python/infinity_embedded/local_infinity/db.py index 71ecbefa1a..d2835e3b11 100644 --- a/python/infinity_embedded/local_infinity/db.py +++ b/python/infinity_embedded/local_infinity/db.py @@ -10,9 +10,10 @@ class LocalDatabase(Database, ABC): - def __init__(self, conn, name: str): + def __init__(self, conn, name: str, comment: str = None): self._conn = conn self._db_name = name + self._db_comment = comment def create_table(self, table_name: str, columns_definition, conflict_type: ConflictType = ConflictType.Error): diff --git a/python/infinity_embedded/local_infinity/infinity.py b/python/infinity_embedded/local_infinity/infinity.py index 402f0c544a..1eb50c6f20 100644 --- a/python/infinity_embedded/local_infinity/infinity.py +++ b/python/infinity_embedded/local_infinity/infinity.py @@ -39,7 +39,7 @@ def check_connect(self): raise Exception("Local infinity is not connected") @name_validity_check("db_name", "DB") - def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.Error): + def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.Error, comment: str = None): self.check_connect() create_database_conflict: LocalConflictType if conflict_type == ConflictType.Error: @@ -50,7 +50,7 @@ def create_database(self, db_name: str, conflict_type: ConflictType = ConflictTy create_database_conflict = LocalConflictType.kReplace else: raise InfinityException(ErrorCode.INVALID_CONFLICT_TYPE, "Invalid conflict type") - res = self._client.create_database(db_name, create_database_conflict) + res = self._client.create_database(db_name, create_database_conflict, comment) if res.error_code == ErrorCode.OK: return LocalDatabase(self._client, db_name) diff --git a/src/embedded_infinity/wrap_infinity.cpp b/src/embedded_infinity/wrap_infinity.cpp index 879166f8e0..3f25f5454c 100644 --- a/src/embedded_infinity/wrap_infinity.cpp +++ b/src/embedded_infinity/wrap_infinity.cpp @@ -577,7 +577,7 @@ WrapQueryResult WrapShowDatabase(Infinity &instance, const String &db_name) { if (query_result.IsOk()) { SharedPtr data_block = query_result.result_table_->GetDataBlockById(0); auto row_count = data_block->row_count(); - if (row_count != 3) { + if (row_count != 4) { String error_message = "ShowDatabase: query result is invalid."; UnrecoverableError(error_message); } @@ -593,6 +593,10 @@ WrapQueryResult WrapShowDatabase(Infinity &instance, const String &db_name) { Value value = data_block->GetValue(1, 2); result.table_count = std::stol(value.GetVarchar()); } + { + Value value = data_block->GetValue(1, 3); + result.database_comment = value.GetVarchar(); + } } return result; } diff --git a/src/embedded_infinity/wrap_infinity.cppm b/src/embedded_infinity/wrap_infinity.cppm index 4e98ab79ba..67d78def56 100644 --- a/src/embedded_infinity/wrap_infinity.cppm +++ b/src/embedded_infinity/wrap_infinity.cppm @@ -127,6 +127,7 @@ export struct WrapQueryResult { // show database String database_name; String store_dir; + String database_comment; BigIntT table_count; WrapQueryResult() = default; @@ -289,9 +290,9 @@ export struct WrapUpdateExpr { UpdateExpr *GetUpdateExpr(Status &status); }; -export WrapQueryResult WrapCreateDatabase(Infinity &instance, const String &db_name, const CreateDatabaseOptions &options); +export WrapQueryResult WrapCreateDatabase(Infinity &instance, const String &db_name, const CreateDatabaseOptions &options, const String &comment); -export WrapQueryResult WrapDropDatabase(Infinity &instance, const String &db_name, const DropDatabaseOptions &options, const String &comment); +export WrapQueryResult WrapDropDatabase(Infinity &instance, const String &db_name, const DropDatabaseOptions &options); export WrapQueryResult WrapListDatabases(Infinity &instance);