Обсуждение: Problem about Bytea and SQL_C_CHAR

Поиск
Список
Период
Сортировка

Problem about Bytea and SQL_C_CHAR

От
"Han"
Дата:
Hi,
    Here is the code:

    strcpy(data, "FF");
    cb = 2;
    rc = SQLBindParameter(hstmt, i,
                        SQL_PARAM_INPUT,
                        SQL_C_CHAR, SQL_VARBINARY,
                        precision, scale,
                        &data, MAX_STRING_SIZE,
                        &cb);
    rc = SQLPrepare(hstmt, "insert into test(ColBytea) values(?)", SQL_NTS);
    rc = SQLExecute(hstmt);

    After this, the value inserted in column ColByteatable(datatype is bytea) of table test was a char string 'FF',
whichwas expected to be 0xFF(255). 

    There's no problem with binary column in Ms Sql Server. I'm porting my code from sql server to postgresql. So help
me,please! 

    Regards!

        


        Han
        zhouhanok@vip.sina.com
          2002-11-27




Re: Problem about Bytea and SQL_C_CHAR

От
Hiroshi Inoue
Дата:
Please try the snapshot dll at http://w2422.nsk.ne.jp/~inoue/ .

regards,
Hiroshi Inoue
    http://w2422.nsk.ne.jp/~inoue/

Han wrote:
>
> Hi,
>         Here is the code:
>
>     strcpy(data, "FF");
>         cb = 2;
>         rc = SQLBindParameter(hstmt, i,
>                                                 SQL_PARAM_INPUT,
>                                                 SQL_C_CHAR,
>                        SQL_VARBINARY,
>                                                 precision, scale,
>                                                 &data, MAX_STRING_SIZE,
>                                                 &cb);
>         rc = SQLPrepare(hstmt, "insert into test(ColBytea) values(?)",
>         SQL_NTS);
>     rc = SQLExecute(hstmt);
>
>         After this, the value inserted in column ColByteatable
>    (datatype is bytea) of table test was a char string 'FF',
>     which was expected to be 0xFF(255).
>
>         There's no problem with binary column in Ms Sql Server.
>     I'm porting my code from sql server to postgresql. So help
>     me, please!
>

Re: Problem about Bytea and SQL_C_CHAR

От
"Han"
Дата:
Hiroshi Inoue,

>Han wrote:
>>
>> Hiroshi Inoue,
>>
>>         I've been using the latest source code in gborg CVS.
>> Is that the latest one?
>
>No. The changes are local though it would be committed
>before long.
>
>>     And then I just tried the snapshot psqlodbc30.dll(7.02.0006)
>>     from your site. But it worked even worth--SQLBindParameter
>>     and SQLExecuteDirect both crashed.
>
>Did you register the driver ?
>It's a diffrent driver from the current ODBC2.50 one.
The previous version I've been using was psqlodbc30.dll(driver name is "PostgreSQL + (Beta)", and I never changed it. I
justreplaced the new 7.02.0006 dll, and the version number in the ODBC Data Source Administrator is right. 
>
>regards,
>Hiroshi Inoue
>    http://w2422.nsk.ne.jp/~inoue/


        Han
        zhouhanok@vip.sina.com
          2002-11-28





Re: Problem about Bytea and SQL_C_CHAR

От
"Han"
Дата:
Hiroshi Inoue,

    Hi! I checked the crashing code and abstracted this:

    int data=1;
    int cb;
    rc = SQLPrepare(hstmt, "insert into test1(a) values(?)", SQL_NTS);
    rc = SQLBindParameter(hstmt, 1,
                        SQL_PARAM_INPUT,
                        SQL_C_TCHAR, SQL_INTEGER,
                        4, 0,
                        &data, MAX_STRING_SIZE,
                        &cb);
    rc = SQLExecute(hstmt);
    rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
    rc = SQLExecDirect(hstmt, "select * from test1", SQL_NTS);

    Table test1 has just one int column a.
    The SQLExecDirect crashed! Replace it with SQLBindParameter after that SQLFreeStmt will lead to crash! Please try
it.


>Han wrote:
>> The previous version I've been using was psqlodbc30.dll(driver name is "PostgreSQL + (Beta)", and I never changed
it.I just replaced the new 7.02.0006 dll, and the version number in the ODBC Data Source Administrator is right. 
>
>A simple test case passed here.
>Hmm could you send me the sample code if it's simple ?
>
>regards,
>Hiroshi Inoue
>    http://w2422.nsk.ne.jp/~inoue/

    regards,

        Han
        zhouhanok@vip.sina.com
          2002-11-28




Re: Problem about Bytea and SQL_C_CHAR

От
Hiroshi Inoue
Дата:
Han wrote:
>
> Hiroshi Inoue,
>
>         Hi! I checked the crashing code and abstracted this:
>
>         int data=1;
>         int cb;
>         rc = SQLPrepare(hstmt, "insert into test1(a) values(?)", SQL_NTS);
>         rc = SQLBindParameter(hstmt, 1,
>                                                 SQL_PARAM_INPUT,
>                                                 SQL_C_TCHAR, SQL_INTEGER,
>                                                 4, 0,
>                                                 &data, MAX_STRING_SIZE,
>                                                 &cb);
>         rc = SQLExecute(hstmt);
>         rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
>         rc = SQLExecDirect(hstmt, "select * from test1", SQL_NTS);
>
>         Table test1 has just one int column a.
>         The SQLExecDirect crashed! Replace it with SQLBindParameter after that SQLFreeStmt will lead to crash! Please
tryit. 

Maybe I found a cause. Please try the snapshot dll again.
Thanks a lot.

Hiroshi Inoue
    http://w2422.nsk.ne.jp/~inoue/

Re: Problem about Bytea and SQL_C_CHAR

От
"Han"
Дата:
Hiroshi Inoue,

    OK, that crash problem solved. But there are even more datatype conversion problems.
    First I prepared an insert statement, bound params all using SQL_C_CHAR and SQL_NTS, and execute it. All type of
columnvalues were inserted properly except bytea--it's null in the column. 
    And then I retrived data from the table I just inserted, binding columns with SQL_C_DEFAULT. Most colums returned
wrongvalue. 
    Notice that I use SQL_C_CHAR for insert and SQL_C_DEFAULT for retrive.
    Please check it. Thanks and regards!
>
>Maybe I found a cause. Please try the snapshot dll again.
>Thanks a lot.
>
>Hiroshi Inoue
>    http://w2422.nsk.ne.jp/~inoue/
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: Have you searched our list archives?
>
>http://archives.postgresql.org



        Han
        zhouhanok@vip.sina.com
          2002-11-28





Re: Problem about Bytea and SQL_C_CHAR

От
Hiroshi Inoue
Дата:
Han wrote:
>
> Hiroshi Inoue,
>
>         OK, that crash problem solved. But there are even more
>     datatype conversion problems.
>         First I prepared an insert statement, bound params all
>     using SQL_C_CHAR and SQL_NTS, and execute it. All type
>     of column values were inserted properly except bytea--
>    it's null in the column.

OK please try the snapshot dll at http://w2422.nsk.ne.jp/~inoue/
again.

>         And then I retrived data from the table I just
>     inserted, binding columns with SQL_C_DEFAULT. Most
>     colums returned wrong value.

Hmm for example ? I don't have much time, sorry.

regards,
Hiroshi Inoue
    http://w2422.nsk.ne.jp/~inoue/

Re: Problem about Bytea and SQL_C_CHAR

От
"Han"
Дата:
Hiroshi Inoue,


>Han wrote:
>>
>> Hiroshi Inoue,
>>
>>         OK, that crash problem solved. But there are even more
>>     datatype conversion problems.
>>         First I prepared an insert statement, bound params all
>>     using SQL_C_CHAR and SQL_NTS, and execute it. All type
>>     of column values were inserted properly except bytea--
>>    it's null in the column.
>
>OK please try the snapshot dll at http://w2422.nsk.ne.jp/~inoue/
>again.
    It's OK now! Expect to CVS :)
>
>>         And then I retrived data from the table I just
>>     inserted, binding columns with SQL_C_DEFAULT. Most
>>     colums returned wrong value.
>
>Hmm for example ? I don't have much time, sorry.
    It's alright. My mistake, sorry!

    Regards,

        Han
        zhouhanok@vip.sina.com
          2002-11-29