Skip to Content.
Sympa Menu

freetds - Re: [freetds] Binary columns problem

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Ian Ashley <iashley AT picdar.com>
  • To: FreeTDS Mailing List <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Binary columns problem
  • Date: Wed, 06 Oct 2004 12:25:08 +0100

Something seemed to go wrong last time I submitted this (I got a blank bit
of mail from the mailing list). Apologies if everyone got it okay the first
time :-(

--------

I had already tried that and it didn¹t work. The code I use is shown below.
I have also tried including the \x00 within the buffer sent in case that was
the problem but to no avail. Any other ideas?

char buf[6] = "\x12\x34\x56\x78\x90";
SQLHANDLE stmtHandle = NULL;
SQLINTEGER ind = 5;

SQLAllocHandle(SQL_HANDLE_STMT, connHandle, &stmtHandle);
SQLPrepare(stmtHandle, "UPDATE P_FILE1 SET P_NONKEYBYTES = ? WHERE P__URN =
1", SQL_NTS);
SQLBindParameter(stmtHandle, 1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_BINARY,
5, 0, buf, 0, &ind);
SQLExecute(stmtHandle);
SQLFreeStmt(stmtHandle, SQL_RESET_PARAMS);
SQLFreeHandle(SQL_HANDLE_STMT, stmtHandle);


Cheers,
Ian



From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
Reply-To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
Date: Wed, 6 Oct 2004 10:25:24 +0200
To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
Subject: RE: [freetds] Binary columns problem

>
> I am having a problem updating binary fields using
> SQLBindParameter. I use
> the following code
>
> char buf[6] = "\x12\x34\x56\x78\x90"
>
> SQLPrepare(stmtHandle, ³UPDATE P_SIMPLE SET P_BINARY = ?
> WHERE P__URN = 1²,
> SQL_NTS)
> SQLBindParameter(stmtHandle, 1, SQL_PARAM_INPUT,
> SQL_C_BINARY, SQL_BINARY,
> 5, 0, buf, 0, NULL)
> SQLExecute(stmtHandle)
>
> Only the first byte of the value at buf gets stored, the
> remaining 4 get set
> to 0.
>
> Again any ideas. I have tried using the BufferLength and
> StrLen_or_IndPtr
> parameters to no avail.
>
> Thanks in advance,
> Ian
>

Try to use StrLen_or_IndPtr (last SQLBindParameter parameters) and set it to
5. Note that you can't use a column of 5 bytes to insert 6 bytes...

So it should be

SQLINTEGER ind = 6;
char buf[6] = "\x12\x34\x56\x78\x90";

SQLPrepare(stmtHandle, "UPDATE P_SIMPLE SET P_BINARY = ? WHERE P__URN = 1",
SQL_NTS);
SQLBindParameter(stmtHandle, 1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_BINARY,
6, 0, buf, 0, &ind);
SQLExecute(stmtHandle);

freddy77
_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________






Archive powered by MHonArc 2.6.24.

Top of Page