Board index » delphi » String or TMemo into a Blob field using stored procedure

String or TMemo into a Blob field using stored procedure

Please take a look at the following and see if you can tell what I am doing
wrong...

I create a table in IB using the following SQL statement...

     Create Table "NOTES"
     (  "NOTEID"    INTEGER,
        "NOTETEXT"   BLOB SUB_TYPE TEXT SEGMENT SIZE 80);

This works fine.  I then create a stored procedure to use when adding
records...

     COMMIT WORK;
     SET AUTODDL OFF;
     SET TERM ^ ;

     /* Stored procedures */

     CREATE PROCEDURE "ADDNOTE"
     (
       "MYID"           INTEGER,
       "NOTETEXT" BLOB
     )
     RETURNS
     (
       "NOTEID" INTEGER
     )
     AS
     BEGIN EXIT; END ^

     ALTER PROCEDURE "ADDNOTE"
     (
       "MYID"           INTEGER,
       "NOTETEXT" BLOB
     )
     RETURNS
     (
       "NOTEID" INTEGER
     )
     AS
       DECLARE VARIABLE TestNoteID int;
     BEGIN
       /* see if the vehicle already exists */
       SELECT NOTEID FROM NOTES
         WHERE MYID = :MYID
         INTO :TestNoteID;
       IF ((:TestNoteID IS NULL) OR (:TestNoteID = 0)) THEN
       BEGIN
         /* it doesn't exist, add it */
         NOTEID = Gen_ID (NotesGen, 1);
         INSERT INTO NOTES VALUES (
           :NOTEID,
           :MYID,
           :NOTETEXT
     );
       END ELSE
         /* if it does exist, simply return its id */
         NOTEID = NOTEID;
       SUSPEND;
     END
      ^

     SET TERM ; ^
     COMMIT WORK;
     SET AUTODDL ON;

This creates the stored procedure and this may be where the problem lies.  I
then set up an IBStoredProc which pulls in the Params designated in the
ADDNOTE stored procedure.  The NOTETEXT field is an ftBlob field type as it
should be.  In the code, I use the following code to assign the params and
execute the query:

  ibtransNotes.StartTransaction;
  try
    procAddNotes.Prepare;
    procAddNotes.ParamByName ('MYID').AsString := ANote.MYID;
    procAddNotes.ParamByName ('NOTETEXT').SetBlobData(@ANote.Notes[1],
Length(ANote.Notes)); {where ANotes.Notes is a string}
    procAddNotes.ExecProc;
    ANotes.NOTEID := procAddNotes.ParamByName ('NOTEID').AsInteger;
    ibtransNotes.Commit;
  except
    ibtransNotes.Rollback;
  end;  { try }

This works fine in all my stored procedures which do not use BLOB fields.
When I try to use this I get an error "invalid BLOB ID".

Any help would be greatly appreciated.

Thanks,
Mark

 

Re:String or TMemo into a Blob field using stored procedure


Quote
"Mark Greenhaw" <mgreen...@tvscan.com> wrote in message

news:3b1bd8fb$1_1@dnews...

Quote
>     procAddNotes.ParamByName ('NOTETEXT').SetBlobData(@ANote.Notes[1],
> Length(ANote.Notes)); {where ANotes.Notes is a string}

Try simply setting it as a stirng:

procAddNotes.ParamByName ('NOTETEXT').AsString := ANote.Notes;

--
Wayne Niddey (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html

Re:String or TMemo into a Blob field using stored procedure


Thanks Wayne,

I had already tried that and it didn't work either.  I found out the problem
last night.  I had cut the code down quite a bit when I posted so as not to
take up to much room.  When I tried the code as it was posted, it worked
fine.  It seems that I was trying to update too many fields AND the Blob
field.  When I inserted a record with the other fields and then Updated just
the Blob field through a separate stored procedure it worked fine.  I was
passing about 24 parameter values including the Blob parameter value. IB
didn't like that.  It takes the other parameters by themselves without the
blob with no problems.

Sincerely,
Mark Greenhaw

"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote in message
news:3b1c540b_2@dnews...

Quote
> "Mark Greenhaw" <mgreen...@tvscan.com> wrote in message
> news:3b1bd8fb$1_1@dnews...

> Try simply setting it as a stirng:

> procAddNotes.ParamByName ('NOTETEXT').AsString := ANote.Notes;
> --
> Wayne Niddey (Logic Fundamentals, Inc.)
> RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html

Other Threads