17405867cSopenharmony_ci/*
27405867cSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
37405867cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47405867cSopenharmony_ci * you may not use this file except in compliance with the License.
57405867cSopenharmony_ci * You may obtain a copy of the License at
67405867cSopenharmony_ci *
77405867cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87405867cSopenharmony_ci *
97405867cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107405867cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117405867cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127405867cSopenharmony_ci * See the License for the specific language governing permissions and
137405867cSopenharmony_ci * limitations under the License.
147405867cSopenharmony_ci */
157405867cSopenharmony_ci#include "sql_util.h"
167405867cSopenharmony_ci
177405867cSopenharmony_cinamespace OHOS {
187405867cSopenharmony_cinamespace HiviewDFX {
197405867cSopenharmony_cinamespace SqlUtil {
207405867cSopenharmony_cistd::string CreateTable(const std::string& table, const std::vector<std::pair<std::string, std::string>>& fields)
217405867cSopenharmony_ci{
227405867cSopenharmony_ci    // default field: seq
237405867cSopenharmony_ci    std::string sql = "CREATE TABLE IF NOT EXISTS " + table + "(" + "seq INTEGER PRIMARY KEY AUTOINCREMENT";
247405867cSopenharmony_ci    for (auto field : fields) {
257405867cSopenharmony_ci        sql += ", " + field.first + " " + field.second;
267405867cSopenharmony_ci    }
277405867cSopenharmony_ci    sql += ")";
287405867cSopenharmony_ci    return sql;
297405867cSopenharmony_ci}
307405867cSopenharmony_ci
317405867cSopenharmony_cistd::string DropTable(const std::string& table)
327405867cSopenharmony_ci{
337405867cSopenharmony_ci    std::string sql = "DROP TABLE IF EXISTS " + table;
347405867cSopenharmony_ci    return sql;
357405867cSopenharmony_ci}
367405867cSopenharmony_ci} // namespace SqlUtil
377405867cSopenharmony_ci} // namespace HiviewDFX
387405867cSopenharmony_ci} // namespace OHOS
39