Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: sravang on July 14, 2021, 07:12:48 pm
-
Hello,
I am trying to update PDATA1 value of an element but I am not able to do that. I have gone through forum and found that we can update it through SQL Query and I did the same but was not able to update the value. Can you please let me know why exactly my query didn't work.
QUERY-
update t_object set PDATA1 = '{665E067B-2978-4331-88A7-735269CC00E6}' where Object_ID = 508
code - C#
string sqlUpdatePdata1 = "update t_object set PDATA1 = '" + embeddedElement.ElementGUID + "'"
+ " where Object_ID = " + property.ElementID;
logger.DebugFormat("Update Query - {0}", sqlUpdatePdata1);
repository.Execute(sqlUpdatePdata1);
Thanks,
Sravan
-
What makes you conclude that it didn't work? Have you checked the database?
The query and the code seems fine, although would use the $ syntax in C# to create the string. Makes it easier to spot syntax error in your SQL code.
var sqlUpdatePdata1 = $"update t_object set PDATA1 = '{embeddedElement.ElementGUID }' where Object_ID = {property.ElementID}";
Geert
-
I have checked in database to verify if it worked, but I was not able to find anything in PDATA1 column. It was empty.
Also tried the same way you mentioned but it also didn't work
Thanks,
Sravan
-
Have you cross check (printed) property.elementid?
q.
-
Yes,this is the query - "update t_object set PDATA1 = '{FDA55682-C924-49a7-A40D-C38C674956E0}' where Object_ID = 522"
and I verified using this query in sparx - "select * from t_object where Object_ID = 522"
I didn't see any value in PDATA1
-
and I verified using this query in sparx - "select * from t_object where Object_ID = 522"
Don't check it in Sparx. Use a proper independent SQL query tool. Sparx sometimes does weird stuff with the results. Often you can avoid that by using an alias for a column name like
select o.pdata1 as myValue from t_object o where o.object_ID = 522
Another thought: is this a new element that you haven't saved yet (update())? In that case it would be logical that the update didn't work, as the record with ID 522 would not be present yet in the database.
Geert
-
Yes this is the new element which was created just before updating PDATA1 value, but I ddid property.Update() before and after executing SQL query.
-
Yes this is the new element which was created just before updating PDATA1 value, but I ddid property.Update() before and after executing SQL query.
the "after" will effectively erase the changes you made in the database.
The object in memory doesn't know you changed the database behind it's back.
When you Update() it will save whatever is in MiscData(0) to the PDATA1 column.
If you need to continue working with your EA.Element object, you will need to do a new Repository.GetElementByID() to make sure you get a object that reflects the status in the database.
Geert
-
That worked!.
I have removed update after sqlquery execute and did repo.getelemetbyID again before using that element anywhere again and it worked.
Thank you so much Geert..