1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NATIVE_RDB_SQLITE_GLOBAL_CONFIG_H 17 #define NATIVE_RDB_SQLITE_GLOBAL_CONFIG_H 18 19 #include <string> 20 21 #include "rdb_store_config.h" 22 23 namespace OHOS { 24 namespace NativeRdb { 25 26 class GlobalExpr { 27 public: 28 static constexpr bool CALLBACK_LOG_SWITCH = true; /* Sqlite callback log switch */ 29 static constexpr int SOFT_HEAP_LIMIT = 8 * 1024 * 1024; /* 8MB */ 30 static constexpr int DB_PAGE_SIZE = 4096; /* default page size : 4k */ 31 static constexpr int DB_JOURNAL_SIZE = 1024 * 1024; /* default file size : 1M */ 32 static constexpr ssize_t DB_WAL_SIZE_LIMIT_MIN = 20 * 1024 * 1024; /* default wal file maximum size : 20M */ 33 static constexpr ssize_t DB_WAL_WARNING_SIZE = 256 * 1024 * 1024; /* default wal file maximum size : 256M */ 34 static constexpr ssize_t DB_WAL_SIZE_LIMIT_MAX = 512 * 1024 * 1024; /* default wal file maximum size : 512M */ 35 static constexpr int WAL_AUTO_CHECKPOINT = 100; /* 100 pages */ 36 static constexpr int APP_DEFAULT_UMASK = 0002; 37 static constexpr int SQLITE_MAX_COLUMN = 2000; 38 static constexpr char ATTACH_BACKUP_SQL[] = "ATTACH ? AS backup KEY ?"; 39 static constexpr char ATTACH_WITH_KEY_SQL[] = "ATTACH DATABASE ? AS ? KEY ?"; 40 static constexpr char ATTACH_SQL[] = "ATTACH DATABASE ? AS ?"; 41 static constexpr char DETACH_SQL[] = "DETACH DATABASE ?"; 42 static constexpr char EXPORT_SQL[] = "SELECT export_database('backup')"; 43 static constexpr char DETACH_BACKUP_SQL[] = "detach backup"; 44 static constexpr char PRAGMA_JOUR_MODE_EXP[] = "PRAGMA journal_mode"; 45 static constexpr char PRAGMA_BACKUP_JOUR_MODE_WAL[] = "PRAGMA backup.journal_mode=WAL"; 46 static constexpr char PRAGMA_VERSION[] = "PRAGMA user_version"; 47 static constexpr char JOURNAL_MODE_WAL[] = "WAL"; 48 static constexpr char DEFAULE_SYNC_MODE[] = "FULL"; 49 static constexpr char MEMORY_DB_PATH[] = ":memory:"; 50 static constexpr char CODEC_HMAC_ALGO[] = "PRAGMA codec_hmac_algo=sha256"; 51 static constexpr char CODEC_REKEY_HMAC_ALGO[] = "PRAGMA codec_rekey_hmac_algo=sha256"; 52 static constexpr char CIPHER_DEFAULT_ALGO[] = "PRAGMA codec_cipher='aes-256-gcm'"; 53 static constexpr char CIPHER_KDF_ITER[] = "PRAGMA codec_kdf_iter="; 54 static constexpr char CIPHER_DEFAULT_ATTACH_HMAC_ALGO[] = "PRAGMA cipher_default_attach_hmac_algo=sha256"; 55 }; 56 57 class SqliteGlobalConfig { 58 public: 59 SqliteGlobalConfig(); 60 ~SqliteGlobalConfig(); 61 static void InitSqliteGlobalConfig(); 62 static void Log(const void *data, int err, const char *msg); 63 static std::string GetMemoryDbPath(); 64 static int GetPageSize(); 65 static std::string GetSyncMode(); 66 static int GetJournalFileSize(); 67 static int GetWalAutoCheckpoint(); 68 static std::string GetDefaultJournalMode(); 69 static int GetDbPath(const RdbStoreConfig &config, std::string &dbPath); 70 }; 71 72 } // namespace NativeRdb 73 } // namespace OHOS 74 75 #endif 76