modules/qi/query_instructions.h

/* [<][>][^][v][top]
[bottom][index][help] */

FUNCTIONS

This source file includes following functions.

#ifndef READ_QUERY_INSTRUCTIONS
#define READ_QUERY_INSTRUCTIONS

/***************************************
  $Revision: 1.21 $

  Query instruction module (qi)
  config module.

  Status: NOT REVUED, NOT TESTED

  ******************/ /******************
  Copyright (c) 1999                              RIPE NCC
 
  All Rights Reserved
  
  Permission to use, copy, modify, and distribute this software and its
  documentation for any purpose and without fee is hereby granted,
  provided that the above copyright notice appear in all copies and that
  both that copyright notice and this permission notice appear in
  supporting documentation, and that the name of the author not be
  used in advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.
  
  THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  ***************************************/
#include "rxroutines.h"
#include "iproutines.h"
#include "mysql_driver.h"
#include "query_command.h"
#include "defs.h"
#include "which_keytypes.h"

#include "access_control.h"


/* RIPE3 version.
#define Q_OBJECTS     "SELECT last.serial, last.prev_serial, last.object FROM last, %s WHERE last.serial=%s.id GROUP BY last.serial"
*/
/* RIPE4 
   #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"
*/
/* RIPE 6 */
#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"

#define Q_REC         "INSERT INTO %s_R SELECT pe_ro_id FROM %s, %s WHERE object_id = %s.id"

/* XXX This takes too long.  :-(
#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"

--- snipped from http://www.tcx.se/Manual/manual.html ---

5.3 Functionality missing from MySQL

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
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). 

5.3.1 Sub-selects

The following will not yet work in MySQL: 

SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);

However, in many cases you can rewrite the query without a sub select: 

SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL

For more complicated sub queries you can create temporary tables to hold the sub query. 

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
contexts, however. 

--- end snip ---

Ie. Try using a LEFT JOIN to do the "NOT IN"/ "MINUS" equivalent.

*/
/* RIPE3 version.
#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"
*/
/* RIPE4 version
   #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"
*/
/* RIPE6 version */
#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"



/* RIPE3 version
#define Q_NO_OBJECTS  "SELECT serial, prev_serial, object FROM last WHERE serial = 0"
*/
#define Q_NO_OBJECTS  "SELECT object_id, sequence_id, object FROM last WHERE object_id = 0"

#define MAX_INSTRUCTIONS 100

typedef enum _R_Type_t {
  R_SQL=0,
  R_RADIX,
  R_END
} R_Type_t;

typedef enum _Q_Type_t {
  Q_LOOKUP=0,
  Q_INVERSE,
} Q_Type_t;

typedef enum _S_Type_t {
  IPv4,
  IPv6
} S_Type_t;

typedef struct Query_instruction_t {
  R_Type_t search_type;
  int  queryindex;/* index into the Query table showing origin of this entry */
  char *query_str;
  char *rx_keys;
  unsigned int rx_srch_mode;
  unsigned int rx_par_a;
  ip_space_t space;
  rx_fam_t family;
} Query_instruction;

typedef struct Query_instructions_t {
  Query_instruction *instruction[MAX_INSTRUCTIONS];
  unsigned int filtered;
  unsigned int fast;
  unsigned int recursive;
  const Query_command *qc; /* pointer to the Query_command structure of this query */
} Query_instructions;


void QI_execute(void *database_voidptr, Query_instructions *qis, Query_environ *qe, acc_st *acc_credit, acl_st *acl);
void QI_free(Query_instructions *qis);
Query_instructions *QI_new(const Query_command *qc, const Query_environ *qe);

#endif /* READ_QUERY_INSTRUCTIONS */

/* [<][>][^][v][top][bottom][index][help] */