1 /**
2     Copyright (C) 1995, 1996 by Ke Jin <kejin@visigenic.com>
3 	Enhanced for unixODBC (1999) by Peter Harvey <pharvey@codebydesign.com>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 **/
15 #ifndef _YYSTMT_H
16 # define _YYSTMT_H
17 
18 # define	MAX_COLUMN_NUMBER	32
19 # define	MAX_PARAM_NUMBER	32
20 
21 # include	<yylex.h>
22 # include	<nndate.h>
23 # include	<nnsql.h>
24 
25 typedef enum {
26 	en_nt_cmpop,	/* en_cmpop_eq, */
27 	en_nt_logop,	/* kwd_and, kwd_or, kwd_not */
28 
29 	en_nt_attr,
30 	en_nt_qstr,
31 	en_nt_num,
32 	en_nt_date,
33 	en_nt_param,
34 	en_nt_null,
35 
36 	en_nt_like,
37 	en_nt_between,
38 	en_nt_in,
39 	en_nt_caselike,
40 	en_nt_isnull
41 } node_type;
42 
43 typedef struct tnode
44 {
45 	int	type;	/* compare operator,
46 			 * logical operator,
47 			 * column value,
48 			 * literal value,
49 			 * dummy parameter
50 			 */
51 
52 	union {
53 		int	cmpop;	/* en_cmpop_eq, en_cmpop_ne, ... */
54 		int	logop;	/* kwd_or, kwd_and, kwd_not */
55 		int	iattr;	/* attribute index */
56 		int	ipar;	/* parameter idx */
57 		char*	qstr;
58 		long	num;
59 		date_t	date;
60 		char	esc;	/* escape for like pattern match */
61 	} value;
62 
63 	struct tnode*	left;
64 	struct tnode*	right;
65 } node_t;
66 
67 typedef struct {
68 	int		iattr;
69 	char*		table;		/* table name from yyparse */
70 
71 	union {
72 		long	num;
73 		char*	qstr;
74 		date_t	date;
75 	} value;
76 } yycol_t;
77 
78 typedef struct {
79 	int	stat;	/* 0 don't needed(either by select list
80 			   or by where tree) 1 needed */
81 	int	wstat;	/* 0 if don't need by where tree, 1 if need */
82 	int	article;/* article number */
83 
84 	union {
85 		char*	location;
86 		long	number;
87 		date_t	date;
88 	} value;
89 
90 	void*	nntp_hand;	/* create with nntp_openheader()
91 				 * freed  with nntp_closeheader()
92 				 * fetch  with nntp_fetchheader() */
93 } yyattr_t;
94 
95 typedef struct
96 {
97 	int		type;	/* can only be en_nt_qstr,
98 				   en_nt_num and en_nt_null */
99 
100 	union {
101 		char*	location;
102 		long	number;
103 		date_t	date;
104 	} value;
105 } yypar_t;
106 
107 enum {
108 	en_stmt_alloc = 0,	/* only in allocated stat */
109 	en_stmt_select,
110 	en_stmt_insert,
111 	en_stmt_srch_delete,
112 
113 	en_stmt_fetch_count = 100
114 };
115 
116 typedef struct {
117 	void*		hcndes; 	/* nntp cndes */
118 
119 	int		type;
120 
121 	int		errcode;
122 	int		errpos;
123 
124 	yycol_t*	pcol;		/* column descriptor */
125 	yyattr_t*	pattr;		/* fetched required column */
126 	yypar_t*	ppar;		/* user parameter area */
127 
128 	char*		table;		/* table name from yyparse */
129 
130 	int		ncol;
131 	int		npar;
132 	int		count;		/* num. of record has been fetched. */
133 
134 	char*		sqlexpr;	/* point to sqlexpr in hstmt_t */
135 	char*		texts_buf;
136 	char		msgbuf[64];	/* buf to hold message string passed to
137 					 * nnsql_yyerror() */
138 
139 	/* search tree */
140 	node_t* 	srchtree;		/* root of search tree */
141 	node_t* 	node_buf;	/* address of array */
142 	int		srchtreesize;	/* search tree array size */
143 	int		srchtreenum;	/* number of nodes in tree */
144 
145 	/* insert headers and values */
146 	char**		ins_heads;
147 	node_t* 	ins_values;
148 
149 	/* article-num range */
150 	long		artnum_min;
151 	long		artnum_max;
152 } yystmt_t;
153 
154 #endif
155