Subject | inserting a blob through a stored procedure |
---|---|
Author | Marcelo Miorelli |
Post date | 2000-12-25T17:35:29Z |
Hello all,
Thanks to our friend Francis I could retrieve a blob from the database,
using a stored procedure.
But now my stored procedure of insertion is returnig a "internal error"
without any known cause. I would like to use the stored procedure delineated
bellow to insert a record into the table Historic, described bellow using
delphi 5 interbase 6, under windows 95/98.
Hope you are all well,
Marcelo Miorelli
=====================THE TABLE ===========================================
CREATE TABLE "HISTORIC"
(
"COD_CLIENT" FLOAT NOT NULL,
"DT_HISTORIC" DATE DEFAULT 'TODAY' NOT NULL,
"SEQ" FLOAT DEFAULT 1 NOT NULL,
"COD_AMB" DOUBLE PRECISION DEFAULT NULL,
"COD_CID" VARCHAR(5) CHARACTER SET ISO8859_1 DEFAULT NULL COLLATE PT_PT,
"COD_PHYSICIAN" FLOAT NOT NULL,
"COD_PACT" FLOAT NOT NULL,
"TXT_MEMO" BLOB SUB_TYPE TEXT SEGMENT SIZE 80 CHARACTER SET ISO8859_1,
CONSTRAINT "PKHISTORICO" PRIMARY KEY ("COD_CLIENT", "DT_HISTORIC", "SEQ")
);
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_AMB" FOREIGN KEY
("COD_AMB") REFERENCES AMB ("COD_AMB");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_CID" FOREIGN KEY
("COD_CID") REFERENCES CID10 ("COD_CID");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_CLIENTE" FOREIGN KEY
("COD_CLIENT") REFERENCES CLIENT ("COD_CLIENT");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_CONVENIO" FOREIGN KEY
("COD_PACT") REFERENCES PACT ("COD_PACT");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_MEDICO" FOREIGN KEY
("COD_PHYSICIAN") REFERENCES PHYSICIAN ("COD_PHYSICIAN");
=====================THE STORED PROCEDURE
===========================================
ALTER PROCEDURE "INHISTORIC"
(
COD_CLIENT FLOAT,
DT_HISTORIC TIMESTAMP,
SEQ FLOAT,
COD_AMB DOUBLE PRECISION,
COD_CID VARCHAR(5) CHARACTER SET ISO8859_1,
COD_PHYSICIAN FLOAT,
COD_PACT FLOAT,
MAHA_VISHNU BLOB CHARACTER SET ISO8859_1,
P1 VARCHAR(1) CHARACTER SET ISO8859_1
)
RETURNS
(
R1 FLOAT
)
AS
/*--------------------------------------------------------------------------
--------*/
/* HARE KRISHNA HARE KRISHNA KRISHNA KRISHNA HARE HARE
*/
/* HARE RAMA HARE RAMA RAMA RAMA HARE HARE
*/
/*--------------------------------------------------------------------------
--------*/
declare variable Shiva float;
begin
r1 = -1;
if ((cod_physician = 0) or (cod_physician is NULL) or (cod_pact = 0) or
(cod_pact is NULL)) then
exception historic_pact_physician;
r1 = 1;
if (:cod_amb <= 0) then
cod_amb = NULL;
if (:cod_cid = '') then
cod_cid = NULL;
if (:Maha_Vishnu = '') then
Maha_Vishnu = NULL;
if ((:seq < 1) or (:seq is NULL)) then
Seq = 1;
select count(*) from historic
where cod_client = :cod_client
and dt_historic = :dt_historic
and seq = :seq
into :Shiva;
if (:Shiva is NULL) then
Shiva = 0;
if (Shiva < 1) then begin
insert into historic( COD_CLIENT,
DT_HISTORIC,
SEQ,
COD_AMB,
COD_CID,
COD_PHYSICIAN,
COD_PACT,
TXT_MEMO)values(
:COD_CLIENT,
:DT_HISTORIC,
:SEQ,
:COD_AMB,
:COD_CID,
:COD_PHYSICIAN,
:COD_PACT,
:Maha_Vishnu);
when SQLCODE -530 do begin
r1 = -1;
exception historico_foreign_key;
end/*WHEN*/
end/*IF*/
else
if (upper(p1) = 'Y') then begin
update Historic
set cod_amb = :cod_amb,
txt_memo = :maha_vishnu,
cod_cid = :cod_cid,
cod_physician = :cod_physician,
cod_pact = :cod_pact
where cod_client = :cod_client
and dt_historic = :dt_historic
and seq = :seq;
when SQLCODE -530 do begin
r1 = -1;
exception historico_foreign_key;
end/*WHEN*/
end /*IF*/
else begin
select (max(seq)+1) from Historic
where cod_client = :cod_client
and dt_historic = :dt_historic
into :seq;
if ((:seq < 1) or (:seq is NULL)) then
Seq = 1;
insert into historic( COD_CLIENT,
DT_HISTORIC,
SEQ,
COD_AMB,
COD_CID,
COD_PHYSICIAN,
COD_PACT,
TXT_MEMO)values(
:COD_CLIENT,
:DT_HISTORIC,
:SEQ,
:COD_AMB,
:COD_CID,
:COD_PHYSICIAN,
:COD_PACT,
:Maha_Vishnu);
when SQLCODE -530 do begin
r1 = -1;
exception historico_foreign_key;
end/*WHEN*/
end/*ELSE*/
/*--------------------------------------------------------------------------
--------*/
/* HARE KRISHNA HARE KRISHNA KRISHNA KRISHNA HARE HARE
*/
/* HARE RAMA HARE RAMA RAMA RAMA HARE HARE
*/
/*--------------------------------------------------------------------------
--------*/
end
=========================================================================
and inside delphi 5:
procedure TfmClmahis0.WriteHistoric(Rama : string); stdcall;
begin
if not verify(16108) then exit;
try
inHistoric.Transaction.active := true;
inHistoric.parambyname('COD_CLIENT').asFloat :=
kstrtofloat(epessoa.text);
inHistoric.parambyname('DT_HISTORIC').asdatetime :=
eHistoric.Date;
inHistoric.parambyname('SEQ').asFloat :=
dbHistoric.Fields[2].asFloat;
inHistoric.parambyname('COD_PACT').asFloat :=
kstrtofloat(epact.text);
inHistoric.parambyname('COD_PHYSICIAN').asFloat :=
kstrtofloat(ephysician.Text);
inHistoric.parambyname('COD_CID').asstring :=
ecid.Text;
inHistoric.parambyname('COD_AMB').asFloat :=
kstrtofloat(eamb.Text);
inHistoric.parambyname('MAHA_VISHNU').AsBlob :=
Maha_Vishnu.lines.Text;
inHistoric.parambyname('P1').asstring :=
Rama;
inHistoric.execproc;
inHistoric.Transaction.Commit;
inHistoric.Transaction.Active := False;
btCancel.Click;
except
on E: EDBEngineError do begin
DBMessage(E);
end; {EDBEngineError}
on E: Exception do begin
MessageDlg (E.Message, mtError, [mbOK], 0);
end; {exception}
end;{try}
end;
Thanks to our friend Francis I could retrieve a blob from the database,
using a stored procedure.
But now my stored procedure of insertion is returnig a "internal error"
without any known cause. I would like to use the stored procedure delineated
bellow to insert a record into the table Historic, described bellow using
delphi 5 interbase 6, under windows 95/98.
Hope you are all well,
Marcelo Miorelli
=====================THE TABLE ===========================================
CREATE TABLE "HISTORIC"
(
"COD_CLIENT" FLOAT NOT NULL,
"DT_HISTORIC" DATE DEFAULT 'TODAY' NOT NULL,
"SEQ" FLOAT DEFAULT 1 NOT NULL,
"COD_AMB" DOUBLE PRECISION DEFAULT NULL,
"COD_CID" VARCHAR(5) CHARACTER SET ISO8859_1 DEFAULT NULL COLLATE PT_PT,
"COD_PHYSICIAN" FLOAT NOT NULL,
"COD_PACT" FLOAT NOT NULL,
"TXT_MEMO" BLOB SUB_TYPE TEXT SEGMENT SIZE 80 CHARACTER SET ISO8859_1,
CONSTRAINT "PKHISTORICO" PRIMARY KEY ("COD_CLIENT", "DT_HISTORIC", "SEQ")
);
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_AMB" FOREIGN KEY
("COD_AMB") REFERENCES AMB ("COD_AMB");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_CID" FOREIGN KEY
("COD_CID") REFERENCES CID10 ("COD_CID");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_CLIENTE" FOREIGN KEY
("COD_CLIENT") REFERENCES CLIENT ("COD_CLIENT");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_CONVENIO" FOREIGN KEY
("COD_PACT") REFERENCES PACT ("COD_PACT");
ALTER TABLE "HISTORIC" ADD CONSTRAINT "FKHISTORICO_MEDICO" FOREIGN KEY
("COD_PHYSICIAN") REFERENCES PHYSICIAN ("COD_PHYSICIAN");
=====================THE STORED PROCEDURE
===========================================
ALTER PROCEDURE "INHISTORIC"
(
COD_CLIENT FLOAT,
DT_HISTORIC TIMESTAMP,
SEQ FLOAT,
COD_AMB DOUBLE PRECISION,
COD_CID VARCHAR(5) CHARACTER SET ISO8859_1,
COD_PHYSICIAN FLOAT,
COD_PACT FLOAT,
MAHA_VISHNU BLOB CHARACTER SET ISO8859_1,
P1 VARCHAR(1) CHARACTER SET ISO8859_1
)
RETURNS
(
R1 FLOAT
)
AS
/*--------------------------------------------------------------------------
--------*/
/* HARE KRISHNA HARE KRISHNA KRISHNA KRISHNA HARE HARE
*/
/* HARE RAMA HARE RAMA RAMA RAMA HARE HARE
*/
/*--------------------------------------------------------------------------
--------*/
declare variable Shiva float;
begin
r1 = -1;
if ((cod_physician = 0) or (cod_physician is NULL) or (cod_pact = 0) or
(cod_pact is NULL)) then
exception historic_pact_physician;
r1 = 1;
if (:cod_amb <= 0) then
cod_amb = NULL;
if (:cod_cid = '') then
cod_cid = NULL;
if (:Maha_Vishnu = '') then
Maha_Vishnu = NULL;
if ((:seq < 1) or (:seq is NULL)) then
Seq = 1;
select count(*) from historic
where cod_client = :cod_client
and dt_historic = :dt_historic
and seq = :seq
into :Shiva;
if (:Shiva is NULL) then
Shiva = 0;
if (Shiva < 1) then begin
insert into historic( COD_CLIENT,
DT_HISTORIC,
SEQ,
COD_AMB,
COD_CID,
COD_PHYSICIAN,
COD_PACT,
TXT_MEMO)values(
:COD_CLIENT,
:DT_HISTORIC,
:SEQ,
:COD_AMB,
:COD_CID,
:COD_PHYSICIAN,
:COD_PACT,
:Maha_Vishnu);
when SQLCODE -530 do begin
r1 = -1;
exception historico_foreign_key;
end/*WHEN*/
end/*IF*/
else
if (upper(p1) = 'Y') then begin
update Historic
set cod_amb = :cod_amb,
txt_memo = :maha_vishnu,
cod_cid = :cod_cid,
cod_physician = :cod_physician,
cod_pact = :cod_pact
where cod_client = :cod_client
and dt_historic = :dt_historic
and seq = :seq;
when SQLCODE -530 do begin
r1 = -1;
exception historico_foreign_key;
end/*WHEN*/
end /*IF*/
else begin
select (max(seq)+1) from Historic
where cod_client = :cod_client
and dt_historic = :dt_historic
into :seq;
if ((:seq < 1) or (:seq is NULL)) then
Seq = 1;
insert into historic( COD_CLIENT,
DT_HISTORIC,
SEQ,
COD_AMB,
COD_CID,
COD_PHYSICIAN,
COD_PACT,
TXT_MEMO)values(
:COD_CLIENT,
:DT_HISTORIC,
:SEQ,
:COD_AMB,
:COD_CID,
:COD_PHYSICIAN,
:COD_PACT,
:Maha_Vishnu);
when SQLCODE -530 do begin
r1 = -1;
exception historico_foreign_key;
end/*WHEN*/
end/*ELSE*/
/*--------------------------------------------------------------------------
--------*/
/* HARE KRISHNA HARE KRISHNA KRISHNA KRISHNA HARE HARE
*/
/* HARE RAMA HARE RAMA RAMA RAMA HARE HARE
*/
/*--------------------------------------------------------------------------
--------*/
end
=========================================================================
and inside delphi 5:
procedure TfmClmahis0.WriteHistoric(Rama : string); stdcall;
begin
if not verify(16108) then exit;
try
inHistoric.Transaction.active := true;
inHistoric.parambyname('COD_CLIENT').asFloat :=
kstrtofloat(epessoa.text);
inHistoric.parambyname('DT_HISTORIC').asdatetime :=
eHistoric.Date;
inHistoric.parambyname('SEQ').asFloat :=
dbHistoric.Fields[2].asFloat;
inHistoric.parambyname('COD_PACT').asFloat :=
kstrtofloat(epact.text);
inHistoric.parambyname('COD_PHYSICIAN').asFloat :=
kstrtofloat(ephysician.Text);
inHistoric.parambyname('COD_CID').asstring :=
ecid.Text;
inHistoric.parambyname('COD_AMB').asFloat :=
kstrtofloat(eamb.Text);
inHistoric.parambyname('MAHA_VISHNU').AsBlob :=
Maha_Vishnu.lines.Text;
inHistoric.parambyname('P1').asstring :=
Rama;
inHistoric.execproc;
inHistoric.Transaction.Commit;
inHistoric.Transaction.Active := False;
btCancel.Click;
except
on E: EDBEngineError do begin
DBMessage(E);
end; {EDBEngineError}
on E: Exception do begin
MessageDlg (E.Message, mtError, [mbOK], 0);
end; {exception}
end;{try}
end;