Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    2

    Unanswered: Help - Problem with BLOBs!!!!

    Here is my problem with Blobs. I'm trying to read a blob field frm the DB in a cursor, using descriptors. Does'nt seem to work... FAisl with SQLCODE -450 , meaning locator is invalid..... It fails at the "FETCH".
    Any help on this wud be really helpful.

    Here is my code snippet:
    -------------------------------
    EXEC SQL BEGIN DECLARE SECTION;
    int i;
    int desc_count;
    char demoquery[800];
    char colname[19];
    char result[ NAME_LEN + 1 ];
    char queryvalue[4];
    int ind;
    loc_t blob_descr;
    int fieldType;
    EXEC SQL END DECLARE SECTION;


    blob_descr.loc_loctype = LOCMEMORY;
    blob_descr.loc_bufsize = -1;
    blob_descr.loc_oflags = 0;
    blob_descr.loc_mflags = 0;

    sprintf(demoquery, "%s %s",
    "select blobtestfield from test_table",
    "where index = ? ");



    EXEC SQL prepare demoid from :demoquery;

    EXEC SQL declare democursor cursor for demoid;

    EXEC SQL allocate descriptor 'demodesc';

    strcpy( queryvalue, "tst7");
    desc_count = 1;

    if(desc_count > MAX_IDESC)
    {
    EXEC SQL deallocate descriptor 'demodesc';
    EXEC SQL allocate descriptor 'demodesc' with max :desc_count;
    }


    printf("SQLSTATE after reallocate is %s\n", SQLSTATE);

    /* number of parameters to be held in descriptor is 1 */
    EXEC SQL set descriptor 'demodesc' COUNT = :desc_count;

    /* Put the value of the parameter into the descriptor */
    i = SQLCHAR;
    EXEC SQL set descriptor 'demodesc' VALUE 1
    TYPE = :i, LENGTH = 16, DATA = :queryvalue;

    /* Associate the cursor with the parameter value */
    EXEC SQL open democursor using sql descriptor 'demodesc';


    /*Reuse the descriptor to determine the contents of the Select-list*/
    EXEC SQL describe demoid using sql descriptor 'demodesc' ;
    printf("SQLCODE:: DESCRIBE [%d] \n", SQLCODE);

    EXEC SQL get descriptor 'demodesc' :desc_count = COUNT;

    printf("There are %d returned columns:\n", desc_count);
    /* Print out what DESCRIBE returns */
    for (i = 1; i <= desc_count; i++)
    prsysdesc(i);
    printf("\n\n");

    /*
    EXEC SQL select blobtestfield
    into :blob_descr from test_frame
    where frame_index = 'tst7';

    printf("From SELECT: %d %s==\n", blob_descr.loc_size, blob_descr.loc_buffer);
    */

    for (;
    {
    EXEC SQL fetch democursor using sql descriptor 'demodesc' ;

    [ HERE IS WHERE IT FAILS WITH SQLDODE -450 !!! ]

    printf("SQLCODE:: FETCH [%d] \n", SQLCODE);
    printf("Fetch done \n");

    if (strncmp(SQLSTATE, "00", 2) != 0)
    break;


    /* Print out the returned values */
    for (i = 1; i <= desc_count; i++)
    {
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :fieldType = TYPE;
    printf("TYPE of the field is [%d] ...", fieldType );
    if(fieldType == SQLTEXT)
    {
    printf("B4 proc the SQL \n");
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :blob_descr = DATA;
    printf("Column: %s\tValue: %s\n", colname, blob_descr.loc_buffer);
    }
    else
    {
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :colname = NAME, :ind = INDICATOR, :result = DATA;
    printf("Column: %s\tValue: %s\n", colname, result);
    }

    }
    printf("\n");
    } /* End of outer for loop */

    if (strncmp(SQLSTATE, "02", 2) != 0)
    printf("SQLSTATE after fetch is %s\n", SQLSTATE);

    EXEC SQL close democursor;

    /* free resources for prepared statement and cursor */
    EXEC SQL free demoid;
    EXEC SQL free democursor;

    /* free system-descriptor area */
    EXEC SQL deallocate descriptor 'demodesc';

  2. #2
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    780

    Re: Help - Problem with BLOBs!!!!

    Originally posted by DBLrn
    Here is my problem with Blobs. I'm trying to read a blob field frm the DB in a cursor, using descriptors. Does'nt seem to work... FAisl with SQLCODE -450 , meaning locator is invalid..... It fails at the "FETCH".
    Any help on this wud be really helpful.

    Here is my code snippet:
    -------------------------------
    EXEC SQL BEGIN DECLARE SECTION;
    int i;
    int desc_count;
    char demoquery[800];
    char colname[19];
    char result[ NAME_LEN + 1 ];
    char queryvalue[4];
    int ind;
    loc_t blob_descr;
    int fieldType;
    EXEC SQL END DECLARE SECTION;


    blob_descr.loc_loctype = LOCMEMORY;
    blob_descr.loc_bufsize = -1;
    blob_descr.loc_oflags = 0;
    blob_descr.loc_mflags = 0;

    sprintf(demoquery, "%s %s",
    "select blobtestfield from test_table",
    "where index = ? ");



    EXEC SQL prepare demoid from :demoquery;

    EXEC SQL declare democursor cursor for demoid;

    EXEC SQL allocate descriptor 'demodesc';

    strcpy( queryvalue, "tst7");
    desc_count = 1;

    if(desc_count > MAX_IDESC)
    {
    EXEC SQL deallocate descriptor 'demodesc';
    EXEC SQL allocate descriptor 'demodesc' with max :desc_count;
    }


    printf("SQLSTATE after reallocate is %s\n", SQLSTATE);

    /* number of parameters to be held in descriptor is 1 */
    EXEC SQL set descriptor 'demodesc' COUNT = :desc_count;

    /* Put the value of the parameter into the descriptor */
    i = SQLCHAR;
    EXEC SQL set descriptor 'demodesc' VALUE 1
    TYPE = :i, LENGTH = 16, DATA = :queryvalue;

    /* Associate the cursor with the parameter value */
    EXEC SQL open democursor using sql descriptor 'demodesc';


    /*Reuse the descriptor to determine the contents of the Select-list*/
    EXEC SQL describe demoid using sql descriptor 'demodesc' ;
    printf("SQLCODE:: DESCRIBE [%d] \n", SQLCODE);

    EXEC SQL get descriptor 'demodesc' :desc_count = COUNT;

    printf("There are %d returned columns:\n", desc_count);
    /* Print out what DESCRIBE returns */
    for (i = 1; i <= desc_count; i++)
    prsysdesc(i);
    printf("\n\n");

    /*
    EXEC SQL select blobtestfield
    into :blob_descr from test_frame
    where frame_index = 'tst7';

    printf("From SELECT: %d %s==\n", blob_descr.loc_size, blob_descr.loc_buffer);
    */

    for (;
    {
    EXEC SQL fetch democursor using sql descriptor 'demodesc' ;

    [ HERE IS WHERE IT FAILS WITH SQLDODE -450 !!! ]

    printf("SQLCODE:: FETCH [%d] \n", SQLCODE);
    printf("Fetch done \n");

    if (strncmp(SQLSTATE, "00", 2) != 0)
    break;


    /* Print out the returned values */
    for (i = 1; i <= desc_count; i++)
    {
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :fieldType = TYPE;
    printf("TYPE of the field is [%d] ...", fieldType );
    if(fieldType == SQLTEXT)
    {
    printf("B4 proc the SQL \n");
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :blob_descr = DATA;
    printf("Column: %s\tValue: %s\n", colname, blob_descr.loc_buffer);
    }
    else
    {
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :colname = NAME, :ind = INDICATOR, :result = DATA;
    printf("Column: %s\tValue: %s\n", colname, result);
    }

    }
    printf("\n");
    } /* End of outer for loop */

    if (strncmp(SQLSTATE, "02", 2) != 0)
    printf("SQLSTATE after fetch is %s\n", SQLSTATE);

    EXEC SQL close democursor;

    /* free resources for prepared statement and cursor */
    EXEC SQL free demoid;
    EXEC SQL free democursor;

    /* free system-descriptor area */
    EXEC SQL deallocate descriptor 'demodesc';
    Hi,

    Test with the environment variable DBBLOBBUF=64.

    Gustavo.

  3. #3
    Join Date
    Oct 2003
    Posts
    2

    Re: Help - Problem with BLOBs!!!!

    Originally posted by DBLrn
    Hi Gustavo,
    I tried with setting DBBLOBBUF = 64, as per your suggestion. Does'nt seem to work. Throws the same error of -450(Meaning locator invalid), during FETCH, when the particular row has some value int he BLOB Field. If empty, then it goes through ok..

    I tried with the sample dyn_sql_teste.ec demo sample that Informix provides with some midfication to suit my needs , it gives the same error.
    Can you please throw some light on this? I'm stuck with this stuff since long..

    Thanks
    -------------------------
    Here is my problem with Blobs. I'm trying to read a blob field frm the DB in a cursor, using descriptors. Does'nt seem to work... FAisl with SQLCODE -450 , meaning locator is invalid..... It fails at the "FETCH".
    Any help on this wud be really helpful.

    Here is my code snippet:
    -------------------------------
    EXEC SQL BEGIN DECLARE SECTION;
    int i;
    int desc_count;
    char demoquery[800];
    char colname[19];
    char result[ NAME_LEN + 1 ];
    char queryvalue[4];
    int ind;
    loc_t blob_descr;
    int fieldType;
    EXEC SQL END DECLARE SECTION;


    blob_descr.loc_loctype = LOCMEMORY;
    blob_descr.loc_bufsize = -1;
    blob_descr.loc_oflags = 0;
    blob_descr.loc_mflags = 0;

    sprintf(demoquery, "%s %s",
    "select blobtestfield from test_table",
    "where index = ? ");



    EXEC SQL prepare demoid from :demoquery;

    EXEC SQL declare democursor cursor for demoid;

    EXEC SQL allocate descriptor 'demodesc';

    strcpy( queryvalue, "tst7");
    desc_count = 1;

    if(desc_count > MAX_IDESC)
    {
    EXEC SQL deallocate descriptor 'demodesc';
    EXEC SQL allocate descriptor 'demodesc' with max :desc_count;
    }


    printf("SQLSTATE after reallocate is %s\n", SQLSTATE);

    /* number of parameters to be held in descriptor is 1 */
    EXEC SQL set descriptor 'demodesc' COUNT = :desc_count;

    /* Put the value of the parameter into the descriptor */
    i = SQLCHAR;
    EXEC SQL set descriptor 'demodesc' VALUE 1
    TYPE = :i, LENGTH = 16, DATA = :queryvalue;

    /* Associate the cursor with the parameter value */
    EXEC SQL open democursor using sql descriptor 'demodesc';


    /*Reuse the descriptor to determine the contents of the Select-list*/
    EXEC SQL describe demoid using sql descriptor 'demodesc' ;
    printf("SQLCODE:: DESCRIBE [%d] \n", SQLCODE);

    EXEC SQL get descriptor 'demodesc' :desc_count = COUNT;

    printf("There are %d returned columns:\n", desc_count);
    /* Print out what DESCRIBE returns */
    for (i = 1; i <= desc_count; i++)
    prsysdesc(i);
    printf("\n\n");

    /*
    EXEC SQL select blobtestfield
    into :blob_descr from test_frame
    where frame_index = 'tst7';

    printf("From SELECT: %d %s==\n", blob_descr.loc_size, blob_descr.loc_buffer);
    */

    for (;
    {
    EXEC SQL fetch democursor using sql descriptor 'demodesc' ;

    [ HERE IS WHERE IT FAILS WITH SQLDODE -450 !!! ]

    printf("SQLCODE:: FETCH [%d] \n", SQLCODE);
    printf("Fetch done \n");

    if (strncmp(SQLSTATE, "00", 2) != 0)
    break;


    /* Print out the returned values */
    for (i = 1; i <= desc_count; i++)
    {
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :fieldType = TYPE;
    printf("TYPE of the field is [%d] ...", fieldType );
    if(fieldType == SQLTEXT)
    {
    printf("B4 proc the SQL \n");
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :blob_descr = DATA;
    printf("Column: %s\tValue: %s\n", colname, blob_descr.loc_buffer);
    }
    else
    {
    EXEC SQL get descriptor 'demodesc' VALUE :i
    :colname = NAME, :ind = INDICATOR, :result = DATA;
    printf("Column: %s\tValue: %s\n", colname, result);
    }

    }
    printf("\n");
    } /* End of outer for loop */

    if (strncmp(SQLSTATE, "02", 2) != 0)
    printf("SQLSTATE after fetch is %s\n", SQLSTATE);

    EXEC SQL close democursor;

    /* free resources for prepared statement and cursor */
    EXEC SQL free demoid;
    EXEC SQL free democursor;

    /* free system-descriptor area */
    EXEC SQL deallocate descriptor 'demodesc';

  4. #4
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    534
    Is this problem solved? What Informix version do you use?
    rws

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •