1 | #ifndef READ_QUERY_INSTRUCTIONS
2 | #define READ_QUERY_INSTRUCTIONS
3 |
4 | /***************************************
5 | $Revision: 1.11 $
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 "mysql_driver.h"
33 | #include "query_command.h"
34 |
35 | #define MAX_INSTRUCTIONS 100
36 |
37 | /* SQL queries for the RIPE database */
38 | #define Q_PRI_NAME "SELECT N00.pe_ro_id FROM %s WHERE %s " /* whois NAME */
39 | #define Q_INV_NAME "SELECT %s.object_id FROM %s, %%s WHERE %s.pe_ro_id = N00.pe_ro_id AND %%s" /* whois -iac,tc,zc NAME */
40 |
41 | #define Q_PRI_NICHDL "SELECT pe_ro_id FROM person_role WHERE person_role.nic_hdl = '%s'" /* whois NICHDL */
42 | #define Q_INV_NICHDL "SELECT %s.object_id FROM person_role, %s WHERE person_role.nic_hdl = '%s' AND person_role.pe_ro_id = %s.pe_ro_id" /* whois -iac,tc,zc NICHDL */
43 |
44 | #define Q_PRI_EMAIL "SELECT object_id FROM e_mail WHERE e_mail = '%s'" /* whois EMAIL */
45 | #define Q_INV_EMAIL "SELECT object_id FROM notify WHERE notify = '%s'" /* whois -iny EMAIL */
46 |
47 | #define Q_PRI_MAINT "SELECT mnt_id FROM mntner WHERE mntner = '%s'" /* whois MAINT */
48 | #define Q_INV_MAINT "SELECT object_id FROM mnt_by WHERE mntner = '%s'" /* whois -imb MAINT */
49 |
50 | #define Q_PRI_KEYCERT "SELECT key_cert_id FROM key_cert WHERE key_cert = '%s'" /* whois KEYCERT */
51 | #define Q_INV_KEYCERT NULL
52 |
53 | #define Q_PRI_IPRANGE "SELECT in_id FROM inetnum WHERE inetnum = '%s'" /* whois IPRANGE */
54 | #define Q_INV_IPRANGE NULL
55 |
56 | #define Q_PRI_IP6RANGE "SELECT i6_id FROM inet6num WHERE inetnum = '%s'" /* whois IP6RANGE */
57 | #define Q_INV_IP6RANGE NULL
58 |
59 | #define Q_PRI_NETNAME "SELECT in_id FROM inetnum WHERE netname = '%s'" /* whois NETNAME */
60 | #define Q_INV_NETNAME NULL
61 |
62 | #define Q_PRI_ASNUM "SELECT an_id FROM aut_num WHERE aut_num = '%s'" /* whois ASNUM */
63 | #define Q_INV_ASNUM "SELECT rt_id FROM route WHERE origin = '%s'" /* whois -ior ASNUM */
64 |
65 | #define Q_PRI_ASSETNAME "SELECT as_id FROM as_set WHERE as_set = '%s'" /* whois ASSETNAME */
66 | #define Q_INV_ASSETNAME NULL
67 |
68 | #define Q_PRI_ROUTESETNAME "SELECT rs_id FROM route_set WHERE route_set = '%s'" /* whois ROUTESETNAME */
69 | #define Q_INV_ROUTESETNAME NULL
70 |
71 | #define Q_PRI_DOMNAME "SELECT dn_id FROM domain WHERE domain = '%s'" /* whois DOMNAME */
72 | #define Q_INV_DOMNAME "SELECT dn_id FROM dn_sub_dom WHERE domain = '%s'" /* whois -isd DOMNAME */
73 |
74 | #define Q_PRI_HOSTNAME NULL /* whois HOSTNAME */
75 | #define Q_INV_HOSTNAME NULL
76 |
77 | #define Q_PRI_LIMERICKNAME "SELECT li_id FROM limerick WHERE limerick = '%s'" /* whois LIMERICKNAME */
78 | #define Q_INV_LIMERICKNAME NULL
79 |
80 |
81 | #define Q_OBJECTS "SELECT last.serial, last.prev_serial, last.object FROM last, %s WHERE last.serial=%s.id GROUP BY last.serial"
82 |
83 | #define Q_REC "INSERT INTO %s_R SELECT pe_ro_id FROM %s, %s WHERE object_id = %s.id"
84 |
85 | /* XXX This takes too long. :-(
86 | #define Q_REC_OBJECTS "SELECT last.serial, last.prev_serial, last.object FROM last, %s, %s_R WHERE last.serial=%s_R.id AND %s.id != %s_R.id GROUP BY last.serial"
87 |
88 | --- snipped from http://www.tcx.se/Manual/manual.html ---
89 |
90 | 5.3 Functionality missing from MySQL
91 |
92 | 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
93 | 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).
94 |
95 | 5.3.1 Sub-selects
96 |
97 | The following will not yet work in MySQL:
98 |
99 | SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
100 | SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
101 |
102 | However, in many cases you can rewrite the query without a sub select:
103 |
104 | SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
105 | SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
106 |
107 | For more complicated sub queries you can create temporary tables to hold the sub query.
108 |
109 | 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
110 | contexts, however.
111 |
112 | --- end snip ---
113 |
114 | Ie. Try using a LEFT JOIN to do the "NOT IN"/ "MINUS" equivalent.
115 |
116 | */
117 | #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"
118 |
119 | #define Q_NO_OBJECTS "SELECT serial, prev_serial, object FROM last WHERE serial = 0"
120 |
121 |
122 | typedef enum QI_Type_t {
123 | QI_SQL=0,
124 | QI_RADIX,
125 | QI_RADIX_IN,
126 | QI_RADIX_RT,
127 | QI_END
128 | } QI_Type;
129 |
130 |
131 | typedef struct Query_instruction_t {
132 | QI_Type search_type;
133 | char *query_str;
134 | char *rx_keys;
135 | unsigned int rx_srch_mode;
136 | unsigned int rx_par_a;
137 | } Query_instruction;
138 |
139 | typedef struct Query_instructions_t {
140 | Query_instruction *instruction[MAX_INSTRUCTIONS];
141 | unsigned int sock;
142 | unsigned int recursive;
143 | } Query_instructions;
144 |
145 |
146 | void QI_execute(void *database_voidptr, void *qis_voidptr);
147 | void QI_free(Query_instructions *qis);
148 | Query_instructions *QI_new(const Query_command *qc, unsigned int sock);
149 |
150 | #endif /* READ_QUERY_INSTRUCTIONS */