
--DELETE FROM rob_pos;
DELETE FROM dbid;
DELETE FROM pos;
DELETE FROM stat;
DELETE FROM ctime;
--DELETE FROM rob;
--DELETE FROM dcs;
--DELETE FROM roc;


INSERT INTO rob(serial,type) VALUES (10,'1A');
INSERT INTO rob(serial,type) VALUES (11,'1B');
INSERT INTO rob(serial,type) VALUES (12,'2B');

SELECT * FROM rob;

INSERT INTO dcs(serial) VALUES (20);

SELECT * FROM dcs;

INSERT INTO roc(type,serial) VALUES ('L1C1', 30);
INSERT INTO roc(type,serial) VALUES ('L1C0', 31);
INSERT INTO roc(type,serial) VALUES ('L0C1', 31);

INSERT INTO roc(type,serial) 
	VALUES ('L0C1', 30);

SELECT *,item_type(dbid) from dbid;

INSERT INTO pos(dbid,loc_dbid,loc_pos)
	SELECT  (SELECT dbid FROM rob WHERE serial=10),
		(SELECT dbid FROM roc WHERE type='L0C1' AND serial=30),
		0;

INSERT INTO pos(dbid,loc_dbid,loc_pos)
	SELECT  (SELECT dbid FROM rob WHERE serial=10),
		(SELECT dbid FROM roc WHERE type='L1C1' AND serial=30),
		0;

INSERT INTO pos(dbid,loc_dbid,loc_pos)
	SELECT  (SELECT dbid FROM rob WHERE serial=12),
		(SELECT dbid FROM roc WHERE type='L1C1' AND serial=30),
		3;


SELECT roc.type,roc.serial AS roc_serial,pos.loc_pos,rob.serial AS rob_serial,ctime.ts,ctime.person
FROM roc,pos,rob,ctime
WHERE rob.dbid=pos.dbid AND roc.dbid=pos.loc_dbid AND pos.ctime=ctime.ctime;

--SELECT move_item( (SELECT itemid FROM rob WHERE id=10), 
--		  (SELECT itemid FROM roc WHERE type='L0C1' AND serial=30), 0,
--		  'asd', 'TD');
		  --CAST('asd' AS CHAR), CAST('TD' AS CHAR));

--SELECT * FROM item;

--SELECT move_item(1,7,0,'asd','TD');


-- Test rob_pos
--INSERT INTO rob_pos(rob,roc,pos,insert_person) VALUES (10,01030,0,'TD');
--INSERT INTO rob_pos(rob,roc,pos,insert_person) VALUES (10,01030,1,'TD');
--INSERT INTO rob_pos(rob,roc,pos,insert_person) VALUES (11,01030,1,'TD');
--INSERT INTO rob_pos(rob,roc,pos,insert_person) VALUES (11,01030,5,'TD');
--INSERT INTO rob_pos(rob,roc,pos,insert_person) VALUES (11,01031,1,'TD');

--INSERT INTO rob_pos(rob,other_location,insert_person) 
--	VALUES (11,'KIP/302','TD');


SELECT * FROM pos;

SELECT * FROM ctime;

