sqlptest.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <string.h>
00003 #include <grass/gis.h>
00004 #include <grass/dbmi.h>
00005 #include <grass/sqlp.h>
00006 
00007 int main(int argc, char **argv)
00008 {
00009     SQLPSTMT *st;
00010     char buf[5000], buf2[5000];
00011     dbString stmt;
00012     int len;
00013 
00014 
00015     st = sqpInitStmt();
00016 
00017     db_init_string(&stmt);
00018 
00019     while (fgets(buf, 5000, stdin)) {
00020         fprintf(stdout, "\nInput row: -->>%s<<--\n", buf);
00021         strcpy(buf2, buf);
00022         G_chop(buf2);
00023         len = strlen(buf2);
00024 
00025         if (buf2[len - 1] == ';') {     /* end of statement */
00026             buf2[len - 1] = 0;  /* truncate ';' */
00027             db_append_string(&stmt, buf2);
00028 
00029             st->stmt = db_get_string(&stmt);
00030             sqpInitParser(st);
00031 
00032             fprintf(stdout, "Input statement: -->>%s<<--\n", st->stmt);
00033 
00034             if (yyparse() != 0) {
00035                 fprintf(stdout,
00036                         "Error: statement was not parsed successfully.\n");
00037                 sqpFreeStmt(st);
00038                 return (1);
00039             }
00040 
00041             sqpPrintStmt(st);
00042 
00043             db_zero_string(&stmt);
00044 
00045         }
00046         else {
00047             db_append_string(&stmt, buf);
00048         }
00049     }
00050 
00051 
00052     sqpFreeStmt(st);
00053 
00054     exit(0);
00055 }

Generated on Sat Oct 24 03:24:24 2009 for GRASS Programmer's Manual by  doxygen 1.6.1