GRASS Programmer's Manual 6.4.1(2011)
|
00001 00015 #include <string.h> 00016 #include <grass/dbmi.h> 00017 #include "macros.h" 00018 00028 int db_create_index(dbDriver * driver, dbIndex * index) 00029 { 00030 int ret_code; 00031 00032 /* start the procedure call */ 00033 db__set_protocol_fds(driver->send, driver->recv); 00034 DB_START_PROCEDURE_CALL(DB_PROC_CREATE_INDEX); 00035 00036 /* send the arguments to the procedure */ 00037 DB_SEND_INDEX(index); 00038 00039 /* get the return code for the procedure call */ 00040 DB_RECV_RETURN_CODE(&ret_code); 00041 00042 if (ret_code != DB_OK) 00043 return ret_code; /* ret_code SHOULD == DB_FAILED */ 00044 00045 /* get results */ 00046 DB_RECV_STRING(&index->indexName); 00047 00048 return DB_OK; 00049 } 00050 00061 int db_create_index2(dbDriver * driver, const char *table_name, 00062 const char *column_name) 00063 { 00064 int ret; 00065 dbIndex index; 00066 char buf[1000]; 00067 const char *tbl; 00068 00069 db_init_index(&index); 00070 db_alloc_index_columns(&index, 1); 00071 00072 tbl = strchr(table_name, '.'); 00073 if (tbl == NULL) 00074 tbl = table_name; 00075 else 00076 tbl++; 00077 00078 sprintf(buf, "%s_%s", tbl, column_name); 00079 db_set_index_name(&index, buf); 00080 00081 db_set_index_table_name(&index, table_name); 00082 db_set_index_column_name(&index, 0, column_name); 00083 db_set_index_type_unique(&index); 00084 00085 ret = db_create_index(driver, &index); 00086 00087 db_free_index(&index); 00088 00089 return ret; 00090 }