SET NAMES WIN1251;

SET SQL DIALECT 3;

CONNECT 'c:\DeliveryRK7_3.1.1.x\DB\DELIVERYRK7.FDB' USER 'SYSDBA' PASSWORD 'masterkey';

SET AUTODDL ON;

ALTER DOMAIN D_TIME TYPE TIME;

/* Create Table... */
CREATE TABLE DLV_CCLOG(ID D_INT64 NOT NULL,
DT D_DATETIME,
RID D_INTEGER,
OPERATION D_STRING_50,
ERROR D_INTEGER,
ERROR_TEXT D_STRING_255,
ORDER_ID D_INT64,
ORDER_NUM D_STRING_15,
RK7VISIT D_INTEGER,
FRK7VISIT D_INTEGER);



ALTER TABLE DLV_CCEVENTS ADD DONETIME D_DATETIME;

ALTER TABLE DLV_CCEVENTS ADD PACKET D_MEMO;

ALTER TABLE DLV_ORDERS ADD ORDER_VERSION D_INTEGER;

ALTER TABLE DLV_ORDERS ADD FRK7VISIT D_INTEGER;


ALTER TABLE DLV_ORDERS ALTER COLUMN ORDER_NUM TYPE D_STRING_15;

/* Create Procedure... */
SET TERM ^ ;

CREATE PROCEDURE SP_GEN_DLV_CCLOG_ID RETURNS(ID INTEGER)
 AS
 BEGIN SUSPEND; END
^


/* Create index... */
SET TERM ; ^

CREATE INDEX DT_IDX ON DLV_CCLOG(DT);


/* Create generator... */
CREATE GENERATOR GEN_DLV_CCLOG_ID;


/* Create Primary Key... */
ALTER TABLE DLV_CCLOG ADD CONSTRAINT PK_DLV_CCLOG PRIMARY KEY (ID);

/* Alter Procedure... */
/* Restore proc. body: SP_GEN_DLV_CCLOG_ID */
SET TERM ^ ;

ALTER PROCEDURE SP_GEN_DLV_CCLOG_ID RETURNS(ID INTEGER)
 AS
begin
  id = gen_id(gen_dlv_cclog_id, 1);
  suspend;
end
^

/* Creating trigger... */
CREATE TRIGGER DLV_CCLOG_BI FOR DLV_CCLOG
ACTIVE BEFORE INSERT POSITION 0 
as
begin
  if (new.id is null) then
    new.id = gen_id(gen_dlv_cclog_id,1);
end
^


/* Alter Procedure... */
/* Create(Add) Crant */
SET TERM ; ^

GRANT ALL ON DLV_CCLOG TO SYSDBA WITH GRANT OPTION;


