List:General Discussion« Previous MessageNext Message »
From:tisnie waarhe Date:March 25 1999 8:00am
Subject:Simple question about inserting an integer into a tinyint
View as plain text  
Ladies, Gents,

I've lurked and surfed a while cause my question is too simple.

When I insert a number that I read from a textfile into a tinyint field 
in a record the value 127 is inserted, rather than the number.

Clues?


 mysql> show fields from Staff;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| Name     | varchar(20) | YES  |     | NULL    |                |
| Fname    | varchar(10) | YES  |     | NULL    |                |
| Xtension | tinyint(4)  | YES  |     | NULL    |                |
| Pager    | varchar(15) | YES  |     | NULL    |                |
| Mobile   | varchar(15) | YES  |     | NULL    |                |
| Team     | tinyint(4)  | YES  |     | NULL    |                |
| Owner_id | varchar(10) | YES  |     | NULL    |                |
| Staff_ID | tinyint(4)  |      | PRI | 0       | auto_increment |
+----------+-------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)

mysql> select * from Staff;
+----------+---------+----------+-------+--------+------+-----------+----------+
| Name     | Fname   | Xtension | Pager | Mobile | Team | Owner_id  | 
Staff_ID |
+----------+---------+----------+-------+--------+------+-----------+----------+
| Dany     | Barat   |      127 | NULL  | NULL   | NULL | dbarat    |        
4 |
| Vanuxem  | Francis |      127 | NULL  | NULL   | NULL | fvanuxem  |        
3 |
| Casier   | Kenny   |      127 | NULL  | NULL   | NULL | kcasier   |        
2 |
| Hegeraat | Michel  |      127 | NULL  | NULL   | NULL | mhegeraat |        
1 |
+----------+---------+----------+-------+--------+------+-----------+----------+
4 rows in set (0.01 sec)


use strict;
use DBI;
use CGI;
use Carp;

my $database    = "CTS";
my $user        = "root";
my $password    = "bogus";
my $Owner_ID    = "";
my $Name        = "";
my $Fname       = "";
my $XT          = 0;

my $dbh = DBI->connect("DBI:mysql:$database",  $user, $password );
my $sth = $dbh->prepare(" INSERT INTO Staff (Owner_ID, Name, Fname, 
Xtension)
        VALUES  (?, ?, ?, ? ) " );

open FH, "<staff.csv" or die "Unable to open staff.csv: $!";
while (<FH>)
{
 chop;
 my ($Owner_ID, $Name, $Fname, $XT) = split /\;/;
 print "\n O ", $Owner_ID," N ", $Name," F ", $Fname , $XT ;
 $sth->execute($Owner_ID, $Name, $Fname, $XT/2 );
}
close FH;

$dbh->disconnect;


Get Your Private, Free Email at http://www.hotmail.com
Thread
Simple question about inserting an integer into a tinyinttisnie waarhe25 Mar
Re: Simple question about inserting an integer into a tinyinttisnie waarhe25 Mar