2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief This is the header file for the %_DatabaseImpl class.
21 * This header file contains the declarations of the %_DatabaseImpl class.
24 #ifndef _FIO_INTERNAL_DATABASE_IMPL_H_
25 #define _FIO_INTERNAL_DATABASE_IMPL_H_
27 #include <FIoDatabase.h>
28 #include <FBaseObject.h>
29 #include <FBaseColLinkedList.h>
30 #include <FOspConfig.h>
32 namespace Tizen { namespace Base
42 namespace Tizen { namespace Io
47 class _DbEnumeratorImpl;
48 class _IDbUserFunctionListener;
49 class _IDbUserAggregateListener;
50 class _IDbUserCollationListener;
52 typedef struct Mem sqlite3_value;
53 typedef struct sqlite3_context sqlite3_context;
55 class _OSP_EXPORT_ _DatabaseImpl
56 : public Tizen::Base::Object
62 virtual ~_DatabaseImpl(void);
64 result Construct(const Tizen::Base::String& dbPath, bool createIfNotExist);
66 result Construct(const Tizen::Base::String& dbPath, long openMode, const Tizen::Base::ByteBuffer* pSecretKey);
68 result Construct(const Tizen::Base::String& dbPath, const char* pOpenMode, const Tizen::Base::ByteBuffer* pSecretKey);
70 DbStatement* CreateStatementN(const Tizen::Base::String& statement);
72 DbEnumerator* ExecuteStatementN(const DbStatement& statement);
74 result ExecuteSql(const Tizen::Base::String& sql, bool autoCommit);
76 DbEnumerator* QueryN(const Tizen::Base::String& query);
78 result BeginTransaction(void);
80 result CommitTransaction(void);
82 result RollbackTransaction(void);
84 Tizen::Base::String GetName(void) const;
87 // This method is for internal use only.
88 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
90 // Registers the user defined SQL function.
93 // @return An error code
94 // @param[in] functionName Name of the SQL function.
95 // @param[in] argumentCount The number of arguments to be used by the SQL function.
96 // @param[in] pUserData User data if any
97 // @param[in] pUserFunctionListener A listener invoked when the SQL function is executed.
98 // @param[in] pUserAggregateListener A listener invoked when the SQL aggregate is executed.
99 // @exception E_SUCCESS The method was successful.
100 // @exception E_INVALID_STATE The database was not opened.
101 // @exception E_INVALID_ARG Either of the following conditions has occurred: @n
102 // - The length of the specified @c functionName exceeded system limitation. @n
103 // - The specified @c argumentCount passed was < 0 or > 127.
104 // - One of the specified @c pUserFunctionListener and the specified @c pUserAggregateListener
105 // cannot be registered together.
106 // @exception E_DATABASE Failed to create the user defined SQL function due to its misuse.
108 result RegisterUserFunction(const Tizen::Base::String& functionName, int argumentCount, void* pUserData, _IDbUserFunctionListener* pUserFunctionListener, _IDbUserAggregateListener* pUserAggregateListener);
111 // This method is for internal use only.
112 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
114 // Registers the user defined SQL collation function.
117 // @return An error code
118 // @param[in] collationName Name of the SQL collating function
119 // @param[in] pUserData User data if any
120 // @param[in] pUserCollationListener A listener invoked when the SQL collating function is executed.
121 // @exception E_SUCCESS The method was successful.
122 // @exception E_INVALID_STATE The database was not opened.
123 // @exception E_DATABASE Failed to create the user defined SQL collating function due to its misuse.
125 result RegisterUserCollation(const Tizen::Base::String& collationName, void* pUserData, _IDbUserCollationListener* pUserCollationListener);
127 long long GetLastInsertRowId(void) const;
129 static result Delete(const Tizen::Base::String& databasePath);
131 static bool Exists(const Tizen::Base::String& databasePath);
133 static result ConvertToSecureDatabase(const Tizen::Base::String& plainDatabasePath, const Tizen::Base::String& secureDatabasePath, const Tizen::Base::ByteBuffer* pKey = null);
135 static _DatabaseImpl* GetInstance(Database& database);
137 static const _DatabaseImpl* GetInstance(const Database& database);
140 _DatabaseImpl(_DatabaseImpl& databaseImpl);
142 _DatabaseImpl& operator =(const _DatabaseImpl& databaseImpl);
144 bool IsDirectory(const Tizen::Base::String& databasePath);
146 bool VerifyDatabaseOpenMode(const char* pOpenMode, long& legacyMode);
148 static void UserFunctionListener(sqlite3_context* pContext, int argumentCount, sqlite3_value** pArgList);
150 static void UserFunctionStepListener(sqlite3_context* pContext, int argumentCount, sqlite3_value** pArgList);
152 static void UserFunctionFinalListener(sqlite3_context* pContext);
154 static int UserCollationListener(void* pContext, int length1, const void* pInput1, int length2, const void* pInput2);
156 Tizen::Base::String __dbName;
158 bool __transactionGoingOn;
159 Tizen::Base::Collection::LinkedList __userFunctionContextList;
160 Tizen::Base::Collection::LinkedList __userCollationContextList;
162 friend class DbStatement;
163 friend class DbEnumerator;
164 friend class _DbEnumeratorImpl;
170 #endif //_FIO_INTERNAL_DATABASE_IMPL_H_