2 // Open Service Platform
3 // Copyright (c) 2012-2013 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.
18 * @file FNet_NetAccountDatabase.cpp
19 * @brief This is the implementation file for the %_NetAccountDatabase class.
21 * This file contains the implementation of the %_NetAccountDatabase class.
24 #include <unique_ptr.h>
25 #include <FBaseString.h>
26 #include <FBaseColIList.h>
27 #include <FBaseColIListT.h>
28 #include <FIoDatabase.h>
29 #include <FIoDbStatement.h>
30 #include <FIoDbEnumerator.h>
31 #include <FIoDirectory.h>
33 #include <FBaseSysLog.h>
34 #include <FApp_AppInfo.h>
35 #include "FNet_NetTypes.h"
36 #include "FNet_NetUtility.h"
37 #include "FNet_NetAccountDatabase.h"
40 using namespace Tizen::App;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Io;
45 namespace Tizen { namespace Net {
48 _NetAccountDatabase::InitializeRepository(void)
50 static const wchar_t _NET_ACCOUNT_DATABASE_CREATE_TABLE_STATEMENT[] =
51 L"CREATE TABLE IF NOT EXISTS NetAccountTable (accountId INTEGER UNIQUE, accountName TEXT(256) UNIQUE, profileName TEXT(256) UNIQUE, isReadOnly INTEGER)";
56 if (!Database::Exists(_NetAccountDatabase::GetDbPath()))
58 SysLog(NID_NET, "NetAccount database is NOT found, so create it now.");
61 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), true);
62 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
64 r = accountDb.ExecuteSql(String(_NET_ACCOUNT_DATABASE_CREATE_TABLE_STATEMENT), true);
65 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
71 _NetAccountDatabase::AddAccount(const String& accountName, const String& profileName, _NetAccountOwner owner, NetAccountId& accountId)
73 static const wchar_t _NET_ACCOUNT_DATABASE_GET_MAX_ACCOUNT_ID_STATEMENT[] =
74 L"SELECT MAX(accountId) FROM NetAccountTable";
75 static const wchar_t _NET_ACCOUNT_DATABASE_ADD_ACCOUNT_STATEMENT[] =
76 L"INSERT INTO NetAccountTable (accountId, accountName, profileName, isReadOnly) VALUES(?, ?, ?, ?)";
80 unique_ptr<DbStatement> pStmt;
81 unique_ptr<DbEnumerator> pEnum;
82 bool isReadOnly = true;
83 NetAccountId netAccountId = INVALID_HANDLE;
85 SysLog(NID_NET, "AddAccount() has been called with accountName:%ls, profileName:%ls, owner:%d",
86 accountName.GetPointer(), profileName.GetPointer(), owner);
88 accountId = INVALID_HANDLE;
90 SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
91 SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
93 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
94 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
96 if (owner == _NET_ACCOUNT_OWNER_THIS)
105 if (owner == _NET_ACCOUNT_OWNER_SYSTEM_INTERNET)
107 netAccountId = _DEFAULT_PS_ACCOUNT_ID;
109 else if (owner == _NET_ACCOUNT_OWNER_SYSTEM_MMS)
111 netAccountId = _DEFAULT_MMS_ACCOUNT_ID;
115 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_MAX_ACCOUNT_ID_STATEMENT)));
117 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
119 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
122 while (pEnum->MoveNext() == E_SUCCESS)
124 pEnum->GetIntAt(0, netAccountId);
129 SysTryReturnResult(NID_NET, netAccountId >= 0, E_SYSTEM,
130 "[%s] A system error has been occurred. Failed to allocate a new accountId.", GetErrorMessage(E_SYSTEM));
132 if (netAccountId >= _CUSTOM_ACCOUNT_ID_START)
138 netAccountId = _CUSTOM_ACCOUNT_ID_START;
142 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_ADD_ACCOUNT_STATEMENT)));
144 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
146 r = pStmt->BindInt(0, netAccountId);
147 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
149 r = pStmt->BindString(1, accountName);
150 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
152 r = pStmt->BindString(2, profileName);
153 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
155 r = pStmt->BindInt(3, (int)isReadOnly);
156 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
158 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
160 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
162 accountId = netAccountId;
168 _NetAccountDatabase::RemoveAccountByAccountId(NetAccountId accountId)
170 static const wchar_t _NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_ACCOUNT_ID_STATEMENT[] =
171 L"DELETE FROM NetAccountTable WHERE accountId=?";
173 SysLog(NID_NET, "RemoveAccountByAccountId() has been called with accountId:%d", accountId);
175 result r = E_SUCCESS;
177 unique_ptr<DbStatement> pStmt;
178 unique_ptr<DbEnumerator> pEnum;
180 SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
182 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
183 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
185 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_ACCOUNT_ID_STATEMENT)));
187 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
189 r = pStmt->BindInt(0, accountId);
190 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
192 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
199 _NetAccountDatabase::RemoveAccountByProfileName(const String& profileName)
201 static const wchar_t _NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_PROFILE_NAME_STATEMENT[] =
202 L"DELETE FROM NetAccountTable WHERE profileName=?";
204 SysLog(NID_NET, "RemoveAccountByProfileName() has been called with profileName:%ls", profileName.GetPointer());
206 result r = E_SUCCESS;
208 unique_ptr<DbStatement> pStmt;
209 unique_ptr<DbEnumerator> pEnum;
211 SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
213 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
214 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
216 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_PROFILE_NAME_STATEMENT)));
218 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
220 r = pStmt->BindString(0, profileName);
221 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
223 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
230 _NetAccountDatabase::UpdateAccountName(NetAccountId accountId, const String& accountName)
232 static const wchar_t _NET_ACCOUNT_DATABASE_UPDATE_ACCOUNT_NAME_STATEMENT[] =
233 L"UPDATE NetAccountTable SET accountName=? WHERE accountId=?";
235 SysLog(NID_NET, "UpdateAccountName() has been called with accountId:%d, accountName:%ls", accountId, accountName.GetPointer());
237 result r = E_SUCCESS;
239 unique_ptr<DbStatement> pStmt;
240 unique_ptr<DbEnumerator> pEnum;
242 SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "AccountId[%d] is invalid.", accountId);
243 SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
245 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
246 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
248 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_UPDATE_ACCOUNT_NAME_STATEMENT)));
250 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
252 r = pStmt->BindString(0, accountName);
253 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
255 r = pStmt->BindInt(1, accountId);
256 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
258 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
264 IListT<NetAccountId>*
265 _NetAccountDatabase::GetAccountIdsN(void)
267 static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_IDS_STATEMENT[] =
268 L"SELECT accountId FROM NetAccountTable";
270 result r = E_SUCCESS;
272 unique_ptr<DbStatement> pStmt;
273 unique_ptr<DbEnumerator> pEnum;
274 unique_ptr< ArrayListT<NetAccountId> > pList;
276 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
277 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
279 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_IDS_STATEMENT)));
281 SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
283 pList.reset(new (std::nothrow) ArrayListT<NetAccountId>());
285 SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
287 r = pList->Construct();
288 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
290 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
292 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
296 while (pEnum->MoveNext() == E_SUCCESS)
298 NetAccountId accountId = INVALID_HANDLE;
300 r = pEnum->GetIntAt(0, accountId);
301 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
303 r = pList->Add(accountId);
304 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
308 ClearLastResult(); // To suppress E_OUT_OF_RANGE
310 return pList.release();
314 _NetAccountDatabase::GetAccountNamesN(void)
316 static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAMES_STATEMENT[] =
317 L"SELECT accountName FROM NetAccountTable";
319 result r = E_SUCCESS;
321 unique_ptr<DbStatement> pStmt;
322 unique_ptr<DbEnumerator> pEnum;
323 unique_ptr<ArrayList, _CollectionDeleter> pList;
325 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
326 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
328 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAMES_STATEMENT)));
330 SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
332 pList.reset(new (std::nothrow) ArrayList());
334 SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
336 r = pList->Construct();
337 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
339 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
341 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
345 while (pEnum->MoveNext() == E_SUCCESS)
347 unique_ptr<String> pAccountName(new (std::nothrow) String());
348 SysTryReturn(NID_NET, pAccountName != null, null, E_OUT_OF_MEMORY,
349 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
351 r = pEnum->GetStringAt(0, *pAccountName);
352 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
354 r = pList->Add(*pAccountName);
355 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
357 pAccountName.release();
361 ClearLastResult(); // To suppress E_OUT_OF_RANGE
363 return pList.release();
367 _NetAccountDatabase::GetProfileNamesN(void)
369 static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT[] =
370 L"SELECT profileName FROM NetAccountTable";
372 result r = E_SUCCESS;
374 unique_ptr<DbStatement> pStmt;
375 unique_ptr<DbEnumerator> pEnum;
376 unique_ptr<ArrayList, _CollectionDeleter> pList;
378 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
379 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
381 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT)));
383 SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
385 pList.reset(new (std::nothrow) ArrayList());
387 SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
389 r = pList->Construct();
390 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
392 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
394 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
398 while (pEnum->MoveNext() == E_SUCCESS)
400 unique_ptr<String> pProfileName(new (std::nothrow) String());
401 SysTryReturn(NID_NET, pProfileName != null, null, E_OUT_OF_MEMORY,
402 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
404 r = pEnum->GetStringAt(0, *pProfileName);
405 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
407 r = pList->Add(*pProfileName);
408 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
410 pProfileName.release();
414 ClearLastResult(); // To suppress E_OUT_OF_RANGE
416 return pList.release();
420 _NetAccountDatabase::GetAppProfileNamesN(void)
422 static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT[] =
423 L"SELECT profileName FROM NetAccountTable WHERE accountId>=?";
425 result r = E_SUCCESS;
427 unique_ptr<DbStatement> pStmt;
428 unique_ptr<DbEnumerator> pEnum;
429 unique_ptr<ArrayList, _CollectionDeleter> pList;
431 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
432 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
434 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT)));
436 SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
438 r = pStmt->BindInt(0, _CUSTOM_ACCOUNT_ID_START);
439 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
441 pList.reset(new (std::nothrow) ArrayList());
443 SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
445 r = pList->Construct();
446 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
448 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
450 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
454 while (pEnum->MoveNext() == E_SUCCESS)
456 unique_ptr<String> pProfileName(new (std::nothrow) String());
457 SysTryReturn(NID_NET, pProfileName != null, null, E_OUT_OF_MEMORY,
458 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
460 r = pEnum->GetStringAt(0, *pProfileName);
461 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
463 r = pList->Add(*pProfileName);
464 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
466 pProfileName.release();
470 ClearLastResult(); // To suppress E_OUT_OF_RANGE
472 return pList.release();
476 _NetAccountDatabase::GetAccountName(NetAccountId accountId, String& accountName)
478 static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAME_STATEMENT[] =
479 L"SELECT accountName FROM NetAccountTable WHERE accountId=?";
481 SysLog(NID_NET, "GetAccountName() has been called with accountId:%d", accountId);
483 result r = E_SUCCESS;
485 unique_ptr<DbStatement> pStmt;
486 unique_ptr<DbEnumerator> pEnum;
488 SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
490 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
491 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
493 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAME_STATEMENT)));
495 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
497 r = pStmt->BindInt(0, accountId);
498 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
502 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
505 while (pEnum->MoveNext() == E_SUCCESS)
507 pEnum->GetStringAt(0, accountName);
517 _NetAccountDatabase::GetProfileName(NetAccountId accountId, String& profileName)
519 static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAME_STATEMENT[] =
520 L"SELECT profileName FROM NetAccountTable WHERE accountId=?";
522 SysLog(NID_NET, "GetProfileName() has been called with accountId:%d", accountId);
524 result r = E_SUCCESS;
526 unique_ptr<DbStatement> pStmt;
527 unique_ptr<DbEnumerator> pEnum;
529 SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
531 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
532 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
534 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_PROFILE_NAME_STATEMENT)));
536 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
538 r = pStmt->BindInt(0, accountId);
539 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
543 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
546 while (pEnum->MoveNext() == E_SUCCESS)
548 pEnum->GetStringAt(0, profileName);
558 _NetAccountDatabase::GetAccountIdByAccountName(const String& accountName, NetAccountId& accountId)
560 static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_ACCOUNT_NAME_STATEMENT[] =
561 L"SELECT accountId FROM NetAccountTable WHERE accountName=?";
563 SysLog(NID_NET, "GetAccountIdByAccountName() has been called with accountName:%ls", accountName.GetPointer());
565 result r = E_SUCCESS;
567 unique_ptr<DbStatement> pStmt;
568 unique_ptr<DbEnumerator> pEnum;
570 SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
572 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
573 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
575 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_ACCOUNT_NAME_STATEMENT)));
576 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
578 r = pStmt->BindString(0, accountName);
579 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
583 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
586 while (pEnum->MoveNext() == E_SUCCESS)
588 pEnum->GetIntAt(0, accountId);
598 _NetAccountDatabase::GetAccountIdByProfileName(const String& profileName, NetAccountId& accountId)
600 static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_PROFILE_NAME_STATEMENT[] =
601 L"SELECT accountId FROM NetAccountTable WHERE profileName=?";
603 SysLog(NID_NET, "GetAccountIdByProfileName() has been called with profileName:%ls", profileName.GetPointer());
605 result r = E_SUCCESS;
607 unique_ptr<DbStatement> pStmt;
608 unique_ptr<DbEnumerator> pEnum;
610 SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
612 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
613 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
615 pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_PROFILE_NAME_STATEMENT)));
617 SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
619 r = pStmt->BindString(0, profileName);
620 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
624 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
627 while (pEnum->MoveNext() == E_SUCCESS)
629 pEnum->GetIntAt(0, accountId);
639 _NetAccountDatabase::IsReadOnly(NetAccountId accountId)
641 static const wchar_t NET_ACCOUNT_DATABASE_GET_IS_READ_ONLY_STATEMENT[] =
642 L"SELECT isReadOnly FROM NetAccountTable WHERE accountId=?";
644 SysLog(NID_NET, "IsReadOnly() has been called with accountId:%d", accountId);
646 result r = E_SUCCESS;
648 unique_ptr<DbStatement> pStmt;
649 unique_ptr<DbEnumerator> pEnum;
652 SysTryReturn(NID_NET, accountId > 0, true, E_INVALID_ARG,
653 "[%s] Invalid argument is used. accountId=%d", GetErrorMessage(E_INVALID_ARG), accountId);
655 r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
656 SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
658 pStmt.reset(accountDb.CreateStatementN(String(NET_ACCOUNT_DATABASE_GET_IS_READ_ONLY_STATEMENT)));
660 SysTryReturn(NID_NET, pStmt != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
662 r = pStmt->BindInt(0, accountId);
663 SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
666 pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
669 while (pEnum->MoveNext() == E_SUCCESS)
671 pEnum->GetIntAt(0, isReadOnly);
676 SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
680 return (bool)isReadOnly;
684 _NetAccountDatabase::GetDbPath(void)
686 static const wchar_t _OLD_DATA_PATH[] = L"/Home/";
687 static const wchar_t _NET_ACCOUNT_DATABASE_FILE_NAME[] = L"netAccount.db";
690 _ApiVersion apiVersion = _AppInfo::GetApiVersion();
692 if (apiVersion == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
694 dbPath = String(_OLD_DATA_PATH);
698 dbPath = Tizen::App::App::GetInstance()->GetAppDataPath();
701 dbPath += String(_NET_ACCOUNT_DATABASE_FILE_NAME);
703 SysLog(NID_NET, "GetDbPath() has been succeeded with the path:%ls", dbPath.GetPointer());