cursor.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "dbmi.h"
00003 
00010 void
00011 db_init_cursor (
00012                 dbCursor *cursor)
00013 {
00014     cursor->driver = NULL;
00015     cursor->token = -1;
00016     cursor->type = 0;
00017     cursor->mode = 0;
00018     cursor->table = NULL;
00019     cursor->column_flags = NULL;
00020 }
00021 
00028 int
00029 db_alloc_cursor_table (
00030                        dbCursor *cursor,
00031                        int ncols)
00032 {
00033     cursor->table = db_alloc_table (ncols);
00034     if (cursor->table == NULL)
00035         return db_get_error_code();
00036     return DB_OK;
00037 }
00038 
00045 void
00046 db_free_cursor (
00047                 dbCursor *cursor)
00048 {
00049     if (cursor->table)
00050         db_free_table (cursor->table);
00051     if (cursor->column_flags)
00052         db_free_cursor_column_flags (cursor);
00053     db_init_cursor(cursor);
00054 }
00055 
00062 dbTable *
00063 db_get_cursor_table(
00064                     dbCursor *cursor)
00065 {
00066     return cursor->table;
00067 }
00068 
00075 void
00076 db_set_cursor_table(
00077                     dbCursor *cursor,
00078                     dbTable *table)
00079 {
00080     cursor->table = table;
00081 }
00082 
00089 dbToken
00090 db_get_cursor_token(
00091                     dbCursor *cursor)
00092 {
00093     return cursor->token;
00094 }
00095 
00102 void
00103 db_set_cursor_token(dbCursor *cursor, dbToken token)
00104 {
00105     cursor->token = token;
00106 }
00107 
00114 void
00115 db_set_cursor_type_readonly (
00116                              dbCursor *cursor)
00117 {
00118     cursor->type = DB_READONLY;
00119 }
00120 
00127 void
00128 db_set_cursor_type_update (dbCursor *cursor)
00129 {
00130     cursor->type = DB_UPDATE;
00131 }
00132 
00139 void
00140 db_set_cursor_type_insert (
00141                            dbCursor *cursor)
00142 {
00143     cursor->type = DB_INSERT;
00144 }
00145 
00152 int
00153 db_test_cursor_type_fetch(
00154                           dbCursor *cursor)
00155 {
00156     return (cursor->type == DB_READONLY || cursor->type == DB_UPDATE);
00157 }
00158 
00165 int
00166 db_test_cursor_type_update(
00167                            dbCursor *cursor)
00168 {
00169     return (cursor->type == DB_UPDATE);
00170 }
00171 
00178 int
00179 db_test_cursor_type_insert(
00180                            dbCursor *cursor)
00181 {
00182     return (cursor->type == DB_INSERT);
00183 }
00184 
00191 void
00192 db_set_cursor_mode(
00193                    dbCursor *cursor,
00194                    int mode)
00195 {
00196     cursor->mode = mode;
00197 }
00198 
00205 void
00206 db_set_cursor_mode_scroll(
00207                           dbCursor *cursor)
00208 {
00209     cursor->mode |= DB_SCROLL;
00210 }
00211 
00218 void
00219 db_unset_cursor_mode_scroll(
00220                             dbCursor *cursor)
00221 {
00222     cursor->mode &= ~DB_SCROLL;
00223 }
00224 
00231 void
00232 db_unset_cursor_mode(dbCursor *cursor)
00233 {
00234     cursor->mode = 0;
00235 }
00236 
00243 void
00244 db_set_cursor_mode_insensitive(
00245                                dbCursor *cursor)
00246 {
00247     cursor->mode |= DB_INSENSITIVE;
00248 }
00249 
00256 void
00257 db_unset_cursor_mode_insensitive(
00258                                  dbCursor *cursor)
00259 {
00260     cursor->mode &= ~DB_INSENSITIVE;
00261 }
00262 
00269 int
00270 db_test_cursor_mode_scroll(
00271                            dbCursor *cursor)
00272 {
00273     return (cursor->mode & DB_SCROLL);
00274 }
00275 
00276 
00283 int
00284 db_test_cursor_mode_insensitive(
00285                                 dbCursor *cursor)
00286 {
00287     return (cursor->mode & DB_INSENSITIVE);
00288 }
00289 
00296 int
00297 db_alloc_cursor_column_flags ( dbCursor *cursor)
00298 {
00299     int ncols;
00300     int col;
00301 
00302     ncols = db_get_cursor_number_of_columns (cursor);
00303     cursor->column_flags = (short *) db_calloc (ncols, sizeof(short));
00304     if (cursor->column_flags == NULL)
00305         return db_get_error_code();
00306     for (col = 0; col < ncols; col++)
00307         db_unset_cursor_column_flag (cursor, col);
00308     return DB_OK ;
00309 }
00310 
00317 void
00318 db_free_cursor_column_flags (
00319                              dbCursor *cursor)
00320 {
00321     if(cursor->column_flags)
00322         free(cursor->column_flags);
00323     cursor->column_flags = NULL;
00324 }
00325 
00332 void
00333 db_set_cursor_column_for_update (
00334                                  dbCursor *cursor,
00335                                  int col)
00336 {
00337     db_set_cursor_column_flag (cursor, col);
00338 }
00339 
00346 void
00347 db_unset_cursor_column_for_update (
00348                                    dbCursor *cursor,
00349                                    int col)
00350 {
00351     db_unset_cursor_column_flag (cursor, col);
00352 }
00353 
00360 int
00361 db_test_cursor_column_for_update (
00362                                   dbCursor *cursor,
00363                                   int col)
00364 {
00365     return db_test_cursor_column_flag (cursor, col);
00366 }
00367 
00374 int
00375 db_test_cursor_any_column_for_update (
00376                                       dbCursor *cursor)
00377 {
00378     return db_test_cursor_any_column_flag (cursor);
00379 }
00380 
00387 void
00388 db_set_cursor_column_flag (
00389                            dbCursor *cursor,
00390                            int col)
00391 {
00392     if (cursor->column_flags)
00393         cursor->column_flags[col] = 1;
00394 }
00395 
00402 void
00403 db_unset_cursor_column_flag (
00404                              dbCursor *cursor,
00405                              int col)
00406 {
00407     if (cursor->column_flags)
00408         cursor->column_flags[col] = 0;
00409 }
00410 
00417 int
00418 db_test_cursor_column_flag (
00419                             dbCursor *cursor,
00420                             int col)
00421 {
00422     return cursor->column_flags && cursor->column_flags[col] ? 1 : 0 ;
00423 }
00424 
00431 int
00432 db_get_cursor_number_of_columns (
00433                                  dbCursor *cursor)
00434 {
00435     dbTable *table;
00436 
00437     table = db_get_cursor_table (cursor);
00438     if (table)
00439         return db_get_table_number_of_columns(table);
00440     return 0;
00441 }
00442 
00449 /* is any cursor column flag set? */
00450 int
00451 db_test_cursor_any_column_flag (
00452                                 dbCursor *cursor)
00453 {
00454     int ncols, col;
00455 
00456     ncols = db_get_cursor_number_of_columns(cursor);
00457     for (col = 0; col < ncols; col++)
00458         if (db_test_cursor_column_flag(cursor, col))
00459             return 1;
00460     return 0;
00461 }

Generated on Wed Aug 23 17:48:31 2006 for GRASS by  doxygen 1.4.7