How to read/write multibyte to database

From: "Jeff" <jklcom(at)mindspring(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to read/write multibyte to database
Date: 2001-03-10 04:47:22
Message-ID: 989nue$l5a$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have a form that contains data with Chinese characters. When it's
submited through http request, how can I write it to the database?

Currently I'm getting garbage when retrieve the records.

Here's code snippets:

contentTypeFromPost = getenv("CONTENT_TYPE");
contentTypeLength = getenv("CONTENT_LENGTH");
icontentLength = atoi(contentTypeLength);

if((queryString = malloc(icontentLength + 1)) == NULL)
{
postMessage("Cannot allocate memory", 0);
return(0);
}
...
for(i=0; *queryString; i++)
{
splitword(items.Item, queryString, '&');
unescape_url(items.Item);
splitword(items.name, items.Item, '=');

if(!strcmp(items.name, "Name"))
{
strcpy(name, items.Item);
}
else if(!strcmp(items.name, "Address"))
{
strcpy(address, items.Item);
}

...

sprintf(query_string, "INSERT INTO info values('%s', '%s')", name,
address);
res = PQexec(conn, query_string);

name & address are in Chinese.
Do I have to do any conversion before writing to the database?

-Jeff

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dave Cramer 2001-03-10 05:51:48 Re: JRelationalFramework
Previous Message Jeff 2001-03-10 04:46:13 How to read/write multibyte to database