GRASS 8 Programmer's Manual 8.6.0dev(2026)-8843f13794
Loading...
Searching...
No Matches
c_create_idx.c
Go to the documentation of this file.
1/*!
2 * \file db/dbmi_client/c_create_idx.c
3 *
4 * \brief DBMI Library (client) - create index
5 *
6 * SPDX-FileCopyrightText: 1999-2008 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Joel Jones (CERL/UIUC), Radim Blazek
10 */
11
12#include <string.h>
13#include <grass/dbmi.h>
14#include "macros.h"
15
16/*!
17 \brief Create index
18
19 \param driver db driver
20 \param index index info (pointer to dbIndex structure)
21
22 \return DB_OK on success
23 \return DB_FAILED on failure
24 */
26{
27 int ret_code;
28
29 /* start the procedure call */
32
33 /* send the arguments to the procedure */
34 DB_SEND_INDEX(index);
35
36 /* get the return code for the procedure call */
38
39 if (ret_code != DB_OK)
40 return ret_code; /* ret_code SHOULD == DB_FAILED */
41
42 /* get results */
44
45 return DB_OK;
46}
47
48/*!
49 \brief Create unique index
50
51 \param driver db driver
52 \param table_name table name
53 \param column_name column name (where to create index)
54
55 \return DB_OK on success
56 \return DB_FAILED on failure
57 */
58int db_create_index2(dbDriver *driver, const char *table_name,
59 const char *column_name)
60{
61 int ret;
62 dbIndex index;
63 char buf[1000];
64 const char *tbl;
65
66 db_init_index(&index);
67 db_alloc_index_columns(&index, 1);
68
69 tbl = strchr(table_name, '.');
70 if (tbl == NULL)
71 tbl = table_name;
72 else
73 tbl++;
74
75 snprintf(buf, sizeof(buf), "%s_%s", tbl, column_name);
76 db_set_index_name(&index, buf);
77
78 db_set_index_table_name(&index, table_name);
79 db_set_index_column_name(&index, 0, column_name);
81
82 ret = db_create_index(driver, &index);
83
84 db_free_index(&index);
85
86 return ret;
87}
int db_create_index2(dbDriver *driver, const char *table_name, const char *column_name)
Create unique index.
int db_create_index(dbDriver *driver, dbIndex *index)
Create index.
#define NULL
Definition ccmath.h:32
Main header of GRASS DataBase Management Interface.
#define DB_PROC_CREATE_INDEX
Definition dbmi.h:59
#define DB_OK
Definition dbmi.h:69
int db_set_index_name(dbIndex *, const char *)
Set index name.
void db_init_index(dbIndex *)
Initialize dbIndex.
int db_set_index_table_name(dbIndex *, const char *)
Set table name.
int db_set_index_column_name(dbIndex *, int, const char *)
Set column name.
void db__set_protocol_fds(FILE *, FILE *)
?
void db_free_index(dbIndex *)
Free allocated dbIndex.
int db_set_index_type_unique(dbIndex *)
Set index type to unique.
int db_alloc_index_columns(dbIndex *, int)
Allocate index columns.
#define DB_RECV_STRING(x)
Definition macros.h:39
#define DB_SEND_INDEX(x)
Definition macros.h:225
#define DB_START_PROCEDURE_CALL(x)
Definition macros.h:2
#define DB_RECV_RETURN_CODE(x)
Definition macros.h:7
dbString indexName
Definition dbmi.h:229