| 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:46:13 | 
| Message-ID: | 989nsa$l4o$1@news.tht.net | 
| Views: | Whole Thread | Raw Message | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jeff | 2001-03-10 04:47:22 | How to read/write multibyte to database | 
| Previous Message | Jack | 2001-03-10 04:41:21 | a psql windows version? |