Line data Source code
1 : #include "common.h"
2 : #include <freetds/macros.h>
3 :
4 : /* test conversion of Hebrew characters (which have shift sequences) */
5 :
6 : static const char * const column_names[] = {
7 : "hebrew",
8 : "cn"
9 : };
10 :
11 : typedef struct {
12 : /* number of column */
13 : int num;
14 : /* hex representation, used during insert */
15 : const char *hex;
16 : /* output */
17 : const char *out;
18 : } column_t;
19 :
20 : static const column_t columns[] = {
21 : { 0, "0xde05d905d305e205", "\xd7\x9e\xd7\x99\xd7\x93\xd7\xa2" },
22 : { 0, "0x69006e0066006f00", "info", },
23 : { 0, "0xd805e705e105d805", "\xd7\x98\xd7\xa7\xd7\xa1\xd7\x98", },
24 : { 0, "0xd005d105db05", "\xd7\x90\xd7\x91\xd7\x9b", },
25 : { 1, "0xf78b7353d153278d3a00228c228c56e02000",
26 : "\xe8\xaf\xb7\xe5\x8d\xb3\xe5\x8f\x91\xe8\xb4\xa7\x3a\xe8\xb0\xa2\xe8\xb0\xa2\xee\x81\x96\x20", },
27 : { 0, NULL, NULL },
28 : };
29 :
30 : int
31 8 : main(void)
32 : {
33 : char tmp[1024];
34 : char out[TDS_VECTOR_SIZE(column_names)][32];
35 : SQLLEN n_len[TDS_VECTOR_SIZE(column_names)];
36 : const column_t *p;
37 : int n;
38 :
39 8 : odbc_use_version3 = 1;
40 8 : odbc_conn_additional_params = "ClientCharset=UTF-8;";
41 :
42 8 : odbc_connect();
43 8 : if (!odbc_driver_is_freetds()) {
44 0 : odbc_disconnect();
45 0 : printf("Driver is not FreeTDS, exiting\n");
46 0 : odbc_test_skipped();
47 0 : return 0;
48 : }
49 :
50 8 : if (!odbc_db_is_microsoft() || odbc_db_version_int() < 0x08000000u || odbc_tds_version() < 0x701) {
51 2 : odbc_disconnect();
52 : /* protocol till 7.1 does not support telling encoding so we
53 : * cannot understand how the string is encoded
54 : */
55 2 : printf("Test for MSSQL only using protocol 7.1\n");
56 2 : odbc_test_skipped();
57 0 : return 0;
58 : }
59 :
60 6 : CHKAllocStmt(&odbc_stmt, "S");
61 :
62 : /* create test table */
63 6 : odbc_command("CREATE TABLE #tmp (i INT"
64 : ", hebrew VARCHAR(20) COLLATE Hebrew_CI_AI NULL"
65 : ", cn VARCHAR(20) COLLATE Chinese_PRC_CI_AS NULL"
66 : ")");
67 :
68 : /* insert with INSERT statements */
69 36 : for (n = 0, p = columns; p[n].hex; ++n) {
70 60 : sprintf(tmp, "INSERT INTO #tmp(i, %s) VALUES(%d, CAST(%s AS NVARCHAR(20)))",
71 30 : column_names[p[n].num], n+1, p[n].hex);
72 30 : odbc_command(tmp);
73 : }
74 :
75 : /* test conversions in libTDS */
76 6 : odbc_command("SELECT hebrew, cn FROM #tmp ORDER BY i");
77 :
78 : /* insert with SQLPrepare/SQLBindParameter/SQLExecute */
79 18 : for (n = 0; n < TDS_VECTOR_SIZE(column_names); ++n)
80 12 : CHKBindCol(n+1, SQL_C_CHAR, out[n], sizeof(out[0]), &n_len[n], "S");
81 30 : for (n = 0, p = columns; p[n].hex; ++n) {
82 30 : memset(out, 0, sizeof(out));
83 30 : CHKFetch("S");
84 30 : if (n_len[p[n].num] != strlen(p[n].out) || strcmp(p[n].out, out[p[n].num]) != 0) {
85 0 : fprintf(stderr, "Wrong row %d %s\n", n+1, out[p[n].num]);
86 0 : odbc_disconnect();
87 0 : return 1;
88 : }
89 : }
90 :
91 6 : odbc_disconnect();
92 6 : printf("Done.\n");
93 6 : return 0;
94 : }
95 :
|