Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: dupe times in Time::HiRes - problem in DBI or DBD::MySQL or MySQL or the SQL Standard.
Jonathan,

I'm still not sure I'm describing the problem correctly, as we're not
talking about stored procedures. In fact, we're talking about the
simplest kind of insert possible. The column types are what will
break/fix the database table. In the example below, column type 'TEXT'
works (assumes that TINYTEXT would as well..), and column type DOUBLE
does not. Allow me to illustrate how bad it is with only 10 rows
inserted:

We start with 2 empty tables with the following schemas:

(Forive any wrapping-it isn't my fault!)

mysql> desc rawText;desc rawDouble;
+-------------------+------------------+------+-----+---------+-------------
---+
| Field             | Type             | Null | Key | Default | Extra
|
+-------------------+------------------+------+-----+---------+-------------
---+
| id                | int(11) unsigned |      | PRI | NULL    |
auto_increment |
| timeDateInserted  | timestamp(14)    | YES  |     | NULL    |
|
| timeDateInsertedP | text             | YES  |     | NULL    |
|
+-------------------+------------------+------+-----+---------+-------------
---+
3 rows in set (0.00 sec)

+-------------------+------------------+------+-----+---------+-------------
---+
| Field             | Type             | Null | Key | Default | Extra
|
+-------------------+------------------+------+-----+---------+-------------
---+
| id                | int(11) unsigned |      | PRI | NULL    |
auto_increment |
| timeDateInserted  | timestamp(14)    | YES  |     | NULL    |
|
| timeDateInsertedP | double(21,6)     | YES  |     | NULL    |
|
+-------------------+------------------+------+-----+---------+-------------
---+
3 rows in set (0.00 sec)

Now for our test script. (Purists: I could have done this in less
lines, but I'm not in a contest. This is just to allow you to reproduce
the error yourself.)

#!/usr/bin/perl
use strict;
use DBI;
use Time::HiRes qw(gettimeofday);
use Time::Format qw(%time %strftime %manip);
my $dbName      = "TimeTest";
my $dbUser      = '';
my $dbPass      = '';
my $tableName   = "rawText";
#my $tableName   = "rawDouble";
$| = 1;
my $dbh = connectDB($dbName,$dbUser,$dbPass);
$dbh->{AutoCommit} = 1;
my $prepareSchema = "INSERT INTO $tableName
(timeDateInserted,timeDateInsertedP) VALUES (NULL,?)";
my $sth = $dbh->prepare(qq{$prepareSchema});
my $count = 1;
while ($count < 11){
undef $ptime; # paranoid...
$ptime = getSuperFineTime();
print "This is my row: [$count] and this is the ptime:
[$ptime]\n";
$sth->execute($ptime);
$count++;
}
disconnect($dbh);
sub getSuperFineTime {
my $ptime = $time{'yyyymmddhhmmss.uuuuuu'};
return $ptime;
}

When inserting into rawText, STDOUT shows:

This is my count: [1] and this is the time: [20050403213102.343628]
This is my count: [2] and this is the time: [20050403213102.351197]
This is my count: [3] and this is the time: [20050403213102.351660]
This is my count: [4] and this is the time: [20050403213102.352056]
This is my count: [5] and this is the time: [20050403213102.352458]
This is my count: [6] and this is the time: [20050403213102.352855]
This is my count: [7] and this is the time: [20050403213102.353236]
This is my count: [8] and this is the time: [20050403213102.353622]
This is my count: [9] and this is the time: [20050403213102.354007]
This is my count: [10] and this is the time: [20050403213102.354396]

Correct.

Database:

mysql> SELECT * FROM rawText;
+----+------------------+-----------------------+
| id | timeDateInserted | timeDateInsertedP     |
+----+------------------+-----------------------+
|  1 |   20050403213102 | 20050403213102.343628 |
|  2 |   20050403213102 | 20050403213102.351197 |
|  3 |   20050403213102 | 20050403213102.351660 |
|  4 |   20050403213102 | 20050403213102.352056 |
|  5 |   20050403213102 | 20050403213102.352458 |
|  6 |   20050403213102 | 20050403213102.352855 |
|  7 |   20050403213102 | 20050403213102.353236 |
|  8 |   20050403213102 | 20050403213102.353622 |
|  9 |   20050403213102 | 20050403213102.354007 |
| 10 |   20050403213102 | 20050403213102.354396 |
+----+------------------+-----------------------+
10 rows in set (0.00 sec)

Good matches, no problem. Row for row, all went in the way it should
have, and came out good as well.

Now, we send the exact same code to rawDouble STDOUT shows:

This is my count: [1] and this is the time: [20050403213307.705955]
This is my count: [2] and this is the time: [20050403213307.712696]
This is my count: [3] and this is the time: [20050403213307.713165]
This is my count: [4] and this is the time: [20050403213307.713572]
This is my count: [5] and this is the time: [20050403213307.713969]
This is my count: [6] and this is the time: [20050403213307.714368]
This is my count: [7] and this is the time: [20050403213307.714756]
This is my count: [8] and this is the time: [20050403213307.715150]
This is my count: [9] and this is the time: [20050403213307.715537]
This is my count: [10] and this is the time: [20050403213307.715926]

No biggie, right? Each row, as above, is a unique number.

Hold on though... Lets look at what was actually stored in the
database:

mysql> SELECT * FROM rawDouble;
+----+------------------+-----------------------+
| id | timeDateInserted | timeDateInsertedP     |
+----+------------------+-----------------------+
|  1 |   20050403213307 | 20050403213307.707031 |
|  2 |   20050403213307 | 20050403213307.710938 |
|  3 |   20050403213307 | 20050403213307.714844 |
|  4 |   20050403213307 | 20050403213307.714844 |
|  5 |   20050403213307 | 20050403213307.714844 |
|  6 |   20050403213307 | 20050403213307.714844 |
|  7 |   20050403213307 | 20050403213307.714844 |
|  8 |   20050403213307 | 20050403213307.714844 |
|  9 |   20050403213307 | 20050403213307.714844 |
| 10 |   20050403213307 | 20050403213307.714844 |
+----+------------------+-----------------------+
10 rows in set (0.01 sec)

Incorrect.

pat
:)


Report this thread to moderator Post Follow-up to this message
Old Post
pat
04-09-05 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Modules archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:10 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.