Line data Source code
1 : #include "common.h"
2 :
3 : /* Test SQLCopyDesc and SQLAllocHandle(SQL_HANDLE_DESC) */
4 :
5 : static void
6 40 : check_alloc_type(SQLHDESC hdesc, SQLSMALLINT expected_alloc_type, const char *exp, int line)
7 : {
8 : SQLSMALLINT alloc_type;
9 : SQLINTEGER ind;
10 :
11 40 : CHKGetDescField(hdesc, 0, SQL_DESC_ALLOC_TYPE, &alloc_type, sizeof(alloc_type), &ind, "S");
12 :
13 40 : if (alloc_type != expected_alloc_type) {
14 0 : fprintf(stderr, "Wrong condition at line %d: SQL_DESC_ALLOC_TYPE expected %s(%d) got %d\n",
15 : line, exp, expected_alloc_type, alloc_type);
16 0 : exit(1);
17 : }
18 40 : }
19 :
20 : #define check_alloc_type(d,e) check_alloc_type(d, e, #e, __LINE__)
21 :
22 10 : TEST_MAIN()
23 : {
24 : SQLHDESC ard, ard2, ard3;
25 : SQLINTEGER id;
26 : SQLLEN ind1, ind2;
27 : char name[64];
28 :
29 10 : odbc_connect();
30 :
31 10 : CHKGetStmtAttr(SQL_ATTR_APP_ROW_DESC, &ard, 0, NULL, "S");
32 10 : check_alloc_type(ard, SQL_DESC_ALLOC_AUTO);
33 :
34 10 : CHKBindCol(1, SQL_C_SLONG, &id, sizeof(SQLINTEGER), &ind1, "S");
35 10 : CHKBindCol(2, SQL_C_CHAR, name, sizeof(name), &ind2, "S");
36 :
37 10 : CHKAllocHandle(SQL_HANDLE_DESC, odbc_conn, &ard2, "S");
38 10 : check_alloc_type(ard2, SQL_DESC_ALLOC_USER);
39 :
40 : /*
41 : * this is an additional test to test additional allocation
42 : * As of 0.64 for a bug in SQLAllocDesc we only allow to allocate one
43 : */
44 10 : CHKAllocHandle(SQL_HANDLE_DESC, odbc_conn, &ard3, "S");
45 10 : check_alloc_type(ard3, SQL_DESC_ALLOC_USER);
46 :
47 10 : CHKR(SQLCopyDesc, (ard, ard2), "S");
48 10 : check_alloc_type(ard2, SQL_DESC_ALLOC_USER);
49 :
50 10 : CHKFreeHandle(SQL_HANDLE_DESC, ard3, "S");
51 :
52 : /* check SQL_INVALID_HANDLE, twice to check a mutex condition */
53 10 : CHKR(SQLCopyDesc, (NULL, ard2), "V");
54 10 : CHKR(SQLCopyDesc, (ard2, NULL), "V");
55 10 : CHKR(SQLCopyDesc, (NULL, ard2), "V");
56 10 : CHKR(SQLCopyDesc, (ard2, NULL), "V");
57 :
58 10 : odbc_disconnect();
59 :
60 10 : printf("Done.\n");
61 10 : return 0;
62 : }
|