{"id":370187,"date":"2024-05-21T04:19:33","date_gmt":"2024-05-21T04:19:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=370187"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=370187","title":{"rendered":"<span>\u041a\u043e\u0442 \u0432 \u043c\u0435\u0448\u043a\u0435: \u043c\u0430\u0441\u0442\u0435\u0440\u0441\u0442\u0432\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 SQLite<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a4d\/ac2\/e66\/a4dac2e66e0d6504272c598b735c7a09.png\" width=\"2438\" height=\"1369\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a4d\/ac2\/e66\/a4dac2e66e0d6504272c598b735c7a09.png\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0422\u0438\u043c\u0443\u0440, \u044f Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 <a href=\"https:\/\/kts.tech\/\">KTS<\/a>.<\/p>\n<p>\u0421\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u044b\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 <code>Foreign Key<\/code> \u0432 SQLite \u0434\u043b\u044f Android? \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u043c \u0437\u0430\u0432\u0435\u0441\u0443 \u0442\u0430\u0439\u043d\u044b \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u043a \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/d15\/93d\/715\/d1593d715bea045dc7c10fdad1b75c4a.jpeg\" width=\"1600\" height=\"900\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d15\/93d\/715\/d1593d715bea045dc7c10fdad1b75c4a.jpeg\" data-blurred=\"true\"\/><\/figure>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"#1\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u00ab\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430\u00bb<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#2\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 Foreign Key \u0438 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0435\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#3\">\u0412 \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e \u043a\u043e\u043f\u0430\u043b\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#4\"><strong>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong> \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f SQLite-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#5\"><strong>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong> \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 SupportSQLiteOpenHelper \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#6\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h3>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u00ab\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430\u00bb<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 SQLite, \u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<ul>\n<li>\n<p>\u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0434\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u0445<\/p>\n<\/li>\n<li>\n<p>\u00ab\u043a\u0443\u0440\u0441\u044b\u00bb \u0434\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u0443\u0440\u0441\u0430\u0445<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u0435\u0441\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0443\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u0438\u043b\u0435\u0442\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0438 \u00ab\u043a\u0443\u0440\u0441\u044b\u00bb \u2014 \u0447\u0442\u043e\u0431\u044b \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b \u043d\u0430 \u043a\u0430\u043a\u0438\u0435 \u043a\u0443\u0440\u0441\u044b \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u00ab\u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u0443\u0440\u0441\u044b\u00bb.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Foreign Key \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u00ab\u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u0443\u0440\u0441\u044b\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 \u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0438 \u00ab\u043a\u0443\u0440\u0441\u044b\u00bb .\u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/511\/70c\/3d9\/51170c3d911243fab913535d059e0ec4.png\" width=\"1600\" height=\"498\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/511\/70c\/3d9\/51170c3d911243fab913535d059e0ec4.png\"\/><\/figure>\n<p>\u0422\u0430\u043a \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u044c, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u00ab\u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430 \u043a\u0443\u0440\u0441\u044b\u00bb \u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u043a\u0443\u0440\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u0442 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u00ab\u0431\u0435\u0441\u0445\u043e\u0437\u043d\u044b\u0445\u00bb \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3a3\/ff7\/157\/3a3ff71576003e33cdbfa875015dad02.png\" width=\"1600\" height=\"494\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a3\/ff7\/157\/3a3ff71576003e33cdbfa875015dad02.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 Foreign Key \u0438 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0435\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/h3>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u043a\u043e\u043d\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u044b\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430 \u043a\u0443\u0440\u0441 \u0441\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u0442\u0447\u0438\u0441\u043b\u0438\u043b\u0438 (\u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b), \u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430 \u043a\u0443\u0440\u0441 \u0441 \u0442\u0430\u043a\u0438\u043c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0435\u0449\u0435 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c. <\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u0443\u0440\u0441 \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u0432 \u0411\u0414, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430. \u041f\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0441\u043a\u0430\u0434\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041d\u043e \u0432\u0441\u0435 \u043c\u044b \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u043a \u043d\u0430\u043c \u043f\u043e\u043f\u0430\u043b\u0438 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/98b\/458\/aba\/98b458aba6d4a46fb4a6944e276d2fae.png\" width=\"1177\" height=\"381\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/98b\/458\/aba\/98b458aba6d4a46fb4a6944e276d2fae.png\"\/><\/figure>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>\"transactions\"<\/code> \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432\u044b\u0437\u0432\u0430\u043b\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0431\u044d\u043a\u0435\u043d\u0434\u0435\u0440\u043e\u0432 \u0438\u043b\u0438 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u043f\u043e\u043d\u044f\u0442\u043d\u0443\u044e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f03\/b3e\/3cb\/f03b3e3cb09bbd6efb8e51ca156432aa.png\" width=\"1202\" height=\"277\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f03\/b3e\/3cb\/f03b3e3cb09bbd6efb8e51ca156432aa.png\"\/><\/figure>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u0430\u043a\u043e\u043c\u0443 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u044b \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0443 \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0412\u0441\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0432 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u043a\u0430\u043a <a href=\"https:\/\/cases.kts.studio\/case_pik_mobile\">\u041f\u0418\u041a<\/a> \u0438 <a href=\"https:\/\/cases.kts.studio\/case_kleo_mobile\">Ascott Group<\/a>.\u00a0<\/p>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u0412 \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e \u043a\u043e\u043f\u0430\u043b\u0438<\/h3>\n<h4>\u041f\u043e\u0434\u043c\u0435\u043d\u0430 \/ \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0430\u0439\u0442 \u043a\u043e\u0434\u0430<\/h4>\n<p>\u041f\u0440\u043e \u043f\u0430\u0442\u0447\u0438\u043d\u0433 \u0431\u0430\u0439\u0442 \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/company\/sberbank\/blog\/685142\/\"><u>\u0432 \u0441\u0442\u0430\u0442\u044c\u0435<\/u><\/a>.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>visitMethod<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u0438\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 Room (insert, update \u0438 delete), \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u044b\u0437\u043e\u0432 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 Foreign Key \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438.\u00a0<\/p>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u2014 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<\/p>\n<p>\u041f\u043e \u0438\u0442\u043e\u0433\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438, \u0447\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0441\u043b\u043e\u043c\u0430\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0438 \u044d\u0442\u0443 \u043f\u043e\u043b\u043e\u043c\u043a\u0443 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u0442\u0430\u043b\u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f SQLite-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h3>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043d\u043e \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u0439\u043b\u0435\u0440\u043f\u043b\u0435\u0439\u0442\u0430. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041f\u043e\u0441\u043b\u0435 \u0441\u0442\u0430\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0435. \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u043f\u0440\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0443 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u043e, \u0431\u0435\u0437 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u0438\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u0438. \u041f\u043e\u043b\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/ktsstudio\/android-fk-helper-sample\">\u044d\u0442\u043e\u043c<\/a> \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u0451\u0440\u0442\u043a\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 <code>SQLiteConstraintException<\/code>. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442, \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0415\u0441\u0442\u044c \u043e\u0431\u0451\u0440\u0442\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>INSERT<\/code>, <code>UPDATE<\/code> \u0438 <code>DELETE<\/code>. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 <code>INSERT<\/code> \u0438 <code>UPDATE<\/code> \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439, \u0430 \u0432\u043e\u0442 \u0434\u043b\u044f <code>DELETE<\/code> \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>INSERT<\/code> \u0438 <code>UPDATE<\/code>. \u041e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f \u043d\u0438\u0445 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">suspend inline fun &lt;reified T : BaseEntity&lt;*>> FinanceDB.insertOrUpdateWithFKCheck(    itemsToInsert: List&lt;T>,    insertCallback: (items: List&lt;T>) -> Unit ) {    if (itemsToInsert.isEmpty()) return      checkFkException(        tryBlock = {            insertCallback(itemsToInsert)        },        catchFkExceptionBlock = {            getFkExceptionFormattingOnSave(                itemsToSave = itemsToInsert,                action = TableAction.INSERT,            )        }    ) } <\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>insertOrUpdateWithFKCheck<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u043e\u0439 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0438. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c <code>SQLiteConstraintException<\/code> \u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.\u00a0<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>checkFkException<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439:<\/p>\n<pre><code class=\"kotlin\">inline fun &lt;T : BaseEntity&lt;*>> checkFkException(       tryBlock: () -> Unit,       catchFkExceptionBlock: () -> FkExceptionFormattingInfo&lt;T>   ) {       try {           tryBlock()       } catch (sqliteException: SQLiteConstraintException) {           sqliteException.message               ?.lowercase(Locale.getDefault())               ?.takeIf { errorMessage -> FOREIGN_KEY_EXCEPTION_TEXT in errorMessage }               ?: throw sqliteException              val errorMessage = createFkExceptionErrorMessage(              messageInfo = catchFkExceptionBlock()         )           throw SQLiteConstraintException(errorMessage)       }   }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u043e\u0432\u0438\u0442 <code>SQLiteConstraintException<\/code>, \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0437\u0432\u0430\u043b\u043e \u043e\u0448\u0438\u0431\u043a\u0443. \u0421\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043b\u044f\u043c\u0431\u0434\u0430 <code>catchFkExceptionBlock<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0442\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u043a\u043b\u0430\u0434\u0451\u0442 \u0435\u0435 \u0432 <code>SQLiteConstraintException<\/code> \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043b\u044c\u0448\u0435.\u00a0<\/p>\n<p>\u0412 \u043b\u044f\u043c\u0431\u0434\u0435 <code>catchFkExceptionBlock<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>getFkExceptionFormattingOnSave<\/code>, \u043e\u043d\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>INSERT<\/code> \u0438 <code>UPDATE<\/code>. <\/p>\n<details class=\"spoiler\">\n<summary>getFkExceptionFormattingOnSave<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">suspend inline fun &lt;reified T : BaseEntity&lt;*>> Db.getFkExceptionFormattingOnSave(       itemsToSave: List&lt;T>,       action: TableAction,       apiQueryName: String? = null   ): FkExceptionFormattingInfo&lt;T> {       val entityInfo = itemsToSave.first()       val entityInfoToFkIds = mutableMapOf&lt;T, List&lt;Any>>()       val foreignKeyRelations = getForeignKeyRelationFor(entityInfo)          val errorItems = itemsToSave.filter { itemToInsert ->           foreignKeyRelations.all { fkRelation ->               val foreignKeyValue = fkRelation.childFkIdExtractor(itemToInsert) ?: return@all true               fkRelation.parentFkIds.contains(foreignKeyValue).not()                   .also { constraintFails ->                       if (constraintFails) {                           val constraintFailsList = entityInfoToFkIds[fkRelation.entityInfo]                               ?.toMutableList()                               ?.apply {                                   add(foreignKeyValue)                               } ?: listOf(foreignKeyValue)                           entityInfoToFkIds[fkRelation.entityInfo] = constraintFailsList                       }                   }           }       }          return FkExceptionFormattingInfo(           tableName = entityInfo.tableName,           action = action,           errorItems = errorItems,           entityInfoToFkIds = entityInfoToFkIds,           apiQueryName = apiQueryName       )   }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 <code>itemsToSave<\/code>, <code>action (INSERT, UPDATE)<\/code> \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0442\u0438\u043f\u043e\u043c \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430 <code>BaseEntity.<\/code><\/p>\n<p><code>BaseEntity<\/code> \u2014 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0438 \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043e\u0448\u0438\u0431\u043a\u0443 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438\u043c\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u0434\u0430\u043d\u043d\u044b\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c: \u0435\u0441\u0442\u044c \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043d \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0442, \u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043f\u0440\u0438\u0447\u0438\u043d\u0443, \u043a\u043b\u0430\u0434\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <code>FkExceptionFormattingInfo<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.\u00a0<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/04d\/eaf\/83c\/04deaf83ca208486411e7cf217b32b4c.png\" width=\"1666\" height=\"1348\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/04d\/eaf\/83c\/04deaf83ca208486411e7cf217b32b4c.png\"\/><\/figure>\n<p>\u0414\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e id, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0435\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0432\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435, \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u044f\u043c \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0431\u0435\u0440\u0451\u043c \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0443\u0441\u0442\u044b\u0435: \u0432 \u043d\u0438\u0445 \u0435\u0449\u0451 \u0435\u0441\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430. \u0414\u0430\u043b\u044c\u0448\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435, \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0434\u043b\u044f <code>INSERT<\/code> \u0438 <code>UPDATE<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">suspend inline fun &lt;reified T : BaseEntity&lt;*>> Db.deleteWithFKCheck(     itemIdsToDelete: List&lt;Long>,     deleteCallback: (items: List&lt;Long>) -> Unit ) {     if (itemIdsToDelete.isEmpty()) return     checkFkException(         tryBlock = {             batchedQueryInTransaction(                 list = itemIdsToDelete,                 query = deleteCallback             )         },         catchFkExceptionBlock = {             val items = getItemsByIds&lt;T>(itemIdsToDelete)             val entityInfo = items.first()             val entityInfoToFkIds = mutableMapOf&lt;BaseEntity&lt;*>, List&lt;Any>>()             val entityRelations: List&lt;Relations&lt;T>> = itemIdsToDelete.queryWithParameterCountCheck { ids ->                 getEntityRelationByIds&lt;T>(ids) as List&lt;Relations&lt;T>>             }              val errorItems = entityRelations.filter { entityRelation ->                 entityRelation.embeddedConstraintsEmpty().not()                     .also { constraintFails ->                         if (constraintFails) {                             entityInfoToFkIds.putAll(                                 entityRelation.getEmbeddedConstraints()                                     .map { relation ->                                         relation to relation.remotePrimaryItem                                     }                                     .filter { it.second != null }                                     .groupBy { it.first }                                     .mapValues { (_, infoItems) ->                                         infoItems.mapNotNull { infoItem -> infoItem.second }                                     }                             )                         }                     }             }.map { it.embeddedValue }              FkExceptionFormattingInfo(                 tableName = entityInfo.tableName,                 action = TableAction.DELETE,                 errorItems = errorItems,                 entityInfoToFkIds = entityInfoToFkIds             )         }     ) }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0435\u0449\u0451 \u043a\u0442\u043e-\u0442\u043e \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e4b\/c26\/924\/e4bc26924ce55fd69b7023dff2ba06af.png\" width=\"1666\" height=\"1382\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e4b\/c26\/924\/e4bc26924ce55fd69b7023dff2ba06af.png\"\/><\/figure>\n<p><strong>\u041f\u043b\u044e\u0441\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p>\u042d\u043a\u0441\u0442\u0435\u043d\u0448\u0435\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 KMP<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041c\u0438\u043d\u0443\u0441\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430. \u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0447\u0442\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0432 \u0446\u0435\u043b\u043e\u043c. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 <code>BaseEntity<\/code> \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>getForeignKeyRelationFor<\/code> \u043a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 id, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e id\u00a0<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e id, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 relations \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0435\u0449\u0451 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c relations \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<li>\n<p>\u0418 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u044d\u043a\u0441\u0442\u0435\u043d\u0448\u0435\u043d\u043e\u043c<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0431\u0430\u0437\u0443, \u044d\u0442\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041d\u043e\u0432\u044b\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043b\u0435\u0433\u043a\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u044f<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0441\u0432\u044f\u0437\u0435\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0434\u0430 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u043c\u0438\u043d\u0443\u0441 \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0438\u043d\u0443\u0441\u044b \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043d\u0430\u0441 \u0438\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p><a class=\"anchor\" name=\"5\" id=\"5\"><\/a><\/p>\n<h3>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 SupportSQLiteOpenHelper<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u0441\u043d\u043e\u0432. <code>SupportSQLiteOpenHelper<\/code> \u2014 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <code>SQLiteOpenHelper<\/code> \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438. <code>SupportSQLiteOpenHelper<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a>Room<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0438 \u0432 KMP-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/cashapp.github.io\/sqldelight\/2.0.1\/\">SQLDelight<\/a> (\u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f Android \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 <a href=\"https:\/\/github.com\/cashapp\/sqldelight\/blob\/5088d8c63479ccf529c4c76d43cbd93e4a10dfda\/drivers\/android-driver\/src\/main\/java\/app\/cash\/sqldelight\/driver\/android\/AndroidSqliteDriver.kt#L29\">AndroidSqliteDriver<\/a>).<\/p>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 <code>SupportSQLiteOpenHelper<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>SupportSQLiteDatabase<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f SQL-\u043a\u043e\u043c\u0430\u043d\u0434 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. <code>SupportSQLiteDatabase<\/code>, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e SQL \u0432 \u0432\u0438\u0434\u0435 <code>SupportSQLiteStatement<\/code>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.\u00a0<\/p>\n<p>\u0418\u0434\u0435\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>SupportSQLiteOpenHelper<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 <code>SupportSQLiteStatement<\/code> \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>SQLiteConstraintException<\/code> \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430.\u00a0\u00a0<\/p>\n<p>\u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043f\u043b\u0430\u043d:<\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 <code>SupportSQLite*<\/code>-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0432 \u043a\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b <a href=\"https:\/\/developer.android.com\/training\/data-storage\/room\">Room<\/a>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e <code>SupportSQLiteOpenHelper<\/code> \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 <code>Foreign Key<\/code><\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u0430\u043a Room \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 SupportSQLite* \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0432 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435<\/h3>\n<p>\u041a\u043e\u0433\u0434\u0430 Room \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u044d\u0442\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c <code>FrameworkSQLiteOpenHelperFactory.<\/code> \u0412 Room \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c DAO-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0430 Room \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u044e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.\u00a0<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>TransactionDao<\/code> \u0441 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u0438:\u00a0<\/p>\n<pre><code class=\"kotlin\">@Dao interface TransactionDao {     @Insert(onConflict = OnConflictStrategy.REPLACE)    suspend fun insert(transactions: List&lt;LocalTransaction>) }<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 Room-\u043e\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 <code>TransactionDao<\/code> \u0440\u0430\u043d\u0435\u0435:<\/p>\n<pre><code class=\"kotlin\">@Override public Object insert(final List&lt;LocalTransaction> transactions,    final Continuation&lt;? super Unit> continuation) {  return CoroutinesRoom.execute(__db, true, new Callable&lt;Unit>() {    @Override    public Unit call() throws Exception {      __db.beginTransaction();      try {        __insertionAdapterOfLocalTransaction.insert(transactions);        __db.setTransactionSuccessful();        return Unit.INSTANCE;      } finally {        __db.endTransaction();      }    }  }, continuation); }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <a href=\"https:\/\/developer.android.com\/reference\/android\/arch\/persistence\/room\/RoomDatabase\">RoomDatabase<\/a>, \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/developer.android.com\/reference\/androidx\/sqlite\/db\/SupportSQLiteDatabase\">SupportSQLiteDatabase<\/a><strong>.<\/strong><\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 <code>insert<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/developer.android.com\/reference\/androidx\/sqlite\/db\/SupportSQLiteStatement\">SupportSQLiteStatement<\/a> \u0434\u043b\u044f \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0438:<\/p>\n<pre><code class=\"kotlin\">fun insert(entity: T) {    val stmt: SupportSQLiteStatement = acquire()    try {        bind(stmt, entity)        stmt.executeInsert()    } finally {        release(stmt)    } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c <code>executeInsert<\/code>\u00a0\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432 \u043d\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0443. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0430\u043a (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>withForeignKeyCheck<\/code> \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435):<\/p>\n<pre><code class=\"kotlin\">override fun executeInsert(): Long {    return database.withForeignKeyCheck(        sqlQuery = sql,         args = bindArgsCache.toTypedArray(),        executeQuery = {              supportSQLiteStatement.executeInsert()        }    )  } <\/code><\/pre>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e SupportSQLiteOpenHelper:<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 Room, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b Room \u043d\u0430\u0447\u0430\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 <code>SupportSQLiteOpenHelper<\/code>, <code>SupportSQLiteDatabase<\/code> \u0438 <code>SupportSQLiteStatement<\/code>.<\/p>\n<p>\u0423 <code>Room.databaseBuilder<\/code> \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>SupportSQLiteOpenHelper<\/code>. \u0422\u043e\u0433\u0434\u0430 Room \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0439, \u0430 \u043d\u0435 \u0441 <code>FrameworkSQLiteOpenHelperFactory<\/code>. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">Room.databaseBuilder(       context,       FinanceDB::class.java,       FinanceDB.DATABASE_NAME,   )       .openHelperFactory(           factory = FinanceQLiteOpenHelperFactory(               delegate = FrameworkSQLiteOpenHelperFactory()           )       )       .build()<\/code><\/pre>\n<p>\u041a\u0430\u043a \u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0440\u0430\u043d\u0435\u0435, \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0432 <code>SqlDelight<\/code>:<\/p>\n<pre><code class=\"kotlin\">AndroidSqliteDriver(    openHelper = FinanceQLiteOpenHelperFactory(        delegate = FrameworkSQLiteOpenHelperFactory()    ) ,    schema = Database.Schema,    context = context,    name = DATABASE_NAME,    callback = object : AndroidSqliteDriver.Callback(Database.Schema) {        override fun onOpen(db: SupportSQLiteDatabase) {            db.setForeignKeyConstraintsEnabled(true)        }    } ) <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0446\u0435\u043b\u0438 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u043d\u0443\u043b\u044f. \u0414\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043c\u0430 \u043a\u043e\u0434\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/kotlinlang.org\/docs\/delegation.html#overriding-a-member-of-an-interface-implemented-by-delegation\">Kotlin Delegation<\/a>. \u042d\u0442\u043e \u0444\u0438\u0447\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u044f \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u043e\u0432.\u00a0<\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c, \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437 <a href=\"https:\/\/developer.android.com\/reference\/android\/arch\/persistence\/db\/framework\/FrameworkSQLiteOpenHelperFactory\">FrameworkSQLiteOpenHelperFactory<\/a>. \u042d\u0442\u043e\u0442 \u0448\u0430\u0433 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 <a href=\"https:\/\/kotlinlang.org\/docs\/delegation.html#overriding-a-member-of-an-interface-implemented-by-delegation\">\u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a>.\u00a0<\/p>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/developer.android.com\/reference\/android\/arch\/persistence\/db\/framework\/FrameworkSQLiteOpenHelperFactory\">FrameworkSQLiteOpenHelperFactory<\/a> \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c SupportSQLiteOpenHelper:<\/p>\n<pre><code class=\"kotlin\">internal class FinanceQLiteOpenHelperFactory(       private val delegate: SupportSQLiteOpenHelper.Factory   ) : SupportSQLiteOpenHelper.Factory {          override fun create(           configuration: SupportSQLiteOpenHelper.Configuration       ): SupportSQLiteOpenHelper {           return InterceptorSQLiteOpenHelper(         openHelper = delegate.create(configuration)         )       }   }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 <a href=\"https:\/\/developer.android.com\/reference\/android\/arch\/persistence\/db\/SupportSQLiteOpenHelper\">SupportSQLiteOpenHelper<\/a> \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 <code>InterceptorSQLiteOpenHelper<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0430\u0451\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437 <code>FrameworkSQLiteOpenHelperFactory<\/code>, \u0430 \u0441\u0430\u043c\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435:<\/p>\n<pre><code class=\"kotlin\">internal class InterceptorSQLiteOpenHelper(       private val openHelper: SupportSQLiteOpenHelper   ) : SupportSQLiteOpenHelper by openHelper {          override val readableDatabase: SupportSQLiteDatabase           get() = InterceptorSQLiteDatabase(openHelper.readableDatabase)          override val writableDatabase: SupportSQLiteDatabase           get() = InterceptorSQLiteDatabase(openHelper.writableDatabase)   }<\/code><\/pre>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0441 <code>SupportSQLiteDatabase<\/code>, \u0442\u0443\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>SupportSQLiteStatement<\/code>.<\/p>\n<pre><code class=\"kotlin\">internal class InterceptorSQLiteDatabase(       private val database: SupportSQLiteDatabase   ) : SupportSQLiteDatabase by database {  override fun compileStatement( sql: String ): SupportSQLiteStatement {   return InterceptorSQLiteStatement(   supportSQLiteStatement = database.compileStatement(sql),   database = database,   sql = sql,   )   } }<\/code><\/pre>\n<p>\u0421 <code>SupportSQLiteStatement<\/code> \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a \u0436\u0435, \u043d\u043e \u0442\u0443\u0442 \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 \u043e\u0448\u0438\u0431\u043e\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b <code>execute<\/code>, <code>executeUpdateDelete<\/code> \u0438 <code>executeInsert<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 \u043e\u0448\u0438\u0431\u043e\u043a, \u0438 \u043c\u0435\u0442\u043e\u0434\u044b <code>bind*<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">internal class InterceptorSQLiteStatement(     private val supportSQLiteStatement: SupportSQLiteStatement,     private val database: SupportSQLiteDatabase,     private val sql: String ) : SupportSQLiteStatement by supportSQLiteStatement {      private val bindArgsCache: MutableList&lt;Any?> = mutableListOf()      override fun bindNull(index: Int) {         saveArgsToCache(index, null)         supportSQLiteStatement.bindNull(index)     }      override fun bindLong(index: Int, value: Long) {         saveArgsToCache(index, value)         supportSQLiteStatement.bindLong(index, value)     }      override fun bindDouble(index: Int, value: Double) {         saveArgsToCache(index, value)         supportSQLiteStatement.bindDouble(index, value)     }      override fun bindString(index: Int, value: String) {         saveArgsToCache(index, value)         supportSQLiteStatement.bindString(index, value)     }      override fun bindBlob(index: Int, value: ByteArray) {         saveArgsToCache(index, value)         supportSQLiteStatement.bindBlob(index, value)     }      override fun clearBindings() {         bindArgsCache.clear()         supportSQLiteStatement.clearBindings()     }      override fun execute() {         database.withForeignKeyCheck(sql, bindArgsCache.toTypedArray()) { _, _ ->             supportSQLiteStatement.execute()         }     }      override fun executeUpdateDelete(): Int {         return database.withForeignKeyCheck(sql, bindArgsCache.toTypedArray()) { _, _ ->             supportSQLiteStatement.executeUpdateDelete()         }     }      override fun executeInsert(): Long {         return database.withForeignKeyCheck(sql, bindArgsCache.toTypedArray()) { _, _ ->             supportSQLiteStatement.executeInsert()         }     }      private fun saveArgsToCache(bindIndex: Int, value: Any?) {         val index = bindIndex - 1         if (index >= bindArgsCache.size) {             \/\/ Add null entries to the list until we have the desired # of indices             for (i in bindArgsCache.size..index) {                 bindArgsCache.add(null)             }         }         bindArgsCache[index] = value     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 <code>execute*<\/code> \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u044d\u043a\u0441\u0442\u0435\u043d\u0448\u0435\u043d <code>withForeignKeyCheck<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0441\u0430\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u042d\u0442\u043e\u0442 \u044d\u043a\u0441\u0442\u0435\u043d\u0448\u0435\u043d \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>SQLiteConstraintException<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. <\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e\u0442 \u044d\u043a\u0441\u0442\u0435\u043d\u0448\u0435\u043d \u0442\u0430\u043a:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">internal inline fun &lt;T, R> SupportSQLiteDatabase.withForeignKeyCheck(    sql: String,    args: Array&lt;T>,    query: (String, Array&lt;T>) -> R ): R {    try {        return query(sql, args)    } catch (e: SQLiteConstraintException) {          val prepareSql = prepareSql(sql)        val argsList = args.map { it.toString() }          val formattedSqlQuery = prepareSql.replace(\"?\", \"%S\").format(*args)          val foreignKeyMessage = try {            getForeignKeyMessage(sql = prepareSql.lowercase(), args = argsList)        } catch (t: Throwable) {            Timber.e(\"Fet foreign key message for sql=$formattedSqlQuery\")            \"\"        }          throw SQLiteConstraintException(\"$formattedSqlQuery\\n$foreignKeyMessage\")    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0443\u0442 \u043c\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 <code>withForeignKeyCheck<\/code>:<\/p>\n<pre><code>INSERT OR REPLACE INTO `transactions`  (`id`,`bill_id`,`category_id`,`amount`,`date`,`comment`) VALUES (?,?,?,?,?,?)<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code>[1, 2, 3, 10, 0, null]<\/code><\/pre>\n<p>\u0418\u043c\u0435\u044f \u0432\u0441\u044e \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<pre><code>INSERT OR REPLACE INTO `transactions`  (`id`,`bill_id`,`category_id`,`amount`,`date`,`comment`) VALUES (1,2,3,10,0,NULL)<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0443\u0436\u0435 \u043a\u0440\u0443\u0442\u043e. \u0412\u0435\u0434\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0435 \u0441\u043a\u0430\u0436\u0435\u0442, \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u0430\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u043d\u0430 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c.<\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0435\u0449\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u043e\u0448\u0438\u0431\u043a\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441, \u0432\u044b\u0442\u0430\u0449\u0438\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u044b\u044f\u0441\u043d\u0438\u043c, \u043a\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0431\u044b\u043b\u0430 \u0443\u0442\u0435\u0440\u044f\u043d\u0430.\u00a0<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u0434 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0434\u043b\u044f SQL \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u0438 \u044f \u043c\u043e\u0433 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0443\u0447\u0435\u0441\u0442\u044c.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u0443\u044e  \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>getForeignKeyMessage<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>getForeignKeyMessage<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">private fun SupportSQLiteDatabase.getForeignKeyMessage(    sql: String,    args: List&lt;String>, ): String {    return when {        sql.isInsert || sql.isUpdate -> {            val tableName = getTableNameFromSqlQuery(sql) ?: return \"\"              getForeignKeyValueForInsertOrUpdate(                sql = sql,                args = args,                tableName = tableName,            )?.joinToString(\",\\n\") { (foreignKey, value) ->                \"FK Error ($tableName.${foreignKey.localColumn} -> \" +                    \"${foreignKey.foreignTable}.${foreignKey.foreignColumn})\\n\" +                    \"There is no field with ${foreignKey.foreignColumn}=${value} \" +                    \"in the ${foreignKey.foreignTable} table\"            }.orEmpty()        }          sql.isDelete -> {            val tableName = getTableNameFromSqlQuery(sql) ?: return \"\"              getForeignKeyValuesForDelete(                sql = sql,                args = args,                tableName = tableName,            )?.joinToString(\",\\n\") { (foreignKey, primaryKeyName, primaryKeyValue, value) ->                \"FK Error ($value.${foreignKey?.localColumn} -> \" +                    \"${foreignKey?.foreignTable}.${foreignKey?.foreignColumn})\\n\" +                    \"For $tableName.$primaryKeyName=$primaryKeyValue: it is not \" +                    \"possible to delete the field, because the \" +                    \"${foreignKey?.foreignTable}.${foreignKey?.foreignColumn} \" +                    \"is used in the table \\\"$value\\\"\"            }.orEmpty()        }          else -> \"\"    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f \u2014 <code>INSERT<\/code>, <code>UPDATE<\/code> \u0438\u043b\u0438 <code>DELETE<\/code>. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0445 \u043c\u0435\u0441\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.\u00a0<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0438\u0441\u043a\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f <code>INSERT<\/code> \u0438 <code>UPDATE<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0434\u043b\u044f <code>DELETE<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0430\u043b\u0438\u043c\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>getForeignKeyValueForInsertOrUpdate<\/code>. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d\u0430 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>getForeignKeyValueForInsertOrUpdate<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">private fun SupportSQLiteDatabase.getForeignKeyValueForInsertOrUpdate(    sql: String,    args: List&lt;String>,    tableName: String, ): List&lt;ForeignKeyInsertUpdate>? {    val foreignKeyList = queryForeignKeyList(tableName)      return foreignKeyList.mapNotNull { foreignKey ->        val value = getValuesFromUpdateAndInsertSqlQueryByColumnName(sql, args, foreignKey)          value?.let {            val cursor = query(                \"SELECT * FROM ${foreignKey.foreignTable} WHERE ${foreignKey.foreignColumn} = ?\",                arrayOf(value)            )              val isForeignKey = cursor.use { it.moveToFirst() }.not()              if (isForeignKey) {                ForeignKeyInsertUpdate(                    foreignKey = foreignKey,                    value = value,                )            } else {                null            }        }    }.ifEmpty { null } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u043d\u0435\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 <code>PRAGMA foreign_key_list(table_name)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438. \u041f\u043e\u0442\u043e\u043c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043b\u0430\u0434\u0451\u043c \u0432\u0441\u044e \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u0441\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043a\u0430\u043a\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443.\u00a0<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>getValuesFromUpdateOrInsertSqlQueryByColumnName.<\/code><\/p>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f <code>INSERT<\/code> \u0438\u043b\u0438 <code>UPDATE<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435&#8230;<\/p>\n<pre><code>INSERT OR REPLACE INTO `transactions`  (`id`,`bill_id`,`category_id`,`amount`,`date`,`comment`)  VALUES (1,2,3,10,0,NULL)<\/code><\/pre>\n<p>&#8230;\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f <code>bill_id<\/code> \u0438 <code>category_id<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044f\u043c\u0438 \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e \u0442\u0430\u043a\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430, \u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430 \u0435\u0441\u0442\u044c. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0443, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b47\/8d3\/f48\/b478d3f48f09fe7759533795f9796960.png\" width=\"1796\" height=\"1378\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b47\/8d3\/f48\/b478d3f48f09fe7759533795f9796960.png\"\/><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0438\u0441\u043a\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435. \u0417\u0430 \u044d\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>getForeignKeyValuesForDelete<\/code>. <\/p>\n<details class=\"spoiler\">\n<summary>getForeignKeyValuesForDelete<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">private fun SupportSQLiteDatabase.getForeignKeyValuesForDelete(    sql: String,    tableName: String,    args: List&lt;String>, ): List&lt;ForeignKeyDelete>? {      val foreignKeyList = findForeignKeysInAllTable(tableName)      if (sql.isDelete.not() || foreignKeyList.isEmpty()) return null      val primaryKeyName = queryPrimaryKeyName(tableName) ?: return null      val sqlWithArgs = formatSqlQuery(sql, args.toTypedArray())    val conditions = getConditionsFromSqlDeleteQuery(sql = sqlWithArgs)      val cursorWithDeleteConditions = query(        \"SELECT * FROM $tableName WHERE $conditions\"    )      val primaryKeyValues = mutableListOf&lt;String>()      cursorWithDeleteConditions.use {        while (it.moveToNext()) {            val primaryKeyIndex = it.getColumnIndex(primaryKeyName)            if (primaryKeyIndex != -1) {                primaryKeyValues += it.getString(primaryKeyIndex)            }        }    }      return primaryKeyValues.mapNotNull { primaryKeyValue ->        findForeignKeyCreateErrorsForDelete(            primaryKeyValue = primaryKeyValue,            foreignKeyList = foreignKeyList,            primaryKeyName = primaryKeyName,        )    }.flatten() } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0437\u0430\u043f\u0438\u0441\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u043e\u0442\u0438\u043c \u0443\u0434\u0430\u043b\u0438\u0442\u044c. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0433\u0434\u0435 \u0435\u0449\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u00a0\u0414\u0435\u043b\u0430\u0435\u043c \u043c\u044b \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>findForeignKeysInAllTable<\/code>:<\/p>\n<pre><code class=\"kotlin\">internal fun SupportSQLiteDatabase.findForeignKeysInAllTable(     foreignTable: String ): List&lt;ForeignKey> {    val tableNames = getAllTableNames()      val foreignKeysList = mutableListOf&lt;ForeignKey>()      for (name in tableNames) {        val foreignKeys = queryForeignKeyList(name)          foreignKeysList.addAll(            foreignKeys.filter { it.foreignTable == foreignTable }        )    }      return foreignKeysList } <\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u0442\u0430\u0431\u043b\u0438\u0446, \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0438 \u043a\u043b\u0430\u0434\u0451\u043c \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u043e\u0441\u043b\u0435 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c, \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0432 <code>SELECT<\/code>.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u0441\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442. \u0414\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>findForeignKeyCreateErrorsForDelete<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>findForeignKeyCreateErrorsForDelete<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">private fun SupportSQLiteDatabase.findForeignKeyCreateErrorsForDelete(    primaryKeyValue: String,    foreignKeyList: List&lt;ForeignKey>,    primaryKeyName: String ): List&lt;ForeignKeyDelete>? {    val result = mutableListOf&lt;ForeignKeyDelete>()       result += foreignKeyList.mapNotNull { foreignKey ->        val cursor = query(            \"SELECT * FROM ${foreignKey.localTable} WHERE ${foreignKey.localColumn} = ?\",            arrayOf(primaryKeyValue)        )          val isForeignKey = cursor.use { it.moveToFirst() }          if (isForeignKey) {            ForeignKeyDelete(                fk = foreignKey,                primaryKeyName = primaryKeyName,                primaryKeyValue = primaryKeyValue,                useTable = foreignKey.localTable,            )        } else {            null        }    }      return result.ifEmpty { null } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447, \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u043e\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435\u0433\u043e \u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430. \u0414\u0430\u043b\u0435\u0435 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>\u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a34\/fc6\/c2f\/a34fc6c2fa92a16359e0266a7f4808fe.png\" width=\"1418\" height=\"1420\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a34\/fc6\/c2f\/a34fc6c2fa92a16359e0266a7f4808fe.png\"\/><\/figure>\n<p><strong>\u041f\u043b\u044e\u0441\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u2014 \u043f\u043e \u0441\u0443\u0442\u0438, \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u0437\u0430\u0431\u044b\u043b, \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u043f\u0440\u043e\u0448\u043b\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u2014 \u043d\u043e\u0432\u044b\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u043e\u0448\u043b\u044b\u043c, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u043e\u0431\u0435\u0440\u0442\u043a\u0443.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>SQLiteOpenHelper<\/code> (\u0432 Room \u0438 <code>SqlDelight<\/code> \u0434\u043b\u044f Android-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041c\u0438\u043d\u0443\u0441\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0434\u043b\u044f SQLite, \u0447\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e. C \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e 1 \u0440\u0430\u0437. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u043d\u0430\u0448\u0435\u0433\u043e <a href=\"https:\/\/github.com\/ktsstudio\/android-fk-helper-sample\/tree\/main\/FKOpenHelper\">\u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0451 \u0435\u0449\u0451 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u042d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043e\u0431\u044a\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445<\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"6\" id=\"6\"><\/a><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438:<br \/><a href=\"https:\/\/github.com\/ktsstudio\/android-fk-helper-sample\">https:\/\/github.com\/ktsstudio\/android-fk-helper-sample<\/a>.\u00a0<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0434\u0432\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 SQLite. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u043d\u043e \u043d\u0430\u0448 \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 <code>SQLiteOpenHelper<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438 \u0438 \u043d\u0438\u0447\u0435\u043c \u043d\u0435 \u0443\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u043c \u043f\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a.\u00a0<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438 <code>Foreign Key<\/code>.\u00a0 \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0443, \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0438\u0445 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u043f\u043e\u0439\u0442\u0438 \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><\/p>\n<div class=\"tm-article-poll-container\"><!--[--><\/p>\n<div class=\"tm-article-poll tm-article-poll_variant-bordered\">\n<div class=\"tm-notice tm-notice_positive tm-article-poll__notice\"><!----><\/p>\n<div class=\"tm-notice__inner\"><!----><\/p>\n<div class=\"tm-notice__content\" data-test-id=\"notice-content\"><!--[--><span>\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a rel=\"nofollow\" href=\"\/kek\/v1\/auth\/habrahabr\/?back=\/ru\/companies\/kts\/articles\/798607\/&#038;hl=ru\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/span><!--]--><\/div>\n<\/div>\n<\/div>\n<p><!--[--><\/p>\n<div class=\"tm-article-poll__header\">\u041a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 FK-\u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438?<\/div>\n<div class=\"tm-article-poll__answers\"><!--[--><\/p>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">33.33% <\/span><span class=\"tm-article-poll__answer-label\">\u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/span><span class=\"tm-article-poll__answer-votes\">1<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 33.33%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">33.33% <\/span><span class=\"tm-article-poll__answer-label\">\u044d\u0442\u0443 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0431\u044d\u043a\u0435\u043d\u0434<\/span><span class=\"tm-article-poll__answer-votes\">1<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 33.33%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">0% <\/span><span class=\"tm-article-poll__answer-label\">\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c FK<\/span><span class=\"tm-article-poll__answer-votes\">0<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 0%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent tm-article-poll__answer-percent_winning\">33.33% <\/span><span class=\"tm-article-poll__answer-label\">\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0411\u0414<\/span><span class=\"tm-article-poll__answer-votes\">1<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress tm-article-poll__answer-progress_winning\" style=\"width: 33.33%\"><\/div>\n<\/div>\n<\/div>\n<p><!--]--><\/div>\n<div class=\"tm-article-poll__stats\"> \u041f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 3 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.    \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u043b\u0438\u0441\u044c 3 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. <\/div>\n<p><!--]--><\/div>\n<p><!--]--><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/798607\/\"> https:\/\/habr.com\/ru\/articles\/798607\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0422\u0438\u043c\u0443\u0440, \u044f Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 <a href=\"https:\/\/kts.tech\/\">KTS<\/a>.<\/p>\n<p>\u0421\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u044b\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 <code>Foreign Key<\/code> \u0432 SQLite \u0434\u043b\u044f Android? \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u043c \u0437\u0430\u0432\u0435\u0441\u0443 \u0442\u0430\u0439\u043d\u044b \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u043a \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"#1\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u00ab\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430\u00bb<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#2\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 Foreign Key \u0438 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0435\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#3\">\u0412 \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e \u043a\u043e\u043f\u0430\u043b\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#4\"><strong>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong> \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f SQLite-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#5\"><strong>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong> \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 SupportSQLiteOpenHelper \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#6\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h3>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u00ab\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430\u00bb<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 SQLite, \u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<ul>\n<li>\n<p>\u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0434\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u0445<\/p>\n<\/li>\n<li>\n<p>\u00ab\u043a\u0443\u0440\u0441\u044b\u00bb \u0434\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u0443\u0440\u0441\u0430\u0445<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u0435\u0441\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0443\u0434\u0435\u043d\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u0438\u043b\u0435\u0442\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0438 \u00ab\u043a\u0443\u0440\u0441\u044b\u00bb \u2014 \u0447\u0442\u043e\u0431\u044b \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b \u043d\u0430 \u043a\u0430\u043a\u0438\u0435 \u043a\u0443\u0440\u0441\u044b \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u00ab\u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u0443\u0440\u0441\u044b\u00bb.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Foreign Key \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u00ab\u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u0443\u0440\u0441\u044b\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 \u00ab\u0441\u0442\u0443\u0434\u0435\u043d\u0442\u044b\u00bb \u0438 \u00ab\u043a\u0443\u0440\u0441\u044b\u00bb .\u00a0<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0422\u0430\u043a \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u044c, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u00ab\u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430 \u043a\u0443\u0440\u0441\u044b\u00bb \u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u043a\u0443\u0440\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u0442 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u00ab\u0431\u0435\u0441\u0445\u043e\u0437\u043d\u044b\u0445\u00bb \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 Foreign Key \u0438 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0435\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/h3>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u043a\u043e\u043d\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u044b\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430 \u043a\u0443\u0440\u0441 \u0441\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u0442\u0447\u0438\u0441\u043b\u0438\u043b\u0438 (\u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b), \u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430 \u043a\u0443\u0440\u0441 \u0441 \u0442\u0430\u043a\u0438\u043c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0435\u0449\u0435 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c. <\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u0443\u0440\u0441 \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u0432 \u0411\u0414, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430. \u041f\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0441\u043a\u0430\u0434\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041d\u043e \u0432\u0441\u0435 \u043c\u044b \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u043a \u043d\u0430\u043c \u043f\u043e\u043f\u0430\u043b\u0438 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>\"transactions\"<\/code> \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432\u044b\u0437\u0432\u0430\u043b\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0431\u044d\u043a\u0435\u043d\u0434\u0435\u0440\u043e\u0432 \u0438\u043b\u0438 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u043f\u043e\u043d\u044f\u0442\u043d\u0443\u044e:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u0430\u043a\u043e\u043c\u0443 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u044b \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0443 \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0412\u0441\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0432 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u043a\u0430\u043a <a href=\"https:\/\/cases.kts.studio\/case_pik_mobile\">\u041f\u0418\u041a<\/a> \u0438 <a href=\"https:\/\/cases.kts.studio\/case_kleo_mobile\">Ascott Group<\/a>.\u00a0<\/p>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u0412 \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e \u043a\u043e\u043f\u0430\u043b\u0438<\/h3>\n<h4>\u041f\u043e\u0434\u043c\u0435\u043d\u0430 \/ \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0430\u0439\u0442 \u043a\u043e\u0434\u0430<\/h4>\n<p>\u041f\u0440\u043e \u043f\u0430\u0442\u0447\u0438\u043d\u0433 \u0431\u0430\u0439\u0442 \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/company\/sberbank\/blog\/685142\/\"><u>\u0432 \u0441\u0442\u0430\u0442\u044c\u0435<\/u><\/a>.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>visitMethod<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u0438\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 Room (insert, update \u0438 delete), \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u044b\u0437\u043e\u0432 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 Foreign Key \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438.\u00a0<\/p>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u2014 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<\/p>\n<p>\u041f\u043e \u0438\u0442\u043e\u0433\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438, \u0447\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0441\u043b\u043e\u043c\u0430\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0438 \u044d\u0442\u0443 \u043f\u043e\u043b\u043e\u043c\u043a\u0443 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u0442\u0430\u043b\u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f SQLite-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h3>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043d\u043e \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u0439\u043b\u0435\u0440\u043f\u043b\u0435\u0439\u0442\u0430. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041f\u043e\u0441\u043b\u0435 \u0441\u0442\u0430\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0435. \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u043f\u0440\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0443 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u043e, \u0431\u0435\u0437 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u0438\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u0438. \u041f\u043e\u043b\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/ktsstudio\/android-fk-helper-sample\">\u044d\u0442\u043e\u043c<\/a> \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u0451\u0440\u0442\u043a\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 <code>SQLiteConstraintException<\/code>. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442, \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0415\u0441\u0442\u044c \u043e\u0431\u0451\u0440\u0442\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>INSERT<\/code>, <code>UPDATE<\/code> \u0438 <code>DELETE<\/code>. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 <code>INSERT<\/code> \u0438 <code>UPDATE<\/code> \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439, \u0430 \u0432\u043e\u0442 \u0434\u043b\u044f <code>DELETE<\/code> \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>INSERT<\/code> \u0438 <code>UPDATE<\/code>. \u041e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f \u043d\u0438\u0445 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">suspend inline fun &lt;reified T : BaseEntity&lt;*>> FinanceDB.insertOrUpdateWithFKCheck(    itemsToInsert: List&lt;T>,    insertCallback: (items: List&lt;T>) -> Unit ) {    if (itemsToInsert.isEmpty()) return      checkFkException(        tryBlock = {            insertCallback(itemsToInsert)        },        catchFkExceptionBlock = {            getFkExceptionFormattingOnSave(                itemsToSave = itemsToInsert,                action = TableAction.INSERT,            )        }    ) } <\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>insertOrUpdateWithFKCheck<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u043e\u0439 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0438. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c <code>SQLiteConstraintException<\/code> \u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.\u00a0<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>checkFkException<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439:<\/p>\n<pre><code class=\"kotlin\">inline fun &lt;T : BaseEntity&lt;*>> checkFkException(       tryBlock: () -> Unit,       catchFkExceptionBlock: () -> FkExceptionFormattingInfo&lt;T>   ) {       try {           tryBlock()       } catch (sqliteException: SQLiteConstraintException) {           sqliteException.message               ?.lowercase(Locale.getDefault())               ?.takeIf { errorMessage -> FOREIGN_KEY_EXCEPTION_TEXT in errorMessage }               ?: throw sqliteException              val errorMessage = createFkExceptionErrorMessage(              messageInfo = catchFkExceptionBlock()         )           throw SQLiteConstraintException(errorMessage)       }   }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u043e\u0432\u0438\u0442 <code>SQLiteConstraintException<\/code>, \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0437\u0432\u0430\u043b\u043e \u043e\u0448\u0438\u0431\u043a\u0443. \u0421\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043b\u044f\u043c\u0431\u0434\u0430 <code>catchFkExceptionBlock<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0442\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u043a\u043b\u0430\u0434\u0451\u0442 \u0435\u0435 \u0432 <code>SQLiteConstraintException<\/code> \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043b\u044c\u0448\u0435.\u00a0<\/p>\n<p>\u0412 \u043b\u044f\u043c\u0431\u0434\u0435 <code>catchFkExceptionBlock<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>getFkExceptionFormattingOnSave<\/code>, \u043e\u043d\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>INSERT<\/code> \u0438 <code>UPDATE<\/code>. <\/p>\n<details class=\"spoiler\">\n<summary>getFkExceptionFormattingOnSave<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">suspend inline fun &lt;reified T : BaseEntity&lt;*>> Db.getFkExceptionFormattingOnSave(       itemsToSave: List&lt;T>,       action: TableAction,       apiQueryName: String? = null   ): FkExceptionFormattingInfo&lt;T> {       val entityInfo = itemsToSave.first()       val entityInfoToFkIds = mutableMapOf&lt;T, List&lt;Any>>()       val foreignKeyRelations = getForeignKeyRelationFor(entityInfo)          val errorItems = itemsToSave.filter { itemToInsert ->           foreignKeyRelations.all { fkRelation ->               val foreignKeyValue = fkRelation.childFkIdExtractor(itemToInsert) ?: return@all true               fkRelation.parentFkIds.contains(foreignKeyValue).not()                   .also { constraintFails ->                       if (constraintFails) {                           val constraintFailsList = entityInfoToFkIds[fkRelation.entityInfo]                               ?.toMutableList()                               ?.apply {                                   add(foreignKeyValue)                               } ?: listOf(foreignKeyValue)                           entityInfoToFkIds[fkRelation.entityInfo] = constraintFailsList                       }                   }           }       }          return FkExceptionFormattingInfo(           tableName = entityInfo.tableName,           action = action,           errorItems = errorItems,           entityInfoToFkIds = entityInfoToFkIds,           apiQueryName = apiQueryName       )   }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 <code>itemsToSave<\/code>, <code>action (INSERT, UPDATE)<\/code> \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0442\u0438\u043f\u043e\u043c \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430 <code>BaseEntity.<\/code><\/p>\n<p><code>BaseEntity<\/code> \u2014 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0438 \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043e\u0448\u0438\u0431\u043a\u0443 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438\u043c\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u0434\u0430\u043d\u043d\u044b\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c: \u0435\u0441\u0442\u044c \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043d \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0442, \u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043f\u0440\u0438\u0447\u0438\u043d\u0443, \u043a\u043b\u0430\u0434\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <code>FkExceptionFormattingInfo<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.\u00a0<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0414\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e id, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0435\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0432\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435, \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u044f\u043c \u0441 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0431\u0435\u0440\u0451\u043c \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0443\u0441\u0442\u044b\u0435: \u0432 \u043d\u0438\u0445 \u0435\u0449\u0451 \u0435\u0441\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430. \u0414\u0430\u043b\u044c\u0448\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435, \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0434\u043b\u044f <code>INSERT<\/code> \u0438 <code>UPDATE<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">suspend inline fun &lt;reified T : BaseEntity&lt;*>> Db.deleteWithFKCheck(     itemIdsToDelete: List&lt;Long>,     deleteCallback: (items: List&lt;Long>) -> Unit ) {     if (itemIdsToDelete.isEmpty()) return     checkFkException(         tryBlock = {             batchedQueryInTransaction(                 list = itemIdsToDelete,                 query = deleteCallback             )         },         catchFkExceptionBlock = {             val items = getItemsByIds&lt;T>(itemIdsToDelete)             val entityInfo = items.first()             val entityInfoToFkIds = mutableMapOf&lt;BaseEntity&lt;*>, List&lt;Any>>()             val entityRelations: List&lt;Relations&lt;T>> = itemIdsToDelete.queryWithParameterCountCheck { ids ->                 getEntityRelationByIds&lt;T>(ids) as List&lt;Relations&lt;T>>             }              val errorItems = entityRelations.filter { entityRelation ->                 entityRelation.embeddedConstraintsEmpty().not()                     .also { constraintFails ->                         if (constraintFails) {                          <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-370187","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=370187"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370187\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}