c_create_idx.c

Go to the documentation of this file.
00001 #include <string.h>
00002 #include <grass/dbmi.h>
00003 #include "macros.h"
00004 
00011 int
00012 db_create_index (dbDriver *driver, dbIndex *index)
00013 {
00014     int ret_code;
00015 
00016 /* start the procedure call */
00017     db__set_protocol_fds (driver->send, driver->recv);
00018     DB_START_PROCEDURE_CALL(DB_PROC_CREATE_INDEX);
00019 
00020 /* send the arguments to the procedure */
00021     DB_SEND_INDEX (index);
00022 
00023 /* get the return code for the procedure call */
00024     DB_RECV_RETURN_CODE(&ret_code);
00025 
00026     if (ret_code != DB_OK)
00027         return ret_code; /* ret_code SHOULD == DB_FAILED */
00028 
00029 /* get results */
00030     DB_RECV_STRING(&index->indexName);
00031 
00032     return DB_OK;
00033 }
00034 
00040 int
00041 db_create_index2 (dbDriver *driver, char *table_name, char *column_name)
00042 {
00043     int ret;
00044     dbIndex index;
00045     char buf[1000];
00046     char *tbl;
00047 
00048     db_init_index ( &index );
00049     db_alloc_index_columns ( &index, 1 );
00050 
00051     tbl = strchr ( table_name, '.' );
00052     if ( tbl == NULL )
00053         tbl = table_name;
00054     else 
00055         tbl++;
00056     
00057     sprintf ( buf, "%s_%s", tbl, column_name );
00058     db_set_index_name ( &index, buf );
00059 
00060     db_set_index_table_name ( &index, table_name );
00061     db_set_index_column_name ( &index, 0, column_name );
00062     db_set_index_type_unique ( &index );
00063 
00064     ret = db_create_index ( driver , &index );
00065 
00066     db_free_index ( &index );
00067 
00068     return ret;
00069 }

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