FW: Libpq - multibyte character support

From: "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: FW: Libpq - multibyte character support
Date: 2005-09-06 14:29:41
Message-ID: 77ED2BF75D59D1439F90412CC5B1097423F87B47@ie10-sahara.hiso.honeywell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

> Hi all,
>
> My question is does PgSQL libpq functions support multibyte
> characters...if not then is there a way to provide multibyte data to
> Postgres using libpq functions. The other question is does Postgres
> support Chinese characters....if I insert chinese characters into a table,
> when I read, will I get the same chinese characters. Please help me out in
> this regard.
>
> I have created a database with UNICODE support which has a table
> GSNames(Gsname varchar(40), status int, errorcode int)
> I tried to insert into this table from a simple C program using
> libpq functions....but it gives error as libpq does not support wchar
> datatypes. Here is the code -
>
> int main()
> {
> // wchar_t szQuery[255];
> char szQuery[255];
>
> PGconn *DBCon;
> PGresult *DBResult;
>
> //Connect to the database with default settings
> DBCon = PQsetdbLogin(NULL, NULL, NULL, NULL, "test1",
> "postgres", ""); //test1 is database created with UNICODE encoding
>
> //check if there is any error in connecting to the database
> if(PQstatus(DBCon) == CONNECTION_BAD)
> {
> fprintf(stderr,"\nGetAttributeInfo(): Connection to
> database failed.");
> fprintf(stderr,"\nGetAttributeInfo(): %s",
> PQerrorMessage(DBCon));
> return ERROR_DB_CON;
> }
> else
> {
> fprintf(stderr,"\nGetAttributeInfo(): Connection to
> database successful.");
> }
>
> //form the DELETE command as character buffer.
> //swprintf(szQuery,500,L"INSERT INTO gsnames
> values('×¢²á',2,2)");
> sprintf(szQuery,"INSERT INTO gsnames values('×¢²á',2,2)");
>
> //execute the command.
> DBResult = PQexec(DBCon, (char *)szQuery);
>
> //check for any errors in executing the query.
> if(PQresultStatus(DBResult) != PGRES_COMMAND_OK)
> {
> fprintf(stderr,"\nGetAttributeInfo(): %s",
> PQresultErrorMessage(DBResult));
> PQclear(DBResult);
> PQfinish(DBCon);
> return ERROR_DB_EXEC;
> }
> else
> {
> fprintf(stderr,"\nDBInsertPointAttribute():
> Insertion successful. No. of rows affected = %d.", PQntuples(DBResult));
> }
>
> PQclear(DBResult);
> PQfinish(DBCon);
>
> return 0;
> }
>
> The problem is I am not able to pass multibyte characters to
> postgres. Please help.....Thanks in advance.
>
Between I am using Postgres version 7.4.3. While installing
Pgsql, I dnt specify any encoding or multi byte character support for
initdb.

> Regs,
> Pradeep
>
>

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Eric Emerton 2005-09-06 15:24:45 Windows pgpass Problems..
Previous Message Guido Barosio 2005-09-06 11:46:26 Comparing MySQL and PostgreSQL 2