Skip to content

Commit

Permalink
Improve Error Message for throwSqlError() (#7308)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Rodriguez <DanRod1999@users.noreply.github.com>
Co-authored-by: imodeljs-admin <38288322+imodeljs-admin@users.noreply.github.com>
(cherry picked from commit a29c7bc)

# Conflicts:
#	common/config/rush/pnpm-lock.yaml
#	core/backend/package.json
#	test-apps/display-test-app/android/imodeljs-test-app/app/build.gradle
#	test-apps/display-test-app/ios/imodeljs-test-app/imodeljs-test-app.xcodeproj/project.pbxproj
#	tools/internal/ios/core-test-runner/core-test-runner.xcodeproj/project.pbxproj
  • Loading branch information
DanRod1999 authored and mergify[bot] committed Nov 16, 2024
1 parent 66a0c64 commit ee00aa0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 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"
}
6 changes: 5 additions & 1 deletion core/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@
"webpack": "^5.76.0"
},
"dependencies": {
<<<<<<< HEAD
"@bentley/imodeljs-native": "4.10.21",
=======
"@bentley/imodeljs-native": "5.0.4",
>>>>>>> a29c7bc29d (Improve Error Message for throwSqlError() (#7308))
"@itwin/cloud-agnostic-core": "^2.2.4",
"@itwin/core-telemetry": "workspace:*",
"@itwin/object-storage-azure": "^2.2.5",
Expand All @@ -116,4 +120,4 @@
"nyc": {
"extends": "./node_modules/@itwin/build-tools/.nycrc"
}
}
}
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,11 @@ 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'
<<<<<<< HEAD
implementation 'com.github.itwin:mobile-native-android:4.10.21'
=======
implementation 'com.github.itwin:mobile-native-android:5.0.4'
>>>>>>> a29c7bc29d (Improve Error Message for throwSqlError() (#7308))
implementation 'androidx.webkit:webkit:1.5.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@
repositoryURL = "https://github.com/iTwin/mobile-native-ios";
requirement = {
kind = exactVersion;
<<<<<<< HEAD
version = 4.10.21;
=======
version = 5.0.4;
>>>>>>> a29c7bc29d (Improve Error Message for throwSqlError() (#7308))
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,11 @@
repositoryURL = "https://github.com/iTwin/mobile-native-ios";
requirement = {
kind = exactVersion;
<<<<<<< HEAD
version = 4.10.21;
=======
version = 5.0.4;
>>>>>>> a29c7bc29d (Improve Error Message for throwSqlError() (#7308))
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down

0 comments on commit ee00aa0

Please sign in to comment.