{"id":761,"date":"2012-08-21T15:35:42","date_gmt":"2012-08-21T13:35:42","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=761"},"modified":"2017-03-13T09:17:21","modified_gmt":"2017-03-13T08:17:21","slug":"ibm-doors-dxl-microsoft-sql-server-bibliothek-library","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=761","title":{"rendered":"IBM Doors DXL: How-to access Microsoft SQL Server &#038; Microsoft Access from DXL (eine Bibliothek f\u00fcr SQL Statements \/ a library to perform sql statements)"},"content":{"rendered":"<h1>Aufgabenstellung &#8212; Problem<\/h1>\n<p>Es wird eine einfache Bibliothek ben\u00f6tigt um SELECT Statements auf eine Microsoft SQL Server Datenbank abzusetzen und diese in einem DXL Programm zu verwenden<br \/>\n&#8212;<br \/>\nA library is needed for easily creating SQL Statements with result sets. This library should be embeddable in a DXL Skript.<\/p>\n<h1>Ansatz &#8212; Approach<\/h1>\n<p>Die Bibliothek wird von Capri-Soft (Bj\u00f6rn Karpenstein) st\u00e4ndig weiterentwickelt und an dieser Stelle mit regelm\u00e4\u00dfigen Updates zur Verf\u00fcgung gestellt.<br \/>\n&#8212;<br \/>\nThe library will be provided on this site with frequently updates and can be downloaded at this site.<\/p>\n<h1>L\u00f6sung &#8212; Solution<\/h1>\n<h2>Implemented Functions<\/h2>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nSkip selectStatement(string sql, string dbServer, string dbName, string dbUsername, string dbPassword)\r\nSkip selectStatementOnMDB(string sql, string mdbFile) &#x5B;since Version 0.3]\r\nArray selectStatement(string sql, string dbServer, string dbName, string dbUsername, string dbPassword)\r\nArray selectStatementOnMDB(string sql, string mdbFile)  &#x5B;since Version 0.3]\r\nint executeQuery(string sql, string dbServer, string dbName, string dbUsername, string dbPassword)\r\nint executeQueryOnMDB(string sql, string mdbFile)  &#x5B;since Version 0.3]\r\nOleAutoObj openDatabase(string dbServer, string dbName, string dbUsername, string dbPassword)\r\nOleAutoObj openDatabaseOnMDB(string mdbFile)  &#x5B;since Version 0.3]\r\n<\/pre>\n<h2>Download<\/h2>\n<p>First download the DXL-Library here&#8230;<\/p>\n<p><a href=\"https:\/\/www.capri-soft.de\/blog\/?attachment_id=2226\" rel=\"attachment wp-att-2226\">sqllibrary.dxl &#8212; Version 0.3 [match filename the includes of the examples!!!]<\/a><br \/>\n<a href='https:\/\/www.capri-soft.de\/blog\/wp-content\/uploads\/2012\/08\/sqlserverlibrary1.zip'>sqlserverlibrary.dxl &#8212; Version 0.2<\/a><br \/>\n<a href='https:\/\/www.capri-soft.de\/blog\/wp-content\/uploads\/2012\/08\/sqlserverlibrary.zip'>sqlserverlibrary.dxl &#8212; Version 0.1<\/a><\/p>\n<h2>Create your DXL Skript in Doors<\/h2>\n<p>Recommendation: When you are writing your SQL Statements, use the CAST-Method every time you define a Field in the SELECT-Clause. <\/p>\n<h3>Eample for Version 0.3 with MS Access Support<\/h3>\n<p>In this example (only works since version 0.3) you can access .mdb Files like in the following example:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n#include &quot;C:\\\\dev\\\\dxl\\\\client\\\\sqllibrary.dxl&quot;;\r\n\r\n\r\nSkip result = selectStatementOnMDB(&quot;SELECT &#x5B;Connector_ID], &#x5B;Connector_Type], &#x5B;Btm_Mid_Label], &#x5B;Stereotype]  FROM q_connector&quot;, &quot;\\\\\\\\bbmag295\\\\ProcessModellingPrototypeAdvanced\\\\mdb\\\\modell.eap&quot;);\r\n\t\t\t\t\r\n\/\/ Iteration through the SkipList\r\nfor myIterator in result do \r\n{\r\n   string keyValue = (string key(result));\r\n   DxlObject currentObject = null;\r\n\r\n   if(find(result, keyValue, currentObject))\r\n   {\r\n       \/\/ Just put the column names here.. it will work\r\n       print (string currentObject-&gt;&quot;Connector_ID&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;Connector_Type&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;Btm_Mid_Label&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;Stereotype&quot;) &quot;\\n&quot;;\r\n   }\r\n}\r\n\r\ndelete result;\r\n\r\n<\/pre>\n<p>Example:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nstring customFieldSQL= &quot;&quot; \/\/-\r\n&quot; SELECT  CAST(pk.PROJECT_KEY+&#039;-&#039;+CAST(ji.issuenum as VARCHAR(7)) as varchar(10)) as pkey,  &quot; \/\/-\r\n&quot;\t     CAST(convert(char, cg.created, 120) as varchar(30)) as on_date, &quot; \/\/-\r\n&quot;\t\t CAST(ci.field as varchar(50)), &quot; \/\/-\r\n&quot;\t\t CAST(cg.author as varchar(10)) as changed_by, &quot; \/\/-\r\n&quot;\t\t CAST(ISNULL(ci.oldstring,&#039;&#039;) as varchar(4096)) as changed_from,  &quot; \/\/-\r\n&quot;\t\t CAST(ISNULL(ci.newstring,&#039;&#039;) as varchar(4096)) as changed_to &quot; \/\/-\r\n&quot; FROM jiraissue ji, changegroup cg, changeitem ci, project_key pk &quot; \/\/-\r\n&quot; WHERE ci.groupid = cg.id &quot; \/\/-\r\n&quot; AND cg.issueid = ji.id  &quot; \/\/-\r\n&quot; AND pk.PROJECT_ID=ji.PROJECT &quot; \/\/-\r\n&quot; AND ci.field = &#039;&quot; customField &quot;&#039; &quot; \r\n<\/pre>\n<h3>Examples for Version 0.2<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n#include &quot;sqlserverlibrary.dxl&quot;; \/\/ renamed to sqllibrary since version 0.3\r\n\r\n\/\/ Here you can define your connection setting\r\nstring dbServer=&quot;IPorSERVERNAME&quot;;\r\nstring dbName=&quot;Databasename&quot;;\r\nstring dbUsername=&quot;databaseuser&quot;;\r\nstring dbPassword=&quot;databasepasswort&quot;;\r\n\r\n\/\/ Reduce methods only to get SQL \r\nSkip selectStatement(string sql) \r\n{\treturn selectStatement(sql,dbServer,dbName,dbUsername,dbPassword); }\r\nArray selectStatement(string sql) \r\n{\treturn selectStatement(sql,dbServer,dbName,dbUsername,dbPassword); }\r\nint executeQuery(string sql) \r\n{ return executeQuery(sql,dbServer,dbName,dbUsername,dbPassword); }\r\n\r\n\/\/ A manipulation like INSERT\/UPDATE\/DELETE\r\nexecuteQuery(&quot;INSERT INTO table(col1) VALUES(&#039;TEST&#039;)&quot;);\r\n\r\n\/\/ SKIPLIST: SELECT statement will return a SKIP-List with \r\n\/\/           dynamic attributes (KEY is first column) \r\nSkip result = \/\/-\r\nselectStatement(&quot;SELECT &#x5B;id], &#x5B;col1], &#x5B;col2], &#x5B;col3], &quot; \/\/-\r\n\t\t\t    &quot;&#x5B;col4], &#x5B;col5], &#x5B;col6] &quot; \/\/-\r\n\t\t\t\t&quot;FROM table &quot; \/\/-\r\n\t\t\t\t&quot;WHERE col1&lt;&gt;&#039;TEST&#039; ORDER BY id ASC&quot;);\r\n\t\t\t\t\r\n\/\/ Iteration through the SkipList\r\nfor myIterator in result do \r\n{\r\n   string keyValue = (string key(result));\r\n   DxlObject currentObject = null;\r\n\r\n   if(find(result, keyValue, currentObject))\r\n   {\r\n       \/\/ Just put the column names here.. it will work\r\n       print (string currentObject-&gt;&quot;id&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;col1&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;col2&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;col3&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;col4&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;col5&quot;) &quot;\\t&quot;;\r\n       print (string currentObject-&gt;&quot;col6&quot;) &quot;\\n&quot;;\r\n   }\r\n}\r\n\r\ndelete result;\r\n\r\n\/\/ Array: SELECT statement will return an  Array \r\nArray result2 = selectStatement(&quot;SELECT &#x5B;id], &#x5B;col1], &#x5B;col2], &quot; \/\/-\r\n\t\t\t\t&quot;&#x5B;col3], &#x5B;col4], &#x5B;col5], &#x5B;col6] &quot; \/\/-\r\n\t\t\t\t&quot;FROM table &quot; \/\/-\r\n\t\t\t\t&quot;WHERE col1&lt;&gt;&#039;TEST&#039; ORDER BY id ASC&quot;);\r\n\r\nint i;\r\nfor (i=0; i&lt;resultCount; i++)\r\n{\r\n   DxlObject currentObject2 = (DxlObject get(result2,i,1));\r\n   \r\n   if(!null(currentObject2))\r\n   {\r\n       \/\/ Just put the column names here.. it will work\r\n       print (string currentObject2-&gt;&quot;id&quot;) &quot;\\t&quot;;\r\n       print (string currentObject2-&gt;&quot;col1&quot;) &quot;\\t&quot;;\r\n       print (string currentObject2-&gt;&quot;col2&quot;) &quot;\\t&quot;;\r\n       print (string currentObject2-&gt;&quot;col3&quot;) &quot;\\t&quot;;\r\n       print (string currentObject2-&gt;&quot;col4&quot;) &quot;\\t&quot;;\r\n       print (string currentObject2-&gt;&quot;col5&quot;) &quot;\\t&quot;;\r\n       print (string currentObject2-&gt;&quot;col6&quot;) &quot;\\n&quot;;\r\n   }\r\n}\r\n\r\ndelete result2;\r\n\r\n<\/pre>\n<h3>Example for Version 0.1<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n#include &quot;sqlserverlibrary.dxl&quot;; \/\/ renamed to sqllibrary since version 0.3\r\n\r\n\/\/ Here you can define your connection setting\r\nSkip selectStatement(string sql)\r\n{\r\n\t\/\/ Connection details for test\r\n\tstring dbServer=&quot;DATABASE_SERVER_OR_IP&quot;;\r\n\tstring dbName=&quot;DATABASE_NAME&quot;;\r\n\tstring dbUsername=&quot;DATABASE_USER&quot;;\r\n\tstring dbPassword=&quot;DATABASE_PASSWORD&quot;;\r\n\r\n\treturn selectStatement(sql,dbServer,dbName,dbUsername,dbPassword);\r\n}\r\n\r\n\/\/ selectStatement will return a SKIP-List with dynamic attributes\r\nSkip result = \/\/-\r\nselectStatement( \/\/-\r\n&quot;SELECT col1,col2,col3,col4,col5,col6 &quot; \/\/-\r\n\t\t\t&quot;FROM table &quot; \/\/-\r\n\t\t\t&quot;WHERE col1 &quot; \/\/-\r\n\t\t\t&quot; NOT IN ( &quot; \/\/-\r\n\t\t\t&quot;\tSELECT col1 &quot; \/\/-\r\n\t\t\t&quot;\tFROM table &quot; \/\/-\r\n\t\t\t&quot; \tWHERE LTRIM(RTRIM(col1))&lt;&gt;&#039;---&#039; &quot; \/\/-\r\n\t\t\t&quot;   GROUP BY alarm_id &quot; \/\/-\r\n\t\t\t&quot;\tHAVING COUNT(*)&gt;1 &quot; \/\/-\r\n\t\t\t&quot;\t) &quot;)\r\n\t\t\t\t\r\n\/\/ Iteration durch SkipList\r\nfor myIterator in result do \r\n{\r\n   string keyValue = (string key(result));\r\n   DxlObject currentObject = null;\r\n\r\n   if(find(result, keyValue, currentObject))\r\n   {\r\n       \/\/ Just put the column names here.. it will work\r\n       print (string currentObject-&gt;&quot;col1&quot;) &quot; &quot;;\r\n       print (string currentObject-&gt;&quot;col2&quot;) &quot; &quot;;\r\n       print (string currentObject-&gt;&quot;col3&quot;) &quot; &quot;;\r\n       print (string currentObject-&gt;&quot;col4&quot;) &quot; &quot;;\r\n       print (string currentObject-&gt;&quot;col5&quot;) &quot; &quot;;\r\n       print (string currentObject-&gt;&quot;col6&quot;) &quot;\\n&quot;;\r\n   }\r\n}\r\n\r\ndelete result;\r\n<\/pre>\n<h1>Comment<\/h1>\n<p>Don&#8217;t forget to leave some improvement comments here!!!<\/p>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D761&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Aufgabenstellung &#8212; Problem Es wird eine einfache Bibliothek ben\u00f6tigt um SELECT Statements auf eine Microsoft SQL Server Datenbank abzusetzen und diese in einem DXL Programm zu verwenden &#8212; A library is needed for easily creating SQL Statements with result sets. This library should be embeddable in a DXL Skript. Ansatz &#8212; Approach Die Bibliothek wird &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=761\" class=\"more-link\"><span class=\"screen-reader-text\">IBM Doors DXL: How-to access Microsoft SQL Server &#038; Microsoft Access from DXL (eine Bibliothek f\u00fcr SQL Statements \/ a library to perform sql statements)<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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},"jetpack_post_was_ever_published":false},"categories":[22,19,11],"tags":[],"class_list":["post-761","post","type-post","status-publish","format-standard","hentry","category-dxl","category-ibm-doors","category-ms-sql-server"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-ch","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=761"}],"version-history":[{"count":12,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions"}],"predecessor-version":[{"id":2229,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions\/2229"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}