I am trying to find a way to run an update query with orientdb where I update multiple properties. I will have two properties on an edge, one called acknowledged_at and one called read_at. The acknowledged_at field can get updated prior to the read_at getting updated. However I want to make sure that when I update all of the read_at fields, that I also ensure that any acknowledged_at fields get updated with the current timestamp as well (if they weren't previously set).
My use case for this is having facebook like notifications. A user can acknowledge a notification but not read it at that time. But if they click a read_all button, or decide to "read" just that notification later, then I want to make sure I am also updating the acknowledged_at property (if it is null).
Is there any way to do a case statement type update on the acknowledged_at field to only update if null?
UPDATE: Just to make it more clear, I always want to update the read_at field but only want to update the acknowledged_at field if it is null. If it was previously acknowledged I want that value to remain.
UPDATE EDGE received SET read_at = '#{DateTime.now}', acknowledged_at = '#{DateTime.now}' WHERE out.employeeId = '#{employeeId}'
UPDATE EDGE received SET ... WHERE acknowledged_at IS NULL
UDPATE
this works for me
update edge received set read_at = "2017-06-23 19:29:00",acknowledged_at=ifnull(acknowledged_at, "2017-06-23 19:29:00") WHERE out.employeeId = 'A002'
ref. https://orientdb.com/docs/2.2/SQL-Functions.html
Try this (or variation)
UPDATE... SET read_at = IF(read_at > 0, read_at, '#{DateTime.now}')
Related
Trying to sync up a postgres record to airtable on create/update. The field has a couple of ids that I would like to check for in airtable to determine whether I should create a new record or update an existing one. The first id (optional_id) I need to search on can possibly be null. This causes the search to fail before it can get to the other id(required_id) that should always be populated. Is there any way I can skip the initial search for optional_id if it turns out to be null in postgres?
My current outline is as follows:
I would use a Formatter > Text > Default Value step in case the input value can be null and then make sure the fallback value is from a record that does not exist.
If further help is needed, feel free to reach out to us here:
https://zapier.com/app/get-help
so I am having this mass import of data to my DB and conditional whether a record exists or not I am inserting or updating (upsert)...
now, what I need is when it is inserting (new record) to populate the "created" property's value and 'modified' value with the current datetime... but only modified one when it is getting updated...
so if I would use operational hook of before save.... how do I know it is for an inserting record or for an updating record?
any ideas?
I solved it in different manner (would still be good to know the original answer)
in my case I upserted them all normaly with updated to current date, after, I find all with created:null and update just those with the created value.
The application I'm working on is a character based application. there is a field adfc.unme-code in a table and another field arbu.unit-code-shu. These two fields are shown in different windows but they must be in sync. When I update unme-code, unit-code-shu must be updated too.
Is a simple assign statement would be enough or should I do something else? Also, should I use the actual fields or a buffer?
You can use the ASSIGN statement in your code to assign both values at the same time. If there's a possibility of some other process changing those fields, you can create a database trigger procedures on each field to copy the value over to the other field. In the Data Dictionary, view the field properties and click on the "Triggers..." button to do that.
Yes, ASSIGN is used to set the value of a buffers/records field. However: certain critera needs to be met:
The buffer/record needs to be available.
You must have the "lock" of the buffer/record.
If you have the record available and locked you can simply do:
ASSIGN arbu.unit-code-shu = adfc.unme-code.
To make this code "safer" you can simply make sure that arbu is available and not locked by any other user. And finally it will handle if your assign fails because you have no lock at all.
IF AVAILABLE arbu AND NOT LOCKED arbu THEN DO:
ASSIGN arbu.unit-code-shu = adfc.unme-code NO-ERROR.
IF ERROR-STATUS:GET-NUMBER(1) = 396 THEN DO:
MESSAGE "Apparently the record is locked." VIEW-AS ALERT-BOX ERROR.
END.
END.
If you do not have the record (or the right locking) you need to look into your application and see how you can add this feature. What identifies the right record of the second table? A single id? Something else? Are there always a 1 to 1 relation between arbu and adfc etc?
Perhaps your application has a simple way of setting the value of a field. If there is a architecture at place you should try to stick to it...
When I try to update a database with some modified values in a dataset, a concurrence exception doesn't raise if i change manually some values in the database after the fill method on the dataset is performed. (I only get the exception if I delete a row manually and then I try call the method update of data adapter).
How should I check if I have a "dirty read" on my dataset?.
You have several options.
Keeping a copy of the original entity set to compare against and make
the is dirty determination at the point you need to know whether it's
dirty.
Checking the datarow's rowstate property and if Modified compare
the values in the Current and Original DataRowVersions. If the second
change makes the value the same as the original then you could call
RejectChanges, however that would reject all changes on the row. You
will have to manually track each field since the dataset only keeps
per-row or per-table changes.
I have inside of a form one hidden field, which must be empty when the form is submitted.
Is any value in it, i want to set a flag in the database column.
How can i realize the check if the value of this hidden field is not filled?
Is it an issue for controllers or for models?
It is an issue for the controller. You want to check the value of that field in the create and update actions and store what ever you want to store there.