00001 #include "dbmi.h"
00002 #include "macros.h"
00003 #include "dbstubs.h"
00004
00005 static int valid_cursor();
00006
00013 int
00014 db_d_fetch()
00015 {
00016 dbToken token;
00017 dbCursor *cursor;
00018 int stat;
00019 int more;
00020 int position;
00021
00022
00023 DB_RECV_TOKEN(&token);
00024 DB_RECV_INT(&position);
00025 cursor = (dbCursor *) db_find_token(token);
00026 if (!valid_cursor(cursor, position))
00027 {
00028 DB_SEND_FAILURE();
00029 return DB_FAILED;
00030 }
00031
00032
00033 stat = db_driver_fetch (cursor, position, &more);
00034
00035
00036 if (stat != DB_OK)
00037 {
00038 DB_SEND_FAILURE();
00039 return DB_OK;
00040 }
00041 DB_SEND_SUCCESS();
00042
00043
00044 DB_SEND_INT (more);
00045 if (more)
00046 {
00047 DB_SEND_TABLE_DATA (cursor->table);
00048 }
00049 return DB_OK;
00050 }
00051
00052 static
00053 valid_cursor (cursor, position)
00054 dbCursor *cursor;
00055 {
00056 if (cursor == NULL)
00057 return 0;
00058 if(!db_test_cursor_type_fetch(cursor))
00059 {
00060 db_error ("not a fetchable cursor");
00061 return 0;
00062 }
00063 if (position != DB_NEXT && !db_test_cursor_mode_scroll(cursor))
00064 {
00065 db_error ("not a scrollable cursor");
00066 return 0;
00067 }
00068 return 1;
00069 }