📄 ex7.c
字号:
/* $Id: ex7.c,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */
#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; /* statement handle */
int status; /* status of sqlo calls */
unsigned int i,j; /* loop counter */
const char ** v; /* values */
const char ** n; /* column names */
CONST unsigned int *nl; /* column name lengths */
CONST unsigned short *vl; /* value lengths */
unsigned int nc; /* number of columns */
sth = reopen_cursor(dbh, min_income); /* see example of sqlo_reopen (ex6.c) */
/* get the output column names */
n = sqlo_ocol_names(sth, &nc);
/* get the output column name lengths */
nl = sqlo_ocol_name_lens(sth, NULL);
printf("Employees with SAL > %-8.2f:\n", min_income);
/* print the header */
for (i = 0; i < nc; ++i)
printf("%-*s ", nl[i], n[i]);
printf("\n");
for (i = 0; i < nc; ++i) {
for (j = 0; j < nl[i]; ++j) {
putchar('-');
}
putchar('+');
}
putchar('\n');
/* fetch the data */
while ( SQLO_SUCCESS == (status = (sqlo_fetch(sth, 1)))) {
/* get one record */
v = sqlo_values(sth, NULL, 1);
/* get the length of the data items */
vl = sqlo_value_lens(sth, NULL);
/* print the column values */
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");
}
if ( SQLO_SUCCESS != sqlo_close(sth))
error_exit(dbh, "sqlo_close");
return 1;
}
/* $Id: ex7.c,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -