testd.ec
上传用户:dgyhgb
上传日期:2007-01-07
资源大小:676k
文件大小:7k
- /*
- * monitor.l - GNU SQL Server DBA utility
- *
- * This file is a paert of GNU SQL Server
- *
- * Copyright (c) 1996, Free Software Foundation, Inc.
- * Developed at Insitute of System Programming of Russian Academy of Science
- * Written by Michael Kimelman.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Contact: gss@ispras.ru
- *
- */
- #pragma ident "Id: scan_c.l,v 1.155 1995/07/30 13:44:43 kml Exp kml "
- #include <string.h>
- #include "sql_decl.h"
- #include "xmem.h"
- #include "dyn_funcs.h"
- #include <assert.h>
- #include "sql.h"
- #include "/home/gsql/zoya/proc"
- static char *statement_scanner_buffer=NULL;
- int ARGC;
- char **ARGV;
- int
- SCANNER_NAME(void)
- {
-
- if (ARGC>0)
- return 1;
- }
- int
- __SQL_connect(char *host,char *user,char *passwd)
- {
- return 0;
- }
- void
- error_rprt(char *st,int rc, char *stmt)
- {
- extern char *err_str[];
- fprintf(stderr,"n#### Error occured in '%s'n%snat "%s"n",
- st,err_str[-rc],stmt);
- }
- int
- main(int argc, char *argv[])
- {
- int stmt = 0;
- int rc;
- int i,j,t,ll,c,ind,null;
- static char *sps =
- " "
- " "
- " "
- " "
- " "
- ;
- statement_scanner_buffer = xmalloc(4096*4);
-
- #define CHECK(st) if((rc=__SQL_##st)!=0){ error_rprt(#st,rc,statement_scanner_buffer); goto error; }
- sprintf(statement_scanner_buffer,
- "(select * from %s.%s)",
- (argc>2?argv[2]:"DEFINITION_SCHEMA"),
- (argc>1?argv[1]:"SYSTABLES"));
- while(stmt==0)
- {
- char *b;
- int l = strlen(statement_scanner_buffer);
- int *clms = NULL;
- int xx;
-
- b = xmalloc(20);
- sprintf(b,"%dth Stmt",stmt++);
- __SQL_prepare(b,statement_scanner_buffer);
- __SQL_allocate_cursor(b,"CURSOR");
-
- __SQL_allocate_descr("IN",0);
-
- __SQL_allocate_descr("OUT",0);
- __SQL_describe(b,1,__SQL_get_descr("IN"));
- __SQL_describe(b,0,__SQL_get_descr("OUT"));
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- xx=tmp_descr->count;
- }
- clms = (int*)xmalloc(xx*sizeof(int));
-
- /* open cursor and write headers */
- j=1;
- fprintf(stderr,"n|");
- for( i=0; i < xx; i++)
-
- {
- int jj, k = 0,u,t;
- char name[100];
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- u=tmp_descr->values[tmp_count].unnamed;
- }
- if (u)
- jj=fprintf(stderr," col_%03d ",i);
- else
- {
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- strcpy(name, tmp_descr->values[tmp_count].name);
- }
- jj=fprintf(stderr," %s ",name);
- }
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- t=tmp_descr->values[tmp_count].type;
- ll=tmp_descr->values[tmp_count].length;
- }
-
- { sql_type_t tt = pack_type(get_sqltype_code(t),ll,0);
- k = tt.len - jj;
- }
- jj += fprintf(stderr,"%s|",sps+strlen(sps)- (k>0?k:0) );
- clms [i] = jj - 1;
- j += jj;
- }
- /* -------------------------------------------------*/
- fprintf(stderr,"n");
- for(i=j;i--;)
- fprintf(stderr,"-");
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("IN");
- c=tmp_descr->count;
- }
- if(c)
- {
- __SQL_open_cursor("CURSOR",__SQL_get_descr("IN"));
- }
- else
- {
- __SQL_open_cursor("CURSOR",NULL);
- }
- while(1)
- {
- __SQL_fetch("CURSOR",__SQL_get_descr("OUT"));
-
- if(SQLCODE!=0)
- break;
-
- fprintf(stderr,"n|");
- for (i=0; i < xx; i++)
- {
- int k,t,i_data ;
- short sh_data;
- int kk = 0;
- char buf[4096],cdata[100];
- double d_data;
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- null=tmp_descr->values[tmp_count].nullable;
- }
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- ind=tmp_descr->values[tmp_count].indicator;
- }
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- t=tmp_descr->values[tmp_count].type;
- }
- if(null && ind<0)
- sprintf(buf,"null");
- else switch(t)
- {
- case __SQL_Char:
- case __SQL_CharVar:
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- PROC_data(tmp_descr->values[tmp_count], &cdata, sizeof(cdata), 0);
- }
- sprintf(buf,"%s",cdata);
- break;
- case __SQL_Double: /* DOUBLE */
- case __SQL_Float: /* FLOAT */
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- PROC_data(tmp_descr->values[tmp_count], &d_data, sizeof(d_data), 0);
- }
- sprintf(buf,"%g",d_data);
- break;
- case __SQL_Real: /* REAL */
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- PROC_data(tmp_descr->values[tmp_count], &d_data, sizeof(d_data), 0);
- }
- sprintf(buf,"%g",d_data);
- break;
- case __SQL_Int: /* int */
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- PROC_data(tmp_descr->values[tmp_count], &i_data, sizeof(i_data), 0);
- }
- sprintf(buf,"%X",i_data);
- break;
- case __SQL_Short: /* small */
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- int tmp_count=i;
- PROC_data(tmp_descr->values[tmp_count], &sh_data, sizeof(sh_data), 0);
- }
- sprintf(buf,"%d",sh_data);
- break;
- default:
- sprintf(buf," **%d** ",t);
- }
- assert(kk==0);
- k = (clms[i] - strlen(buf))/2;
- if (k > 4*clms[i])
- {
- /* fprintf(stderr,"!!");*/
- k = 0;
- }
- k = fprintf(stderr,"%s%s", sps + strlen(sps) - (k>0?k:0),buf);
- k = clms[i] - k;
- fprintf(stderr,"%s|", sps + strlen(sps) - (k>0?k:0));
- }
- }
-
- /* -------------------------------------------------*/
- fprintf(stderr,"n");
- for(i=j;i--;)
- fprintf(stderr,"-");
- fprintf(stderr,"nn");
- __SQL_close_cursor("CURSOR");
-
- __SQL_deallocate_prepare(b);
-
- error:
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("IN");
- __SQL_deallocate_descr(&tmp_descr);
- }
-
- {
- SQL_DESCR tmp_descr=__SQL_get_descr("OUT");
- __SQL_deallocate_descr(&tmp_descr);
- }
- xfree(clms);
- xfree(b);
- b = NULL;
- }
- _SQL_commit();
- return 0;
- }