GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-bceeab9228
dbmi_base/column.c File Reference

DBMI Library (base) - columns management. More...

#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
Include dependency graph for dbmi_base/column.c:

Go to the source code of this file.

Functions

dbValuedb_get_column_value (dbColumn *column)
 Returns column value for given column structure. More...
 
dbValuedb_get_column_default_value (dbColumn *column)
 Returns column default value for given column structure. More...
 
void db_set_column_sqltype (dbColumn *column, int sqltype)
 Define column sqltype for column. More...
 
void db_set_column_host_type (dbColumn *column, int type)
 Set column host data type. More...
 
int db_get_column_scale (dbColumn *column)
 Get column scale. More...
 
void db_set_column_scale (dbColumn *column, int scale)
 Set column scale. More...
 
int db_get_column_precision (dbColumn *column)
 Get column precision. More...
 
void db_set_column_precision (dbColumn *column, int precision)
 Set column precision. More...
 
int db_get_column_sqltype (dbColumn *column)
 Returns column sqltype for column. More...
 
int db_get_column_host_type (dbColumn *column)
 Get column host type. More...
 
void db_set_column_has_defined_default_value (dbColumn *column)
 Set default value identificator. More...
 
void db_set_column_has_undefined_default_value (dbColumn *column)
 Unset default value identificator. More...
 
void db_unset_column_has_default_value (dbColumn *column)
 Unset default value identificator. More...
 
int db_test_column_has_default_value (dbColumn *column)
 Check if column has defined default value. More...
 
int db_test_column_has_defined_default_value (dbColumn *column)
 Check if column has defined default value. More...
 
int db_test_column_has_undefined_default_value (dbColumn *column)
 Check if column has defined default value. More...
 
void db_set_column_use_default_value (dbColumn *column)
 Set default value to be used. More...
 
void db_unset_column_use_default_value (dbColumn *column)
 Unset default value to be used. More...
 
int db_test_column_use_default_value (dbColumn *column)
 Checks if default value is used. More...
 
void db_set_column_null_allowed (dbColumn *column)
 Set null value to be allowed. More...
 
void db_unset_column_null_allowed (dbColumn *column)
 Unset null value to be allowed. More...
 
int db_test_column_null_allowed (dbColumn *column)
 Checks if null value is allowed. More...
 
int db_get_column_length (dbColumn *column)
 Get column's length. More...
 
void db_set_column_length (dbColumn *column, int length)
 Set column's length. More...
 
void db_set_column_select_priv_granted (dbColumn *column)
 Set select privileges to be granted. More...
 
void db_set_column_select_priv_not_granted (dbColumn *column)
 Unset select privileges. More...
 
int db_get_column_select_priv (dbColumn *column)
 Get select privileges. More...
 
void db_set_column_update_priv_granted (dbColumn *column)
 Set update privileges to be granted. More...
 
void db_set_column_update_priv_not_granted (dbColumn *column)
 Unset update privileges. More...
 
int db_get_column_update_priv (dbColumn *column)
 Get update privileges. More...
 
void db_init_column (dbColumn *column)
 Initialize dbColumn. More...
 
int db_set_column_name (dbColumn *column, const char *name)
 Set column name. More...
 
const char * db_get_column_name (dbColumn *column)
 Returns column name for given column. More...
 
int db_set_column_description (dbColumn *column, const char *description)
 Set column description. More...
 
const char * db_get_column_description (dbColumn *column)
 Returns column description for given column. More...
 
void db_free_column (dbColumn *column)
 Frees column structure. More...
 
dbColumndb_copy_column (dbColumn *dest, dbColumn *src)
 Copy a db column from source to destination. More...
 

Detailed Description

DBMI Library (base) - columns management.

(C) 1999-2009, 2011 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Joel Jones (CERL/UIUC), Radim Blazek
Doxygenized by Martin Landa <landa.martin gmail.com> (2011)

Definition in file dbmi_base/column.c.

Function Documentation

◆ db_copy_column()

dbColumn* db_copy_column ( dbColumn dest,
dbColumn src 
)

Copy a db column from source to destination.

Parameters
srcThe column to copy from
destAn allocated column to copy to which will be initialized. In case dest is NULL a new column will be allocated and returned
Returns
The pointer of copied/allocated column

Definition at line 472 of file dbmi_base/column.c.

References db_calloc(), db_copy_string(), db_copy_value(), db_init_column(), NULL, and src.

Referenced by db_clone_table().

◆ db_free_column()

void db_free_column ( dbColumn column)

Frees column structure.

Parameters
columnpointer to dbColumn

Definition at line 454 of file dbmi_base/column.c.

References _db_column::columnName, db_free_string(), _db_column::defaultValue, _db_column::description, _db_value::s, and _db_column::value.

Referenced by db_d_add_column().

◆ db_get_column_default_value()

dbValue* db_get_column_default_value ( dbColumn column)

Returns column default value for given column structure.

Parameters
columnpointer to dbColumn
Returns
pointer to dbValue

Definition at line 39 of file dbmi_base/column.c.

References _db_column::defaultValue.

Referenced by db__recv_column_default_value(), db__send_column_default_value(), db_convert_column_default_value_to_string(), and db_convert_Cstring_to_column_default_value().

◆ db_get_column_description()

const char* db_get_column_description ( dbColumn column)

Returns column description for given column.

Parameters
columnpointer to dbColumn
Returns
pointer to string with column's description

Definition at line 444 of file dbmi_base/column.c.

References db_get_string(), and _db_column::description.

Referenced by db_print_column_definition().

◆ db_get_column_host_type()

int db_get_column_host_type ( dbColumn column)

Get column host type.

Parameters
columnpointer to dbColumn
Returns
data type (see include/dbmi.h)

Definition at line 154 of file dbmi_base/column.c.

References _db_column::hostDataType.

◆ db_get_column_length()

int db_get_column_length ( dbColumn column)

Get column's length.

Parameters
columnpointer to dbColumn
Returns
length

Definition at line 303 of file dbmi_base/column.c.

References _db_column::dataLen.

Referenced by db_print_column_definition().

◆ db_get_column_name()

const char* db_get_column_name ( dbColumn column)

Returns column name for given column.

Parameters
columnpointer to dbColumn
Returns
pointer to string with column name

Definition at line 418 of file dbmi_base/column.c.

References _db_column::columnName, and db_get_string().

Referenced by db_print_column_definition().

◆ db_get_column_precision()

int db_get_column_precision ( dbColumn column)

Get column precision.

Parameters
columnpointer to dbColumn
Returns
precision

Definition at line 117 of file dbmi_base/column.c.

References _db_column::precision.

Referenced by db_print_column_definition().

◆ db_get_column_scale()

int db_get_column_scale ( dbColumn column)

Get column scale.

Parameters
columnpointer to dbColumn
Returns
scale

Definition at line 94 of file dbmi_base/column.c.

References _db_column::scale.

Referenced by db_print_column_definition().

◆ db_get_column_select_priv()

int db_get_column_select_priv ( dbColumn column)

Get select privileges.

Parameters
columnpointer to dbColumn
Returns
privileges

Definition at line 346 of file dbmi_base/column.c.

References _db_column::select.

◆ db_get_column_sqltype()

int db_get_column_sqltype ( dbColumn column)

Returns column sqltype for column.

The function db_sqltype_name() returns sqltype description.

Parameters
columnpointer to dbColumn
Returns
sql data type (see include/dbmi.h)

Definition at line 142 of file dbmi_base/column.c.

References _db_column::sqlDataType.

Referenced by db__recv_column_default_value(), db__recv_column_value(), db__send_column_default_value(), db__send_column_value(), db_convert_column_default_value_to_string(), db_convert_column_value_to_string(), db_convert_Cstring_to_column_default_value(), db_convert_Cstring_to_column_value(), and db_print_column_definition().

◆ db_get_column_update_priv()

int db_get_column_update_priv ( dbColumn column)

Get update privileges.

Parameters
columnpointer to dbColumn
Returns
privileges

Definition at line 378 of file dbmi_base/column.c.

References _db_column::update.

◆ db_get_column_value()

dbValue* db_get_column_value ( dbColumn column)

Returns column value for given column structure.

Parameters
columnpointer to dbColumn
Returns
pointer to dbValue

Definition at line 27 of file dbmi_base/column.c.

References _db_column::value.

Referenced by db__recv_column_value(), db__send_column_value(), db_convert_column_value_to_string(), and db_convert_Cstring_to_column_value().

◆ db_init_column()

void db_init_column ( dbColumn column)

Initialize dbColumn.

Parameters
columnpointer to dbColumn to be initialized

Definition at line 388 of file dbmi_base/column.c.

References _db_column::columnName, db_init_string(), db_zero(), _db_column::defaultValue, _db_column::description, _db_value::s, and _db_column::value.

Referenced by db_copy_column(), and db_d_add_column().

◆ db_set_column_description()

int db_set_column_description ( dbColumn column,
const char *  description 
)

Set column description.

Parameters
columnpointer to dbColumn
descriptioncolumn's description
Returns
DB_OK on success
error code on failure

Definition at line 432 of file dbmi_base/column.c.

References db_set_string(), and _db_column::description.

◆ db_set_column_has_defined_default_value()

void db_set_column_has_defined_default_value ( dbColumn column)

Set default value identificator.

Parameters
columnpointer to dbColumn

Definition at line 164 of file dbmi_base/column.c.

References _db_column::hasDefaultValue.

◆ db_set_column_has_undefined_default_value()

void db_set_column_has_undefined_default_value ( dbColumn column)

Unset default value identificator.

Todo:
Replace by db_unset_column_has_default_value() ?
Parameters
columnpointer to dbColumn

Definition at line 176 of file dbmi_base/column.c.

References _db_column::hasDefaultValue.

◆ db_set_column_host_type()

void db_set_column_host_type ( dbColumn column,
int  type 
)

Set column host data type.

Parameters
columnpointer to dbColumn
typedata type

Definition at line 82 of file dbmi_base/column.c.

◆ db_set_column_length()

void db_set_column_length ( dbColumn column,
int  length 
)

Set column's length.

Parameters
columnpointer to dbColumn
lengthvalue

Definition at line 314 of file dbmi_base/column.c.

References _db_column::dataLen.

◆ db_set_column_name()

int db_set_column_name ( dbColumn column,
const char *  name 
)

Set column name.

Parameters
columnpointer to dbColumn
namecolumn name
Returns
DB_OK on success
error code on failure

Definition at line 406 of file dbmi_base/column.c.

References _db_column::columnName, db_set_string(), and name.

Referenced by P_Create_Aux2_Table(), and P_Create_Aux4_Table().

◆ db_set_column_null_allowed()

void db_set_column_null_allowed ( dbColumn column)

Set null value to be allowed.

Parameters
columnpointer to dbColumn

Definition at line 268 of file dbmi_base/column.c.

References _db_column::nullAllowed.

◆ db_set_column_precision()

void db_set_column_precision ( dbColumn column,
int  precision 
)

Set column precision.

Parameters
columnpointer to dbColumn
precisionvalue

Definition at line 128 of file dbmi_base/column.c.

References _db_column::precision.

◆ db_set_column_scale()

void db_set_column_scale ( dbColumn column,
int  scale 
)

Set column scale.

Parameters
columnpointer to dbColumn
scalecolumn scale value

Definition at line 105 of file dbmi_base/column.c.

◆ db_set_column_select_priv_granted()

void db_set_column_select_priv_granted ( dbColumn column)

Set select privileges to be granted.

Parameters
columnpointer to dbColumn

Definition at line 324 of file dbmi_base/column.c.

References DB_GRANTED, and _db_column::select.

◆ db_set_column_select_priv_not_granted()

void db_set_column_select_priv_not_granted ( dbColumn column)

Unset select privileges.

Parameters
columnpointer to dbColumn

Definition at line 334 of file dbmi_base/column.c.

References DB_NOT_GRANTED, and _db_column::select.

◆ db_set_column_sqltype()

void db_set_column_sqltype ( dbColumn column,
int  sqltype 
)

Define column sqltype for column.

The function db_sqltype_name() returns sqltype description.

#define DB_SQL_TYPE_UNKNOWN 0
#define DB_SQL_TYPE_CHARACTER 1
#define DB_SQL_TYPE_SMALLINT 2
#define DB_SQL_TYPE_INTEGER 3
#define DB_SQL_TYPE_REAL 4
#define DB_SQL_TYPE_DOUBLE_PRECISION 6
#define DB_SQL_TYPE_DECIMAL 7
#define DB_SQL_TYPE_NUMERIC 8
#define DB_SQL_TYPE_DATE 9
#define DB_SQL_TYPE_TIME 10
#define DB_SQL_TYPE_TIMESTAMP 11
#define DB_SQL_TYPE_INTERVAL 12
#define DB_SQL_TYPE_TEXT 13
#define DB_SQL_TYPE_SERIAL 21
Parameters
columnpointer to dbColumn
sqltypeSQL data type (see list)

Definition at line 71 of file dbmi_base/column.c.

References _db_column::sqlDataType.

Referenced by P_Create_Aux2_Table(), and P_Create_Aux4_Table().

◆ db_set_column_update_priv_granted()

void db_set_column_update_priv_granted ( dbColumn column)

Set update privileges to be granted.

Parameters
columnpointer to dbColumn

Definition at line 356 of file dbmi_base/column.c.

References DB_GRANTED, and _db_column::update.

◆ db_set_column_update_priv_not_granted()

void db_set_column_update_priv_not_granted ( dbColumn column)

Unset update privileges.

Parameters
columnpointer to dbColumn

Definition at line 366 of file dbmi_base/column.c.

References DB_NOT_GRANTED, and _db_column::update.

◆ db_set_column_use_default_value()

void db_set_column_use_default_value ( dbColumn column)

Set default value to be used.

Parameters
columnpointer to dbColumn

Definition at line 235 of file dbmi_base/column.c.

References _db_column::useDefaultValue.

◆ db_test_column_has_default_value()

int db_test_column_has_default_value ( dbColumn column)

Check if column has defined default value.

Parameters
columnpointer to dbColumn
Returns
1 if true
0 if false

Definition at line 199 of file dbmi_base/column.c.

References _db_column::hasDefaultValue.

Referenced by db_print_column_definition().

◆ db_test_column_has_defined_default_value()

int db_test_column_has_defined_default_value ( dbColumn column)

Check if column has defined default value.

Parameters
columnpointer to dbColumn
Returns
1 if true
0 if false

Definition at line 212 of file dbmi_base/column.c.

References _db_column::hasDefaultValue.

◆ db_test_column_has_undefined_default_value()

int db_test_column_has_undefined_default_value ( dbColumn column)

Check if column has defined default value.

Parameters
columnpointer to dbColumn
Returns
1 if false
0 if true

Definition at line 225 of file dbmi_base/column.c.

References _db_column::hasDefaultValue.

◆ db_test_column_null_allowed()

int db_test_column_null_allowed ( dbColumn column)

Checks if null value is allowed.

Parameters
columnpointer to dbColumn
Returns
1 if true
0 if false

Definition at line 291 of file dbmi_base/column.c.

References _db_column::nullAllowed.

Referenced by db_print_column_definition().

◆ db_test_column_use_default_value()

int db_test_column_use_default_value ( dbColumn column)

Checks if default value is used.

Parameters
columnpointer to dbColumn
Returns
1 if true
0 if false

Definition at line 258 of file dbmi_base/column.c.

References _db_column::useDefaultValue.

◆ db_unset_column_has_default_value()

void db_unset_column_has_default_value ( dbColumn column)

Unset default value identificator.

Parameters
columnpointer to dbColumn

Definition at line 186 of file dbmi_base/column.c.

References _db_column::hasDefaultValue.

◆ db_unset_column_null_allowed()

void db_unset_column_null_allowed ( dbColumn column)

Unset null value to be allowed.

Parameters
columnpointer to dbColumn

Definition at line 278 of file dbmi_base/column.c.

References _db_column::nullAllowed.

◆ db_unset_column_use_default_value()

void db_unset_column_use_default_value ( dbColumn column)

Unset default value to be used.

Parameters
columnpointer to dbColumn

Definition at line 245 of file dbmi_base/column.c.

References _db_column::useDefaultValue.