From 04e5a5d05593f06c0b82c6a6e78a7d86e5e0e0c2 Mon Sep 17 00:00:00 2001 From: lobty Date: Thu, 12 Feb 2026 17:29:52 +0800 Subject: [PATCH] mprove schema mismatch logs to show field name and type differences Signed-off-by: lobty --- .../storage/include/cloud/schema_mgr.h | 2 + .../storage/src/cloud/schema_mgr.cpp | 42 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/frameworks/libs/distributeddb/storage/include/cloud/schema_mgr.h b/frameworks/libs/distributeddb/storage/include/cloud/schema_mgr.h index 71ffce60311..dbb2533ee14 100644 --- a/frameworks/libs/distributeddb/storage/include/cloud/schema_mgr.h +++ b/frameworks/libs/distributeddb/storage/include/cloud/schema_mgr.h @@ -38,6 +38,8 @@ public: private: bool IsAssetPrimaryField(const Field &cloudField); + std::string GetStorageTypeName(StorageType type); + std::string GetCloudTypeName(int32_t type); bool CompareType(const FieldInfo &localField, const Field &cloudField); bool CompareNullable(const FieldInfo &localField, const Field &cloudField); bool ComparePrimaryField(std::map &localPrimaryKeys, const Field &cloudField); diff --git a/frameworks/libs/distributeddb/storage/src/cloud/schema_mgr.cpp b/frameworks/libs/distributeddb/storage/src/cloud/schema_mgr.cpp index 4f5eca04255..fac6dbb350e 100644 --- a/frameworks/libs/distributeddb/storage/src/cloud/schema_mgr.cpp +++ b/frameworks/libs/distributeddb/storage/src/cloud/schema_mgr.cpp @@ -71,15 +71,24 @@ int SchemaMgr::CompareFieldSchema(std::map &primaryKeys, FieldIn } FieldInfo &localField = localFields[cloudField.colName]; if (!CompareType(localField, cloudField)) { - LOGE("Type mismatch between local and cloud schema"); + LOGE("Type mismatch for field [%s]: local=%s, cloud=%s", + DBCommon::StringMiddleMasking(cloudField.colName).c_str(), + GetStorageTypeName(localField.GetStorageType()).c_str(), + GetCloudTypeName(cloudField.type).c_str()); return -E_SCHEMA_MISMATCH; } if (!CompareNullable(localField, cloudField)) { - LOGE("The nullable property is mismatched between local and cloud schema"); + LOGE("Nullable mismatch for field [%s]: local=%s, cloud=%s", + DBCommon::StringMiddleMasking(cloudField.colName).c_str(), + localField.IsNotNull() ? "NOT_NULL" : "NULLABLE", + cloudField.nullable ? "NULLABLE" : "NOT_NULL"); return -E_SCHEMA_MISMATCH; } if (!ComparePrimaryField(primaryKeys, cloudField)) { - LOGE("The primary key property is mismatched between local and cloud schema"); + LOGE("Primary key mismatch for field [%s]: local=%s, cloud=%s", + DBCommon::StringMiddleMasking(cloudField.colName).c_str(), + cloudField.primary ? "NOT_PRIMARY" : "PRIMARY", + cloudField.primary ? "PRIMARY" : "NOT_PRIMARY"); return -E_SCHEMA_MISMATCH; } cloudColNames.emplace(cloudField.colName); @@ -104,6 +113,33 @@ bool SchemaMgr::IsAssetPrimaryField(const Field &cloudField) return cloudField.primary && (cloudField.type == TYPE_INDEX || cloudField.type == TYPE_INDEX); } +std::string SchemaMgr::GetStorageTypeName(StorageType type) +{ + switch (type) { + case StorageType::STORAGE_TYPE_NULL: return "NULL"; + case StorageType::STORAGE_TYPE_INTEGER: return "INTEGER"; + case StorageType::STORAGE_TYPE_REAL: return "REAL"; + case StorageType::STORAGE_TYPE_TEXT: return "TEXT"; + case StorageType::STORAGE_TYPE_BLOB: return "BLOB"; + default: return "UNKNOWN"; + } +} + +std::string SchemaMgr::GetCloudTypeName(int32_t type) +{ + switch (type) { + case TYPE_INDEX: return "NULL"; + case TYPE_INDEX: return "BOOL"; + case TYPE_INDEX: return "INTEGER"; + case TYPE_INDEX: return "REAL"; + case TYPE_INDEX: return "TEXT"; + case TYPE_INDEX: return "BLOB"; + case TYPE_INDEX: return "ASSET"; + case TYPE_INDEX: return "ASSETS"; + default: return "UNKNOWN"; + } +} + bool SchemaMgr::CompareType(const FieldInfo &localField, const Field &cloudField) { StorageType localType = localField.GetStorageType(); -- Gitee