d_fetch.c

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

Generated on Sat Oct 24 03:24:24 2009 for GRASS Programmer's Manual by  doxygen 1.6.1