From: | Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | PostgresQL or PHP bug? |
Date: | 2002-09-07 15:48:20 |
Message-ID: | 3D7A1FC4.6070306@mega-bucks.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Sorry if this is a known issue/problem but I couldn't find any related
bugs or postings ... also sorry for the length of the post but I am
pretty much at my wit's end ...
I've been tearing my hair out trying to find out if the problem I am
seeing is a bug in my program, PHP, or PostgresQl. After all the
hair pulling I am pretty sure it is not in my program (but I *could* be
wrong). So that leaves me with PostgresQl or PHP.
I'm inclined to think it is a PHP bug but since I don't know much about
PostgresQl it could also be my understanding of how the DB works.
Basically I am inserting data into my DB using PHP to read the data from
a file and then insert it into the DB. Before inserting an item into the
DB I check to see if it is already in the DB. (there are a few duplicate
entries in the data file I am using) The data file contains 14562 items.
Of these there are 15 duplicates.
The problem I am seeing is that when I run my PHP program I have it
print out how many times the data it wanted to insert was already in DB
(a duplicate entry from the data file presumably). I have run the
program four times and each time I get a different result!
But the total number of inserted items is always the same ...
Each are the results after four runs:
Duplicate Items Total DB inserts
5099 14285
5000 14285
5125 14285
5098 14285
The program looks like this:
(no transactions are explicitly used in any of the code)
1- prepare some accessory tables
2- go through the data file line by line (each line is one row)
2-1 extract the column data from the line (one datum is a product id)
2-1 check if there is already a row with this product id in the DB
2-1-1 IF there is log it as a duplicate item and move onto next line
2-2 add the data into various tables (about 6)
Why would I get differing results for the number of duplicate items? I'm
guessing it has something to do with the psql backend and/or how PHP
connects to it.
Why do I get different results on each of the four runs??
I ran another program that doesn't do step 2-2 and it worked fine. At
every run the number of duplicate items is 15.
It's not a problem right now because in the end all the data gets
inserted but it is making me worried about the "correctness" of the
results returned to me by the DB.
Can someone give me a hint as to how to pin down where this problem is
coming from?
I'm including the PHP code for steps 2-1 as it is quite short:
if (product_id_exists($prod_id)) {
return 3; //this will cause the prod_id to be logged as a duplicate
}
function sql_query($sql) {
$conn = pg_connect("dbname=JC user=postgres");
$res = pg_exec($conn, $sql);
if (!$res) {
echo "CONNECTION: could not execute query ($sql)<br>";
die;
}
else {return $res;}
}
Thanks!
Jc
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Wolff III | 2002-09-07 16:20:40 | Re: Making small bits of code available |
Previous Message | Joel Rodrigues | 2002-09-07 14:06:15 | Unable to locate type name '? in catalog ERROR |