utils/history/dbsupport.c

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

DEFINITIONS

This source file includes following functions.
  1. prepare_string_attribute
  2. check_null

   1 /***************************************
   2   $Revision: 1.1 $
   3 
   4   DB support.  dbsupport.c - SQL utility functions.
   5 
   6   Status: NOT REVIEWED, NOT TESTED, NOT COMPLETE
   7 
   8   Implementation by: Tiago Antao
   9 
  10   ******************/ /******************
  11   Copyright (c) 2002               RIPE NCC
  12  
  13   All Rights Reserved
  14   
  15   Permission to use, copy, modify, and distribute this software and its
  16   documentation for any purpose and without fee is hereby granted,
  17   provided that the above copyright notice appear in all copies and that
  18   both that copyright notice and this permission notice appear in
  19   supporting documentation, and that the name of the author not be
  20   used in advertising or publicity pertaining to distribution of the
  21   software without specific, written prior permission.
  22 
  23   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  24   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  25   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  26   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  27   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  28   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  29   ***************************************/
  30 
  31 
  32 #include <stdio.h>
  33 #include <stdlib.h>
  34 #include <time.h>
  35 #include <rip.h>
  36 
  37 SQ_connection_t* RIPE_conn;
  38 SQ_connection_t* archive_conn;
  39 
  40 /*
  41   prepare_string_attribute: Prepares a string to be SQL inserted.
  42 */
  43 void prepare_string_attribute(char* dirty, char* clean){
     /* [<][>][^][v][top][bottom][index][help] */
  44   //printf("STRL: %d", strlen(dirty));
  45   while (*dirty) {
  46     if (*dirty == 39 || *dirty == 92) { // ' | \
  47       //      printf("DIRTY\n");
  48       *clean = *dirty;
  49       clean++;
  50     }
  51     if (*dirty == 10) { // \n
  52       *clean = '\\';
  53       clean++;
  54       *clean = 'n';
  55     }
  56     else {
  57       *clean = *dirty;
  58     }
  59     clean++;
  60     dirty++;
  61   }
  62   *clean = 0;
  63 }
  64 
  65 
  66 /*
  67   check_null: Checks if an attribute is NULL
  68 
  69   Technicaly this is wrong, as the content can be NULL (string)
  70 */
  71 void check_null(SQ_result_set_t* rs, SQ_row_t* row,
     /* [<][>][^][v][top][bottom][index][help] */
  72                 int attribute, char* result) {
  73   if (SQ_get_column_string_nocopy(rs,row,attribute) == NULL) {
  74     strcpy(result, "NULL");
  75   }
  76   else {
  77     strcpy(result, SQ_get_column_string_nocopy(rs,row,attribute));
  78   }
  79 }
  80 
  81 

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