1 /* 2 * Copyright (C) 2024 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 #ifndef OHOS_MEDIA_DATATRANSFER_DB_UPGRADE_UTILS_H 16 #define OHOS_MEDIA_DATATRANSFER_DB_UPGRADE_UTILS_H 17 18 #include <string> 19 20 #include "rdb_store.h" 21 22 namespace OHOS::Media { 23 namespace DataTransfer { 24 class DbUpgradeUtils { 25 public: 26 bool IsTableExists(NativeRdb::RdbStore &store, const std::string &tableName); 27 bool IsColumnExists(NativeRdb::RdbStore &store, const std::string &tableName, const std::string &columnName); 28 29 private: 30 const std::string SQL_PRAGMA_TABLE_INFO_QUERY = "\ 31 SELECT \ 32 name, \ 33 type, \ 34 [notnull], \ 35 dflt_value, \ 36 pk \ 37 FROM \ 38 pragma_table_info(?) \ 39 WHERE name = ?;"; 40 const std::string SQL_SQLITE_MASTER_QUERY = "\ 41 SELECT \ 42 type, \ 43 name, \ 44 tbl_name \ 45 FROM sqlite_master \ 46 WHERE type='table' AND \ 47 tbl_name = ?;"; 48 }; 49 } // namespace DataTransfer 50 } // namespace OHOS::Media 51 #endif // OHOS_MEDIA_DATATRANSFER_DB_UPGRADE_UTILS_H