GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_create_idx.c
Go to the documentation of this file.
1 
15 #include <string.h>
16 #include <grass/dbmi.h>
17 #include "macros.h"
18 
28 int db_create_index(dbDriver * driver, dbIndex * index)
29 {
30  int ret_code;
31 
32  /* start the procedure call */
33  db__set_protocol_fds(driver->send, driver->recv);
34  DB_START_PROCEDURE_CALL(DB_PROC_CREATE_INDEX);
35 
36  /* send the arguments to the procedure */
37  DB_SEND_INDEX(index);
38 
39  /* get the return code for the procedure call */
40  DB_RECV_RETURN_CODE(&ret_code);
41 
42  if (ret_code != DB_OK)
43  return ret_code; /* ret_code SHOULD == DB_FAILED */
44 
45  /* get results */
46  DB_RECV_STRING(&index->indexName);
47 
48  return DB_OK;
49 }
50 
61 int db_create_index2(dbDriver * driver, const char *table_name,
62  const char *column_name)
63 {
64  int ret;
65  dbIndex index;
66  char buf[1000];
67  const char *tbl;
68 
69  db_init_index(&index);
70  db_alloc_index_columns(&index, 1);
71 
72  tbl = strchr(table_name, '.');
73  if (tbl == NULL)
74  tbl = table_name;
75  else
76  tbl++;
77 
78  sprintf(buf, "%s_%s", tbl, column_name);
79  db_set_index_name(&index, buf);
80 
81  db_set_index_table_name(&index, table_name);
82  db_set_index_column_name(&index, 0, column_name);
84 
85  ret = db_create_index(driver, &index);
86 
87  db_free_index(&index);
88 
89  return ret;
90 }
int db_create_index(dbDriver *driver, dbIndex *index)
Create index.
Definition: c_create_idx.c:28
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int db_set_index_type_unique(dbIndex *index)
void db__set_protocol_fds(FILE *send, FILE *recv)
Definition: xdr.c:71
void db_init_index(dbIndex *index)
void db_free_index(dbIndex *index)
int db_alloc_index_columns(dbIndex *index, int ncols)
int db_set_index_name(dbIndex *index, const char *name)
int db_set_index_column_name(dbIndex *index, int column_num, const char *name)
#define DB_SEND_INDEX(x)
Definition: macros.h:102
#define DB_START_PROCEDURE_CALL(x)
Definition: macros.h:2
#define DB_RECV_RETURN_CODE(x)
Definition: macros.h:4
int db_create_index2(dbDriver *driver, const char *table_name, const char *column_name)
Create unique index.
Definition: c_create_idx.c:61
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
return NULL
Definition: dbfopen.c:1394
Definition: driver.h:25
int db_set_index_table_name(dbIndex *index, const char *name)
#define DB_RECV_STRING(x)
Definition: macros.h:18