<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.talis.com/tdn" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Talis Developer Network - Updating a table - Comments</title>
 <link>http://www.talis.com/tdn/node/1713</link>
 <description>Comments for &quot;Updating a table&quot;</description>
 <language>en</language>
<item>
 <title>Here&#039;s a chunk of a perl</title>
 <link>http://www.talis.com/tdn/node/1713#comment-589</link>
 <description>&lt;p&gt;Here&#039;s a chunk of a perl script that reads in people&#039;s barcodes and registration numbers from an external field and then finds the record from the barcode and updates the registration number field. The input data in our case is an 8 character barcode, a comma and a 7 character reg number:&lt;/p&gt;
&lt;p&gt;sub Do_main&lt;br /&gt;
{&lt;br /&gt;
# Main processing loop.&lt;br /&gt;
open (INPUT, &quot;/users/report/addreg.data&quot;);&lt;/p&gt;
&lt;p&gt;# Assign data from the file to variables&lt;br /&gt;
while () {&lt;br /&gt;
chop;&lt;br /&gt;
($barcode,$comma,$regno) = unpack(&quot;A8A1A7&quot;, $_);&lt;br /&gt;
($result) = &amp;amp;sql($d,&quot;&lt;br /&gt;
UPDATE BORROWER&lt;br /&gt;
SET REGISTRATION_NUMBER=&#039;$regno&#039;,&lt;br /&gt;
NOTE=NOTE+&#039; Regno ammended 12.10.06&#039;&lt;br /&gt;
WHERE BARCODE=&#039;$barcode&#039;&lt;br /&gt;
   &quot;);&lt;/p&gt;
&lt;p&gt;print LOG &quot;BARCODE:$barcode  Regno:$regno  \n&quot;;&lt;br /&gt;
# End of processing that line - get next line&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;# End of processing file&lt;br /&gt;
close INPUT;&lt;/p&gt;
&lt;p&gt;print LOG &quot;\n\n\nFinished running regno change ...   &quot;;&lt;/p&gt;
&lt;p&gt;Use with care!!!&lt;/p&gt;
&lt;p&gt;Steve&lt;/p&gt;
</description>
 <pubDate>Mon, 10 Sep 2007 11:07:24 +0100</pubDate>
 <dc:creator>Steve Campbell</dc:creator>
 <guid isPermaLink="false">comment 589 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>inserting data from a file</title>
 <link>http://www.talis.com/tdn/node/1713#comment-588</link>
 <description>&lt;p&gt;It may not be necessary to insert the data from the file into a database table.  The data can be read into an array within the PERL script and then the array can be manipulated.  This approach obviously depends on exactly what you are wanting to achieve and if you need to keep a record of the items in the database. &lt;/p&gt;
&lt;p&gt;Even if are going to insert the data into a table I tend to put the data into an array first and then use the data in the array to insert into the table.  It allows you to check the data and remove any anomalies before the database inserts. &lt;/p&gt;
&lt;p&gt;Below is a extract from a script that would read in data from an pipe-delimited file and create an array called @rows.  The first data element is the item barcode followed by undefined data elements.&lt;/p&gt;
&lt;p&gt;The @rows array can then be processed.  In the example it is just updating the item type. &lt;/p&gt;
&lt;p&gt;($path_file) = &quot;/scratch/input_file.out&quot;;&lt;br /&gt;
($delimiter) = &quot;~&quot;;&lt;/p&gt;
&lt;p&gt;open(INPUT_FILE, $path_file);&lt;/p&gt;
&lt;p&gt;while (&lt;INPUT_FILE&gt;)&lt;/p&gt;
&lt;p&gt;{&lt;br /&gt;
  ($record) = &quot;&quot;;&lt;/p&gt;
&lt;p&gt;  chop;&lt;br /&gt;
  next if /^#/;&lt;br /&gt;
  next if ($_ eq &quot;&quot;);&lt;/p&gt;
&lt;p&gt;  ($position01,$position02,$position03,&lt;br /&gt;
   $position04,$position05,$position06)= denull(despace(split(&#039;\|&#039;,$_)));&lt;/p&gt;
&lt;p&gt;  $position01 .= $delimiter;&lt;br /&gt;
  $position02 .= $delimiter;&lt;br /&gt;
  $position03 .= $delimiter;&lt;br /&gt;
  $position04 .= $delimiter;&lt;br /&gt;
  $position05 .= $delimiter;&lt;br /&gt;
  $position06 .= $delimiter;&lt;/p&gt;
&lt;p&gt;	($record)= $position01 . $position02 . $position03 . $position04 . $position05 .&lt;br /&gt;
	           $position06;&lt;/p&gt;
&lt;p&gt;  push(@rows,$record);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;foreach $row(@rows)&lt;br /&gt;
{&lt;br /&gt;
	($barcode,$variable02,$variable03,&lt;br /&gt;
   	 $variable04,$variable05,$variable06) = denull(despace(split(&#039;~&#039;,$row)));&lt;/p&gt;
&lt;p&gt;	print &quot;$barcode,$variable02,$variable03,$variable04,$variable05,$variable06\n&quot;;&lt;/p&gt;
&lt;p&gt;	$sql($d,&quot;update ITEM set TYPE_ID=20 where BARCODE like &quot;$barcode&quot;&quot;);&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;As I said this is a section of a possible script and I haven&#039;t included the code that would be required around the example. I can look at creating an article to expand on this concept but I can&#039;t guarantee when this would be available so please post any questions and I will try to expand.&lt;/p&gt;
&lt;p&gt;For your specific example it does depend on your exact requirements both in terms of the structure of the data file and also what you mean by traps and tagging.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Brian Crampton&lt;br /&gt;
Developer, Talis&lt;/p&gt;
</description>
 <pubDate>Thu,  6 Sep 2007 09:23:33 +0100</pubDate>
 <dc:creator>Brian Crampton</dc:creator>
 <guid isPermaLink="false">comment 588 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>Updating from a text file</title>
 <link>http://www.talis.com/tdn/node/1713#comment-587</link>
 <description>&lt;p&gt;Hello,&lt;br /&gt;
I&#039;m wanting to do something along these lines as part of our RFID implementation. I need to update a table we have created on Talis from a text or csv file generated from the portable RFID workstation, this file contains barcodes or ID&#039;s of tagged items. I could then cross reference this table against the item table and place traps for on loan items or create lists of the stock that still requires tagging. I&#039;ll also be able to use the process as a stock check at the same time and remove any items not found and not on loan.&lt;/p&gt;
&lt;p&gt;Any help would be much appreciated&lt;br /&gt;
Regards&lt;br /&gt;
John&lt;/p&gt;
</description>
 <pubDate>Wed,  5 Sep 2007 16:33:17 +0100</pubDate>
 <dc:creator>John Springett</dc:creator>
 <guid isPermaLink="false">comment 587 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>Hi Mark, I would echo</title>
 <link>http://www.talis.com/tdn/node/1713#comment-486</link>
 <description>&lt;p&gt;Hi Mark, I would echo Brian&#039;s warning to be careful, as this sort of thing, if it goes wrong, can do a lot of damage in a very small fraction of a second... However a perl script containing something like this:&lt;/p&gt;
&lt;p&gt;sub Do_main&lt;br /&gt;
{&lt;br /&gt;
open (INPUT, &quot;/users/report/filename&quot;);&lt;/p&gt;
&lt;p&gt;while () {&lt;br /&gt;
chop;&lt;br /&gt;
($barcode) = unpack(&quot;A8&quot;, $_);&lt;br /&gt;
($result) = &amp;amp;sql($d,&quot;&lt;br /&gt;
UPDATE BORROWER&lt;br /&gt;
SET WHATEVER_FIELD = &#039;some value&#039;&lt;br /&gt;
WHERE BARCODE=&#039;$barcode&#039;&lt;br /&gt;
   &quot;);&lt;br /&gt;
}&lt;br /&gt;
ammended as required locally, could do the trick.&lt;/p&gt;
</description>
 <pubDate>Wed, 14 Mar 2007 16:30:30 +0000</pubDate>
 <dc:creator>Steve Campbell</dc:creator>
 <guid isPermaLink="false">comment 486 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>updating from a text file</title>
 <link>http://www.talis.com/tdn/node/1713#comment-463</link>
 <description>&lt;p&gt;There are a number of ways although I don&#039;t think it would be a SQL statement in itself.  &lt;/p&gt;
&lt;p&gt;The best approach would probably be a PERL script to do the input stuff and then using SQL statements. &lt;/p&gt;
&lt;p&gt;It could also be done in UNIX shell scripts I guess.  &lt;/p&gt;
&lt;p&gt;However it may be possible using the borrower import script providing the input information is correctly formatted e.g. the right tags.  It should be possible to set up borrower import so that data is not overwritable except for the borrower type although it is something that needs to be tested (on the MIS server) to be certain.&lt;/p&gt;
&lt;p&gt;However with any import of data the format of the incoming data is going to be critical e.g. what is the delimiter, are you using borrower type codes, names or TYPE_STATUS values etc and how can you change the format of the incoming file.&lt;/p&gt;
&lt;p&gt;With any type of database update you would have to be very careful. &lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Brian Crampton&lt;br /&gt;
Developer, Talis&lt;/p&gt;
</description>
 <pubDate>Tue, 20 Feb 2007 10:31:14 +0000</pubDate>
 <dc:creator>Brian Crampton</dc:creator>
 <guid isPermaLink="false">comment 463 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>Updating a table</title>
 <link>http://www.talis.com/tdn/node/1713</link>
 <description>&lt;p&gt;I was wondering....&lt;/p&gt;
&lt;p&gt;If I had a text file of borrower numbers, and would like to update a table (e.g. the borrower table) using this text file, how would I go about writing the SQL to take it&#039;s input from the text file?&lt;/p&gt;
&lt;p&gt;E.g.  If I wished to update the Borrower Type from a text file containing a list of borrower numbers.&lt;/p&gt;
&lt;p&gt;Can this be done?&lt;/p&gt;
&lt;p&gt;Cheers&lt;br /&gt;
Mark&lt;/p&gt;
</description>
 <comments>http://www.talis.com/tdn/node/1713#comments</comments>
 <category domain="http://www.talis.com/tdn/taxonomy/term/60">Talis Library System</category>
 <pubDate>Mon, 19 Feb 2007 13:18:31 +0000</pubDate>
 <dc:creator>markhughes</dc:creator>
 <guid isPermaLink="false">1713 at http://www.talis.com/tdn</guid>
</item>
</channel>
</rss>
