1    | #ifndef READ_QUERY_INSTRUCTIONS
2    | #define READ_QUERY_INSTRUCTIONS
3    | 
4    | /***************************************
5    |   $Revision: 1.21 $
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   | /* RIPE3 version.
43   | #define Q_OBJECTS     "SELECT last.serial, last.prev_serial, last.object FROM last, %s WHERE last.serial=%s.id GROUP BY last.serial"
44   | */
45   | /* RIPE4 
46   |    #define Q_OBJECTS     "SELECT last.object_id, last.sequence_id, last.object FROM last, %s WHERE last.object_id=%s.id AND last.object_type != 100 GROUP BY last.object_id"
47   | */
48   | /* RIPE 6 */
49   | #define Q_OBJECTS     "SELECT last.object_id, last.sequence_id, last.object ,last.object_type FROM last, %s WHERE last.object_id=%s.id AND last.object_type != 100 GROUP BY last.object_id"
50   | 
51   | #define Q_REC         "INSERT INTO %s_R SELECT pe_ro_id FROM %s, %s WHERE object_id = %s.id"
52   | 
53   | /* XXX This takes too long.  :-(
54   | #define Q_REC_OBJECTS "SELECT last.serial, last.prev_serial, last.object FROM last, %s_R, %s WHERE last.serial=%s_R.id AND %s.id != %s_R.id GROUP BY last.serial"
55   | 
56   | --- snipped from http://www.tcx.se/Manual/manual.html ---
57   | 
58   | 5.3 Functionality missing from MySQL
59   | 
60   | 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
61   | 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). 
62   | 
63   | 5.3.1 Sub-selects
64   | 
65   | The following will not yet work in MySQL: 
66   | 
67   | SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
68   | SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
69   | 
70   | However, in many cases you can rewrite the query without a sub select: 
71   | 
72   | SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
73   | SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
74   | 
75   | For more complicated sub queries you can create temporary tables to hold the sub query. 
76   | 
77   | 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
78   | contexts, however. 
79   | 
80   | --- end snip ---
81   | 
82   | Ie. Try using a LEFT JOIN to do the "NOT IN"/ "MINUS" equivalent.
83   | 
84   | */
85   | /* RIPE3 version.
86   | #define Q_REC_OBJECTS "SELECT last.serial, last.prev_serial, last.object FROM last, %s_R WHERE last.serial=%s_R.id GROUP BY last.serial"
87   | */
88   | /* RIPE4 version
89   |    #define Q_REC_OBJECTS "SELECT last.object_id, last.sequence_id, last.object FROM last, %s_R WHERE last.object_id=%s_R.id AND last.object_type != 100 GROUP BY last.object_id"
90   | */
91   | /* RIPE6 version */
92   | #define Q_REC_OBJECTS "SELECT last.object_id, last.sequence_id, last.object,last.object_type FROM last, %s_R WHERE last.object_id=%s_R.id AND last.object_type != 100 GROUP BY last.object_id"
93   | 
94   | 
95   | 
96   | /* RIPE3 version
97   | #define Q_NO_OBJECTS  "SELECT serial, prev_serial, object FROM last WHERE serial = 0"
98   | */
99   | #define Q_NO_OBJECTS  "SELECT object_id, sequence_id, object FROM last WHERE object_id = 0"
100  | 
101  | #define MAX_INSTRUCTIONS 100
102  | 
103  | typedef enum _R_Type_t {
104  |   R_SQL=0,
105  |   R_RADIX,
106  |   R_END
107  | } R_Type_t;
108  | 
109  | typedef enum _Q_Type_t {
110  |   Q_LOOKUP=0,
111  |   Q_INVERSE,
112  | } Q_Type_t;
113  | 
114  | typedef enum _S_Type_t {
115  |   IPv4,
116  |   IPv6
117  | } S_Type_t;
118  | 
119  | typedef struct Query_instruction_t {
120  |   R_Type_t search_type;
121  |   int  queryindex;/* index into the Query table showing origin of this entry */
122  |   char *query_str;
123  |   char *rx_keys;
124  |   unsigned int rx_srch_mode;
125  |   unsigned int rx_par_a;
126  |   ip_space_t space;
127  |   rx_fam_t family;
128  | } Query_instruction;
129  | 
130  | typedef struct Query_instructions_t {
131  |   Query_instruction *instruction[MAX_INSTRUCTIONS];
132  |   unsigned int filtered;
133  |   unsigned int fast;
134  |   unsigned int recursive;
135  |   const Query_command *qc; /* pointer to the Query_command structure of this query */
136  | } Query_instructions;
137  | 
138  | 
139  | void QI_execute(void *database_voidptr, Query_instructions *qis, Query_environ *qe, acc_st *acc_credit, acl_st *acl);
140  | void QI_free(Query_instructions *qis);
141  | Query_instructions *QI_new(const Query_command *qc, const Query_environ *qe);
142  | 
143  | #endif /* READ_QUERY_INSTRUCTIONS */