GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
db/sqlp/alloc.c
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * MODULE: SQL statement parser library
5 *
6 * AUTHOR(S): lex.l and yac.y were originaly taken from unixODBC and
7 * probably written by Peter Harvey <pharvey@codebydesigns.com>,
8 * modifications and other code by Radim Blazek
9 *
10 * PURPOSE: Parse input string containing SQL statement to
11 * SQLPSTMT structure.
12 * SQL parser may be used by simple database drivers.
13 *
14 * COPYRIGHT: (C) 2000 by the GRASS Development Team
15 *
16 * This program is free software under the GNU General Public
17 * License (>=v2). Read the file COPYING that comes with GRASS
18 * for details.
19 *
20 *****************************************************************************/
21 
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <grass/sqlp.h>
25 
26 /* alloc structure */
27 SQLPSTMT *sqpInitStmt(void)
28 {
29  SQLPSTMT *st;
30 
31  st = (SQLPSTMT *) calloc(1, sizeof(SQLPSTMT));
32 
33  return (st);
34 }
35 
36 /* allocate space for columns */
37 int sqpAllocCol(SQLPSTMT * st, int n)
38 {
39  int i;
40 
41  if (n > st->aCol) {
42  n += 15;
43  st->Col = (SQLPVALUE *) realloc(st->Col, n * sizeof(SQLPVALUE));
44  st->ColType = (int *)realloc(st->ColType, n * sizeof(int));
45  st->ColWidth = (int *)realloc(st->ColWidth, n * sizeof(int));
46  st->ColDecim = (int *)realloc(st->ColDecim, n * sizeof(int));
47 
48  for (i = st->nCol; i < n; i++) {
49  st->Col[i].s = NULL;
50  }
51 
52  st->aCol = n;
53  }
54  return (1);
55 }
56 
57 /* allocate space for values */
58 int sqpAllocVal(SQLPSTMT * st, int n)
59 {
60  int i;
61 
62  if (n > st->aVal) {
63  n += 15;
64  st->Val = (SQLPVALUE *) realloc(st->Val, n * sizeof(SQLPVALUE));
65 
66  for (i = st->nVal; i < n; i++) {
67  st->Val[i].s = NULL;
68  }
69 
70  st->aVal = n;
71  }
72  return (1);
73 }
74 
75 /* free space allocated by parser */
76 int sqpFreeStmt(SQLPSTMT * st)
77 {
78  int i;
79 
80  /* columns */
81  for (i = 0; i < st->aCol; i++)
82  free(st->Col[i].s);
83 
84  free(st->Col);
85  free(st->ColType);
86  free(st->ColWidth);
87  free(st->ColDecim);
88  st->aCol = 0;
89  st->nCol = 0;
90 
91  /* values */
92  for (i = 0; i < st->aVal; i++)
93  free(st->Val[i].s);
94 
95  free(st->Val);
96  st->aVal = 0;
97  st->nVal = 0;
98 
99  free(st->orderCol);
100 
101  /* Nodes (where) */
102  if (st->upperNodeptr)
103  sqpFreeNode(st->upperNodeptr);
104 
105  free(st);
106  return (1);
107 }
int sqpAllocVal(SQLPSTMT *st, int n)
Definition: db/sqlp/alloc.c:58
void sqpFreeNode(SQLPNODE *np)
Definition: sql.c:260
int sqpFreeStmt(SQLPSTMT *st)
Definition: db/sqlp/alloc.c:76
int sqpAllocCol(SQLPSTMT *st, int n)
Definition: db/sqlp/alloc.c:37
return NULL
Definition: dbfopen.c:1394
void free(void *)
SQLPSTMT * sqpInitStmt(void)
Definition: db/sqlp/alloc.c:27
int n
Definition: dataquad.c:291