Subject Re: [IBO] Hello and a question
Author nosix06
--- In IBObjects@yahoogroups.com, Aage Johansen <aagjohan@...> wrote:
>
> nosix06 wrote:
> > Hello Helen thank you for the reply and I have looked over the blob
> > example in the Files section for the group and while it does explain
> > how to show the images from the database once they are there it
really
> > doesn't show how to insert them there in the first place so what I
> > need to know now is how do I insert the images, text, ... in the
first
> > place.
> >
>
> (Untested:)
> Start with an (insert) query in a TIB_DSQL component:
> insert into PICTS (ID, ..., PICTBLOB)
> values (:ID, ..., :PICTBLOB)
> Prepare it, and set the parameters. For your picture you can e.g.
> load it from a file:
> dsqlPICT.ParamByName('PICTBLOB').LoadFromFile(SomeFilename);
> dsqlPICT.ExecSQL;
> You can also load it from a MemoryStream if you so wish.
>
>
> --
> Aage J.
>

Hello Aage and thank you for your reply but I think I am doing
something wrong because I keep getting this error message when trying
to insert an image to the db.

ISC ERROR CODE:335544665

ISC ERROR MESSAGE:
Violation of PRIMARY or UNIQUE KEY contraint "INTEG_2" on table IMAGES

To help track down my mistake here is an outline of what I did.

I created a new database and gave it 1 table with the name of "IMAGES"
which has 2 fields in it named.

- IMAGE_ID (Integer, PK, not null)
- THEIMAGE (Blob, subtype binary segment size 4096, not null)

I then setup a trigger & generator for the IMAGE_ID field because this
is what I thought I would need to do to make sure each new image I
inserted into the table didn't simply overwrite any previous image
that was there. Anyway the SQL for my generator & trigger looks like
this.

CREATE TRIGGER INSERT_IMAGES FOR IMAGES
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.IMAGE_ID IS NULL) THEN
NEW.IMAGE_ID = GEN_ID(GEN_IMAGES_ID,1);
END^


Finally I started a new project in delpi and placed the following
controls on my form.

1 Button
1 OpenPictureDialog
1 IB_Connection
1 IB_DSQL

I left the name for each component as they are by default and then
linked the IB_Connection component upto my database and linked up the
IB_DSQL component to the IB_Connection component and set up the SQL
for it like so.

INSERT into IMAGES (IMAGE_ID, THEIMAGE) VALUES(:IMAGE_ID, :THEIMAGE)

And finally I added the following code to my buttons Onclick event.

procedure TForm1.Button1Click(Sender: TObject);
begin
If OpenPictureDialog1.Execute then
IB_DSQL1.ParamByName('THEIMAGE').LoadFromFile(OpenPictureDialog1.FileName);
IB_DSQL1.ExecSQL;
end;

I then ran the program and tried to select an image (bmp) to insert
the database but once the image was selected the program gave me the
error mentioned above and this where I am at now and don't really know
how to continue on from here so again if you or anyone else can see
where I made my mistake then I would be greatful if you could show me
how I can fix it.

Thanks,
Nosix