00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include "examples.h"
00005
00006 int select_refcursor2(sqlo_db_handle_t dbh, double min_salary)
00007 {
00008 sqlo_stmt_handle_t sth = SQLO_STH_INIT;
00009 sqlo_stmt_handle_t st2h;
00010 double sal = min_salary;
00011 int status;
00012 char name[30];
00013 double salary;
00014 short nind, sind;
00015
00016 CONST char * stmt =
00017 "BEGIN\n"
00018 " OPEN :c1 FOR SELECT ENAME, SAL FROM EMP WHERE SAL >= :min_sal ORDER BY 2,1;\n"
00019 "END;\n";
00020
00021
00022
00023 if ( 0 <= (sth = sqlo_prepare(dbh, stmt))) {
00024
00025
00026 if (SQLO_SUCCESS !=
00027 (sqlo_bind_by_name(sth, ":c1", SQLOT_RSET, &st2h, 0, 0, 0)) ||
00028 (sqlo_bind_by_name(sth, ":min_sal", SQLOT_FLT, &sal, sizeof(sal), 0, 0) ) ) {
00029 error_exit(dbh, "sqlo_bind_by_name");
00030 } else {
00031
00032
00033 if (SQLO_SUCCESS != sqlo_execute(sth, 1))
00034 error_exit(dbh, "sqlo_execute");
00035 }
00036
00037
00038 if(SQLO_SUCCESS != sqlo_execute(st2h, 1))
00039 error_exit(dbh, "sqlo_execute");
00040
00041 if (SQLO_SUCCESS !=
00042 ( sqlo_define_by_pos(st2h, 1, SQLOT_STR, name, sizeof(name), &nind, 0, 0) ) ||
00043 ( sqlo_define_by_pos(st2h, 2, SQLOT_FLT, &salary, sizeof(salary), &sind, 0, 0) ) )
00044 {
00045 error_exit(dbh, "sqlo_define_by_pos");
00046 }
00047
00048 while (SQLO_SUCCESS == (status = sqlo_fetch(st2h, 1))) {
00049 printf("Name=%-8s Salary= %6.2f\n", name, salary);
00050 }
00051
00052 if (status != SQLO_NO_DATA)
00053 error_exit(dbh, "sqlo_fetch(st2)");
00054
00055 if (SQLO_SUCCESS != sqlo_close(sth))
00056 error_exit(dbh, "sqlo_close(1)");
00057
00058 if (SQLO_SUCCESS != sqlo_close(st2h))
00059 error_exit(dbh, "sqlo_close(2)");
00060
00061 } else {
00062 error_exit(dbh, "sqlo_prepare");
00063 }
00064
00065 return 1;
00066 }
00067
00068