00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include "examples.h"
00005
00006 enum {
00007 MAX_NAME_LEN = 64,
00008 MAX_ARRAY_SIZE = 4
00009
00010
00011 };
00012
00016 typedef struct _result_t {
00017 char name[MAX_NAME_LEN+1];
00018 double salary;
00019 short name_ind;
00020 short sal_ind;
00021 unsigned short name_rlen;
00022 unsigned short name_rcode;
00023 } result_t;
00024
00025 void print_record __P((result_t * r));
00026
00027
00028 int do_array_select(sqlo_db_handle_t dbh, double min_salary)
00029 {
00030 sqlo_stmt_handle_t sth;
00031 int i;
00032 int status;
00033 result_t result[MAX_ARRAY_SIZE];
00034 int rows_fetched;
00035 int rows_fetched_total = 0;
00036 int done_fetching = 0;
00037 double salary = min_salary;
00038 int skip_size = sizeof(result[0]);
00039
00040 sth = prepare_cursor(dbh, &salary);
00041
00042
00043 if (SQLO_SUCCESS !=
00044 (sqlo_define_by_pos2(sth, 1, SQLOT_STR, result[0].name, sizeof(result[0].name),
00045 &result[0].name_ind, &result[0].name_rlen,
00046 &result[0].name_rcode, skip_size)) ||
00047 (sqlo_define_by_pos2(sth, 2, SQLOT_FLT, &result[0].salary, sizeof(result[0].salary),
00048 &result[0].sal_ind, 0, 0, skip_size))) {
00049 error_exit(dbh, "sqlo_define_by_pos");
00050 }
00051
00052
00053 status = sqlo_execute(sth, 0);
00054
00055 while (!done_fetching) {
00056
00057 rows_fetched = MAX_ARRAY_SIZE;
00058
00059
00060 status = sqlo_fetch(sth, MAX_ARRAY_SIZE);
00061
00062 if (0 > status)
00063 error_exit(dbh, "sqlo_execute(NEXT)");
00064 else if (SQLO_NO_DATA == status) {
00065
00066 rows_fetched = sqlo_prows(sth);
00067
00068
00069
00070
00071
00072 rows_fetched = rows_fetched - rows_fetched_total;
00073 done_fetching = 1;
00074
00075 }
00076
00077
00078 for (i = 0; i < rows_fetched; ++i)
00079 print_record(&result[i]);
00080
00081 rows_fetched_total += rows_fetched;
00082
00083 }
00084 printf("Selected %d employees\n", rows_fetched_total);
00085
00086 sqlo_close(sth);
00087
00088 return 1;
00089 }
00090
00091
00092 void print_record(result_t * r )
00093 {
00094 printf("Name=%-8s Salary= %6.2f\n",
00095 (r->name_ind == SQLO_NULL_IND ? "NULL" : r->name),
00096 (r->sal_ind == SQLO_NULL_IND ? -1.0 : r->salary));
00097 }
00098
00099