2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the %_DatabaseImpl class.
22 * This header file contains the declarations of the %_DatabaseImpl class.
25 #ifndef _FIO_INTERNAL_DATABASE_IMPL_H_
26 #define _FIO_INTERNAL_DATABASE_IMPL_H_
28 #include <FIoDatabase.h>
29 #include <FBaseObject.h>
30 #include <FBaseColLinkedList.h>
31 #include <FOspConfig.h>
33 namespace Tizen { namespace Base
43 namespace Tizen { namespace Io
48 class _DbEnumeratorImpl;
49 class _IDbUserFunctionListener;
50 class _IDbUserAggregateListener;
51 class _IDbUserCollationListener;
53 typedef struct Mem sqlite3_value;
54 typedef struct sqlite3_context sqlite3_context;
56 class _OSP_EXPORT_ _DatabaseImpl
57 : public Tizen::Base::Object
63 virtual ~_DatabaseImpl(void);
65 result Construct(const Tizen::Base::String& dbPath, bool createIfNotExist);
67 result Construct(const Tizen::Base::String& dbPath, long openMode, const Tizen::Base::ByteBuffer* pSecretKey);
69 result Construct(const Tizen::Base::String& dbPath, const char* pOpenMode, const Tizen::Base::ByteBuffer* pSecretKey);
71 DbStatement* CreateStatementN(const Tizen::Base::String& statement);
73 DbEnumerator* ExecuteStatementN(const DbStatement& statement);
75 result ExecuteSql(const Tizen::Base::String& sql, bool autoCommit);
77 DbEnumerator* QueryN(const Tizen::Base::String& query);
79 result BeginTransaction(void);
81 result CommitTransaction(void);
83 result RollbackTransaction(void);
85 Tizen::Base::String GetName(void) const;
88 // This method is for internal use only.
89 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
91 // Registers the user defined SQL function.
94 // @return An error code
95 // @param[in] functionName Name of the SQL function.
96 // @param[in] argumentCount The number of arguments to be used by the SQL function.
97 // @param[in] pUserData User data if any
98 // @param[in] pUserFunctionListener A listener invoked when the SQL function is executed.
99 // @param[in] pUserAggregateListener A listener invoked when the SQL aggregate is executed.
100 // @exception E_SUCCESS The method was successful.
101 // @exception E_INVALID_STATE The database was not opened.
102 // @exception E_INVALID_ARG Either of the following conditions has occurred: @n
103 // - The length of the specified @c functionName exceeded system limitation. @n
104 // - The specified @c argumentCount passed was < 0 or > 127.
105 // - One of the specified @c pUserFunctionListener and the specified @c pUserAggregateListener
106 // cannot be registered together.
107 // @exception E_DATABASE Failed to create the user defined SQL function due to its misuse.
109 result RegisterUserFunction(const Tizen::Base::String& functionName, int argumentCount, void* pUserData, _IDbUserFunctionListener* pUserFunctionListener, _IDbUserAggregateListener* pUserAggregateListener);
112 // This method is for internal use only.
113 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
115 // Registers the user defined SQL collation function.
118 // @return An error code
119 // @param[in] collationName Name of the SQL collating function
120 // @param[in] pUserData User data if any
121 // @param[in] pUserCollationListener A listener invoked when the SQL collating function is executed.
122 // @exception E_SUCCESS The method was successful.
123 // @exception E_INVALID_STATE The database was not opened.
124 // @exception E_DATABASE Failed to create the user defined SQL collating function due to its misuse.
126 result RegisterUserCollation(const Tizen::Base::String& collationName, void* pUserData, _IDbUserCollationListener* pUserCollationListener);
128 long long GetLastInsertRowId(void) const;
130 static result Delete(const Tizen::Base::String& databasePath);
132 static bool Exists(const Tizen::Base::String& databasePath);
134 static result ConvertToSecureDatabase(const Tizen::Base::String& plainDatabasePath, const Tizen::Base::String& secureDatabasePath, const Tizen::Base::ByteBuffer* pKey = null);
136 static _DatabaseImpl* GetInstance(Database& database);
138 static const _DatabaseImpl* GetInstance(const Database& database);
141 _DatabaseImpl(_DatabaseImpl& databaseImpl);
143 _DatabaseImpl& operator =(const _DatabaseImpl& databaseImpl);
145 bool IsDirectory(const Tizen::Base::String& databasePath);
147 bool VerifyDatabaseOpenMode(const char* pOpenMode, long& legacyMode);
149 static void UserFunctionListener(sqlite3_context* pContext, int argumentCount, sqlite3_value** pArgList);
151 static void UserFunctionStepListener(sqlite3_context* pContext, int argumentCount, sqlite3_value** pArgList);
153 static void UserFunctionFinalListener(sqlite3_context* pContext);
155 static int UserCollationListener(void* pContext, int length1, const void* pInput1, int length2, const void* pInput2);
157 Tizen::Base::String __dbName;
159 bool __transactionGoingOn;
160 Tizen::Base::Collection::LinkedList __userFunctionContextList;
161 Tizen::Base::Collection::LinkedList __userCollationContextList;
163 friend class DbStatement;
164 friend class DbEnumerator;
165 friend class _DbEnumeratorImpl;
171 #endif //_FIO_INTERNAL_DATABASE_IMPL_H_