Oracle: How to extract XML data from attributes in table - xml-parsing

I have a table whit XmlType attributes as follow
<data>
<subdata name='FIRST'>AAA</subdata>
<subdata name='SECOND'>BBB</subdata>
<subdata name='THIRD'>CCC</subdata>
...
</data>
I want to extract the XML to obtain the following result:
----------------------------
| FIRST | SECOND | THIRD
|---------|---------|-------
| AAA | BBB | CCC
----------------------------
Any idea?
I want to add that I know the structure of the result table but every element is optionally in the xml.
<data>
<subdata name='FIRST'>AAA</subdata>
<subdata name='SECOND'>BBB</subdata>
<subdata name='THIRD'>CCC</subdata>
...
</data>
<data>
<subdata name='SECOND'>EEE</subdata>
<subdata name='THIRD'>DDD</subdata>
...
</data>
| FIRST | SECOND | THIRD
|---------|---------|-------
| AAA | BBB | CCC
| | EEE | DDD
----------------------------

you can try to do it like this:
SELECT
ExtractValue(Value(p),'/data/subdata[#name="FIRST"]/text()') as name1
, ExtractValue(Value(p),'/data/subdata[#name="SECOND"]/text()') as name2
, ExtractValue(Value(p),'/data/subdata[#name="THIRD"]/text()') as name3
FROM TABLE(XMLSequence(Extract(xmltype('<doc><data><subdata name="FIRST">AAA</subdata><subdata name="SECOND">BBB</subdata><subdata name="THIRD">CCC</subdata></data><data><subdata name="SECOND">EEE</subdata><subdata name="THIRD">DDD</subdata></data></doc>')
,'/doc/data'))) p

Related

Can you use parameter/variables/placeholders for values for future use in a Specflow scenario?

In previous job I have used DBFit and used parameters (variables/placeholders) for values
example:
|Key? |
|>>Key|
!|Query|SELECT Status FROM Confirm WHERE Name='xyz' |
| Status | Key |
| Confirmed | <<Key |
I am now using SpecFlow and wondered if it has similar functionality
example: ( I have used << and >> here just for explanation )
Given I get Initial for
And the 1st response should contain
| Name | string | "xyz" |
| Key | string | >>{Key} |
When I get Confirm for
Then the 1st response should contain
| Name | string | "xyz" |
| Key | string | <<{Key} |
I think you are looking for Scenario Outlines.
With them, you can specify a table with your parameters. So in your case, it is looking something like this:
Scenario Outline: Title for your Scenario Outline
Given I get Initial for And the 1st response should contain
| field | type | assertion |
| Name | string | "xyz" |
| Key | string | <Key> |
When I get Confirm for
Then the 1st response should contain
| field | type | assertion |
| Name | string | "xyz" |
| Key | string | <Key> |
Examples:
| Key |
| example1 |
| example2 |
| example3 |
Be aware that you have here two different types of tables. The table at your steps is an argument for the step.
The Examples table at the end are the concrete examples. So the Scenario is executed once per each entry in this table.
You can use the parameters from the example table with a simple <COLUMN_NAME> placeholder.
Docs: https://docs.specflow.org/projects/specflow/en/latest/Gherkin/Gherkin-Reference.html#scenario-outline

How to prevent rows from shifting when syncing with main data source?

I am creating a directory of people in a group. In the first sheet are the names, address, phone, and email info. The basics.
Then in Sheet 2 I am keeping a record of attendance.
In the third sheet I am keeping a record of some goals that are accomplished.
I used =ARRAYFORMULA(BASE!A:A) to get the first column and put that in the second and third sheets.
This worked great for a while. Then we got a new member. I added their info to the base sheet. His name was brought over to the second and third sheet. That's good. But it didn't keep the rows connected on the second and third sheet. They were off by one row since adding the new member shifted the cells that he was added on.
SO...
Base Sheet
|--------------|------------|------------|------------------|
|First Name | Last Name | Address | and so on...... |
|--------------|------------|------------|------------------|
|John | Doe | 123 Main | |
|--------------|------------|------------|------------------|
|Jim | Smith | 123 Elm | |
|--------------|------------|------------|------------------|
|Jill | Summers | 123 Aspen | |
|--------------|------------|------------|------------------|
Then I have another sheet for tracking attendance taking the first name and last name from the base sheet.
The top row and first two columns are frozen on both sheets.
|--------------|------------|------------|---------|---------------|
| First Name | Last Name | 10/1/19 | 10/7/19 | and so on.....|
|--------------|------------|------------|---------|---------------|
| John | Doe | x | x | |
|--------------|------------|------------|---------|---------------|
| Jim | Smith | | x | |
|--------------|------------|------------|---------|---------------|
| Jill | Summers | x | | |
|--------------|------------|------------|---------|---------------|
What I would like to do is be able to add a new row for a new name and it create a new row in the secondary sheets as well. For example...
|--------------|------------|------------|------------------|
|First Name | Last Name | Address | and so on...... |
|--------------|------------|------------|------------------|
|John | Doe | 123 Main | |
|--------------|------------|------------|------------------|
|Julie | Fry | 123 Oak | |
|--------------|------------|------------|------------------|
|Jim | Smith | 123 Elm | |
|--------------|------------|------------|------------------|
|Jill | Summers | 123 Aspen | |
|--------------|------------|------------|------------------|
which would result in ...
|--------------|------------|------------|---------|---------------|
| First Name | Last Name | 10/1/19 | 10/7/19 | and so on.....|
|--------------|------------|------------|---------|---------------|
| John | Doe | x | x | |
|--------------|------------|------------|---------|---------------|
| Julie | Fry | | | |
|--------------|------------|------------|---------|---------------|
| Jim | Smith | | x | |
|--------------|------------|------------|---------|---------------|
| Jill | Summers | x | | |
|--------------|------------|------------|---------|---------------|
Is there a way to fix this situation? Or perhaps just a better way to do this?
I know I could add the name to the bottom of the list and that would "kinda" work, but then I wouldn't be able to sort by first of last name. The sort would work on the base page, but it would also sort the name on the attendance page, but the data in the rows would be unaffected.
you can try to lock it down with INDIRECT like:
=ARRAYFORMULA(INDIRECT("BASE!B:B"))

Gherkin Scenario Outline using the same table multiple times

I'm writing a Scenario Outline in Specflow for Visual Studio. The objective is to test a Person Name comparer feature, in order to choose the best name between the two.
In my case, I have properties that belong to the names and properties external to them, which belong to the Person entity.
The comparison flow is mad in two parts: first I check the properties of the persons (owners of the names) to decide and if that doesn't yield me a result (meaning their properties are the same) then I check the names' properties.
I've written separate tests for the names' properties comparison, so in this test I only care about the Person properties and the relation between the names - which can be: Name1 < Name2, Name1 > Name2 or Name1 ≡ Name2.
By now I have written a scenario outline for each of those three cases, since I need to run each of the parameters in my Examples table once for each of those cases.
The code looks something like this:
Scenario Outline: Comparing names
Given I have a first name <name1>
And the first person has properties <properties1>
And I have a second name <name2>
And the second person has properties <properties2>
When I choose the best name
Then the best name should be <best name>
Examples:
| properties1 | properties2 |
| FirstName:"Carlos" | FirstName:"Johny" |
| LastName:"Smith" | FirstName:"Johny" |
| FirstName:"John",LastName:"Smith" | LastName:"Smith" |
Now in place of the names, I wrote this 3 times, one time for each case of the relation between the names, where I have the names hard-coded on the scenario.
Ideally, I would like to have a table of tables to be able to have a primary parameter that is ran with every line of the table.
Any idea how to implement that without having three different Scenario Outlines?
A SpecFlow table for creating each person might be the ideal solution. This allows you to pass values for each name, or a null value:
Scenario Outline: Comparing names
Given I have a first name <name1>
And the first person has properties:
| Field | Value |
| First Name | <first name 1> |
| Last Name | <last name 1> |
And I have a second name <name2>
And the second person has properties:
| Field | Value |
| First Name | <first name 2> |
| Last Name | <last name 2> |
When I choose the best name
Then the best name should be <best name>
Examples:
| name1 | first name 1 | last name 1 | first name 2 | last name 2| best name |
| X | Carlos | | Johnny | | X |
| X | | Smith | Johnny | | X |
| X | John | Smith | | Smith | X |
The advantage of this approach is you can expand the properties you set on each person.

Extract UUID from a mixed string in mariadb

I have a mariadb table as follows:
This is an example of how a row looks like
| 4 | test/1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd/kuva.jpeg | {"Records":
The content in Records have been omitted to keep it short and simple. When I issue SQL select like this select key_name from minio_images where id=4;, it returns me a normal output like this
+-----------------------------------------------------+
| key_name |
+-----------------------------------------------------+
| test/1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd/kuva.jpeg |
+-----------------------------------------------------+
1 row in set (0.09 sec)
My question is how can I use select so that it just returns me the UUID in key_name instead of the whole string. For example, 1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd and not test/1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd/kuva.jpeg? I'd really appreciate any sort of help with this.
Luckily, I found a similar post # extract substring from mysql column using regex and I tried a solution suggested there, by issuing a SELECT statement which I guess, returns the value from a column based on the regular expression. In my case, the regular expression to extract UUID is '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}' and the statement was like
SELECT REGEXP_SUBSTR(key_name, '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')
FROM minio_images;
Which gave me an output, just like I needed
+--------------------------------------------------------------------------------------------------------+
| REGEXP_SUBSTR(key_name, '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}') |
+--------------------------------------------------------------------------------------------------------+
| 1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd |
| 1edd460e-b19a-4b16-a460-d433eac60833 |
| 281a890f-0b8b-4693-9227-fc8c57d6045e |
| 37a14ddb-eeda-41f2-a2b6-ec0bad34aaed |
| 37d4f3d2-2282-4b9f-8e1e-f8a26570c5b4 |
| 387da0c1-1caf-4394-a023-92e7eec19b66 |
| 49a29478-4799-4a8b-8757-42060020fc99 |
| 9214e1f0-77e3-435a-a329-d1829a973903 |
| ae67c69a-a2cf-4c21-88ca-bd17e254bc4c |
| b6491e64-34a6-4aa3-a54e-200b1cd946fe |
| c0f6864b-2ab8-41fa-a1c2-6b974a1895c1 |
| cfd61927-557e-47d2-aeb9-229ec1aba5b4 |
| df566110-c2a0-4d9c-8389-fcbaf6c8bb30 |
+------------------------------------------------------------------------------------- -------------------+
16 rows in set (0.03 sec)

Can I have a cucumber example with several values in a single column x row position

Hi here is what I what I have:
Scenario Outline: Seatching for stuff
Given that the following simple things exists:
| id | title | description | temp |
| 1 | First title | First description | low |
| 2 | Second title | Second description with öl | Medium |
| 3 | Third title | Third description | High |
| 11 | A title with number 2 | can searching numbers find this 2 | Exreme |
When I search for <criteria>
Then I should get <result>
And I should not get <excluded>
Examples
|criteria|results | excluded |
| 1 | 1 | 2,3,11 |
| 11 | 11 | 1,2,3 |
| title | 1,2,3 | 11 |
| öl | 2 | 1,3,11 |
| Fir* | 1 | 2,3,11 |
| third | 3 | 1,2,11 |
| High | 3 | 1,2,11 |
As you can see I'm trying to test a search field for a web-application using cucumber and the scenario outline structure in order to test several search criteria.
I'm not sure how to handle the input I would get as result and excluded in my steps.
Maybe this doesn't work at all?
Is there a workaround?
There's nothing wrong with what you're doing. Cucumber will just take that as a single string. The fact that it's actually comma-separated values means nothing to Cucumber.
Your step definition would still look like this:
Then /^I should not get ([^"]*)$/ do |excluded|
# excluded will be a string, "2,3,11"
values = excluded.split(",")
# Do whatever you want with the values
end

Resources