GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sqlptest.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <string.h>
3 #include <grass/gis.h>
4 #include <grass/dbmi.h>
5 #include <grass/sqlp.h>
6 
7 int main(int argc, char **argv)
8 {
9  SQLPSTMT *st;
10  char buf[5000], buf2[5000];
11  dbString stmt;
12  int len;
13 
14 
15  st = sqpInitStmt();
16 
17  db_init_string(&stmt);
18 
19  while (fgets(buf, 5000, stdin)) {
20  fprintf(stdout, "\nInput row: -->>%s<<--\n", buf);
21  strcpy(buf2, buf);
22  G_chop(buf2);
23  len = strlen(buf2);
24 
25  if (buf2[len - 1] == ';') { /* end of statement */
26  buf2[len - 1] = 0; /* truncate ';' */
27  db_append_string(&stmt, buf2);
28 
29  st->stmt = db_get_string(&stmt);
30  sqpInitParser(st);
31 
32  fprintf(stdout, "Input statement: -->>%s<<--\n", st->stmt);
33 
34  if (yyparse() != 0) {
35  fprintf(stdout,
36  "Error: statement was not parsed successfully.\n");
37  sqpFreeStmt(st);
38  return (1);
39  }
40 
41  sqpPrintStmt(st);
42 
43  db_zero_string(&stmt);
44 
45  }
46  else {
47  db_append_string(&stmt, buf);
48  }
49  }
50 
51 
52  sqpFreeStmt(st);
53 
54  exit(0);
55 }