Fixed web app can't update.
authorSoyoung Kim <sy037.kim@samsung.com>
Fri, 24 May 2013 13:49:37 +0000 (22:49 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Mon, 27 May 2013 05:08:08 +0000 (14:08 +0900)
[Issue#] N/A
[Problem] can't update
[Cause] widget preference db has tizen_appid instead of app_id(handle).
So db error occur during update.
db error is "foreign key constraint failed".
[Solution] modify foreign key from tizen_appid to app_id.
[SCMRequest] N/A

Change-Id: I7299fd34f125e574eeeeffb111ac022b08e3987b

modules/widget_dao/dao/property_dao.cpp
modules/widget_dao/dao/property_dao_read_only.cpp
modules/widget_dao/dao/widget_dao.cpp
modules/widget_dao/include/dpl/wrt-dao-ro/property_dao_read_only.h
modules/widget_dao/include/dpl/wrt-dao-rw/property_dao.h
modules/widget_dao/orm/wrt_db

index 8b3dabb..434e842 100644 (file)
@@ -102,9 +102,11 @@ void SetProperty(TizenAppId tzAppid,
             ThrowMsg(PropertyDAOReadOnly::Exception::ReadOnlyProperty,
                      "Property is readonly");
         }
+        DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
 
         if (readonly.IsNull()) {
             WidgetPreference::Row row;
+            row.Set_app_id(widgetHandle);
             row.Set_tizen_appid(tzAppid);
             row.Set_key_name(key);
             row.Set_key_value(value);
@@ -133,7 +135,7 @@ void SetProperty(TizenAppId tzAppid,
     }
 }
 
-void RegisterProperties(TizenAppId tzAppid,
+void RegisterProperties(DbWidgetHandle widgetHandle, TizenAppId tzAppid,
                         const WidgetRegisterInfo &regInfo)
 {
     LogDebug("Registering proferences for widget. appid: " << tzAppid);
@@ -148,6 +150,7 @@ void RegisterProperties(TizenAppId tzAppid,
     {
         { // Insert into table Widget Preferences
             WidgetPreference::Row row;
+            row.Set_app_id(widgetHandle);
             row.Set_tizen_appid(tzAppid);
             row.Set_key_name(it->name);
             row.Set_key_value(it->value);
index c475f2a..5e06afc 100644 (file)
@@ -57,6 +57,7 @@ void convertWidgetPreferenceRow(const ORMWidgetPreferenceList& ormWidgetPrefRow,
     FOREACH(it, ormWidgetPrefRow) {
         WidgetPreferenceRow row;
 
+        row.appId = it->Get_app_id();
         row.tizen_appid = it->Get_tizen_appid();
         row.key_name = it->Get_key_name();
         row.key_value = it->Get_key_value();
@@ -92,8 +93,11 @@ DPL::OptionalInt CheckPropertyReadFlag(TizenAppId tzAppid,
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
+
+        DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
+
         WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
-        select->Where(And(Equals<WidgetPreference::tizen_appid>(tzAppid),
+        select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
                           Equals<WidgetPreference::key_name>(key)));
 
         return select->GetSingleValue<WidgetPreference::readonly>();
@@ -110,9 +114,12 @@ WidgetPropertyKeyList GetPropertyKeyList(TizenAppId tzAppid)
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
+
+        DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
+
         ORMWidgetPropertyKeyList keyList;
         WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
-        select->Where(Equals<WidgetPreference::tizen_appid>(tzAppid));
+        select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
         keyList = select->GetValueList<WidgetPreference::key_name>();
 
         WidgetPropertyKeyList retKeyList;
@@ -144,8 +151,11 @@ WidgetPreferenceList GetPropertyList(TizenAppId tzAppId)
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
+
+        DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppId));
+
         WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
-        select->Where(Equals<WidgetPreference::tizen_appid>(tzAppId));
+        select->Where(Equals<WidgetPreference::app_id>(widgetHandle));
 
         ORMWidgetPreferenceList ormPrefList = select->GetRowList();
         WidgetPreferenceList prefList;
@@ -167,8 +177,11 @@ WidgetPropertyValue GetPropertyValue(TizenAppId tzAppid,
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
+
+        DbWidgetHandle widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid));
+
         WRT_DB_SELECT(select, WidgetPreference, &WrtDatabase::interface())
-        select->Where(And(Equals<WidgetPreference::tizen_appid>(tzAppid),
+        select->Where(And(Equals<WidgetPreference::app_id>(widgetHandle),
                           Equals<WidgetPreference::key_name>(key)));
 
         ORMWidgetPropertyValue ormPropValue =
index 47b19aa..ad1b7dc 100644 (file)
@@ -260,7 +260,7 @@ void WidgetDAO::registerWidgetInternal(
 
     registerWidgetStartFile(widgetHandle, widgetRegInfo);
 
-    PropertyDAO::RegisterProperties(tzAppId, widgetRegInfo);
+    PropertyDAO::RegisterProperties(widgetHandle, tzAppId, widgetRegInfo);
 
     registerWidgetFeatures(widgetHandle, widgetRegInfo);
 
@@ -920,7 +920,12 @@ void WidgetDAO::updateWidgetAppIdInternal(
                      "Cannot find widget. tzAppId: " << fromAppId);
         }
 
-        WidgetInfo::Row row;
+        WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
+        select->Where(Equals<WidgetInfo::tizen_appid>(fromAppId));
+
+        WidgetInfo::Row row = select->GetSingleRow();
+
+        //WidgetInfo::Row row;
         row.Set_tizen_appid(toAppId);
 
         WRT_DB_UPDATE(update, WidgetInfo, &WrtDatabase::interface())
index d7ff799..88e308a 100644 (file)
@@ -37,6 +37,7 @@ typedef DPL::OptionalString WidgetPropertyValue;
 typedef std::list<WidgetPropertyKey> WidgetPropertyKeyList;
 
 struct WidgetPreferenceRow {
+    int appId;
     TizenAppId tizen_appid;
     WidgetPropertyKey key_name;
     WidgetPropertyValue key_value;
index faecc0d..7e3f215 100644 (file)
@@ -51,7 +51,7 @@ void SetProperty(TizenAppId tzAppid,
 /* This method registers properties for widget.
  * Properties unregistering is done via "delete cascade" mechanism in SQL
  */
-void RegisterProperties(TizenAppId tzAppid,
+void RegisterProperties(DbWidgetHandle widgetHandle, TizenAppId tzAppid,
                         const WidgetRegisterInfo &regInfo);
 } // namespace PropertyDAO
 } // namespace WrtDB
index 2bd3a73..86103e4 100644 (file)
@@ -102,14 +102,15 @@ CREATE_TABLE(WidgetExtendedInfo)
 CREATE_TABLE_END()
 
 CREATE_TABLE(WidgetPreference)
+    COLUMN_NOT_NULL(app_id,     INTEGER,)
     COLUMN_NOT_NULL(tizen_appid,    TEXT,           DEFAULT 0)
     COLUMN_NOT_NULL(key_name,       TEXT,)
     COLUMN(key_value,               TEXT,           DEFAULT '')
     COLUMN(readonly,                INT,            DEFAULT 0)
 
     TABLE_CONSTRAINTS(
-        PRIMARY KEY(tizen_appid, key_name),
-        FOREIGN KEY(tizen_appid) REFERENCES WidgetInfo (tizen_appid) ON DELETE CASCADE
+        PRIMARY KEY(app_id, key_name),
+        FOREIGN KEY(app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE
     )
 CREATE_TABLE_END()