sqlp/alloc.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002 *
00003 * MODULE:       SQL statement parser library 
00004 *               
00005 * AUTHOR(S):    lex.l and yac.y were originaly taken from unixODBC and
00006 *               probably written by Peter Harvey <pharvey@codebydesigns.com>,
00007 *               modifications and other code by Radim Blazek
00008 *
00009 * PURPOSE:      Parse input string containing SQL statement to 
00010 *               SQLPSTMT structure.
00011 *               SQL parser may be used by simple database drivers. 
00012 *
00013 * COPYRIGHT:    (C) 2000 by the GRASS Development Team
00014 *
00015 *               This program is free software under the GNU General Public
00016 *               License (>=v2). Read the file COPYING that comes with GRASS
00017 *               for details.
00018 *
00019 *****************************************************************************/
00020 
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <grass/sqlp.h>
00024 
00025 /* alloc structure */
00026 SQLPSTMT * sqpInitStmt( void  )
00027 {
00028     SQLPSTMT *st;
00029     
00030     st = (SQLPSTMT *) calloc (1, sizeof (SQLPSTMT));
00031 
00032     return (st);
00033 }
00034 
00035 /* allocate space for columns */
00036 int sqpAllocCol(SQLPSTMT *st, int n)
00037 {
00038     int i;
00039 
00040     if ( n > st->aCol )
00041       {
00042         n += 15;      
00043         st->Col = (SQLPVALUE *) realloc ( st->Col, n * sizeof(SQLPVALUE));
00044         st->ColType = (int *) realloc ( st->ColType, n * sizeof(int));
00045         st->ColWidth = (int *) realloc ( st->ColWidth, n * sizeof(int));
00046         st->ColDecim = (int *) realloc ( st->ColDecim, n * sizeof(int));
00047         
00048         for (i = st->nCol; i < n; i++)
00049           {
00050             st->Col[i].s = NULL ;
00051           }
00052             
00053         st->aCol = n;
00054       }
00055    return (1); 
00056 }
00057     
00058 /* allocate space for values */
00059 int sqpAllocVal(SQLPSTMT *st, int n)
00060 {
00061     int i;
00062 
00063     if ( n > st->aVal )
00064       {
00065         n += 15;      
00066         st->Val = (SQLPVALUE *) realloc ( st->Val, n * sizeof(SQLPVALUE));
00067         
00068         for (i = st->nVal; i < n; i++)
00069           {
00070             st->Val[i].s = NULL ;
00071           }
00072             
00073         st->aVal = n;
00074       }
00075    return (1); 
00076 }
00077 
00078 /* free space allocated by parser */
00079 int sqpFreeStmt(SQLPSTMT *st)
00080 {
00081     int i;
00082 
00083     /* columns */
00084     for (i=0; i < st->aCol; i++)
00085         free ( st->Col[i].s );
00086 
00087     free ( st->Col );
00088     free ( st->ColType );
00089     free ( st->ColWidth );
00090     free ( st->ColDecim );
00091     st->aCol = 0;
00092     st->nCol = 0;
00093     
00094     /* values */
00095     for (i=0; i < st->aVal; i++)
00096         free ( st->Val[i].s );
00097 
00098     free ( st->Val );
00099     st->aVal = 0;
00100     st->nVal = 0;
00101 
00102     free (st->orderCol);
00103 
00104     /* Nodes (where) */
00105     if ( st->upperNodeptr )
00106         sqpFreeNode ( st->upperNodeptr );
00107     
00108     free ( st );
00109     return (1);
00110 }
00111         
00112 

Generated on Sun Apr 6 17:31:38 2008 for GRASS by  doxygen 1.5.5