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_ERRNO_H 17 #define NATIVE_RDB_SQLITE_ERRNO_H 18 19 #include <sqlite3sym.h> 20 21 #include <map> 22 23 #include "rdb_errno.h" 24 25 namespace OHOS { 26 namespace NativeRdb { 27 const static std::map<int, int> ERROR_CODE_MAPPINT_TABLE = { 28 { SQLITE_ERROR, E_SQLITE_ERROR }, 29 { SQLITE_ABORT, E_SQLITE_ABORT }, 30 { SQLITE_PERM, E_SQLITE_PERM }, 31 { SQLITE_BUSY, E_SQLITE_BUSY }, 32 { SQLITE_LOCKED, E_SQLITE_LOCKED }, 33 { SQLITE_NOMEM, E_SQLITE_NOMEM }, 34 { SQLITE_READONLY, E_SQLITE_READONLY }, 35 { SQLITE_IOERR, E_SQLITE_IOERR }, 36 { SQLITE_CORRUPT, E_SQLITE_CORRUPT }, 37 { SQLITE_FULL, E_SQLITE_FULL }, 38 { SQLITE_SCHEMA, E_SQLITE_SCHEMA }, 39 { SQLITE_CANTOPEN, E_SQLITE_CANTOPEN }, 40 { SQLITE_TOOBIG, E_SQLITE_TOOBIG }, 41 { SQLITE_CONSTRAINT, E_SQLITE_CONSTRAINT }, 42 { SQLITE_MISMATCH, E_SQLITE_MISMATCH }, 43 { SQLITE_MISUSE, E_SQLITE_MISUSE }, 44 { SQLITE_NOTADB, E_SQLITE_CORRUPT }, 45 { SQLITE_DONE, E_NO_MORE_ROWS }, 46 { SQLITE_ROW, E_OK }, 47 }; 48 class SQLiteError { 49 public: ErrNo(int sqliteErr)50 static int ErrNo(int sqliteErr) 51 { 52 auto iter = ERROR_CODE_MAPPINT_TABLE.find(sqliteErr); 53 if (iter != ERROR_CODE_MAPPINT_TABLE.end()) { 54 return iter->second; 55 } 56 return -sqliteErr; 57 } 58 }; 59 } // namespace NativeRdb 60 } // namespace OHOS 61 62 #endif 63