{"id":5834,"date":"2013-02-01T17:51:26","date_gmt":"2013-02-01T08:51:26","guid":{"rendered":"http:\/\/www.gesource.jp\/weblog\/?p=5834"},"modified":"2017-07-16T10:37:52","modified_gmt":"2017-07-16T01:37:52","slug":"%e3%83%88%e3%83%a9%e3%83%b3%e3%82%b6%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e5%87%a6%e7%90%86%e3%82%92%e7%b0%a1%e6%bd%94%e3%81%ab%e6%9b%b8%e3%81%91%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%97","status":"publish","type":"post","link":"https:\/\/www.gesource.jp\/weblog\/?p=5834","title":{"rendered":"\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u51e6\u7406\u3092\u7c21\u6f54\u306b\u66f8\u3051\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u305f"},"content":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u3001\u30a8\u30e9\u30fc\u304c\u306a\u3051\u308c\u3070\u30b3\u30df\u30c3\u30c8\u3001\u30a8\u30e9\u30fc\u304c\u3042\u308c\u3070\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3068\u3044\u3046\u51e6\u7406\u304c\u983b\u7e41\u306b\u898b\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u305f\u3044\u3066\u3044\u306f\u6b21\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code>var\n  transaction: TDBXTransaction;\nbegin\n  \/\/\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u958b\u59cb\u3059\u308b\n  transaction := SQLConnection1.BeginTransaction;\n  try\n    \/\/SQL\u3092\u5b9f\u884c\u3059\u308b\n    SQLConnection1.Execute('insert into \u2026');\n    \/\/\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u30b3\u30df\u30c3\u30c8\u3059\u308b\n    SQLConnection1.CommitFreeAndNil(transaction);\n  except\n    \/\/\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3059\u308b\n    SQLConnection1.RollbackFreeAndNil(transaction);\n    raise;\n  end;\nend;\n<\/code><\/pre>\n<p>\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306e\u30b3\u30fc\u30c9\u306f\u3001SQL\u3092\u5b9f\u884c\u3059\u308b\u7b87\u6240\u4ee5\u5916\u306f\u540c\u3058\u51e6\u7406\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u305d\u3053\u3067\u5171\u901a\u90e8\u5206\u3092\u307e\u3068\u3081\u3066\u3001\u6b21\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><code>begin\n  FTransactor.Perform(procedure\n  begin\n    SQLConnection1.Execute('insert into \u2026');\n  end);\nend;\n<\/code><\/pre>\n<p>SQL\u3092\u5b9f\u884c\u3059\u308b\u90e8\u5206\u306e\u30b3\u30fc\u30c9\u3092\u7121\u540d\u95a2\u6570\u3067\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\n\u7121\u540d\u95a2\u6570\u3092\u6e21\u305b\u308b\u3088\u3046\u306b\u3059\u308b\u3068\u3001\u81ea\u7531\u5ea6\u304c\u9ad8\u304f\u3066\u4f7f\u3044\u52dd\u624b\u304c\u3088\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>FTransactor\u306fTTransactor\u578b\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3067\u3059\u3002<br \/>\nTTransactor\u578b\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code>type\n  TTransactor = record\n    FSQLConnection: TSQLConnection;\n    constructor Create(SQLConnection: TSQLConnection);\n    procedure Perform(Proc: TProc);\n  end;\n<\/code><\/pre>\n<p>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u5f15\u6570\u3067TSQLConnection\u3092\u6e21\u3057\u307e\u3059\u3002<\/p>\n<pre><code>constructor TTransactor.Create(SQLConnection: TSQLConnection);\nbegin\n  FSQLConnection := SQLConnection;\nend;\n<\/code><\/pre>\n<p>\u30d5\u30a9\u30fc\u30e0\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306f\u3001FTransactor\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>procedure TForm1.FormCreate(Sender: TObject);\nbegin\n  FTransactor := TTransactor.Create(SQLConnection1);\nend;\n<\/code><\/pre>\n<p>\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u30b3\u30df\u30c3\u30c8\u30fb\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u884c\u3046Perform\u30e1\u30bd\u30c3\u30c9\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code>procedure TTransactor.Perform(Proc: TProc);\nvar\n  transaction: TDBXTransaction;\nbegin\n  transaction := FSQLConnection.BeginTransaction;\n  try\n    Proc;\n    FSQLConnection.CommitFreeAndNil(transaction);\n  except\n    FSQLConnection.RollbackFreeAndNil(transaction);\n    raise;\n  end;\nend;\n<\/code><\/pre>\n<p>\u5f15\u6570Proc\u3067\u7121\u540d\u95a2\u6570\u3092\u53d7\u3051\u53d6\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u7121\u540d\u95a2\u6570\u306f\u4fbf\u5229\u3067\u3059\u306d\u3002<\/p>\n<p>\u3053\u306eTTransactor\u578b\u306f\u300e<a href=\"http:\/\/www.amazon.co.jp\/gp\/product\/4798124583\/ref=as_li_ss_tl?ie=UTF8&amp;camp=247&amp;creative=7399&amp;creativeASIN=4798124583&amp;linkCode=as2&amp;tag=gesource-22\">\u5b9f\u8df5\u30c6\u30b9\u30c8\u99c6\u52d5\u958b\u767a \u30c6\u30b9\u30c8\u306b\u5c0e\u304b\u308c\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u3092\u80b2\u3066\u308b<\/a>\u300f\u3067Java\u3067\u66f8\u304b\u308c\u3066\u3044\u305f\u30b3\u30fc\u30c9\u3092\u53c2\u8003\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u3001\u30a8\u30e9\u30fc\u304c\u306a\u3051\u308c\u3070\u30b3\u30df\u30c3\u30c8\u3001\u30a8\u30e9\u30fc\u304c\u3042\u308c\u3070\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3068\u3044\u3046\u51e6\u7406\u304c\u983b\u7e41\u306b\u898b\u3089\u308c\u307e\u3059\u3002 \u305f\u3044\u3066\u3044\u306f\u6b21\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002 var transaction: TDBXTransactio &#8230;<\/p>\n<p><a href=\"https:\/\/www.gesource.jp\/weblog\/?p=5834\" class=\"more-link\">Continue reading &lsquo;\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u51e6\u7406\u3092\u7c21\u6f54\u306b\u66f8\u3051\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u305f&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[48],"tags":[156],"class_list":["post-5834","post","type-post","status-publish","format-standard","hentry","category-delphi","tag-delphi"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/5834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5834"}],"version-history":[{"count":0,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/5834\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}