Update OrientDB EmbeddedMap Value via SQL - orientdb

Two related issues:
1) I can set (i.e. completely replace the content of an EmbeddedMap field) with this statement:
update #14:1 set Options = {"555":{"Action":"Test555","Enabled":false},"444":{"Action":"Test444","Enabled":false}}
But I can add or update a value, for example:
update #14:1 add Options = {"222":{"Action":"Test222","Enabled":false},"333":{"Action":"Test333","Enabled":false}}
2) I can't seem to figure out a syntax for setting the EmbeddedMap field along with the other fields in the record while creating it.
I've searched high and low for examples of these, and experimented with every variant I could think of, but haven't had any luck on either front. Any advise would be greatly appreciated.

You can use
update #14:1 put Options = '222', {"Action":"Test222","Enabled":false}
EDIT
I used 2.2.0GA
I used these commands:
create class MyClass extends V
insert into MyClass(name) values("test")
update #21:0 set Options = {"555":{"Action":"Test555","Enabled":false},"444":{"Action":"Test444","Enabled":false}}
update #21:0 put Options = '222', {"Action":"Test222","Enabled":false}
select from MyClass
EDIT 2
create property MyClass4.Options EmbeddedMap V
insert into MyClass4(name) values("test4")
update #34:0 set Options = {"555":{"#type":"d", "#class":"V","Action":"Test555","Enabled":false},"444":{"#type":"d", "#class":"V","Action":"Test444","Enabled":false}}
update #34:0 put Options = '222', {"#type":"d", "#class":"v","Action":"Test222","Enabled":false}
Hope it helps.

Related

SAPUI5 Variant key on Save strange behaviour

I am trying to implement a Variant management in SAPUI5 using Personalization service of sap.ushell.Container. I have written functions to Save, Manage(delete, rename) and select Variants from the drop down. However i see strange behavior when i select a variant in the method mentioned below.
onSelectVariant: function (oEvent) {
var sSelectedVariantKey = oEvent.getParameter('key');
Assume i have existing variants 'A1', 'A2' and 'A3'.
When i SaveAs a new variant with new values (lets call it 'X1'), the new variant is created. Then i select another already existing variant from dropdown( A1 or A2 or A3), i see the corresponding values. Now i again select the newly created variant X1 but i don't see the new values.
When i debug the above mentioned method, i see that for all the existing variants, the oEvent.getParameter('key') returns the variant indexs like 0,1,2,3 etc. but for the newly created variant X1, it returns the value 'sv1579082806311' and hence it doens't find it in variantset
oPersonalizationVariantSet.getVariant(sVariantKey)
and then it doesn't show the new values.
If i run the program again, i see that previously created variant X1 now shows correct values as the method oEvent.getParameter('key') returns the index and not 'sv....'. but if i now create a new variant X2, the same issue happens with X2.
I am running the App on cloud WebIDE and not on the FIORI launchpad.
Can someone help me what may be going wrong while saving the variant ?
Thanks
Br
Nilesh Puranik
I had the exact same issue recently. I assume that this is a bug in the VariantManagement control. You could create an Issue in the openui5 github project.
I also had this problem and came to the conclusion its a bug in VM control. It gives a new and long key to a newly saved variant. In the oEvent parameter "key" of your onSelect function you will see this new key.
I soved the issue by adding a new property to my JSON object I bound for variants.
In Variant Save event:
tableModel.oData.tabVariants.push({key: VariantParam.key,
text: VariantParam.name,
newKey:this.oVariant.getVariantKey()})
Then in variant select event:
var selectedKey = oEvent.getParameter("key");
var variant = this.woTableSet.getVariant(selectedKey);
if(!variant){
//In this case its a newly created variant with an internal key
//This is a workaround for the key confusion in variants
selectedKey = tableModel.oData.tabVariants.find(t => t.key ===
selectedKey).newKey;
variant = this.woTableSet.getVariant(selectedKey)
if(!variant){return} //then I give up
}
You need replace the auto generated key by variant key:
const autoGeneratedKey = oEvent.getParameters().key;
this.oContainer.save().done(function (cb) {
const oVM = that.getView().byId("vm");
oVM.replaceKey(autoGeneratedKey, that.oVariant.getVariantKey());
oVM.setInitialSelectionKey(that.oVariant.getVariantKey());
});

embeddedmap of strings not working after 2.2

I had been developing some base queries for about 6 months prior to the release of 2.2
CREATE CLASS Flag_Definitions EXTENDS V
CREATE PROPERTY Flag_Definitions.V_status EMBEDDEDMAP STRING
CREATE PROPERTY Flag_Definitions.V_branding EMBEDDEDMAP STRING
CREATE PROPERTY Flag_Definitions.Block_type EMBEDDEDMAP STRING
CREATE VERTEX Flag_Definitions SET title = "developer reference for all data flags", V_status = {"ACTIVE":"Normal active record", "SUSPENDED":"Currently inactive record","DELETED":"Discontinued record maintained for archiving"}, Block_type = {"Prop":"Holds text from a data object property","HTML":"Holds basic HTML for content","Container":"Holds other blocks"}
but now I'm getting this error in studio
{"errors":[{"code":400,"reason":400,"content":"Map found but entries are not defined as :\r\n\tDB name=\"TestDB\""}]}
From console, the phrasing is slightly different
Map found but entries are not defined as <key>:<value>
Either way, the format 'SET mapfield = {"key":"val"}' no longer seems to be working, and I can't find an explanation. I even looked into the orient code on github (line 118), but, having 2 parts, the format should be passing the check on line 117.
Solved this one, it has nothing to do with the Flag_Definitions object, but I had a default status flag being applied to all created vertices
CREATE PROPERTY V.flags EMBEDDEDMAP STRING
ALTER PROPERTY V.flags DEFAULT {"status":"ACTIVE"}
The issue is the DEFAULT, which needs to be
DEFAULT '{"status":"ACTIVE"}'
Similarly, I had to change
DEFAULT sysdate() to DEFAULT "sysdate()"

Toggle boolean value inside a non updatable view in PostgreSQL (using a rule)

I have created a view in PostgreSQL (9.4), which pulls information from several tables, so as far as I understand, is not updatable unless I use triggers or rules.
For instance, this is the view definition (the tables and everything are located inside a scheme called pra1:
CREATE VIEW pra1.vacunaciones AS
SELECT pra1.responsable.poliza,
pra1.recibe.niño,
pra1.niño.nombre,
pra1.vacunas.nombre_vacuna,
pra1.recibe.fecha,
pra1.recibe.fiebre
FROM pra1.responsable, pra1.recibe, pra1.niño, pra1.vacunas
WHERE pra1.recibe.vacuna = pra1.vacunas.id
AND pra1.niño.id = pra1.recibe.niño
AND pra1.responsable.dni = pra1.niño.responsable;
So if I do
SELECT * FROM pra1.vacunaciones
Everything works fine and I get the information I want to get.
My question: The field coming from pra1.recibe.fiebre is a boolean value. I would like to set a rule, so whenever I do an UPDATEstatement specifying the pra1.recibe.niño value (which is a bigint), then the pra1.recibe.fiebre field corresponding to pra1.recibe.niño toggles from true to false or viceversa.
I got as far as this:
RULE DEFINITION:
CREATE or REPLACE RULE vac_boolean AS
ON UPDATE TO pra1.vacunaciones
DO INSTEAD
UPDATE pra1.recibe SET fiebre (no idea how to follow)
WHERE pra1.recibe.niño =
//I don't know how to specify that it needs to act
on the pra1.recibe.niño value that I pass to the UPDATE.
So after the rule is created I would like to do a short UPDATE statement specifying WHERE pra1.recibe.niño = XXX, and the rule should act on the view and update the pra1.recibe.fiebre toggling its boolean value.
Is this idea easy to accomplish? I am a newcomer to PostgreSQL, and so far I am pleased with it, but there are still many confusing areas I need to understand well.
Maybe someone comes with a better suggestion, but I just realized what I needed:
The rule:
CREATE or REPLACE RULE vacunaciones_fiebre AS
ON UPDATE TO pra1.vacunaciones
DO INSTEAD
UPDATE pra1.recibe SET fiebre = NOT fiebre WHERE niño = NEW.niño;
The update (for instance, to update the status of niño = 4:
UPDATE pra1.vacunaciones SET fiebre = NOT fiebre WHERE niño='4';
Like I said, maybe there is a better way, but this does it.

Passing arguments to Access Forms created with 'New'

I have a form called 'detail' which shows a detailed view of a selected record. The record is selected from a different form called 'search'. Because I want to be able to open multiple instances of 'detail', each showing details of a different record, I used the following code:
Public detailCollection As New Collection
Function openDetail(patID As Integer, pName As String)
'Purpose: Open an independent instance of form
Dim frm As Form
Debug.Print "ID: " & patID
'Open a new instance, show it, and set a caption.
Set frm = New Form_detail
frm.Visible = True
frm.Caption = pName
detailCollection.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
End Function
PatID is the Primary Key of the record I wish to show in this new instance of 'detail.' The debug print line prints out the correct PatID, so i have it available. How do I pass it to this new instance of the form?
I tried to set the OpenArgs of the new form, but I get an error stating that OpenArgs is read only. After researching, OpenArgs can only be set by DoCmd (which won't work, because then I don't get independent instances of the form). I can find no documentation on the allowable parameters when creating a Form object. Apparently, Microsoft doesn't consider a Constructor to be a Method, at least according to the docs. How should I handle this? (plz don't tell me to set it to an invisible text box or something) Thanks guys, you guys are the best on the net at answering these questions for me. I love you all!
Source Code for the multi-instance form taken from: http://allenbrowne.com/ser-35.html
Inside your Form_detail, create a custom property.
Private mItemId As Long
Property Let ItemID(value as Long)
mItemId = value
' some code to re query Me
End Property
Property Get ItemId() As Long
ItemId = mItemId
End Property
Then, in the code that creates the form, you can do this.
Set frm = New Form_detail
frm.ItemId = patId
frm.Visible = True
frm.Caption = pName
This will allow you to pass an ID to the new form instance, and ensure it gets requeried before making it visible. No need to load all of the results every time if you're always opening the form by Newing it. You let the property load the data instead of the traditional Form_Load event.
This works because Access Form modules are nothing more than glorified classes. Hope this helps.
You could try applying a filter:
frm.Filter = "[ID] = " & patID
frm.FilterOn = True
The Record Source of the Detail form will need to be set to the table to which the ID belongs.
UPDATE
As you requested, here is the code to set the RecordSource:
frm.RecordSource = "select * from TableName where [ID] = " & patID
This is probably cleaner than using a filter given that a user can remove the filter (depending on the type of form).

Specifying a DB table dynamically? Is it possible?

I am writing a BSP and based on user-input I need to select data from different DB tables. These tables are in different packages. Is it possible to specify the table I want to use, based on its path, like this:
data: path1 type string value 'package1/DbTableName',
path2 type string value 'package2/OtherDbTableName',
table_to_use type string.
if some condition
table_to_use = path1.
elseif some condition
table_to_use = path2.
endif.
select *
from table_to_use
...
endselect
I am new to ABAP & Open SQL and am aware this could be an easy/silly question :) Any help at all would be very much appreciated!
You can define the name of the table to use in a variable, and then use the variable in the FROM close of your request :
data tableName type tabname.
if <some condition>.
tableName='PA0001'.
else.
tableName='PA0002'.
endif.
select * from (tableName) where ...
there are a few limitation to this method, as the stable can not contains fields of type RAWSTRING, STRING or SSTRING.
as for the fact that the table are in different package, i don't think it matters.
Regards,