Re: SQLSetPos problem ? - Mailing list pgsql-odbc

From lothar.behrens@lollisoft.de
Subject Re: SQLSetPos problem ?
Date
Msg-id 1166311419.967140.317720@16g2000cwy.googlegroups.com
Whole thread Raw
In response to Re: SQLSetPos problem ?  (Hiroshi Inoue <inoue@tpf.co.jp>)
Responses Still SQLSetPos problem even with minimal sample, SQL_NULL_DATA and SQL_COLUMN_IGNORE ?  ("lothar.behrens@lollisoft.de" <lothar.behrens@lollisoft.de>)
List pgsql-odbc
Hiroshi Inoue schrieb:

> lothar.behrens@lollisoft.de wrote:
> > Hiroshi Inoue schrieb:
> >
> >> lothar.behrens@lollisoft.de wrote:
> >>> Hiroshi Inoue schrieb:
> >>>
> >>>> lothar.behrens@lollisoft.de wrote:
> >>>>> Hi,
> >>>>>
> >>>>> I am using unixodbc in the latest version and psqlodbc 07.03.0200.
> >>>>> Having many queries working
> >>>>> good in my application one gives me this error, when updating a row.
> >>>> The version 7.3.0200 is pretty old.
> >>>> Please try the 8.2.xxxx version.
> >>>>
> >>> I need cursor functionality like first,back,next,last. Does the latest
> >>> driver support it ?
> >> Yes at least on Windows.
> >
> > Currently I have figured out, that my SQL_ADD statement fails
> > (SQLSetPos).
> > It seems, that I cannot insert new rows, because of foreign key
> > constraints.
> >
> > Removing the NOT NULL clauses of that columns didn't helped.
> >
> > With PGAdmin I was able to test inserting such a row. That worked.
> >
> > Any ideas ?
>
> How do you setting the foreign key column using PGadmin ?
>
> > If the bound columns having the wrong value - such as a non exsisting
> > foreign key -
> > how must it be filled to indicate a NULL value ?
> >
> > I bind such a column that way:
> >
> > buffer = malloc((ColumnSize+1)*rows);
> > memset(buffer, 0, (ColumnSize+1)*rows);
> > ret = SQLBindCol(hstmt, column, SQL_C_CHAR, buffer, (ColumnSize+1),
> > &cbBufferLength);
> >
> > Is that wrong ?
>
> I'm afraid I'm misunderstanding your point.
> Please set SQL_NULL_DATA to cbBufferLength to indicate the column is NULL.
> Also set SQL_COLUMN_IGNORE to cbBufferLength to ignore the column.
>

Hi,

I have added functions to set a column to be NULL and therefore, if I
add a new row,
my update function rebinds the relevant column as follows, before the
update:

cbBufferLength = SQL_NULL_DATA+SQL_COLUMN_IGNORE;
ret = SQLBindCol(hstmt, _column, DataType, buffer, 0, &cbBufferLength);

The information I got before this (SQLDescribeCol) returns Nullable = 1
and Datatype = 4.
So it should work.

But it haven't helped until I change the SQLSetPos line as follows:

from
        retcode = SQLSetPos(hstmt, 2, SQL_ADD, SQL_LOCK_NO_CHANGE);
to
        retcode = SQLSetPos(hstmt, 1, SQL_ADD, SQL_LOCK_NO_CHANGE);

It seems that I haven't correctly bound my columns. The second column
(2) came from
the documentation, that uses a special adding row. Thus, if I only have
one row for my data
to be shown, the second row was for adding.

But I only have provided one cbBufferSize variable, not an array of
two.

This was the cause, why my first try to only set SQL_NULL_DATA and
SQL_COLUMN_IGNORE
has been failed.

Is that correct ?

For the issue of adding a new row, the bug may be found.

One bug is remaining and it belongs to the same table and it may be
clear to me, what the cause
is.

But I am still wondering why my error handling code crashes :-(

Do you see any mistake ?

Here it is:

void lbQuery::dbError(char* lp, HSTMT hstmt)
{
    SQLCHAR  SqlState[6], SQLStmt[100], Msg[SQL_MAX_MESSAGE_LENGTH];
    SQLINTEGER NativeError;
    SQLSMALLINT i, MsgLen;
    SQLRETURN  rc;

    i = 1;

    while ((rc = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState,
&NativeError,
          Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA) {

        cout << "Error in lbQuery: (" << lp << ") " <<
            SqlState << ": " << (int) NativeError << " - " << Msg << endl;
        i++;
    }
}

Thanks, Lothar

> regards,
> Hiroshi Inoue
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly


pgsql-odbc by date:

Previous
From: Hiroshi Inoue
Date:
Subject: Re: NaN values and ODBC/OLE
Next
From: Hiroshi Inoue
Date:
Subject: Re: Invalid byte sequence for encoding "UTF8": 0xa1 - when