Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / 000750.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: Using PDSQL to update Clearquest databases</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/000749.html" title="Outlook Top Posting" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/000751.html" title="Perl::Critic" />
17
18    <!--
19 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20          xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
21          xmlns:dc="http://purl.org/dc/elements/1.1/">
22 <rdf:Description
23     rdf:about="http://defaria.com/blogs/Status/archives/000750.html"
24     trackback:ping="http://defaria.com/mt/mt-tb.cgi/114"
25     dc:title="Using PDSQL to update Clearquest databases"
26     dc:identifier="http://defaria.com/blogs/Status/archives/000750.html"
27     dc:subject="Broadcom"
28     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..."
29     dc:creator=""
30     dc:date="2012-02-13T15:10:03-06:00" />
31 </rdf:RDF>
32 -->
33
34
35    
36
37    <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
38 </head>
39 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
40    <div id="container">
41       <div id="container-inner" class="pkg">
42
43          <div id="banner">
44             <div id="banner-inner" class="pkg">
45                <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
46                <h2 id="banner-description">Searchable status reports and work log</h2>
47             </div>
48          </div>
49
50          <div id="pagebody">
51             <div id="pagebody-inner" class="pkg">
52                <div id="alpha">
53                   <div id="alpha-inner" class="pkg">
54
55                      <p class="content-nav">
56                         <a href="http://defaria.com/blogs/Status/archives/000749.html">&laquo; Outlook Top Posting</a> |
57                         <a href="http://defaria.com/blogs/Status/">Main</a>
58                         | <a href="http://defaria.com/blogs/Status/archives/000751.html">Perl::Critic &raquo;</a>
59                      </p>
60
61                      <a id="a000750"></a>
62                      <div class="entry" id="entry-750">
63                         <h3 class="entry-header">Using PDSQL to update Clearquest databases</h3>
64                         <div class="entry-content">
65                            <div class="entry-body">
66                               <h2>Using PDSQL to update Clearquest databases</h2>
67
68 <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>
69
70 <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>
71                            </div>
72                            <div id="more" class="entry-more">
73                               <h3>Running PDSQL</h3>
74
75 <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>
76
77 <div class=code><pre>
78 $ pdsql -u &lt;username&gt; -p &lt;password&gt; -v ss -s &lt;server&gt; -db &lt;database&gt;
79 </pre></div>
80
81 <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>
82
83 <div class=code><pre>
84 Ltsdo-adefaria:cat /mcsi/scm_tools/cq/cqsql.sh
85 #!/bin/bash
86 if [ $# -ne 1 ]; then
87   echo "Usage: cqsql <db>"
88   exit 1
89 fi
90  
91 if [ -n "$(type -p rlwrap)" ]; then
92   rlwrap=rlwrap
93 fi
94  
95 $rlwrap pdsql -u &lt;username&gt; -p &lt;password&gt; -v ss -s &lt;server&gt; -db $1
96 </pre></div>
97
98 <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>
99
100 <h3>Issuing SQL commands</h3>
101
102 <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>
103
104 <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>
105
106 <div class=code><pre>
107 >select count(*) from defect where reproducible is not null;
108  
109    <EXPR-1>
110          11
111  
112 >select reproducible from defect where reproducible is not null;
113  
114                            reproducible
115                                                 NO
116                                                 NO
117                                                 NO
118                                                 NO
119                                                 NO
120                                                 NO
121                                                 NO
122                                                 NO
123                                                 NO
124                                                 NO
125                                                 NO
126                                                YES
127  
128 >update defect set reproducible = 'NO' where reproducible  is null;
129 93326 rows affected.
130 >
131 </pre></div>
132
133 <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>
134
135 <h3>Setting a reference field</h3>
136
137 <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>
138
139 <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>
140
141 <div class=code><pre>
142 >select * from new1;
143  
144        dbid   is_active     version lock_version   locked_by ratl_mastership ratl_keysite          name
145           0        NULL           1            0           0               0            0          NULL
146    35541119           1           1            0           0        16777313     16777313          Grade A
147    35541121           1           1            0           0        16777313     16777313          Grade B
148    35541123           1           1            0           0        16777313     16777313          Grade C
149    35541125           1           1            0           0        16777313     16777313          Grade D
150    35541127           1           1            0           0        16777313     16777313          N/A
151  
152 >select certification from defect where id='DB00031023';
153  
154 certification
155                    0
156  
157 >update defect set certification=35541127 where id='DB00031023';
158 1 rows affected.
159  
160 >select id from defect where id='DB00031024' and certification = 0;
161  
162            id
163 DB00031024
164  
165  
166 >select id from defect where id='DB00031024' and certification = 1;
167  
168            id
169  
170 >select count(*) from defect;
171    <EXPR-1>
172       93407
173  
174 >select count(*) from defect where certification = 0;
175    <EXPR-1>
176       93026
177  
178 >update defect set certification = 35541127 where certification= 0;
179 93025 rows affected.
180 </pre></div>
181                            </div>
182                         </div>
183                         <p class="entry-footer">
184                            <span class="post-footers">Posted by  on February 13, 2012  3:10 PM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000750.html">Permalink</a>
185                         </p>
186                      </div>
187
188                      
189                      <div class="trackbacks">
190                         <h3 id="trackback" class="trackbacks-header">TrackBack</h3>
191                         <div id="trackbacks-info">
192                            <p>TrackBack URL for this entry:<br />http://defaria.com/mt/mt-tb.cgi/114</p>
193                         </div>
194                         <div class="trackbacks-content">
195                            
196                         </div>
197                      </div>
198                      
199
200                      
201                   </div>
202                </div>
203             </div>
204          </div>
205       </div>
206    </div>
207 </body>
208 </html>