Skip to content

Commit

Permalink
Improve Error Message for throwSqlError() (backport #7308) [release/4…
Browse files Browse the repository at this point in the history
….11.x] (#7384)

Co-authored-by: Daniel Rodriguez <44824788+DanRod1999@users.noreply.github.com>
Co-authored-by: Daniel Rodriguez <DanRod1999@users.noreply.github.com>
Co-authored-by: imodeljs-admin <38288322+imodeljs-admin@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 21, 2024
1 parent 087a2d1 commit 2dd73f1
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-backend",
"comment": "Add test for BE_SQLITE_CONSTRAINT_UNIQUE",
"type": "none"
}
],
"packageName": "@itwin/core-backend"
}
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"webpack": "^5.76.0"
},
"dependencies": {
"@bentley/imodeljs-native": "4.10.23",
"@bentley/imodeljs-native": "4.11.7",
"@itwin/cloud-agnostic-core": "^2.2.4",
"@itwin/core-telemetry": "workspace:*",
"@itwin/object-storage-azure": "^2.2.5",
Expand Down
36 changes: 35 additions & 1 deletion core/backend/src/test/imodel/IModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
DisplayStyleProps, DisplayStyleSettings, DisplayStyleSettingsProps, EcefLocation, ElementProps, EntityMetaData, EntityProps, FilePropertyProps,
FontMap, FontType, GeoCoordinatesRequestProps, GeoCoordStatus, GeographicCRS, GeographicCRSProps, GeometricElementProps, GeometryParams, GeometryStreamBuilder,
ImageSourceFormat, IModel, IModelCoordinatesRequestProps, IModelError, IModelStatus, LightLocationProps, MapImageryProps, PhysicalElementProps,
PointWithStatus, PrimitiveTypeCode, RelatedElement, RenderMode, SchemaState, SpatialViewDefinitionProps, SubCategoryAppearance, SubjectProps, TextureMapping,
PointWithStatus, PrimitiveTypeCode, RelatedElement, RelationshipProps, RenderMode, SchemaState, SpatialViewDefinitionProps, SubCategoryAppearance, SubjectProps, TextureMapping,
TextureMapProps, TextureMapUnits, ViewDefinitionProps, ViewFlagProps, ViewFlags,
} from "@itwin/core-common";
import {
Expand Down Expand Up @@ -2844,4 +2844,38 @@ describe("iModel", () => {

expect(() => imodel.elements.getElement<Subject>(IModel.rootSubjectId)).to.throw(IModelError, "Element=0x1", "Not Found");
});

it("should throw \"constraint failed (BE_SQLITE_CONSTRAINT_UNIQUE)\" when inserting a relationsip instance with the same prop twice", () => {
const imodelPath = IModelTestUtils.prepareOutputFile("IModel", "insertDuplicateInstance.bim");
const imodel = SnapshotDb.createEmpty(imodelPath, { rootSubject: { name: "insertDuplicateInstance" } });
const elements = imodel.elements;

// Create a new physical model
const newModelId = PhysicalModel.insert(imodel, IModel.rootSubjectId, "TestModel");

// create a SpatialCategory
const spatialCategoryId = SpatialCategory.insert(imodel, IModel.dictionaryId, "MySpatialCategory", new SubCategoryAppearance({ color: ColorByName.darkRed }));

// Create a couple of physical elements.
const elementProps: GeometricElementProps = {
classFullName: PhysicalObject.classFullName,
model: newModelId,
category: spatialCategoryId,
code: Code.createEmpty(),
};

const id0 = elements.insertElement(elementProps);
const id1 = elements.insertElement(elementProps);

const props: RelationshipProps = {
classFullName: "BisCore:ElementGroupsMembers",
sourceId: id0,
targetId: id1,
};

imodel.relationships.insertInstance(props)
expect(() => imodel.relationships.insertInstance(props)).to.throw(`Failed to insert relationship [${imodelPath}]: rc=2067, constraint failed (BE_SQLITE_CONSTRAINT_UNIQUE)`);

imodel.close();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-ui:2.5.3'
implementation 'com.github.itwin:mobile-native-android:4.10.23'
implementation 'com.github.itwin:mobile-native-android:4.11.7'
implementation 'androidx.webkit:webkit:1.5.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
repositoryURL = "/~https://github.com/iTwin/mobile-native-ios";
requirement = {
kind = exactVersion;
version = 4.10.23;
version = 4.11.7;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
repositoryURL = "/~https://github.com/iTwin/mobile-native-ios";
requirement = {
kind = exactVersion;
version = 4.10.23;
version = 4.11.7;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down

0 comments on commit 2dd73f1

Please sign in to comment.