#include <stdio.h>
#include <stdlib.h>
#include "examples.h"
int do_select(sqlo_db_handle_t dbh, double min_income)
{
sqlo_stmt_handle_t sth;
int status;
unsigned int i,j;
const char ** v;
const char ** col_names;
CONST unsigned int *nl;
CONST unsigned short *vl;
unsigned int nc;
sth = reopen_cursor(dbh, min_income);
status = sqlo_ocol_names2(sth, &nc, &col_names);
if (0 > status) {
error_exit(dbh, "sqlo_ocol_names2");
}
nl = sqlo_ocol_name_lens(sth, NULL);
printf("Employees with SAL > %-8.2f:\n", min_income);
for (i = 0; i < nc; ++i)
printf("%-*s ", nl[i], col_names[i]);
printf("\n");
for (i = 0; i < nc; ++i) {
for (j = 0; j < nl[i]; ++j) {
putchar('-');
}
putchar('+');
}
putchar('\n');
while ( SQLO_SUCCESS == (status = (sqlo_fetch(sth, 1)))) {
v = sqlo_values(sth, NULL, 1);
vl = sqlo_value_lens(sth, NULL);
for (i = 0; i < nc; ++i)
printf("%-*s ", (vl[i] > nl[i] ? vl[i] : nl[i]), v[i]);
printf("\n");
}
if (0 > status) {
error_exit(dbh, "sqlo_fetch");
}
return 1;
}