OpenDNSSEC-enforcer  1.3.8
/build/buildd/opendnssec-1.3.8/enforcer/ksm/include/ksm/database_statement.h
Go to the documentation of this file.
00001 /*
00002  * $Id: database_statement.h 3776 2010-08-24 14:55:39Z sion $
00003  *
00004  * Copyright (c) 2008-2009 Nominet UK. All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00017  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00019  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00020  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00021  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00023  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00024  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00025  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *
00027  */
00028 
00029 #ifndef KSM_DATABASE_STATEMENT_H
00030 #define KSM_DATABASE_STATEMENT_H
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 /*+
00037  * database_statement.h - Database SQL Statement Construction
00038  *
00039  * Description:
00040  *      Prototypes for all the functions concerned with creating database
00041  *      query strings.
00042 -*/
00043 
00044 /* Database comparison operators */
00045 
00046 typedef enum {
00047     DQS_END_OF_LIST,    /* Used to make the end of a list */
00048     DQS_COMPARE_LT,
00049     DQS_COMPARE_LE,
00050     DQS_COMPARE_EQ,
00051     DQS_COMPARE_NE,
00052     DQS_COMPARE_GT,
00053     DQS_COMPARE_GE,
00054     DQS_COMPARE_IN,
00055     DQS_COMPARE_NOT_IN,
00056     DQS_COMPARE_IS
00057 } DQS_COMPARISON;
00058 
00059 /* General comparsion structure */
00060 
00061 typedef struct {                /* Structure for a query */
00062     int             code;       /* Code to query for */
00063     DQS_COMPARISON  compare;    /* What comparison to use */
00064     union {                     /* Data value to compare for */
00065         int         number;
00066         const char* string;
00067         void*       binary;
00068         struct tm*  datetime;
00069     } data;
00070 } DQS_QUERY_CONDITION;
00071 
00072 /* SELECT function prototypes */
00073 
00074 char* DqsInit(const char* table);
00075 char* DqsCountInit(const char* table);
00076 char* DqsSpecifyInit(const char* table, const char* fields);
00077 void DqsConditionInt(char** query, const char* field, DQS_COMPARISON compare,
00078     int value, int clause);
00079 void DqsConditionString(char** query, const char* field, DQS_COMPARISON compare,
00080     const char* value, int clause);
00081 void DqsConditionKeyword(char** query, const char* field,
00082     DQS_COMPARISON compare, const char* value, int clause);
00083 void DqsOrderBy(char** query, const char* field);
00084 void DqsEnd(char** query);
00085 void DqsFree(char* query);
00086 
00087 /* INSERT helper functions */
00088 
00089 char* DisInit(const char* table);
00090 char* DisSpecifyInit(const char* table, const char* cols);
00091 void DisAppendInt(char** sql, int what);
00092 void DisAppendString(char** sql, const char* what);
00093 void DisEnd(char** sql);
00094 void DisFree(char* sql);
00095 
00096 /* UPDATE helper functions */
00097 
00098 char* DusInit(const char* table);
00099 void DusSetInt(char** sql, const char* field, int data, int clause);
00100 void DusSetString(char** sql, const char* field, const char* data, int clause);
00101 void DusConditionInt(char** query, const char* field, DQS_COMPARISON compare,
00102     int value, int clause);
00103 void DusConditionString(char** query, const char* field, DQS_COMPARISON compare,
00104     const char* value, int clause);
00105 void DusConditionKeyword(char** query, const char* field,
00106     DQS_COMPARISON compare, const char* value, int clause);
00107 void DusEnd(char** sql);
00108 void DusFree(char* sql);
00109 
00110 /* DELETE function prototypes */
00111 
00112 char* DdsInit(const char* table);
00113 void DdsConditionInt(char** query, const char* field, DQS_COMPARISON compare,
00114     int value, int clause);
00115 void DdsConditionString(char** query, const char* field, DQS_COMPARISON compare,
00116     const char* value, int clause);
00117 void DdsConditionKeyword(char** query, const char* field,
00118     DQS_COMPARISON compare, const char* value, int clause);
00119 void DdsEnd(char** query);
00120 void DdsFree(char* query);
00121 
00122 #ifdef __cplusplus
00123 };
00124 #endif
00125 
00126 #endif /* KSM_DATABASE_STATEMENT_H */