1 | #ifndef READ_QUERY_INSTRUCTIONS
2 | #define READ_QUERY_INSTRUCTIONS
3 |
4 | /***************************************
5 | $Revision: 1.25 $
6 |
7 | Query instruction module (qi)
8 | config module.
9 |
10 | Status: NOT REVUED, NOT TESTED
11 |
12 | ******************/ /******************
13 | Copyright (c) 1999 RIPE NCC
14 |
15 | All Rights Reserved
16 |
17 | Permission to use, copy, modify, and distribute this software and its
18 | documentation for any purpose and without fee is hereby granted,
19 | provided that the above copyright notice appear in all copies and that
20 | both that copyright notice and this permission notice appear in
21 | supporting documentation, and that the name of the author not be
22 | used in advertising or publicity pertaining to distribution of the
23 | software without specific, written prior permission.
24 |
25 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
26 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
27 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
28 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
29 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
30 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 | ***************************************/
32 | #include "rxroutines.h"
33 | #include "iproutines.h"
34 | #include "mysql_driver.h"
35 | #include "query_command.h"
36 | #include "defs.h"
37 | #include "which_keytypes.h"
38 |
39 | #include "access_control.h"
40 |
41 |
42 |
43 | /*
44 | --- snipped from http://www.tcx.se/Manual/manual.html ---
45 |
46 | 5.3 Functionality missing from MySQL
47 |
48 | The following functionality is missing in the current version of MySQL. For a prioritized list indicating when new extensions may be added to MySQL, you should consult the
49 | online MySQL TODO list. That is the latest version of the TODO list in this manual. See section F List of things we want to add to MySQL in the future (The TODO).
50 |
51 | 5.3.1 Sub-selects
52 |
53 | The following will not yet work in MySQL:
54 |
55 | SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
56 | SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
57 |
58 | However, in many cases you can rewrite the query without a sub select:
59 |
60 | SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
61 | SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
62 |
63 | For more complicated sub queries you can create temporary tables to hold the sub query.
64 |
65 | MySQL only supports INSERT ... SELECT ... and REPLACE ... SELECT ... Independent sub-selects will be probably be available in 3.24.0. You can now use the function IN() in other
66 | contexts, however.
67 |
68 | --- end snip ---
69 |
70 | Ie. Try using a LEFT JOIN to do the "NOT IN"/ "MINUS" equivalent.
71 |
72 | */
73 |
74 | /*
75 | mysql optimizer is sometimes sub-optimal,
76 | therefore we force the join order with STRAIGHT_JOIN (MB, 2000/05/02)
77 |
78 |
79 | */
80 |
81 | /* RIPE 6 */
82 | #define Q_OBJECTS "SELECT last.object_id, last.sequence_id, last.object ,last.object_type FROM %s IDS STRAIGHT_JOIN last,object_order WHERE last.object_id=IDS.id AND last.object_type != 100 AND last.object_type = object_order.object_type ORDER BY ord83 | er_code"
84 |
85 | #define Q_REC "INSERT INTO %s SELECT pe_ro_id FROM %s IDS STRAIGHT_JOIN %s WHERE object_id = IDS.id"
86 |
87 | #define Q_NO_OBJECTS "SELECT object_id, sequence_id, object FROM last WHERE object_id = 0"
88 |
89 | #define MAX_INSTRUCTIONS 100
90 |
91 |
92 | typedef struct Query_instruction_t {
93 | R_Type_t search_type;
94 | int queryindex;/* index into the Query table showing origin of this entry */
95 | char *query_str;
96 | char *rx_keys;
97 | unsigned int rx_srch_mode;
98 | unsigned int rx_par_a;
99 | ip_space_t space;
100 | rx_fam_t family;
101 | } Query_instruction;
102 |
103 | typedef struct Query_instructions_t {
104 | Query_instruction *instruction[MAX_INSTRUCTIONS];
105 | unsigned int filtered;
106 | unsigned int fast;
107 | unsigned int recursive;
108 | const Query_command *qc; /* pointer to the Query_command structure of this query */
109 | } Query_instructions;
110 |
111 |
112 | void QI_execute(void *database_voidptr, Query_instructions *qis, Query_environ *qe, acc_st *acc_credit, acl_st *acl);
113 | void QI_free(Query_instructions *qis);
114 | Query_instructions *QI_new(const Query_command *qc, const Query_environ *qe);
115 | char *QI_queries_to_string(Query_instructions *qis);
116 |
117 | #endif /* READ_QUERY_INSTRUCTIONS */