sivann / itdb

IT Items Database
http://www.sivann.gr/software/itdb/
GNU General Public License v3.0
153 stars 104 forks source link

Duplicate SN with id X #47

Closed nikband closed 8 years ago

nikband commented 8 years ago

Hi, I try to modify an id 25 changing the location from A to B and obtain the error:

Error: Item not saved, correct these errors: Duplicate SN with id 5

With version 1.22 or 1.23, i have opened the sqllite db with a browser and there are no equal sn into items table.

Follow my personal debug...

it's possible problem with or before this query ?

$sql="SELECT id from items where id <> $myid AND ((length(sn)>0 AND sn in ('{$_POST['sn']}', '{$_POST['sn2']}')) OR (length(sn2)>0 AND sn2 in ('{$_POST['sn']}', '{$_POST['sn2']}'))) LIMIT 1";

I try using with myid = 25 (the right value) and obtain 0 field with any other value obtain as result 25

SELECT id from items where id <> 25 AND ((length(sn)>0 AND sn in ('XXX', '')) OR (length(sn2)>0 AND sn2 in ('XXX, ''))) LIMIT 1 result: null

SELECT id from items where id <> Y AND ((length(sn)>0 AND sn in ('XXX', '')) OR (length(sn2)>0 AND sn2 in ('XXX, ''))) LIMIT 1 result: 25

How can i verify myid it's correct?

Thanks in advance Nicola

sivann commented 8 years ago

SN is the serial number, not the ID. If you tried importing the items and it failed because of empty owner, the items may have been imported but are invisible. Please do the following on sqlite: delete from items where userid < 0;

Please backup first. From now on the importer will check for empty owner.

nikband commented 8 years ago

Hi Sivan, Thanks, yes my error regarding who work the edititems.php select * from items where userid < 0; 0 rows returned in 1ms from: SELECT * from items where userid < 0;

I check the col userid and there is "number" for each record. So I suppose that something may be wrong into my db... I have sn, and sn3 filled with the same Dell Tag (as all other items) so I can't understand why i obtain the error releted... so suppose the only change from 1.12 - 1.14 (now i have 1.22 or 1.23) is

this part: $myid=$_GET['id']; if ($myid != "new" && is_numeric($myid) && (strlen($_POST['sn']) || strlen($_P OST['sn2']))) { $sql="SELECT id from items where id <> $myid AND ((length(sn)>0 AND sn in ('{$_POST['sn']}', '{$_POST['sn2']}')) OR (length(sn2)>0 AND sn2 in ('{$_POS T['sn']}', '{$_POST['sn2']}'))) LIMIT 1"; $sth=db_execute($dbh,$sql); $dups=$sth->fetchAll(PDO::FETCH_ASSOC); if (count($dups[0])) { $err.="Duplicate SN with id <a href='$scriptname?action=editite m&id={$dups[0]['id']}'>{$dups[0]['id']}"; } }

For me or the GET don't obtain the right value... why id 5 with an item id of 25?

id25

id5

The userid is 1 for both...

Thanks if you can find some way to help me

sivann commented 8 years ago

I do not understand your question. If you have the string "number" instead of a number on sqlite, then you could try to reassign those items to an existing user. Try this: UPDATE items set userid=1 where userid='number';

nikband commented 8 years ago

sivann sorry it-s my English... I only would say that userid it-s populated with number, 1 is administrator and so on... like configured into User table... the strange is if i change location to item n.25 i receive error duplicate sn with id 5... that have different SN, sn2, sn3

There is a way to debug the editidem.php? let me know if you know (and if you have time..) otherwise i have to recover from backup with 1.12

nikband commented 8 years ago

A little advance... that may be resolve (i hope) SELECT id from items where id <> 25 AND ((length(sn)>0 AND sn in ('TAGX', ' ')) OR (length(sn2)>0 AND sn2 in ('TAGX', ' '))) LIMIT 1 with sn2 = " " (A SPACE) the select return a record with id 5

if I remove the space SELECT id from items where id <> 25 AND ((length(sn)>0 AND sn in ('TAGX', '')) OR (length(sn2)>0 AND sn2 in ('TAGX', ''))) LIMIT 1 the select return no record may be a problem in my db with empty sn2/3 populated by space...

with select count(sn2) from items where sn2=" " i found 181 empty sn2

so i have to fixed my db I suppose that there are no sn with space in head or tail os string...

$niksn=trim($_POST['sn']); $niksn2=trim($_POST['sn2']); $sql="SELECT id from items where id <> $myid AND ((length(sn)>0 AND sn in ('{$niksn}', '{$niksn2}')) OR (length(sn2)>0 AND sn2 in ('{$niksn}', '{$niksn2}'))) LIMIT 1"; it's work but ovviusly is not a good code, good night

sivann commented 8 years ago

Please if you like email me your itdb.db so I can debug. I cannot reproduce this issue, sorry. Regards, -Spiros

On 13 April 2016 at 23:33, nikband notifications@github.com wrote:

sivann sorry it-s my English... I only would say that userid it-s populated with number, 1 is administrator and so on... like configured into User table... the strange is if i change location to item n.25 i receive error duplicate sn with id 5... that have different SN, sn2, sn3

There is a way to debug the editidem.php? let me know if you know (and if you have time..) otherwise i have to recover from backup with 1.12

— You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub https://github.com/sivann/itdb/issues/47#issuecomment-209636298

nikband commented 8 years ago

I can't send the db :( but you can replicate in simple

Add a space " " on two (or more) items sn2 filed and after try to edit one of this item, a filed like location, save and you obtain the duplicate sn error. The string " " are the serial number (on filed sn2) for two or more items... it's not a big problem but a trim(sn) trim(sn2) in insert/update may be resolve the problem.

nikband commented 8 years ago

I fix my db with: update items set sn2="" where sn2=" ";

sivann commented 8 years ago

Ok thanks for the report, I will apply trim on import and save of sn.

On 14 April 2016 at 12:05, nikband notifications@github.com wrote:

I fix my db with: update items set sn2="" where sn2=" ";

— You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub https://github.com/sivann/itdb/issues/47#issuecomment-209838326

sivann commented 8 years ago

This is strange, as all form elements are already trimmed before saving. I cannot understand why you had a space on your sn2 fields. I have tried and could not save an item with a space as sn or sn2.

nikband commented 8 years ago

Spiros may be a my error regarding the space into sn or sn2. In past I imported my items data with sql insert into db for use the itdb software, and after last ITDB update you have added the check into update/insert procedure. So if there are no way to insert space(not trimmed) from items form the problem need only to be closed without new code.

sivann commented 8 years ago

ok thanks, closing.