1 /*
2 * Copyright (c) 2023 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 #include <sys/stat.h>
17 #include <unistd.h>
18
19 #include <algorithm>
20 #include <cstdio>
21 #ifdef WINDOWS_PLATFORM
22 #include <dir.h>
23 #endif
24
25 #include "rdb_errno.h"
26 #include "rdb_sql_utils.h"
27 #include "sqlite_sql_builder.h"
28
29 #ifdef WINDOWS_PLATFORM
30 #define MKDIR(filePath) (mkdir(filePath))
31 #else
32 #define MKDIR(filePath) (mkdir(filePath, 0771))
33 #endif
34
35 namespace OHOS {
36 namespace NativeRdb {
37
38 /**
39 * Get and Check default path.
40 */
GetDefaultDatabasePath(const std::string & baseDir,const std::string & name,int & errorCode)41 std::string RdbSqlUtils::GetDefaultDatabasePath(const std::string &baseDir, const std::string &name, int &errorCode)
42 {
43 errorCode = E_OK;
44 std::string databasePath = baseDir + "/rdb";
45 if (access(databasePath.c_str(), F_OK) != 0) {
46 if (MKDIR(databasePath.c_str())) {
47 errorCode = E_CREATE_FOLDER_FAIL;
48 }
49 }
50 return databasePath.append("/").append(name);
51 }
52
BuildQueryString(const AbsRdbPredicates & predicates,const std::vector<std::string> & columns)53 std::string RdbSqlUtils::BuildQueryString(const AbsRdbPredicates &predicates, const std::vector<std::string> &columns)
54 {
55 return SqliteSqlBuilder::BuildQueryString(predicates, columns);
56 }
57 } // namespace NativeRdb
58 } // namespace OHOS