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