05-31-2021 05:20 AM - edited 05-31-2021 06:33 AM
I want to do an INSERT INTO on a CUCM table.
There are two SQL requests:
- ExecuteSQLQueryReq
- ExecuteSQLUpdateReq
I need the PKID of that insert.
How to do that? Which of the two Req to use?
05-31-2021 06:23 AM
It looks like an INSERT INTO has to be done with ExecuteSQLUpdateReq.
I found this example:
https://community.cisco.com/t5/management/get-pkid-of-inserted-row/td-p/3429510
Which shows an example to use "newId()" function.
But what kind of function is "newId()"?
But when I try so with AXL, adding "newId()" to my INSERT INTO statment:
String sqlStmtUpdateTemplate =
"""
INSERT INTO telecastersubscribedservice (
pkid,
fkdevice,
serviceurl,
servicename,
fktelecasterservice
)
VALUES (newId(), '%s', '%s', '%s', '%s')
""";
Replacing the %s with String values, and executing it with ExecuteSQLUpdateReq, results in:
com.cisco.axlapiservice.AXLError: Failure
AXLError-Code: -1
06-01-2021 06:35 AM
Try newid() instead of newId().
06-02-2021 07:05 AM - edited 06-02-2021 07:14 AM
newid() would be the correct method.
But, it doesn't give back the PKID.
In fact I can remove the newid() entirely in the INSERT INTO statement, as according to the Data Dictionary the default value for the PKID will be generated with newid().
INSERT INTO telecastersubscribedservice ( pkid, fkdevice, serviceurl, servicename, fktelecasterservice, secureserviceurl ) VALUES ( newid(), '...fkdevice lower-case without { and }...', 'http://...?param1=...', 'MyTestService', '...fktelecasterservice lower-case without { and }...', 'https://...?param1=..' )
I can insert that into telecastersubscribedservice.
ExecuteSQLUpdateRes executeSQLUpdateRes = null; try { executeSQLUpdateRes = axlService.getAxlPort().executeSQLUpdate(executeSQLUpdateReq); } catch (AXLError axlError) { ... } return executeSQLUpdateRes.getReturn().getRowsUpdated();
The response ExecuteSQLUpdateRes of the ExecuteSQLUpdateReq returns the rows updated, which in case of one INSERT INTO result in 1.
I don't get the PKID ot the insert back.
06-02-2021 09:34 AM - edited 06-02-2021 09:34 AM
I'm not sure why you would expect to get the PKID back from the insert. It's a SQL operation, and that operation doesn't return a PKID value.
If you want to get the PKID, then you should create a SQLQuery to get it. Perhaps something like Select pkid from telecastersubscribedservice where servicename = "MyTestService".
06-02-2021 10:54 PM
In theory your right, after the INSERT INTO simply query the tuple.
But as far as I can see, the primary key is PKID.
That means, that there could be possibly many tuples where only the PKID differs.
After the INSERT INTO I could get back more then the just inserted tuple.
06-03-2021 07:52 AM
You're dealing with the limitations of using SQL. That's just the way SQL works.
Perhaps you should, instead, use AXL API updatePhone, which includes this section in the XML:
<services>
<!--Zero or more repetitions:-->
<service>
<telecasterServiceName uuid="?">?</telecasterServiceName>
<name>?</name>
<!--Optional:-->
<url>?</url>
<!--Optional:-->
<urlButtonIndex>0</urlButtonIndex>
<!--Optional:-->
<urlLabel>?</urlLabel>
<!--Optional:-->
<serviceNameAscii>?</serviceNameAscii>
</service>
</services>
Then you can use getPhone for that particular phone. If you tell getPhone to return <services>, you'll see the UUID of the telecaster service, which is the same as the PKID.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide