Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / week_2012_02_12.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
4 <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6    <meta name="generator" content="Movable Type 5.2.3" />
7
8    <link rel="stylesheet" href="http://defaria.com/blogs/Status/styles-site.css" type="text/css" />
9    <link rel="alternate" type="application/atom+xml" title="Atom" href="http://defaria.com/blogs/Status/atom.xml" />
10    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://defaria.com/blogs/Status/index.xml"$>" />
11
12    <title>Status for Andrew DeFaria: February 12, 2012 - February 18, 2012 Archives</title>
13
14    <link rel="start" href="http://defaria.com/blogs/Status/" title="Home" />
15    <link rel="prev" href="http://defaria.com/blogs/Status/archives/week_2012_01_22.html" title="January 22, 2012 - January 28, 2012" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/week_2012_04_08.html" title="April  8, 2012 - April 14, 2012" />
17 </head>
18 <body class="layout-one-column">
19    <div id="container">
20       <div id="container-inner" class="pkg">
21
22          <div id="banner">
23             <div id="banner-inner" class="pkg">
24                <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
25                <h2 id="banner-description">Searchable status reports and work log</h2>
26             </div>
27          </div>
28
29          <div id="pagebody">
30             <div id="pagebody-inner" class="pkg">
31                <div id="alpha">
32                   <div id="alpha-inner" class="pkg">
33                      
34                      <p class="content-nav">
35                         <a href="http://defaria.com/blogs/Status/archives/week_2012_01_22.html">&laquo; January 22, 2012 - January 28, 2012</a> |
36                         <a href="http://defaria.com/blogs/Status/">Main</a>
37                         | <a href="http://defaria.com/blogs/Status/archives/week_2012_04_08.html">April  8, 2012 - April 14, 2012 &raquo;</a>
38                      </p>
39                      
40                      
41                      <!--
42 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
43          xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
44          xmlns:dc="http://purl.org/dc/elements/1.1/">
45 <rdf:Description
46     rdf:about="http://defaria.com/blogs/Status/archives/week_2012_02_12.html#entry-000750"
47     trackback:ping="http://defaria.com/mt/mt-tb.cgi/114"
48     dc:title="Using PDSQL to update Clearquest databases"
49     dc:identifier="http://defaria.com/blogs/Status/archives/week_2012_02_12.html#entry-000750"
50     dc:subject="Broadcom"
51     dc:description="Using PDSQL to update Clearquest databases Often when you add a new field to a Clearquest database you need to tackle the problem of how to update or set the value on all of your old records. Often specialized scripts..."
52     dc:creator=""
53     dc:date="2012-02-13T15:10:03-06:00" />
54 </rdf:RDF>
55 -->
56
57
58                      <h2 class="date-header">February 13, 2012</h2>
59                      <a id="a000750"></a>
60                      <div class="entry" id="entry-750">
61                         <h3 class="entry-header">Using PDSQL to update Clearquest databases</h3>
62                         <div class="entry-content">
63                            <div class="entry-body">
64                               <h2>Using PDSQL to update Clearquest databases</h2>
65
66 <p>Often when you add a new field to a Clearquest database you need to tackle the problem of how to update or set the value on all of your old records. Often specialized scripts are created to say set the new field to some known value in all of the older records by using the Clearquest API. This takes time to write such scripts and it takes time to run because all of the action hook code needs to be executed to validate the record, etc. Often this is needless rechecking of already correct values of all of the fields in the record. Updates of this kind can take literally hours to process large numbers of records and have all of that action hook code run for no particular reason.</p>
67
68 <p>There is a utility in C:\Program Files\IBM\RationalSDLC\ClearQuest named pdsql. It provides a command line interface to the database directly which you can use to perform updates of fields in a lightning fast manner. The updating of all defect records setting a new field to say "foo" would take literally hours using the Clearquest API but less than a second or two in pdsql.</p>
69                               
70                               <h3>Running PDSQL</h3>
71
72 <p>You should have C:\Program Files\IBM\RationalSDLC\ClearQuest in your PATH. When you start up pdsql you need to specify a lot of parameters to connect to the database. Remember you are talking to the database so you must use the true database name, not the Clearquest database name. You can use pdsql -help to see the help usage but usually you'll specify the following parameters:</p>
73
74 <div class=code><pre>
75 $ pdsql -u &lt;username&gt; -p &lt;password&gt; -v ss -s &lt;server&gt; -db &lt;database&gt;
76 </pre></div>
77
78 <p>Note that the username (-u) is the database username. Also the -db is the database name not the Clearquest database name. The -v ss stands for SQLServer and -s is the server name. for ease I have a simply Bash script to get into pdsql that I've named cqsql.sh:</p>
79
80 <div class=code><pre>
81 Ltsdo-adefaria:cat /mcsi/scm_tools/cq/cqsql.sh
82 #!/bin/bash
83 if [ $# -ne 1 ]; then
84   echo "Usage: cqsql <db>"
85   exit 1
86 fi
87  
88 if [ -n "$(type -p rlwrap)" ]; then
89   rlwrap=rlwrap
90 fi
91  
92 $rlwrap pdsql -u &lt;username&gt; -p &lt;password&gt; -v ss -s &lt;server&gt; -db $1
93 </pre></div>
94
95 <p>Once in pdsql you can issue SQL statements. Note that ';' is required to terminate all commands - even quit! Also note there is no command line history and very poor editing. If, for example, you forget and do say an up arrow you have put unprintable characters in your command line and your command will fail. If you use Cygwin and have installed the wonderful utility rlwrap (readline wrap) then you will have a full, bash like command history which is extremely useful!</p>
96
97 <h3>Issuing SQL commands</h3>
98
99 <p>Remember, you are talking to the back end database directly so all field names will be the database field names shown in Clearquest Designer - not the field names that Clearquest users use. Some useful, non SQL commands are tables; and columns <tablename>;. These commands show the table names in the database and the columns in the a particular table.</p>
100
101 <p>Most standard SQL commands work as expected. Here is an example session where I used pdsql to set Reproducible to the string "NO" if it was previously NULL (New short strings are set to NULL when a field is added to a record).</p>
102
103 <div class=code><pre>
104 >select count(*) from defect where reproducible is not null;
105  
106    <EXPR-1>
107          11
108  
109 >select reproducible from defect where reproducible is not null;
110  
111                            reproducible
112                                                 NO
113                                                 NO
114                                                 NO
115                                                 NO
116                                                 NO
117                                                 NO
118                                                 NO
119                                                 NO
120                                                 NO
121                                                 NO
122                                                 NO
123                                                YES
124  
125 >update defect set reproducible = 'NO' where reproducible  is null;
126 93326 rows affected.
127 >
128 </pre></div>
129
130 <p>I used to the count(*) syntax to determine how many of the defect records had reproducible not set to NULL. These would be from any new records created since the action hook code makes sure to set this field to either "YES" or "NO". It's the old records we need to set to "NO" if they were NULL. Since there were only 11 records that were not null I decided to see what they contained. Good, they contain what I expect - "NO"'s and "YES"'s only. Then the simple update command to set reproducible = 'NO' if it was null. This command took a second or two to update 93326 defects!</p>
131
132 <h3>Setting a reference field</h3>
133
134 <p>When you look into the database directly you start learning how Clearquest does some of its magic. For a reference field one does not see the key to the reference field in textual form rather one sees an integer field, a dbid. Records have a dbid which allows direct access to the particular record. This way if the textual representation of the key (i.e. Name in the Certification stateless record as shown here) you only need update one record instead of potentially thousands of referenced records.</p>
135
136 <p>So then how do you change a reference field? The trick is to find the dbid for that stateless record and plop it into the record that references it. Unfortunately, when the stateless record Certification was created its internal table name was never changed from the default "new1" so we need to use the database name for this table - new1. We select the fields for new1 to reveal that 35541127 is the dbid for the "N/A" record in Certification. We then do a small test changing only one record - DB00031023 - carriercertification reference from 0 -> 35541127. Next I checked that this defect (DB00031023) had a Certification of "N/A" in the Clearquest client. It did. So I know this method works.</p>
137
138 <div class=code><pre>
139 >select * from new1;
140  
141        dbid   is_active     version lock_version   locked_by ratl_mastership ratl_keysite          name
142           0        NULL           1            0           0               0            0          NULL
143    35541119           1           1            0           0        16777313     16777313          Grade A
144    35541121           1           1            0           0        16777313     16777313          Grade B
145    35541123           1           1            0           0        16777313     16777313          Grade C
146    35541125           1           1            0           0        16777313     16777313          Grade D
147    35541127           1           1            0           0        16777313     16777313          N/A
148  
149 >select certification from defect where id='DB00031023';
150  
151 certification
152                    0
153  
154 >update defect set certification=35541127 where id='DB00031023';
155 1 rows affected.
156  
157 >select id from defect where id='DB00031024' and certification = 0;
158  
159            id
160 DB00031024
161  
162  
163 >select id from defect where id='DB00031024' and certification = 1;
164  
165            id
166  
167 >select count(*) from defect;
168    <EXPR-1>
169       93407
170  
171 >select count(*) from defect where certification = 0;
172    <EXPR-1>
173       93026
174  
175 >update defect set certification = 35541127 where certification= 0;
176 93025 rows affected.
177 </pre></div>
178                               
179                               <p class="entry-footer">
180                                  <span class="post-footers">Posted by  at  3:10 PM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000750.html">Permalink</a>
181                                  
182                                  | <a href="http://defaria.com/blogs/Status/archives/000750.html#trackback">TrackBacks (0)</a>
183                               </p>
184                            </div>
185                         </div>
186                      </div>
187                      
188                   </div>
189                </div>
190             </div>
191          </div>
192       </div>
193    </div>
194 </body>
195 </html>