Re: Regarding PostgreSQL BIT datatype binding in ODBC.......

Lists: pgsql-odbc
From: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
To: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Regarding PostgreSQL BIT datatype binding in ODBC.......
Date: 2012-08-02 07:25:23
Message-ID: 1343892323.97562.YahooMailNeo@web190004.mail.sg3.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Hello All,

I am new to this mailing list and this is my first post :)

I want to pass numeric data (2345) into a PostgreSQL BIT datatype column bit(1) using dynamic sql thru ODBC. I very much understand the risk of data getting truncated...
On PSQL, I simply can do -- insert into tab values(CAST(2345 AS BIT(1))) to acheive what i want (and I understand only 1 would get inserted). But I want to do this through ODBC and dynamic sql.

I will have to prepare my query as 

insert into tab values(CAST(? AS bit(1));

then bind 2345 and then execute the statement. 

Can someone help me on how the binding should happen... 
I mean wat should be the "ValueType" and the "ParameterType" etc. in the call to the SQLBindParameter function....

SQLRETURN SQLBindParameter(
      SQLHSTMT        StatementHandle,
      SQLUSMALLINT    ParameterNumber,
      SQLSMALLINT     InputOutputType,
      SQLSMALLINT     ValueType,
      SQLSMALLINT     ParameterType,
      SQLULEN         ColumnSize,
      SQLSMALLINT     DecimalDigits,
      SQLPOINTER      ParameterValuePtr,
      SQLLEN          BufferLength,
      SQLLEN *        StrLen_or_IndPtr);

Quick help is appreciated and additional inputs/coments are also most welcome...

Thanks and Regards,
Ranjeeth. 


From: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
To: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Regarding PostgreSQL BIT datatype binding in ODBC.......
Date: 2012-09-10 04:32:04
Message-ID: 1347251524.26745.YahooMailNeo@web190003.mail.sg3.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Hello All,

I have a table with a bit(10) type colmn. I can insert "1010110110" into that column from PSQL.
i.e.,
postgres=# insert into public.ranc2b values(1,'1101010101');
INSERT 0 1

I want to insert the same character data "1010110110" into the same bit(10) typed column from an ODBC application program,
Can somebody please suggest me how should I bind the data in the SQLBindParameter call.

I tried to bind the data as SQL_BINARY and SQL_CHAR but I got Incorrect binary data format error.

Quick help is appreciated.

Thanks in Advance.

Regards,
Ranjeeth.

________________________________
From: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
To: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Sent: Thursday, 2 August 2012 12:55 PM
Subject: Regarding PostgreSQL BIT datatype binding in ODBC.......

Hello All,

I am new to this mailing list and this is my first post :)

I want to pass numeric data (2345) into a PostgreSQL BIT datatype column bit(1) using dynamic sql thru ODBC. I very much understand the risk of data getting truncated...
On PSQL, I simply can do -- insert into tab values(CAST(2345 AS BIT(1))) to acheive what i want (and I understand only 1 would get inserted). But I want to do this through ODBC and dynamic sql.

I will have to prepare my query as 

insert into tab values(CAST(? AS bit(1));

then bind 2345 and then execute the statement. 

Can someone help me on how the binding should happen... 
I mean wat should be the "ValueType" and the "ParameterType" etc. in the call to the SQLBindParameter function....

SQLRETURN SQLBindParameter(
      SQLHSTMT        StatementHandle,
      SQLUSMALLINT    ParameterNumber,
      SQLSMALLINT     InputOutputType,
      SQLSMALLINT     ValueType,
      SQLSMALLINT     ParameterType,
      SQLULEN         ColumnSize,
      SQLSMALLINT     DecimalDigits,
      SQLPOINTER      ParameterValuePtr,
      SQLLEN          BufferLength,
      SQLLEN *        StrLen_or_IndPtr);

Quick help is appreciated and additional inputs/coments are also most welcome...

Thanks and Regards,
Ranjeeth. 


From: Hiroshi Saito <hiroshi(at)winpg(dot)jp>
To: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
Cc: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Regarding PostgreSQL BIT datatype binding in ODBC.......
Date: 2012-09-10 14:31:27
Message-ID: 504DF9BF.3030602@winpg.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Hi.

Is this helpful to you?
one example)
== odbc
SQLTCHAR kd[100];
strcpy(kd, "1101010101");
...
SQLPrepare(hstmt, "INSERT INTO bbb VALUES (?)", SQL_NTS);
SQLBindParameter(hstmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT,
SQL_C_TCHAR, SQL_CHAR, 0, 0, &kd[0], 100, &len);
== psql
postgres=# select * from bbb;
key
------------
1101010101

Regards,
Hiroshi Saito

(2012/09/10 13:32), ranjeeth kumar wrote:
> Hello All,
>
> I have a table with a bit(10) type colmn. I can insert "1010110110" into
> that column from PSQL.
> i.e.,
> postgres=# insert into public.ranc2b values(1,'1101010101');
> INSERT 0 1
>
> I want to insert the same character data "1010110110" into the same
> bit(10) typed column from an ODBC application program,
> Can somebody please suggest me how should I bind the data in the
> SQLBindParameter call.
>
> I tried to bind the data as SQL_BINARY and SQL_CHAR but I got Incorrect
> binary data format error.
>
> Quick help is appreciated.
>
> Thanks in Advance.
>
> Regards,
> Ranjeeth.


From: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
To: Hiroshi Saito <hiroshi(at)winpg(dot)jp>
Cc: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Regarding PostgreSQL BIT datatype binding in ODBC.......
Date: 2012-09-10 15:17:45
Message-ID: 1347290265.7494.YahooMailNeo@web190001.mail.sg3.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Hello Saito,

Thanks a lot for your response.
I tried using SQL_C_TCHAR and SQL_CHAR as you suggested but I still get the same "Incorrect binary data format in bind parameter" error.

I am not sure if I am missing something here...

Thanks and Regards,
Ranjeeth.

________________________________
From: Hiroshi Saito <hiroshi(at)winpg(dot)jp>
To: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
Cc: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Sent: Monday, 10 September 2012 8:01 PM
Subject: Re: [ODBC] Regarding PostgreSQL BIT datatype binding in ODBC.......

Hi.

Is this helpful to you?
one example)
== odbc
SQLTCHAR kd[100];
strcpy(kd, "1101010101");
...
SQLPrepare(hstmt, "INSERT INTO bbb VALUES (?)", SQL_NTS);
SQLBindParameter(hstmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT,
    SQL_C_TCHAR, SQL_CHAR, 0, 0, &kd[0], 100, &len);
== psql
postgres=# select * from bbb;
    key
------------
  1101010101

Regards,
Hiroshi Saito

(2012/09/10 13:32), ranjeeth kumar wrote:
> Hello All,
>
> I have a table with a bit(10) type colmn. I can insert "1010110110" into
> that column from PSQL.
> i.e.,
> postgres=# insert into public.ranc2b values(1,'1101010101');
> INSERT 0 1
>
> I want to insert the same character data "1010110110" into the same
> bit(10) typed column from an ODBC application program,
> Can somebody please suggest me how should I bind the data in the
> SQLBindParameter call.
>
> I tried to bind the data as SQL_BINARY and SQL_CHAR but I got Incorrect
> binary data format error.
>
> Quick help is appreciated.
>
> Thanks in Advance.
>
> Regards,
> Ranjeeth.


From: Hiroshi Saito <hiroshi(at)winpg(dot)jp>
To: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
Cc: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Regarding PostgreSQL BIT datatype binding in ODBC.......
Date: 2012-09-11 13:23:26
Message-ID: 504F3B4E.4080707@winpg.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Hi.

Umm,
It can check in this simple test code.

Regards,
Hiroshi Saito

(2012/09/11 0:17), ranjeeth kumar wrote:
> Hello Saito,
>
> Thanks a lot for your response.
> I tried using SQL_C_TCHAR and SQL_CHAR as you suggested but I still get
> the same "Incorrect binary data format in bind parameter" error.
> I am not sure if I am missing something here...
>
>
> Thanks and Regards,
> Ranjeeth.
>
>
> ------------------------------------------------------------------------
> *From:* Hiroshi Saito <hiroshi(at)winpg(dot)jp>
> *To:* ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
> *Cc:* "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
> *Sent:* Monday, 10 September 2012 8:01 PM
> *Subject:* Re: [ODBC] Regarding PostgreSQL BIT datatype binding in
> ODBC.......
>
> Hi.
>
> Is this helpful to you?
> one example)
> == odbc
> SQLTCHAR kd[100];
> strcpy(kd, "1101010101");
> ...
> SQLPrepare(hstmt, "INSERT INTO bbb VALUES (?)", SQL_NTS);
> SQLBindParameter(hstmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT,
> SQL_C_TCHAR, SQL_CHAR, 0, 0, &kd[0], 100, &len);
> == psql
> postgres=# select * from bbb;
> key
> ------------
> 1101010101
>
> Regards,
> Hiroshi Saito
>
> (2012/09/10 13:32), ranjeeth kumar wrote:
> > Hello All,
> >
> > I have a table with a bit(10) type colmn. I can insert "1010110110" into
> > that column from PSQL.
> > i.e.,
> > postgres=# insert into public.ranc2b values(1,'1101010101');
> > INSERT 0 1
> >
> > I want to insert the same character data "1010110110" into the same
> > bit(10) typed column from an ODBC application program,
> > Can somebody please suggest me how should I bind the data in the
> > SQLBindParameter call.
> >
> > I tried to bind the data as SQL_BINARY and SQL_CHAR but I got Incorrect
> > binary data format error.
> >
> > Quick help is appreciated.
> >
> > Thanks in Advance.
> >
> > Regards,
> > Ranjeeth.
>
>

Attachment Content-Type Size
SQLBindParameter.c text/plain 2.5 KB

From: Hiroshi Saito <hiroshi(at)winpg(dot)jp>
To: ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
Cc: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Regarding PostgreSQL BIT datatype binding in ODBC.......
Date: 2012-09-12 14:11:36
Message-ID: 50509818.8070507@winpg.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Ooops sorry, different was sended....
Please this.

(2012/09/11 22:23), Hiroshi Saito wrote:
> Hi.
>
> Umm,
> It can check in this simple test code.
>
> Regards,
> Hiroshi Saito
>
> (2012/09/11 0:17), ranjeeth kumar wrote:
>> Hello Saito,
>>
>> Thanks a lot for your response.
>> I tried using SQL_C_TCHAR and SQL_CHAR as you suggested but I still get
>> the same "Incorrect binary data format in bind parameter" error.
>> I am not sure if I am missing something here...
>>
>>
>> Thanks and Regards,
>> Ranjeeth.
>>
>>
>> ------------------------------------------------------------------------
>> *From:* Hiroshi Saito <hiroshi(at)winpg(dot)jp>
>> *To:* ranjeeth kumar <ranjeeth_cool(at)yahoo(dot)co(dot)in>
>> *Cc:* "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
>> *Sent:* Monday, 10 September 2012 8:01 PM
>> *Subject:* Re: [ODBC] Regarding PostgreSQL BIT datatype binding in
>> ODBC.......
>>
>> Hi.
>>
>> Is this helpful to you?
>> one example)
>> == odbc
>> SQLTCHAR kd[100];
>> strcpy(kd, "1101010101");
>> ...
>> SQLPrepare(hstmt, "INSERT INTO bbb VALUES (?)", SQL_NTS);
>> SQLBindParameter(hstmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT,
>> SQL_C_TCHAR, SQL_CHAR, 0, 0, &kd[0], 100, &len);
>> == psql
>> postgres=# select * from bbb;
>> key
>> ------------
>> 1101010101
>>
>> Regards,
>> Hiroshi Saito
>>
>> (2012/09/10 13:32), ranjeeth kumar wrote:
>> > Hello All,
>> >
>> > I have a table with a bit(10) type colmn. I can insert "1010110110"
>> into
>> > that column from PSQL.
>> > i.e.,
>> > postgres=# insert into public.ranc2b values(1,'1101010101');
>> > INSERT 0 1
>> >
>> > I want to insert the same character data "1010110110" into the same
>> > bit(10) typed column from an ODBC application program,
>> > Can somebody please suggest me how should I bind the data in the
>> > SQLBindParameter call.
>> >
>> > I tried to bind the data as SQL_BINARY and SQL_CHAR but I got Incorrect
>> > binary data format error.
>> >
>> > Quick help is appreciated.
>> >
>> > Thanks in Advance.
>> >
>> > Regards,
>> > Ranjeeth.
>>
>>
>
>
>
>

Attachment Content-Type Size
SQLBindParameter_bittest.c text/plain 2.6 KB