JdbcSQLException: Referential integrity constraint violation [on delete] - sql

I am setting up unit tests on my application, and that for I need to mockup the database so I am not altering the actual one.
So, I am using DBUnit to simulate a database based on a XML File :
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<ACTION_TYPE ID="1" NAME="INVALID_CPT"/>
<ACTION_TYPE ID="2" NAME="INTEGRATED_FLOW"/>
<ACTION_TYPE ID="3" NAME="CLOSING_TECHNICAL_FLOW"/>
<ACTION_TYPE ID="4" NAME="AUDIT_FLOW"/>
<ACTION_TYPE ID="5" NAME="VALIDATION_FLOW"/>
<ACTION_TYPE ID="6" NAME="RETURN_DRAFT_FLOW"/>
<USER_GROUP ID="1" NAME="AKA_CPT"/>
<USER_GROUP ID="2" NAME="AKA_ADMIN_SECU"/>
<USER_GROUP ID="3" NAME="AKA_CISO"/>
<USER_GROUP ID="4" NAME="AKA_ADMIN_NETWORK"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="1" USER_GROUP_ID="1"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="4" USER_GROUP_ID="1"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="6" USER_GROUP_ID="1"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="2" USER_GROUP_ID="2"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="3" USER_GROUP_ID="2"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="5" USER_GROUP_ID="2"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="5" USER_GROUP_ID="3"/>
<ACTION_USER_GROUP ACTION_TYPE_ID="2" USER_GROUP_ID="4"/>
</dataset>
This is just a part of the whole XML file, but this is where my problem come from.
I have these 2 objects ACTION_TYPE and USER_GROUP which are linked by a Many to Many relationship.
But as soon as I run my test code, I am getting this error:
org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FKFA9ACTE184RNO1RS40IW6E1LK: PUBLIC.ACTION FOREIGN KEY(USER_GROUP_ID) REFERENCES PUBLIC.USER_GROUP(ID) (2)"; SQL statement:
delete from USER_GROUP [23503-193]
I know what an integrity constraint violation is, but despite I do not think I made one in the XML file above.
Does someone know where this error is coming from, and maybe how I could fix it?
Thank you in advance

Related

XML Import txt file to to SQL. Duplicate id error message?

My administrative program uses an xml-file to import pricelists (txt files) to the SQL database.
There is a lot of rows in the XML file but this is the rows I have problems with.
<?xml version="1.0"?>
<BCPFORMAT>
<RECORD>
<FIELD ID="41" xsi:type="CharFixed" LENGTH="5" COLLATION=""/>
</RECORD>
<ROW>
<COLUMN SOURCE="41" NAME="VGRNR1" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="41" NAME="VGRNR2" xsi:type="SQLVARYCHAR"/>
</ROW>
</BCPFORMAT>
I have changed the eighth row to COLUMN SOURCE="41" because I want the data from FIELD ID="41" in both fields VGRNR1 and VGRNR2 in the SQL database.
When I make the change I get this error message from my administrative program:
duplicate element id "41"
Is it possible to edit the xml-file so I can get data from FIELD ID="41" in both fields VGRNR1 and VGRNR2 in the database?

How to get PreConditions working from Java applied changelogs?

I am trying to use PreConditions to skip CreateTable changesets and MARK_RAN if the table exists. The PreConditions seem to be ignored as Liquibase logs a table exists error as it tries to create an existing table in MYSQL (in AWS Aurora).
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd">
<changeSet author="xxx" id="1231">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="tenant"/>
</not>
</preConditions>
<createTable tableName="tenant">
<column autoIncrement="true" name="tenantId" type="int(11)">
<constraints primaryKey="true" nullable="false"
unique="false" />
</column>
...
The changelogs are being applied using the following Java code:
final Database dataBase = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(new JdbcConnection(connection));
final Liquibase liquiBase = new liquibase.Liquibase(CHANGE_LOG_FILE, RESOURCE_ACCESSOR, dataBase);
liquiBase.update(CONTEXTS, LABEL_EXPRESSION);
The error:
Response: {"errorMessage":"Failed to connect to Liquibase due to Migration failed for change set db.changelog-1.1.xml::1231::xxx:\n Reason: liquibase.exception.DatabaseException: Table 'tenant' already exists [Failed SQL: CREATE TABLE xxx_global.tenant (tenantId INT AUTO_INCREMENT NOT NULL, region VARCHAR(255) NULL, tenantName VARCHAR(255) NULL, CONSTRAINT PK_TENANT PRIMARY KEY (tenantId))]"}
My only other thought would be to try to use a custom context on the CreateTable changesets for clean installations
I found the issue and it was not a Liquibase issue. The AWS stack containing the Lambda code to call Liquibase was not updating. I deleted and recreated the stack and it started working.

Alter cube dimension by using XMLA

By using XMLA how to access WriteEnabled dimension property and modify it?
Here is a sample I'm using for that
<Alter ObjectExpansion="ExpandFull" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>DB</DatabaseID>
<DimensionID>My dimension</DimensionID>
</Object>
<ObjectDefinition>
<Dimension xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2"
xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100">
<WriteEnabled>false</WriteEnabled>
<ID>My dimension</ID>
<Name>Dimension name</Name>
<Attributes>
<Attribute>
<Name>Attribute name/Name>
</Attribute>
</Attributes>
</Dimension>
</ObjectDefinition>
</Alter>
Running this script I'm getting following error: Errors in the metadata manager. The 'My dimension' dimension has either zero or multiple key attributes.
What is missing in a script above?
Seems the key columns node and Name columns nodes for your attribute have missing:
Here is an example for a dim attributes node, hope it helps:
You can create a cube manually, and then check the alter script by right click the cube name for a reference also.

Silverpop <ImportList> API error "Mapping Failed. Cannot Import Column: RECIPIENT_ID Unable to continue"

I'm running into the below error
Mapping Failed. Cannot Import Column: RECIPIENT_ID Unable to continue
I’m using API method (snippet below), and
<Envelope>
<Body>
<ImportList><MAP_FILE>ODS_To_Silverpop_Mapping.XML</MAP_FILE>
<SOURCE_FILE>ODS_To_Silverpop_20170123171113.TXT</SOURCE_FILE></ImportList>
</Body>
</Envelope>
and passing the XML file for mapping information (snippet below), along with the raw data file (not attached here). As per the API documentation, I'm saving these two files in the silverpop FTP folder and making the API call. This code is working if I don't use the 'RECIPIENT_ID' (which is the auto generated hidden system field) in the mapping xml file (in columns mapping list and in the sync fields list), and use some other key to sync. However, in this specific case, I need too use the RECIPIENT_ID as there is no other reliable field. Does any one have experience with the Silverpop ImportList API method? and thoughts about this issue?
<?xml version="1.0" encoding="UTF-8"?>
<LIST_IMPORT>
<LIST_INFO>
<ACTION>ADD_AND_UPDATE</ACTION>
<LIST_ID>23232323</LIST_ID>
<FILE_TYPE>0</FILE_TYPE>
<HASHEADERS>true</HASHEADERS>
</LIST_INFO>
<SYNC_FIELDS>
<SYNC_FIELD>
<NAME>RECIPIENT_ID</NAME>
</SYNC_FIELD>
</SYNC_FIELDS>
<MAPPING>
<COLUMN>
<INDEX>1</INDEX>
<NAME>Email</NAME>
<INCLUDE>true</INCLUDE>
</COLUMN>
<COLUMN>
<INDEX>2</INDEX>
<NAME>RECIPIENT_ID</NAME>
<INCLUDE>true</INCLUDE>
</COLUMN>
<COLUMN>
<INDEX>3</INDEX>
<NAME>FirstName</NAME>
<INCLUDE>true</INCLUDE>
</COLUMN>
<COLUMN>
<INDEX>4</INDEX>
<NAME>LastName</NAME>
<INCLUDE>true</INCLUDE>
</COLUMN>
<INDEX>5</INDEX>
<NAME>Last Modified Date</NAME>
<INCLUDE>false</INCLUDE>
</COLUMN>
</MAPPING>
</LIST_IMPORT>
Yes In your mapping XML file please Add
<USE_RECIPIENT_ID>true</USE_RECIPIENT_ID> inside list_info
below is the snippet
<LIST_INFO>
<ACTION>ADD_AND_UPDATE</ACTION>
<LIST_ID>23232323</LIST_ID>
<FILE_TYPE>0</FILE_TYPE>
<HASHEADERS>true</HASHEADERS>
<USE_RECIPIENT_ID>true</USE_RECIPIENT_ID>
</LIST_INFO>

Approving "One" in a one-to-many DB relationship only when ALL "Many"s are approved

I've tried looking for this I promise, but its kind of a hard question to search for...
I have a database with two tables linked in a one-to-many relationship where each "one" is an invoice header linked to "many" invoice lines.
I am designing a tool that will match each invoice line to a purchase order and I want to be able to mark an invoice header as "matched" only when all lines have been matched.
Does anyone know how to write this update query?
The relational operator you seek is known formally as division and colloquially as "the suppliers who supply all parts". For various reasons, a division operator has not appeared in any SQL product I know of, Access included. Instead, you need to use other operators in combination to do the same. See Divided we stand: the SQL of relational division by Joe Celko.
An approach available to users of Access 2010 and later is to use event-driven data macros in the child table to maintain the status flag in the parent table. For example, with a parent table
[InvHeader]
InvID AllMatched
----- ----------
1 No
and a child table
[InvItem]
ItemID InvID Matched
------ ----- -------
1 1 Yes
2 1 No
the following After Update data macro will automatically update the corresponding row in [InvHeader] after a child row has been changed in [InvItem]
Code:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
<DataMacro Event="AfterUpdate">
<Statements>
<Action Collapsed="true" Name="SetLocalVar">
<Argument Name="Name">newAllMatched</Argument>
<Argument Name="Value">True</Argument>
</Action>
<ForEachRecord>
<Data Alias="i">
<Reference>InvItem</Reference>
<WhereCondition>[i].[InvID]=[InvItem].[InvID]</WhereCondition>
</Data>
<Statements>
<ConditionalBlock>
<If>
<Condition>Not [i].[Matched]</Condition>
<Statements>
<Action Collapsed="true" Name="SetLocalVar">
<Argument Name="Name">newAllMatched</Argument>
<Argument Name="Value">False</Argument>
</Action>
<Action Name="ExitForEachRecord"/>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</ForEachRecord>
<LookUpRecord>
<Data Alias="hdr">
<Reference>InvHeader</Reference>
<WhereCondition>[hdr].[InvID]=[InvItem].[InvID]</WhereCondition>
</Data>
<Statements>
<ConditionalBlock>
<If>
<Condition>[hdr].[AllMatched]<>[newAllMatched]</Condition>
<Statements>
<EditRecord>
<Data Alias="hdr"/>
<Statements>
<Action Collapsed="true" Name="SetField">
<Argument Name="Field">AllMatched</Argument>
<Argument Name="Value">[newAllMatched]</Argument>
</Action>
</Statements>
</EditRecord>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</LookUpRecord>
</Statements>
</DataMacro>
</DataMacros>
Note that this is an example for updates only. For completeness, one would normally put the above code in a named data macro and call it from After Insert, After Update, and After Delete.