From: | Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp> |
---|---|
To: | sc404885(at)bucc3(dot)buu(dot)ac(dot)th |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Program test strcoll(). |
Date: | 2001-01-19 02:31:45 |
Message-ID: | 20010119113145D.t-ishii@sra.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
It seems for me your test program do same thing as PostgreSQL backend
does. So I would say if the program worked well, why not PostgreSQL
works?
What do you think Oleg?
From: Maneerat Sappaso <sc404885(at)bucc3(dot)buu(dot)ac(dot)th>
Subject: Program test strcoll().
Date: Thu, 18 Jan 2001 19:52:39 -0700 (GMT)
Message-ID: <Pine(dot)SOL(dot)4(dot)10(dot)10101181925420(dot)19935-200000(at)bucc3(dot)buu(dot)ac(dot)th>
> Deer sir,
>
> Program collsort.c is a test program in THAI locale version
> th_TH-2.1.1-5.src.tar.gz for testing strcoll(). It sort by
> thai dictionary not by ascii. I use to test this program with
> thai or english (or thai+english) words and it sorted correctly.
>
> I found that before run this program we must
> setlocale(LC_COLLATE,"th_TH");
>
> When I install PostgreSQL with locale I try to test data by
> use sql command like this " select * from table order by name"
> The result are sorted by ascii.
>
> regards,
> maneerat sappaso
[the test program from Maneerat]
/*
* collsort.c - a word list sorting tool using strcoll()
* Created: 26 Nov 1998
* Author: Theppitak Karoonboonyanan
*/
/*
Copyright (C) 1999 Theppiak Karoonboonyanan
collsort.c is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
*/
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef unsigned char tchar;
/* for qsort() */
typedef int (*CMPFUNC)(const void *, const void *);
static size_t readData(FILE *dataFile, tchar *data[], int maxData)
{
size_t nData = 0;
static char wordBuf[128];
while (nData < maxData && fgets(wordBuf, sizeof wordBuf, dataFile) != NULL)
{
int len = strlen(wordBuf);
if (len == 0) { return nData; }
/* eliminate terminating '\n' */
wordBuf[--len] = 0;
/* allocate & copy the line */
data[nData] = (tchar*)malloc(len+1);
if (data[nData] == NULL) {
printf("Warning: Only %d items were read\n", nData);
return nData;
}
strcpy((char*)data[nData], wordBuf);
nData++;
}
return nData;
}
static void freeData(tchar *data[], size_t nItems)
{
size_t i;
for (i=0; i<nItems; i++) {
free(data[i]);
}
}
static int dataCmp(const char **pStr1, const char **pStr2)
{
return strcoll(*pStr1, *pStr2);
}
static void sortData(tchar *data[], size_t nItems)
{
qsort(data, nItems, sizeof data[0], (CMPFUNC)dataCmp);
}
static void writeData(FILE *outFile, tchar *data[], size_t nItems)
{
size_t i;
for (i = nItems; i > 0; i--) {
fprintf(outFile, "%s\n", *data);
data++;
}
}
#define MAX_DATA 40000
static tchar *data[MAX_DATA];
int main(int argc, char *argv[])
{
FILE *dataFile;
FILE *outFile;
size_t dataRead;
char DataFileName[64];
char OutFileName[64];
const char* pPrevLocale;
pPrevLocale = setlocale(LC_COLLATE, "");
if (pPrevLocale == 0) {
fprintf(stderr, "Cannot set locale\n");
exit(1);
}
if (argc == 3) {
strcpy(DataFileName, argv[1]);
strcpy(OutFileName, argv[2]);
} else {
fprintf(stderr, "Usage: collsort <input file> <output file>\n");
return 1;
}
dataFile = fopen(DataFileName, "rt");
if (dataFile == NULL) {
fprintf(stderr, "Can't open file %s\n", DataFileName);
perror("fopen");
return 1;
}
outFile = fopen(OutFileName, "wt");
if (outFile == NULL) {
fprintf(stderr, "Can't open file %s for write\n", OutFileName);
perror("fopen");
return 1;
}
dataRead = readData(dataFile, data, MAX_DATA);
sortData(data, dataRead);
writeData(outFile, data, dataRead);
freeData(data, dataRead);
fclose(outFile);
fclose(dataFile);
setlocale(LC_COLLATE, pPrevLocale);
return 0;
}
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-01-19 02:38:13 | Re: 7.0.3 reproduceable serious select error |
Previous Message | Barry Lind | 2001-01-19 02:30:25 | Re: 7.0.3 reproduceable serious select error |