d_fetch.c

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

Generated on Sun Apr 6 17:31:38 2008 for GRASS by  doxygen 1.5.5