Author Topic: Update PDATA1 value not working  (Read 4031 times)

sravang

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Update PDATA1 value not working
« 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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11249
  • Karma: +414/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update PDATA1 value not working
« Reply #1 on: July 14, 2021, 07:23:46 pm »
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.

Code: [Select]
var sqlUpdatePdata1 = $"update t_object set PDATA1 = '{embeddedElement.ElementGUID }' where Object_ID = {property.ElementID}";
Geert

sravang

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: Update PDATA1 value not working
« Reply #2 on: July 14, 2021, 07:44:01 pm »
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

qwerty

  • EA Guru
  • *****
  • Posts: 12334
  • Karma: +347/-287
  • I'm no guru at all
    • View Profile
Re: Update PDATA1 value not working
« Reply #3 on: July 14, 2021, 08:39:24 pm »
Have you cross check (printed) property.elementid?

q.

sravang

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: Update PDATA1 value not working
« Reply #4 on: July 14, 2021, 08:48:19 pm »
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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11249
  • Karma: +414/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update PDATA1 value not working
« Reply #5 on: July 14, 2021, 09:03:07 pm »
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
Code: [Select]
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

sravang

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: Update PDATA1 value not working
« Reply #6 on: July 14, 2021, 09:14:28 pm »
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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11249
  • Karma: +414/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update PDATA1 value not working
« Reply #7 on: July 14, 2021, 09:19:13 pm »
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

sravang

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: Update PDATA1 value not working
« Reply #8 on: July 14, 2021, 09:40:45 pm »
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..