Languages

Menu
Sites
Language
SQLite

Hello! Tell me please. How to use sqlite db in application! Give me please link to datasheet how to using sqlite in the Tizen.

Thanx:D

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

8 Replies
There are good example in the documentation. For me, I create database file using sqliteman tool and then put the database.db file in data folder and the access it using Tizen::Io::Database methods
y Rajyalakshmi
Hi Nour Saffaf, can you please send me your project code(sample) using Database. and select those fields as a list. i was fully confused with these methods. Thanks Rajyalakshmi
y Rajyalakshmi
Hi Nour Saffaf, can you please send me your project code(sample) using Database. and select those fields as a list. i was fully confused with these methods. Thanks Rajyalakshmi
wil smith
Sample code @https://developer.tizen.org/documentation/articles/dbcontrol-sample-code-using-dbmanager-class could be reffered
y Rajyalakshmi
Hi smith, Thanks for your response. please let me know when we have to use Tizen::App::ISqlDataControlResponseListener: and Tizen::App::ISqlDataControlResponseListener:... I have a database. with so many tables. just i have to extract the data from those tables. (this Query i have to use ) SELECT page_instance.Title, page_html.Html FROM page_instance INNER JOIN page_html ON page_instance.PageInstanceId=page_html.PageInstanceId; Title html .......... ................... Blue Shark ..................... Blue Tartan ..................... Booster ..................... Bosom Caresser ..................... Boston Cocktail (2) ..................... on the first form we have to display titles. w.r.t titles in the next form we have to display html pages I have refered DictionaryDataControlProvider and DictionaryDataControl.. but i was fully confused. Thanks Rajyalakshmi
wil smith
Have a look into the documentation part first, https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fapp%2Fdata_controls.htm This will give you a better understanding of SQL data control and how it works. Read them patiently,I am sure you won't be confused.
y Rajyalakshmi
Hi, how can we define the providerId. In the DataControl example we have used "http://tizen.org/datacontrol/provider/DictionaryDataControlProvider".. how to define providerId... Upto ( http://tizen.org/datacontrol/provider/) is it common for every ProviderId.. Last DictionaryDataControlProvider is the implemented class of ProviderEventListener..? can you please explain me each part in the providerId. Thanks Rajyalakshmi
y Rajyalakshmi
Hi I have tried this code.. it is showing some runtime error please check it and guide me for further /** * Name : DatabaseProviderApp * Version : * Vendor : * Description : */ #include "DatabaseProvider.h" #include using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Io; using namespace Tizen::System; using namespace Tizen::App; static const wchar_t* PROVIDER_ID = L"http://tizen.org/datacontrol/provider/DatabaseProvider"; DatabaseProviderApp::DatabaseProviderApp(void) { } DatabaseProviderApp::~DatabaseProviderApp(void) { } ServiceApp* DatabaseProviderApp::CreateInstance(void) { // Create the instance through the constructor. return new DatabaseProviderApp(); } bool DatabaseProviderApp::OnAppInitializing(AppRegistry& appRegistry) { // TODO: // Initialize App specific data. // The App's permanent data and context can be obtained from the appRegistry. // // If this method is successful, return true; otherwise, return false. // If this method returns false, the App will be terminated. // TODO: Add your initialization code here result r = E_SUCCESS; bool ret = true; DataControlProviderManager* pDcMgr = DataControlProviderManager::GetInstance(); TryReturn(pDcMgr != null, false, "Failed to get the data control provider manager instance."); r = pDcMgr->SetSqlDataControlProviderEventListener(this); TryReturn(!IsFailed(r), false, "Failed to Set the Sql data control provider listener."); Database* pDb = null; // String sqlCommand(L"CREATE TABLE IF NOT EXISTS Dictionary ( WORD VARCHAR(30) PRIMARY KEY, WORD_DESC TEXT )"); String dataPath = App::GetInstance()->GetAppDataPath(); __dbPath.Append(String(dataPath + L"data/bartendersbible_minerva.db")); if (File::IsFileExist(__dbPath)) { File::Remove(__dbPath); } pDb = new (std::nothrow) Database(); TryCatch(pDb != null, ret = false, "new Database() is null"); r = pDb->Construct(__dbPath, true); TryCatch(!IsFailed(r), ret = false, "Database Construct failed with error [%s] \n", GetErrorMessage(r)); //r = pDb->ExecuteSql(sqlCommand, true); //TryCatch(!IsFailed(r), ret = false, "ExecuteSql failed with error [%s] \n", GetErrorMessage(r)); // fall thru CATCH: delete pDb; return ret; return true; } bool DatabaseProviderApp::OnAppInitialized(void) { // TODO: // Comment. return true; } bool DatabaseProviderApp::OnAppWillTerminate(void) { // TODO: // Comment. return true; } bool DatabaseProviderApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination) { // TODO: // Deallocate resources allocated by this App for termination. // The App's permanent data and context can be saved via appRegistry. // TODO: Add your termination code here return true; } void DatabaseProviderApp::OnLowMemory(void) { // TODO: // Free unused resources or close the App. } void DatabaseProviderApp::OnBatteryLevelChanged(BatteryLevel batteryLevel) { // TODO: // Handle any changes in battery level here. // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL. } void DatabaseProviderApp::OnSqlDataControlInsertRequestReceived(RequestId reqId, const Tizen::Base::String& providerId, const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap) { } void DatabaseProviderApp::OnSqlDataControlSelectRequestReceived(RequestId reqId, const Tizen::Base::String& providerId, const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList, const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder) { Database* pDb = null; DbEnumerator* pEnum = null; result r = E_SUCCESS; bool providerResult = false; String errorMsg; String sql; if (providerId.CompareTo(String(PROVIDER_ID)) == 0) { if (dataId.CompareTo(L"page_instance") == 0) { pDb = new (std::nothrow) Database(); if (pDb == null) { errorMsg.Append(L"[E_OUT_OF_MEMORY] Db could not be instantiated. Insufficient memory"); r = E_OUT_OF_MEMORY; goto CATCH; } r = pDb->Construct(__dbPath, DB_OPEN_READ_ONLY, 0); if (IsFailed(r)) { errorMsg.Format(32, L"[%s]", GetErrorMessage(r)); errorMsg.Append(L"Database::Construct failed"); r = E_SYSTEM; goto CATCH; } sql = SqlStatementBuilder::CreateSelectStatement(dataId, pColumnList, pWhere, pOrder, null, null, null); r = GetLastResult(); if (IsFailed(r)) { errorMsg.Format(32, L"[%s]", GetErrorMessage(r)); errorMsg.Append(L"CreateSelectStatement failed"); goto CATCH; } AppLog("Select sql:%ls", sql.GetPointer()); pEnum = pDb->QueryN(sql); r = GetLastResult(); if (IsFailed(r)) { errorMsg.Format(32, L"[%s]", GetErrorMessage(r)); errorMsg.Append(L"QueryN failed"); if (r == E_INVALID_OPERATION) { r = E_INVALID_ARG; } else { r = E_SYSTEM; } goto CATCH; } providerResult = true; } else { errorMsg.Append(L"[E_INVALID_ARG] Invalid dataId was passed"); r = E_INVALID_ARG; } } else { errorMsg.Append(L"[E_INVALID_ARG] Invalid ProviderId was passed"); r = E_INVALID_ARG; } // fall thru CATCH: if (providerResult == true) { r = DataControlProviderManager::GetInstance()->SendSqlDataControlSelectResult(reqId, pEnum); } else { AppLog("errorMsg: %ls", errorMsg.GetPointer()); r = DataControlProviderManager::GetInstance()->SendDataControlError(reqId, errorMsg); } if (IsFailed(r)) { AppLog("The data control provider failed to send the result."); } delete pEnum; delete pDb; } void DatabaseProviderApp::OnSqlDataControlUpdateRequestReceived(RequestId reqId, const Tizen::Base::String& providerId, const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap, const Tizen::Base::String* pWhere) { } void DatabaseProviderApp::OnSqlDataControlDeleteRequestReceived(RequestId reqId, const Tizen::Base::String& providerId, const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere) { } //SqlDataControl class //.................................. #include "SqlDataControlMainForm.h" #include "AppResourceId.h" #include #include #include using namespace Tizen::Base::Collection; using namespace Tizen::App; using namespace Tizen::Base; using namespace Tizen::Io; using namespace Tizen::Ui; using namespace Tizen::Ui::Controls; using namespace Tizen::Ui::Scenes; using namespace Tizen::Graphics; static const int _MAX_DB_COLUMNS = 2; SqlDataControlMainForm::SqlDataControlMainForm(void) { } SqlDataControlMainForm::~SqlDataControlMainForm(void) { } bool SqlDataControlMainForm::Initialize(void) { Form::Construct(FORM_STYLE_HEADER | FORM_STYLE_INDICATOR); TryReturn(LoadTitles() == true, false, "LoadTitles() failed."); return true; } result SqlDataControlMainForm::OnInitializing(void) { result r = E_SUCCESS; SetFormBackEventListener(this); Header* pHeader = GetHeader(); pHeader->SetTitleText(L"List of words"); ListView* pListView = new ListView(); pListView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, false); pListView->SetItemProvider(*this); // pListView->AddListViewItemEventListener(*this); AddControl(pListView); __pPopup = new Popup(); __pPopup->Construct(true, Dimension(600, 250)); __pPopup->SetTitleText(L"Please wait."); Rectangle rect; rect = __pPopup->GetClientAreaBounds(); __pLabel = new Label(); __pLabel->Construct(Rectangle(0, 0, rect.width, 80), L"Processing your request."); __pLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER); __pPopup->AddControl(__pLabel); return r; } result SqlDataControlMainForm::OnTerminating(void) { delete __pPopup; if (__pSqlDataControl != null) { __pSqlDataControl->SetSqlDataControlResponseListener(null); } return E_SUCCESS; } void SqlDataControlMainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source) { AppLog("OnFormBackRequested."); if (__pSqlDataControl != null) { __pSqlDataControl->SetSqlDataControlResponseListener(null); } SceneManager* pSceneManager = SceneManager::GetInstance(); pSceneManager->GoBackward(BackwardSceneTransition()); } void SqlDataControlMainForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs) { // TODO: // Add your scene activate code here AppLog("OnSceneActivatedN"); } void SqlDataControlMainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId) { // TODO: // Add your scene deactivate code here AppLog("OnSceneDeactivated"); } ListItemBase* SqlDataControlMainForm::CreateItem(int index, int itemWidth) { ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL; result r; String* pWord = null; CustomItem* pItem = new (std::nothrow) CustomItem(); TryReturn(pItem != null, null, "new CustomItem() is null"); pItem->Construct(Tizen::Graphics::Dimension(itemWidth, 112), style); pWord = dynamic_cast< String* >(__title.GetValue(Integer(index))); r = pItem->AddElement(Rectangle(26, 32, 200, 80), 0, *pWord, false); TryLog(!IsFailed(r), "CustomItem::AddElement() is failed by %s", GetErrorMessage(r)); return pItem; } bool SqlDataControlMainForm::LoadTitles(void) { bool ret=true; if (__pSqlDataControl == null) { // send insert command __pSqlDataControl = AppManager::GetSqlDataControlN(L"http://tizen.org/datacontrol/provider/DatabaseProvider"); if (__pSqlDataControl == null) { // hide the popup and show result message. AppLog("GetSqlDataControlN() Failed"); MessageBox myMSGBox; myMSGBox.Construct(L"GetSqlDataControlN() failed", L"DatabaseProvider is not installed. Please install it !!", MSGBOX_STYLE_OK, 0); // Call ShowAndWait } } __pSqlDataControl->SetSqlDataControlResponseListener(this); __title.Construct(); return ret; } void SqlDataControlMainForm::OnSqlDataControlInsertResponseReceived(RequestId reqId, const String& providerId, const String& dataId, long long insertRowId, bool providerResult, const String* pErrorMsg) { } void SqlDataControlMainForm::OnSqlDataControlSelectResponseReceived(RequestId reqId, const String& providerId, const String& dataId, IDbEnumerator& resultSetEnum, bool providerResult, const String* pErrorMsg) { String where; RequestId selectReqId; ArrayList* pColumnList = null; String columnNames[_MAX_DB_COLUMNS] = { L"Title", L"Html" }; pColumnList = new (std::nothrow) ArrayList(); TryReturnVoid(pColumnList != null, "new ArrayList() is null."); result r = pColumnList->Add(*new String(columnNames[0])); TryCatch(!IsFailed(r), , "ArrayList::Add() failed to return E_SUCCESS, instead %s occured \n", GetErrorMessage(r)); where.Format(10, L"rowid=%ls", __lastInsertRowId); r = __pSqlDataControl->Select(L"Page_Instance", pColumnList, &where, null, selectReqId, 1, 1); if (IsFailed(r)) { AppLog("SqlDataControl::Select() failed to return E_SUCCESS, instead %s occured \n", GetErrorMessage(r)); // hide the popup and show result message. MessageBox myMSGBox; myMSGBox.Construct(L"SqlDataControl::Select", L"Request Failed!!", MSGBOX_STYLE_OK, 0); // Call ShowAndWait int modalResult = 0; myMSGBox.ShowAndWait(modalResult); //ShowAndWait() draw, show itself and process events } CATCH: AppLog("selectReqId:%d", selectReqId); pColumnList->RemoveAll(true); delete pColumnList; result ret = E_SUCCESS; AppLog("Tizen::Io >> reqId: %d, providerId: %ls, dataId: %ls, providerResult: %d", reqId, providerId.GetPointer(), dataId.GetPointer(), providerResult); // hide the popup. // show result message (word description on success or error message). if (providerResult == false) { AppLog("SqlDataControl::Select() failed. ErrorMsg (%ls). \n", pErrorMsg->GetPointer()); MessageBox myMSGBox; myMSGBox.Construct(L"SqlDataControl::Select", L"Response Failed!!", MSGBOX_STYLE_OK, 0); // Call ShowAndWait int modalResult = 0; myMSGBox.ShowAndWait(modalResult); //ShowAndWait() draw, show itself and process events return; } r = resultSetEnum.MoveNext(); AppLog("we have titles in enum"); String str = L"Test"; // Print the debug message "string: Test" to the console AppLogDebug("string: %ls", str.GetPointer()); if (r == E_SUCCESS) { String title; ret = resultSetEnum.GetStringAt(0, title); TryReturnVoid(!IsFailed(ret), "GetStringAt() failed to return E_SUCCESS, instead %s occured \n", GetErrorMessage(ret)); LinkedList* pList = new LinkedList(); pList->Add(*(new String(title))); String where; where.Format(10, L"rowid=%lld", __lastInsertRowId); } return; } void SqlDataControlMainForm::OnSqlDataControlUpdateResponseReceived(RequestId reqId, const String& providerId, const String& dataId, bool providerResult, const String* pErrorMsg) { TryLog(providerResult == true, "ErrorMsg (%ls). \n", pErrorMsg->GetPointer()); } void SqlDataControlMainForm::OnSqlDataControlDeleteResponseReceived(RequestId reqId, const String& providerId, const String& dataId, bool providerResult, const String* pErrorMsg) { TryLog(providerResult == true, "reqId(%d) ErrorMsg (%ls). \n", reqId, pErrorMsg->GetPointer()); } please let me know how to display the "title" in the table Page_Instance in .db file on the first form