How to read/write multibyte to database - Mailing list pgsql-general

From Jeff
Subject How to read/write multibyte to database
Date
Msg-id 989nue$l5a$1@news.tht.net
Whole thread Raw
Responses Re: How to read/write multibyte to database
List 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





pgsql-general by date:

Previous
From: "Sam and Lisa Snow"
Date:
Subject: RE: Win32 Postgresql
Next
From: "Jeff"
Date:
Subject: How to read/write multibyte to database