UPDATING an IMAGE column in Sybase with PREPARED statement fails

338 Views Asked by At

This is with ASE 15.7 and ESQL/C. Updating a row in a CURSOR with a prepared statement:

EXEC SQL BEGIN DECLARE SECTION;
CS_IMAGE image[512];
EXEC SQL END DECLARE SECTION;

strcpy(image, "foo");

EXEC SQL PREPARE updt FROM "UPDATE image_test SET nettodaten = ? WHERE CURRENT OF hc_image_test";
EXEC SQL EXECUTE updt USING :image;

fails with the message from ASE:

** SQLCODE=(-201)
** ASE Error
** Procedure *sq1625128094_1900377684ss* expects parameter
Invalid pointer param number 4, pointer value 0x(nil)
, which was not supplied.

What could be the reason for this?

Update 1

I modified the ESQL/C code a bit so it looks like this:

strcpy(anweisung, "UPDATE image_test SET katkey = ?, nettodaten = ? WHERE CURRENT OF hc_image_test");
EXEC SQL PREPARE updt FROM :anweisung;
EXEC SQL EXECUTE updt USING :key, :blobfld;
EXEC SQL CLOSE hc_image_test;

The error remains the same as above. But a look into the produced C-code by CPRE shows an interesting detail:

   /*
   ** SQL STATEMENT: 17
   ** EXEC SQL EXECUTE updt USING :key, :blobfld;
   */
   {
        _SQL_CT_HANDLES * _sql;
       _sqlinitctx(&_sql, CS_CURRENT_VERSION, CS_TRUE, &sqlca, (long
           *)NULL, (CS_CHAR *)NULL);
       if (_sql != (_SQL_CT_HANDLES *) NULL)
       {
           _sql->stmtData.persistent = CS_FALSE;
           _sql->stmttype = SQL_EXECUTE;
           _sql->connName.lnlen = CS_UNUSED;
           _sql->stmtName.fnlen = 4;
           strcpy(_sql->stmtName.first_name, "updt");
           if ((_sql->retcode = _sqlprolog(_sql)) == CS_SUCCEED)
           {
               _sql->retcode = ct_dynamic(_sql->conn.command,
                   CS_EXECUTE, "updt", 4, NULL, CS_UNUSED);
               if (_sql->retcode == CS_SUCCEED)
               {
                   _sql->dfmtCS_INT_TYPE.count = 0;
                   _sql->dfmtCS_INT_TYPE.status = CS_INPUTVALUE;
                   _sql->retcode = ct_param(_sql->conn.command,
                       &_sql->dfmtCS_INT_TYPE, &key, (CS_INT)
                       CS_UNUSED, (CS_SMALLINT) 0);
                   _sql->dfmtCS_INT_TYPE.status = 0;
               }

               _sql->retcode = ct_send(_sql->conn.command);
               _sql->hastate = (_sql->retcode == CS_RET_HAFAILOVER);
               _sql->retcode = _sqlResults(_sql);
               _sql->retcode = _sqlepilog(_sql);
           }

           if (sqlca.sqlcode < 0)
           {
               error_handler();
           }

As one can see above, a pointer to the host variable CS_INT :key is placed with a call to ct_param() into the internal structures, but not any reference to the host variable CS_IMAGE :blobfld. And that's why ASE is complaining with a missing param value because it sees two question marks ? in the prepared UPDATE statement. This looks to me somehow as a bug in the CPRE compiler and not in ASE itself.

1

There are 1 best solutions below

0
On

I have contacted through our maintenance contract the company SAP (the issue number there is 390674 / 2018) and some engineer is looking into this CPRE issue...

For the moment, I'm adding to the C-code produce by CPRE, short before the ct_send() call, the following lines of code to add the missing reference to the IMAGE column:

                   /* additional code for host var :blobfld */
                   if (_sql->retcode == CS_SUCCEED)
                   {
                       _sql->dfmtCS_IMAGE_TYPE.count = 0;
                       _sql->dfmtCS_IMAGE_TYPE.maxlength = (CS_INT) 65535;
                       _sql->dfmtCS_IMAGE_TYPE.format = CS_FMT_UNUSED;
                       _sql->dfmtCS_IMAGE_TYPE.status = CS_INPUTVALUE;
                           _sql->retcode = ct_param(_sql->conn.command,
                               &_sql->dfmtCS_IMAGE_TYPE, blobfld, (CS_INT) ImageLengthField,
                               (CS_SMALLINT) 0);
                       _sql->dfmtCS_IMAGE_TYPE.status = 0;
                   }
                   /* end of additional code for host var :blobfld */

                   _sql->retcode = ct_send(_sql->conn.command);
                   ...

And all works fine.