Re: [BUGS] libpgtcl doesn't use UTF encoding of TCL

Поиск
Список
Период
Сортировка
От Tatsuo Ishii
Тема Re: [BUGS] libpgtcl doesn't use UTF encoding of TCL
Дата
Msg-id 20010722201032E.t-ishii@sra.co.jp
обсуждение исходный текст
Ответы Re: [BUGS] libpgtcl doesn't use UTF encoding of TCL  (Eugene Fokin <elf@solvo.ru>)
Список pgsql-hackers
Hum. Why don't you enable --enable-multibyte and
--enable-unicode-conversion and set client_encoding to UNICODE? That
would do a conversion from/to UTF-8 for Tcl 8.x (x > 9) clients?
--
Tatsuo Ishii

> Eugene Faukin (elf@solvo.ru) reports a bug with a severity of 2
> The lower the number the more severe it is.
> 
> Short Description
> libpgtcl doesn't use UTF encoding of TCL
> 
> Long Description
> Modern versions of the TCL (8.2 at least) use UTF encoding to internal
> storage of the text. libpgtcl uses TCL functions to insert strings directly
> into TCL internal structure without any conversion.
> 
> 
> Sample Code
> I can suggest you next patch I use for myself:
> 
> diff -uNr postgresql-7.0.2.orig/src/interfaces/libpgtcl/pgtclCmds.c
postgresql-7.0.2/src/interfaces/libpgtcl/pgtclCmds.c
> --- postgresql-7.0.2.orig/src/interfaces/libpgtcl/pgtclCmds.c   Wed Apr 12 21:17:11 2000
> +++ postgresql-7.0.2/src/interfaces/libpgtcl/pgtclCmds.c        Thu Nov 16 20:26:37 2000
> @@ -431,6 +431,7 @@
>         Pg_ConnectionId *connid;
>         PGconn     *conn;
>         PGresult   *result;
> +       Tcl_DString putString;
>  
>         if (argc != 3)
>         {
> @@ -449,7 +450,9 @@
>                 return TCL_ERROR;
>         }
>  
> -       result = PQexec(conn, argv[2]);
> +       Tcl_UtfToExternalDString(NULL, argv[2], -1, &putString);
> +       result = PQexec(conn, Tcl_DStringValue(&putString));
> +       Tcl_DStringFree(&putString);
>  
>         /* Transfer any notify events from libpq to Tcl event queue. */
>         PgNotifyTransferEvents(connid);
> @@ -535,6 +538,7 @@
>         char       *arrVar;
>         char            nameBuffer[256];
>         const char *appendstr;
> +       Tcl_DString retString;
>  
>         if (argc < 3 || argc > 5)
>         {
> @@ -685,11 +689,24 @@
>                 }
>  #ifdef TCL_ARRAYS
>                 for (i = 0; i < PQnfields(result); i++)
> -                       Tcl_AppendElement(interp, tcl_value(PQgetvalue(result, tupno, i)));
> +               {
> +                   Tcl_ExternalToUtfDString(NULL,
> +                                            tcl_value(PQgetvalue(result,
> +                                                                 tupno, i)),
> +                                            -1, &retString);
> +                   Tcl_AppendElement(interp, Tcl_DStringValue(&retString));
> +               }
>  #else
>                 for (i = 0; i < PQnfields(result); i++)
> -                       Tcl_AppendElement(interp, PQgetvalue(result, tupno, i));
> +               {
> +                   Tcl_ExternalToUtfDString(NULL,
> +                                            PQgetvalue(result, tupno, i),
> +                                            -1, &retString);
> +               
> +                   Tcl_AppendElement(interp, Tcl_DStringValue(&retString));
> +               }
>  #endif
> +               Tcl_DStringFree(&retString);
>                 return TCL_OK;
>         }
>         else if (strcmp(opt, "-tupleArray") == 0)
> @@ -707,21 +724,35 @@
>                 }
>                 for (i = 0; i < PQnfields(result); i++)
>                 {
> -                       if (Tcl_SetVar2(interp, argv[4], PQfname(result, i),
> +                   Tcl_ExternalToUtfDString(NULL, 
>  #ifdef TCL_ARRAYS
> -                                                       tcl_value(PQgetvalue(result, tupno, i)),
> +                                            tcl_value(PQgetvalue(result,
> +                                                                 tupno, i)),
>  #else
> -                                                       PQgetvalue(result, tupno, i),
> +                                            PQgetvalue(result, tupno, i),
>  #endif
> -                                                       TCL_LEAVE_ERR_MSG) == NULL)
> -                               return TCL_ERROR;
> +                                            -1, &retString);
> +
> +                   if (Tcl_SetVar2(interp, argv[4], PQfname(result, i),
> +                                   Tcl_DStringValue(&retString),
> +                                   TCL_LEAVE_ERR_MSG) == NULL)
> +                   {
> +                       Tcl_DStringFree(&retString);
> +                       return TCL_ERROR;
> +                   }
>                 }
> +               Tcl_DStringFree(&retString);
>                 return TCL_OK;
>         }
>         else if (strcmp(opt, "-attributes") == 0)
>         {
>                 for (i = 0; i < PQnfields(result); i++)
> -                       Tcl_AppendElement(interp, PQfname(result, i));
> +               {
> +                   Tcl_ExternalToUtfDString(NULL, PQfname(result, i),
> +                                            -1, &retString);
> +                   Tcl_AppendElement(interp, Tcl_DStringValue(&retString));
> +                   Tcl_DStringFree(&retString);
> +               }
>                 return TCL_OK;
>         }
>         else if (strcmp(opt, "-lAttributes") == 0)
> @@ -1274,6 +1305,8 @@
>                                 column,
>                                 ncols;
>         Tcl_DString headers;
> +       Tcl_DString retString;
> +       Tcl_DString putString;
>         char            buffer[2048];
>         struct info_s
>         {
> @@ -1292,7 +1325,11 @@
>         if (conn == (PGconn *) NULL)
>                 return TCL_ERROR;
>  
> -       if ((result = PQexec(conn, argv[2])) == 0)
> +       Tcl_UtfToExternalDString(NULL, argv[2], -1, &putString);
> +       result = PQexec(conn, Tcl_DStringValue(&putString));
> +       Tcl_DStringFree(&putString);
> +
> +       if (result == 0)
>         {
>                 /* error occurred sending the query */
>                 Tcl_SetResult(interp, PQerrorMessage(conn), TCL_VOLATILE);
> @@ -1340,13 +1377,21 @@
>                 Tcl_SetVar2(interp, argv[3], ".tupno", buffer, 0);
>  
>                 for (column = 0; column < ncols; column++)
> -                       Tcl_SetVar2(interp, argv[3], info[column].cname,
> +               {
> +                   Tcl_ExternalToUtfDString(NULL,
>  #ifdef TCL_ARRAYS
> -                                               tcl_value(PQgetvalue(result, tupno, column)),
> +                                            tcl_value(PQgetvalue(result,
> +                                                                 tupno,
> +                                                                 column)),
>  #else
> -                                               PQgetvalue(result, tupno, column),
> +                                            PQgetvalue(result, tupno, column),
>  #endif
> -                                               0);
> +                                            -1, &retString);
> +
> +                   Tcl_SetVar2(interp, argv[3], info[column].cname,
> +                               Tcl_DStringValue(&retString), 0);
> +                   Tcl_DStringFree(&retString);
> +               }
>  
>                 Tcl_SetVar2(interp, argv[3], ".command", "update", 0);
>  
> 
> 
> No file was uploaded with this report
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tatsuo Ishii
Дата:
Сообщение: Re: Thai data import into PostgreSQL
Следующее
От: Andrew McMillan
Дата:
Сообщение: Re: Incomplete idea about views and INSERT...RETURNING