GRASS Programmer's Manual
6.4.1(2011)
|
00001 00015 #include <stdlib.h> 00016 #include <grass/dbmi.h> 00017 #include "macros.h" 00018 #include "dbstubs.h" 00019 00026 int db_d_open_select_cursor(void) 00027 { 00028 dbCursor *cursor; 00029 int stat; 00030 dbToken token; 00031 dbString select; 00032 int mode; 00033 00034 /* get the arg(s) */ 00035 db_init_string(&select); 00036 DB_RECV_STRING(&select); 00037 DB_RECV_INT(&mode); 00038 00039 /* create a cursor */ 00040 cursor = (dbCursor *) db_malloc(sizeof(dbCursor)); 00041 if (cursor == NULL) 00042 return db_get_error_code(); 00043 token = db_new_token((dbAddress) cursor); 00044 if (token < 0) 00045 return db_get_error_code(); 00046 db_init_cursor(cursor); 00047 00048 /* call the procedure */ 00049 stat = db_driver_open_select_cursor(&select, cursor, mode); 00050 db_free_string(&select); 00051 00052 /* send the return code */ 00053 if (stat != DB_OK) { 00054 DB_SEND_FAILURE(); 00055 return DB_OK; 00056 } 00057 DB_SEND_SUCCESS(); 00058 00059 /* mark this as a readonly cursor */ 00060 db_set_cursor_type_readonly(cursor); 00061 00062 /* add this cursor to the cursors managed by the driver state */ 00063 db__add_cursor_to_driver_state(cursor); 00064 00065 /* results */ 00066 DB_SEND_TOKEN(&token); 00067 DB_SEND_INT(cursor->type); 00068 DB_SEND_INT(cursor->mode); 00069 DB_SEND_TABLE_DEFINITION(cursor->table); 00070 return DB_OK; 00071 }