00001
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;
00009 int status;
00010 unsigned int i,j;
00011 const char ** v;
00012 const char ** col_names;
00013 CONST unsigned int *nl;
00014 CONST unsigned short *vl;
00015 unsigned int nc;
00016
00017
00018 sth = reopen_cursor(dbh, min_income);
00019
00020
00021 status = sqlo_ocol_names2(sth, &nc, &col_names);
00022
00023 if (0 > status) {
00024 error_exit(dbh, "sqlo_ocol_names2");
00025 }
00026
00027
00028 nl = sqlo_ocol_name_lens(sth, NULL);
00029
00030 printf("Employees with SAL > %-8.2f:\n", min_income);
00031
00032
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
00046 while ( SQLO_SUCCESS == (status = (sqlo_fetch(sth, 1)))) {
00047
00048
00049 v = sqlo_values(sth, NULL, 1);
00050
00051
00052 vl = sqlo_value_lens(sth, NULL);
00053
00054
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
00068
00069
00070 return 1;
00071
00072 }
00073
00074