2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file HmGenericDatabaseManager.h
19 * @brief Keeps the declaration of DatabaseManager and related interfaces
20 * declaration of the various functions which may be needed for various database operations
23 #ifndef _HM_GENERIC_DATABASE_MANAGER_H_
24 #define _HM_GENERIC_DATABASE_MANAGER_H_
30 * @class GenericDatabaseManager
31 * @brief The class contains declaration of various database functions.
33 class GenericDatabaseManager
34 : public Tizen::Base::Object
38 * Returns an object of the database manager
40 * @return HomeDatabaseManager*, pointer to the singleton object of HomeDatabaseManager
42 static GenericDatabaseManager* GetInstance(void);
45 * Creates or opens(if already created) the database.
47 * @return E_SUCCESS in case of success else system wide error code
48 * @param[in] dbName, absolute path for the database file.
50 result CreateDataBase(const Tizen::Base::String& dbName);
53 * Creates a Table of given name if not already exists.
55 * @return E_SUCCESS in case of success else system wide error code
56 * @param[in] tableName, name of the table to be created.
57 * @param[in] pColumnNames, the names for each columns in the table
58 * @param[in] pColumnTypes, the type of corresponding column names
60 result CreateTable(const Tizen::Base::String& tableName, Tizen::Base::Collection::ArrayList* pColumnNames, Tizen::Base::Collection::ArrayList* pColumnTypes);
63 * Deletes records from the table
65 * @return E_SUCCESS in case of success else system wide error code
66 * @param[in] tableName, the table name from which the rows to be deleted
67 * @param[in] whereCondition, the criteria to select the correct row to be modified
69 result DeleteFromTable(const Tizen::Base::String& tableName, const Tizen::Base::String& whereCondition);
72 * Reads data from the database.
74 * @return E_SUCCESS in case of success else system wide error code
75 * @param[in] tableName, the table name from which the rows to be deleted
76 * @param[in] whereCondition, the criteria to select the correct row to be modified
77 * @param[out] the retrieved data, the column name to be keys and values as value.
79 result GetDataRowFromTable(const Tizen::Base::String& tableName, const Tizen::Base::String& whereCondition, Tizen::Base::Collection::HashMap& rowDataHashMap);
82 * Returns the last added records recordId,
83 * this record id is the value of the PRIMARY AutoIncremented column in the table
85 * @return int, the value of record id.
86 * @param[in] tableName, table name for which the record id has to be fetched
88 * @remark : if fails it returns -1 and the error can be fetched using GetLastResult() Method
90 int GetLastAddedRowID(const Tizen::Base::String& tableName);
93 * Inserts the data in given table.
95 * @return E_SUCCESS in case of success else system wide error code
96 * @param[in] tableName, name of the table to be created.
97 * @param[in] pColumnNames, the names for each columns in the table
98 * @param[in] pColumnTypes, the type of corresponding columns
99 * @param[in] pColumnValues, the values for corresponding columns
101 result InsertToTable(const Tizen::Base::String& tableName, Tizen::Base::Collection::ArrayList* pColumnNames, Tizen::Base::Collection::ArrayList* pColumnTypes, Tizen::Base::Collection::ArrayList* pColumnValues);
104 * Inserts the data in given table.
106 * @return E_SUCCESS in case of success else system wide error code
107 * @param[in] tableName, name of the table to be created.
108 * @param[in] pColumnsToModify, the column names which needs to be updated
109 * @param[in] pColumnTypes, the type of corresponding columns
110 * @param[in] pColumnsNewData, the values for corresponding columns
111 * @param[in] whereCondition, the criteria to select the correct row to be modified
113 result UpdateTable(const Tizen::Base::String& tableName, Tizen::Base::Collection::ArrayList* pColumnsToModify, Tizen::Base::Collection::ArrayList* pColumnTypes, Tizen::Base::Collection::ArrayList* pColumnsNewData, const Tizen::Base::String* pWhereCondition);
118 * This destructor is intentionally declared as private to implement the Singleton semantic.
120 ~GenericDatabaseManager(void);
124 * This Constructor is intentionally declared as private to implement the Singleton semantic.
126 GenericDatabaseManager(void);
129 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
131 GenericDatabaseManager(const GenericDatabaseManager&);
134 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
136 GenericDatabaseManager& operator =(const GenericDatabaseManager&);
139 * Creates the singleton object of HomeDatabaseManager
141 static void CreateInstance(void);
144 * Destroys the singleton object of HomeDatabaseManager
146 static void DestroyInstance(void);
149 * returns the column type of the mentioned column name
151 * @return DbColumnType, tells about the data type of the column.
152 * @param[in] columnName, column name for which type is to be known.
154 Tizen::Io::DbColumnType GetColumnType(Tizen::Io::DbEnumerator* pDbEnumerator, Tizen::Base::String* pColumnName);
157 * returns the columntype of the mentioned columnName
159 * @return int, tells about the datatype of the column.
160 * @param[in] pColumnName, column name for which type is to be known.
162 int GetColumnIndex(Tizen::Io::DbEnumerator* pDbEnumerator, Tizen::Base::String* pColumnName);
165 static GenericDatabaseManager* __pDatabaseManager; // singleton object of this class
166 Tizen::Io::Database* __pDatabase; // database instance
169 #endif //_HM_GENERIC_DATABASE_MANAGER_H_