1 | #ifndef READ_QUERY_INSTRUCTIONS
2 | #define READ_QUERY_INSTRUCTIONS
3 |
4 | /***************************************
5 | $Revision: 1.31 $
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 | #include "ca_configFns.h"
43 | #include "ca_dictionary.h"
44 | #include "ca_macros.h"
45 | #include "ca_srcAttribs.h"
46 |
47 | /*
48 | --- snipped from http://www.tcx.se/Manual/manual.html ---
49 |
50 | 5.3 Functionality missing from MySQL
51 |
52 | 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
53 | 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).
54 |
55 | 5.3.1 Sub-selects
56 |
57 | The following will not yet work in MySQL:
58 |
59 | SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
60 | SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
61 |
62 | However, in many cases you can rewrite the query without a sub select:
63 |
64 | SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
65 | SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
66 |
67 | For more complicated sub queries you can create temporary tables to hold the sub query.
68 |
69 | 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
70 | contexts, however.
71 |
72 | --- end snip ---
73 |
74 | Ie. Try using a LEFT JOIN to do the "NOT IN"/ "MINUS" equivalent.
75 |
76 | */
77 |
78 | /*
79 | mysql optimizer is sometimes sub-optimal,
80 | therefore we force the join order with STRAIGHT_JOIN (MB, 2000/05/02)
81 |
82 |
83 | */
84 |
85 | /* RIPE 6 */
86 | #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 ord87 | er_code"
88 |
89 |
90 |
91 | #define Q_REC "INSERT INTO %s SELECT pe_ro_id FROM %s IDS STRAIGHT_JOIN %s WHERE object_id = IDS.id"
92 |
93 | #if 0
94 | #define Q_NO_OBJECTS "SELECT object_id, sequence_id, object FROM last WHERE object_id = 0"
95 | #endif
96 |
97 | #define MAX_INSTRUCTIONS 100
98 |
99 |
100 | typedef struct Query_instruction_t {
101 | R_Type_t search_type;
102 | int queryindex;/* index into the Query table showing origin of this entry */
103 | char *query_str;
104 | char *rx_keys;
105 | unsigned int rx_srch_mode;
106 | int rx_par_a;
107 | ip_space_t space;
108 | rx_fam_t family;
109 | } Query_instruction;
110 |
111 | typedef struct Query_instructions_t {
112 | Query_instruction *instruction[MAX_INSTRUCTIONS];
113 | unsigned int filtered;
114 | unsigned int fast;
115 | unsigned int recursive;
116 | const Query_command *qc; /* pointer to the Query_command structure of this query */
117 | } Query_instructions;
118 |
119 |
120 | er_ret_t QI_execute(ca_dbSource_t *dbhdl, Query_instructions *qis, Query_environ *qe, acc_st *acc_credit, acl_st *acl);
121 | void QI_free(Query_instructions *qis);
122 | Query_instructions *QI_new(const Query_command *qc, const Query_environ *qe);
123 | char *QI_queries_to_string(Query_instructions *qis);
124 | char *QI_fast_output(const char *str);
125 |
126 | #endif /* READ_QUERY_INSTRUCTIONS */