Line data Source code
1 : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 : * Copyright (C) 2008 Frediano Ziglio
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Library General Public
6 : * License as published by the Free Software Foundation; either
7 : * version 2 of the License, or (at your option) any later version.
8 : *
9 : * This library is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : * Library General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Library General Public
15 : * License along with this library; if not, write to the
16 : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 : * Boston, MA 02111-1307, USA.
18 : */
19 : #include "common.h"
20 :
21 : /*
22 : * Test creating a lot of dynamics. This can cause some problems cause
23 : * generated IDs are reused on a base of 2^16
24 : */
25 :
26 : static void
27 0 : fatal_error(const char *msg)
28 : {
29 0 : fprintf(stderr, "%s\n", msg);
30 0 : exit(1);
31 : }
32 :
33 : int
34 8 : main(void)
35 : {
36 : TDSLOGIN *login;
37 : TDSSOCKET *tds;
38 8 : int verbose = 0;
39 8 : TDSDYNAMIC *dyn = NULL;
40 : int rc;
41 : unsigned int n;
42 :
43 8 : printf("%s: Test creating a lot of dynamic queries\n", __FILE__);
44 8 : rc = try_tds_login(&login, &tds, __FILE__, verbose);
45 8 : if (rc != TDS_SUCCESS)
46 0 : fatal_error("try_tds_login() failed");
47 :
48 8 : run_query(tds, "DROP TABLE #test");
49 8 : if (run_query(tds, "CREATE TABLE #test (i INT, c VARCHAR(40))") != TDS_SUCCESS)
50 0 : fatal_error("creating table error");
51 :
52 8 : if (tds->cur_dyn)
53 0 : fatal_error("already a dynamic query??");
54 :
55 : /* prepare to insert */
56 8 : if (tds_submit_prepare(tds, "UPDATE #test SET c = 'test' WHERE i = ?", NULL, &dyn, NULL) != TDS_SUCCESS)
57 0 : fatal_error("tds_submit_prepare() error");
58 8 : if (tds_process_simple_query(tds) != TDS_SUCCESS)
59 0 : fatal_error("tds_process_simple_query() error");
60 8 : if (!dyn)
61 0 : fatal_error("dynamic not present??");
62 :
63 : /* waste some ids */
64 524200 : for (n = 0; n < 65525; ++n) {
65 : TDSDYNAMIC *dyn;
66 :
67 524200 : dyn = tds_alloc_dynamic(tds->conn, NULL);
68 524200 : if (!dyn)
69 0 : fatal_error("create dynamic");
70 :
71 524200 : tds_dynamic_deallocated(tds->conn, dyn);
72 524200 : tds_release_dynamic(&dyn);
73 : }
74 :
75 : /* this should not cause duplicate IDs or erros*/
76 160 : for (n = 0; n < 20; ++n) {
77 160 : TDSDYNAMIC *dyn2 = NULL;
78 :
79 160 : if (tds_submit_prepare(tds, "INSERT INTO #test(i,c) VALUES(?,?)", NULL, &dyn2, NULL) != TDS_SUCCESS)
80 0 : fatal_error("tds_submit_prepare() error");
81 160 : if (dyn == dyn2)
82 0 : fatal_error("got duplicated dynamic");
83 160 : if (tds_process_simple_query(tds) != TDS_SUCCESS)
84 0 : fatal_error("tds_process_simple_query() error");
85 160 : if (!dyn2)
86 0 : fatal_error("dynamic not present??");
87 160 : if (tds_submit_unprepare(tds, dyn2) != TDS_SUCCESS || tds_process_simple_query(tds) != TDS_SUCCESS)
88 0 : fatal_error("unprepare error");
89 160 : tds_dynamic_deallocated(tds->conn, dyn2);
90 160 : tds_release_dynamic(&dyn2);
91 : }
92 :
93 8 : tds_dynamic_deallocated(tds->conn, dyn);
94 8 : tds_release_dynamic(&dyn);
95 :
96 8 : try_tds_logout(login, tds, verbose);
97 : return 0;
98 : }
99 :
|