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 10 : TEST_MAIN()
31 : {
32 : char tmp[1024];
33 : char out[TDS_VECTOR_SIZE(column_names)][32];
34 : SQLLEN n_len[TDS_VECTOR_SIZE(column_names)];
35 : const column_t *p;
36 : int n;
37 :
38 10 : odbc_use_version3 = 1;
39 10 : odbc_conn_additional_params = "ClientCharset=UTF-8;";
40 :
41 10 : odbc_connect();
42 10 : if (!odbc_driver_is_freetds()) {
43 0 : odbc_disconnect();
44 0 : printf("Driver is not FreeTDS, exiting\n");
45 0 : odbc_test_skipped();
46 0 : return 0;
47 : }
48 :
49 10 : if (!odbc_db_is_microsoft() || odbc_db_version_int() < 0x08000000u || odbc_tds_version() < 0x701) {
50 2 : odbc_disconnect();
51 : /* protocol till 7.1 does not support telling encoding so we
52 : * cannot understand how the string is encoded
53 : */
54 2 : printf("Test for MSSQL only using protocol 7.1\n");
55 2 : odbc_test_skipped();
56 0 : return 0;
57 : }
58 :
59 8 : CHKAllocStmt(&odbc_stmt, "S");
60 :
61 : /* create test table */
62 8 : odbc_command("CREATE TABLE #tmp (i INT"
63 : ", hebrew VARCHAR(20) COLLATE Hebrew_CI_AI NULL"
64 : ", cn VARCHAR(20) COLLATE Chinese_PRC_CI_AS NULL"
65 : ")");
66 :
67 : /* insert with INSERT statements */
68 48 : for (n = 0, p = columns; p[n].hex; ++n) {
69 80 : sprintf(tmp, "INSERT INTO #tmp(i, %s) VALUES(%d, CAST(%s AS NVARCHAR(20)))",
70 40 : column_names[p[n].num], n+1, p[n].hex);
71 40 : odbc_command(tmp);
72 : }
73 :
74 : /* test conversions in libTDS */
75 8 : odbc_command("SELECT hebrew, cn FROM #tmp ORDER BY i");
76 :
77 : /* insert with SQLPrepare/SQLBindParameter/SQLExecute */
78 24 : for (n = 0; n < TDS_VECTOR_SIZE(column_names); ++n)
79 16 : CHKBindCol(n+1, SQL_C_CHAR, out[n], sizeof(out[0]), &n_len[n], "S");
80 40 : for (n = 0, p = columns; p[n].hex; ++n) {
81 40 : memset(out, 0, sizeof(out));
82 40 : CHKFetch("S");
83 40 : if (n_len[p[n].num] != strlen(p[n].out) || strcmp(p[n].out, out[p[n].num]) != 0) {
84 0 : fprintf(stderr, "Wrong row %d %s\n", n+1, out[p[n].num]);
85 0 : odbc_disconnect();
86 0 : return 1;
87 : }
88 : }
89 :
90 8 : odbc_disconnect();
91 8 : printf("Done.\n");
92 8 : return 0;
93 : }
94 :
|