00001 /* $Id: ex7.c 287 2004-07-30 16:28:21Z kpoitschke $ */ 00002 #include <stdio.h> 00003 #include <stdlib.h> 00004 #include "examples.h" 00005 00006 int do_select(sqlo_db_handle_t dbh, double min_income) 00007 { 00008 sqlo_stmt_handle_t sth; /* statement handle */ 00009 int status; /* status of sqlo calls */ 00010 unsigned int i,j; /* loop counter */ 00011 const char ** v; /* values */ 00012 const char ** col_names; /* column names */ 00013 CONST unsigned int *nl; /* column name lengths */ 00014 CONST unsigned short *vl; /* value lengths */ 00015 unsigned int nc; /* number of columns */ 00016 00017 00018 sth = reopen_cursor(dbh, min_income); /* see example of sqlo_reopen (ex6.c) */ 00019 00020 /* get the output column names */ 00021 status = sqlo_ocol_names2(sth, &nc, &col_names); 00022 00023 if (0 > status) { 00024 error_exit(dbh, "sqlo_ocol_names2"); 00025 } 00026 00027 /* get the output column name lengths */ 00028 nl = sqlo_ocol_name_lens(sth, NULL); 00029 00030 printf("Employees with SAL > %-8.2f:\n", min_income); 00031 00032 /* print the header */ 00033 for (i = 0; i < nc; ++i) 00034 printf("%-*s ", nl[i], col_names[i]); 00035 00036 printf("\n"); 00037 for (i = 0; i < nc; ++i) { 00038 for (j = 0; j < nl[i]; ++j) { 00039 putchar('-'); 00040 } 00041 putchar('+'); 00042 } 00043 putchar('\n'); 00044 00045 /* fetch the data */ 00046 while ( SQLO_SUCCESS == (status = (sqlo_fetch(sth, 1)))) { 00047 00048 /* get one record */ 00049 v = sqlo_values(sth, NULL, 1); 00050 00051 /* get the length of the data items */ 00052 vl = sqlo_value_lens(sth, NULL); 00053 00054 /* print the column values */ 00055 for (i = 0; i < nc; ++i) 00056 printf("%-*s ", (vl[i] > nl[i] ? vl[i] : nl[i]), v[i]); 00057 00058 printf("\n"); 00059 00060 } 00061 00062 if (0 > status) { 00063 error_exit(dbh, "sqlo_fetch"); 00064 } 00065 00066 /* 00067 if ( SQLO_SUCCESS != sqlo_close(sth)) 00068 error_exit(dbh, "sqlo_close"); 00069 */ 00070 return 1; 00071 00072 } 00073 00074 /* $Id: ex7.c 287 2004-07-30 16:28:21Z kpoitschke $ */