21 #include <freetds/iconv.h>
34 # define isatty(fd) _isatty(fd)
48 unsigned char dig[16];
50 ret =
asprintf(&
sql,
"convert(nvarchar(1024), bin) collate %s", name);
53 ret =
asprintf(&p,
"convert(varchar(4096), %s)",
sql);
58 ret =
asprintf(&
sql,
"select convert(varbinary(8000), %s) from #all_chars order by id", p);
84 memset(dig, 0,
sizeof(dig));
86 for (
i = 0;
i < 16; ++
i)
87 sprintf(digest +
i * 2,
"%02x", dig[
i]);
98 static char old_digest[33];
100 sprintf(
sql,
"SELECT CAST(CAST('a' AS NVARCHAR(10)) COLLATE %s AS VARCHAR(10)) COLLATE %s", name, name);
127 strcpy(cp, curcol->
char_conv->to.charset.name);
131 coll->
flags = c[2] + 256 * c[3];
136 fprintf(stderr,
"tds_process_tokens() unexpected return\n");
141 switch (result_type) {
152 fprintf(stderr,
"tds_proces_tokens() unexpected result_type\n");
159 memcpy(digest, old_digest, 33);
164 memcpy(old_digest, digest, 33);
165 memcpy(&old_coll, coll,
sizeof(*coll));
171 FILE *
f = fopen(
"collations.txt",
"r");
175 while (fgets(line,
sizeof(line),
f)) {
177 char cp[128], digest[33];
178 char *s = strtok(line,
" \n");
183 memset(&coll, 0,
sizeof(coll));
196 enum { CHUNK = 512 };
197 static char buf[CHUNK * 4+1];
204 sprintf(
buf +
cnt * 4,
"%02x%02x",
n & 0xff, (
n >> 8) & 0xff);
212 ret =
asprintf(&
sql,
"insert into #all_chars values(%d, convert(varbinary(2048), 0x%s))",
id,
buf);
215 if (isatty(fileno(stdout))) {
216 printf(
"\rInserting: %d",
id);
230 for (
n = 0;
n < 65536; ++
n)
238 for (
n = 0;
n <= 0xfffff; ++
n) {
249 ret =
run_query(
tds,
"CREATE TABLE #all_chars(id int, bin varbinary(2048))");
265 f = fopen(
"collations.txt",
"w");
302 fprintf(stderr,
"try_tds_login() failed\n");
307 printf(
"Preparing table with all characters\n");
310 printf(
"Extracting collation list\n");
313 printf(
"Testing encodings\n");
#define TDS_DONEPROC_RESULT
#define TDS_ROWFMT_RESULT
tds_sysdep_int32_type TDS_INT
#define TDS_NO_MORE_RESULTS
#define TDS_COMPUTE_RESULT
@ TDS_DONE_ERROR
error occurred
#define TDS_DONEINPROC_RESULT
static void prepare_all_chars(void)
static void add_plane0(void)
static void add_couple(unsigned n)
static void add_couples(void)
int main(int argc, char **argv)
static void extract_collations(void)
static void get_coll_md5(const char *name, char *digest)
static void get_encoding_coll(TDS71_COLLATION *coll, char *digest, char *cp, const char *name)
static void test_column_encoding(void)
int run_query(TDSSOCKET *tds, const char *query)
int try_tds_logout(TDSLOGIN *login, TDSSOCKET *tds, int verbose)
int try_tds_login(TDSLOGIN **login, TDSSOCKET **tds, const char *appname, int verbose)
#define tds_process_tokens
TDS 7.1 collation informations.
Metadata about columns in regular and compute rows.
TDS_UCHAR column_collation[5]
TDS_SERVER_TYPE column_type
This type can be different from wire type because conversion (e.g.
TDSICONV * char_conv
refers to previously allocated iconv information
unsigned char * column_data
struct tds_column::@124 on_server
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Information for a server connection.
TDSRESULTINFO * current_results
Current query information.