## GdaDbColumn GdaDbColumn — Object to represent table column |

## Stability Level

Stable, unless otherwise indicated

## Functions

GQuark | gda_db_column_error_quark ()
GdaDbColumn * | gda_db_column_new ()
GdaDbColumn * | gda_db_column_new_from_meta ()
gboolean | gda_db_column_get_autoinc ()
void | gda_db_column_set_autoinc ()
const gchar * | gda_db_column_get_check ()
void | gda_db_column_set_check ()
const gchar * | gda_db_column_get_comment ()
void | gda_db_column_set_comment ()
GType | gda_db_column_get_gtype ()
const gchar * | gda_db_column_get_ctype ()
void | gda_db_column_set_type ()
const gchar * | gda_db_column_get_default ()
void | gda_db_column_set_default ()
const gchar * | gda_db_column_get_name ()
void | gda_db_column_set_name ()
gboolean | gda_db_column_get_nnul ()
void | gda_db_column_set_nnul ()
gboolean | gda_db_column_get_pkey ()
void | gda_db_column_set_pkey ()
guint | gda_db_column_get_scale ()
void | gda_db_column_set_scale ()
guint | gda_db_column_get_size ()
void | gda_db_column_set_size ()
gboolean | gda_db_column_get_unique ()
void | gda_db_column_set_unique ()
gboolean | gda_db_column_prepare_add ()
gboolean | gda_db_column_prepare_create ()

## Properties

gboolean | autoinc | Read / Write
char * | check | Read / Write
char * | comment | Read / Write
char * | default | Read / Write
char * | name | Read / Write
gboolean | nnul | Read / Write
gboolean | pkey | Read / Write
guint | scale | Read / Write
guint | size | Read / Write
GdaDbTable * | table | Read / Write
gboolean | unique | Read / Write

## Types and Values

| GdaDbColumn
enum | GdaDbColumnError
#define | GDA_TYPE_DB_COLUMN
#define | GDA_DB_COLUMN_ERROR

## Object Hierarchy

        GObject
        ╰── GdaDbColumn

## Implemented Interfaces

GdaDbColumn implements GdaDbBuildable and GdaDdlModifiable.

## Includes

    #include <libgda/libgda.h>

## Description

This object represents a column of a table or a view. The column can be constracted manually using API or generated from xml file together with other databse objects. See GdaDbCatalog. GdaDbColumn implements GdaDbBuildable interface for parsing xml file. This is a typical example how the GdaDbColumn API can be used.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    GdaDbTable *tproject = gda_db_table_new ();
    gda_db_base_set_name (GDA_DB_BASE (tproject), "Project");

    GdaDbColumn *pid = gda_db_column_new ();
    gda_db_column_set_name (pid, "id");
    gda_db_column_set_type (pid, G_TYPE_INT);
    gda_db_column_set_nnul (pid, TRUE);
    gda_db_column_set_autoinc (pid, TRUE);
    gda_db_column_set_unique (pid, TRUE);
    gda_db_column_set_pkey (pid, TRUE);

    gda_db_table_append_column (tproject, pid);

    g_object_unref (pid);

## Functions

### gda_db_column_error_quark ()

    GQuark
    gda_db_column_error_quark (void);

### gda_db_column_new ()

    GdaDbColumn *
    gda_db_column_new (void);

#### Returns

New instance of GdaDbColumn, to free with `g_object_unref()` once not needed anymore

Since: 6.0

Stability Level: Stable

### gda_db_column_new_from_meta ()

    GdaDbColumn *
    gda_db_column_new_from_meta (GdaMetaTableColumn *column);

Create new GdaDbColumn instance from the corresponding GdaMetaTableColumn object. If `NULL` is passed this function works exactly as `gda_db_column_new()`.

#### Parameters

column | a GdaMetaTableColumn instance |

#### Returns

New object that should be freed with `g_object_unref()`

### gda_db_column_get_autoinc ()

    gboolean
    gda_db_column_get_autoinc (GdaDbColumn *self);

Get value for autoinc key

#### Parameters

self | a GdaDbColumn object |

#### Returns

`TRUE` if column should be auto-incremented, `FALSE` otherwise.

Since: 6.0

Stability Level: Stable

### gda_db_column_set_autoinc ()

    void
    gda_db_column_set_autoinc (GdaDbColumn *self,
                               gboolean autoinc);

Set value for auto-incremented key.

#### Parameters

self | a GdaDbColumn object |
autoinc | value to set |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_check ()

    const gchar *
    gda_db_column_get_check (GdaDbColumn *self);

Returns value of the check field.

#### Parameters

self | a GdaDbColumn instance |

#### Returns

Column check string

Since: 6.0

Stability Level: Stable

### gda_db_column_set_check ()

    void
    gda_db_column_set_check (GdaDbColumn *self,
                             const gchar *value);

Sets check string to the column.

#### Parameters

self | a GdaDbColumn instance |
value | value to set |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_comment ()

    const gchar *
    gda_db_column_get_comment (GdaDbColumn *self);

Get value for column comment.

#### Parameters

self | a GdaDbColumn object |

#### Returns

Column comment as a string. `NULL` is returned if comment is not set.

Since: 6.0

Stability Level: Stable

### gda_db_column_set_comment ()

    void
    gda_db_column_set_comment (GdaDbColumn *self,
                               const gchar *comnt);

Set value for column comment.

#### Parameters

self | a GdaDbColumn object |
comnt | comment to set |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_gtype ()

    GType
    gda_db_column_get_gtype (GdaDbColumn *self);

Return of column type as GType

#### Parameters

self | a GdaDbColumn object |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_ctype ()

    const gchar *
    gda_db_column_get_ctype (GdaDbColumn *self);

Returns column type as a string derivied from GType

#### Parameters

self | a GdaDbColumn object |

#### Returns

column type as a string or `NULL`

Since: 6.0

Stability Level: Stable

### gda_db_column_set_type ()

    void
    gda_db_column_set_type (GdaDbColumn *self,
                            GType type);

Set type of the column as a GType. For numeric type, GDA_TYPE_NUMERIC should be used. Other types, e.g. `G_TYPE_FLOAT` or `G_TYPE_DOUBLE` can also be used but precision and scale should not be set. In this case appropriate types for DB implementation will be used, e.g. float4.

#### Parameters

self | a GdaDbColumn instance |
type | GType for column |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_default ()

    const gchar *
    gda_db_column_get_default (GdaDbColumn *self);

Returns default value for the column. Can be `NULL` if the default value hasn't been set.

#### Parameters

self | a GdaDbColumn instance |

#### Returns

Default value for the column as a string.

Since: 6.0

Stability Level: Stable

### gda_db_column_set_default ()

    void
    gda_db_column_set_default (GdaDbColumn *self,
                               const gchar *value);

#### Parameters

self | a GdaDbColumn instance |
value | default value to set for column as a string |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_name ()

    const gchar *
    gda_db_column_get_name (GdaDbColumn *self);

Returns name of the column

#### Parameters

self | a GdaDbColumn instance |

#### Returns

Column name as a string or `NULL`.

Since: 6.0

Stability Level: Stable

### gda_db_column_set_name ()

    void
    gda_db_column_set_name (GdaDbColumn *self,
                            const gchar *name);

Set column name.

#### Parameters

self | a GdaDbColumn object |
name | name as a string |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_nnul ()

    gboolean
    gda_db_column_get_nnul (GdaDbColumn *self);

Specify if the column's value can be NULL.

#### Parameters

self | a `GdaDbColumn` object |

#### Returns

`TRUE` if value can be `NULL`, `FALSE` otherwise.

Since: 6.0

Stability Level: Stable

### gda_db_column_set_nnul ()

    void
    gda_db_column_set_nnul (GdaDbColumn *self,
                            gboolean nnul);

#### Parameters

self | a GdaDbColumn object |
nnul | value to set for nnul If `nnul` is `TRUE` the column will be marked with NON NULL flag |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_pkey ()

    gboolean
    gda_db_column_get_pkey (GdaDbColumn *self);

Returns a primary key flag

#### Parameters

self | a GdaDbColumn object |

#### Returns

`TRUE` if the column is primary key, `FALSE` otherwise

Since: 6.0

Stability Level: Stable

### gda_db_column_set_pkey ()

    void
    gda_db_column_set_pkey (GdaDbColumn *self,
                            gboolean pkey);

If `pkey` is `TRUE`, the given column will be marked with PRIMERY KEY flag

#### Parameters

self | a GdaDbColumn object |
pkey | value to set |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_scale ()

    guint
    gda_db_column_get_scale (GdaDbColumn *self);

Scale is used for float number representation to specify a number of decimal digits. This value is ignore for column types except float or double.

#### Parameters

self | a GdaDbColumn object |

#### Returns

Current scale value

Since: 6.0

Stability Level: Stable

### gda_db_column_set_scale ()

    void
    gda_db_column_set_scale (GdaDbColumn *self,
                             guint scale);

Scale is used for float number representation to specify a number of decimal digits. This value is ignore for column types except float or double.

#### Parameters

self | a GdaDbColumn |
scale | scale value to set |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_size ()

    guint
    gda_db_column_get_size (GdaDbColumn *self);

#### Parameters

self | a GdaDbColumn instance |

#### Returns

Current value for column size.

Since: 6.0

Stability Level: Stable

### gda_db_column_set_size ()

    void
    gda_db_column_set_size (GdaDbColumn *self,
                            guint size);

Set value for column size. This is relevant only for string column type.

#### Parameters

self | a GdaDbColumn instance |
size | value to set |

Since: 6.0

Stability Level: Stable

### gda_db_column_get_unique ()

    gboolean
    gda_db_column_get_unique (GdaDbColumn *self);

Get value for unique key

#### Parameters

self | a GdaDbColumn object |

#### Returns

`TRUE` if column should have a unique value, `FALSE` otherwise.

Since: 6.0

Stability Level: Stable

### gda_db_column_set_unique ()

    void
    gda_db_column_set_unique (GdaDbColumn *self,
                              gboolean unique);

Set value for unique key.

#### Parameters

self | a GdaDbColumn object |
unique | value to set |

Since: 6.0

Stability Level: Stable

### gda_db_column_prepare_add ()

    gboolean
    gda_db_column_prepare_add (GdaDbColumn *self,
                               GdaServerOperation *op,
                               GError **error);

Populate `op` with information stored in `self` . This method is used to prepare `op` for `GDA_SERVER_OPERATION_ADD_COLUMN` operation.

#### Parameters

self | a GdaDbColumn instance |
op | GdaServerOperation to add information |
error | error storage container |

#### Returns

`TRUE` if success, `FALSE` otherwise.

Since: 6.0

Stability Level: Stable

### gda_db_column_prepare_create ()

    gboolean
    gda_db_column_prepare_create (GdaDbColumn *self,
                                  GdaServerOperation *op,
                                  guint order,
                                  GError **error);

This method populate `op` with information stored in `self` .

#### Parameters

self | a GdaDbColumn instance |
op | a GdaServerOperation instance to update for TABLE_CREATE operation |
order | Order number for the column |
error | a GError container |

#### Returns

`TRUE` if successful, `FALSE` otherwise.

Since: 6.0

Stability Level: Stable

## Types and Values

### GdaDbColumn

    typedef struct _GdaDbColumn GdaDbColumn;

### enum GdaDbColumnError

Values used to describe the source of the error.

#### Members

GDA_DB_COLUMN_ERROR_TYPE | Set if wrong column type was given in the xml file. |
GDA_DB_COLUMN_ERROR_WRONG_OPERATION | Wrong operation requested |

### GDA_TYPE_DB_COLUMN

    #define GDA_TYPE_DB_COLUMN (gda_db_column_get_type())

### GDA_DB_COLUMN_ERROR

    #define GDA_DB_COLUMN_ERROR gda_db_column_error_quark()

## Property Details

### The `“autoinc”` property

      “autoinc”                  gboolean

Can value be autoincremented.

Owner: GdaDbColumn

Flags: Read / Write

Default value: FALSE

### The `“check”` property

      “check”                    char *

Column check string.

Owner: GdaDbColumn

Flags: Read / Write

Default value: NULL

### The `“comment”` property

      “comment”                  char *

Column comment.

Owner: GdaDbColumn

Flags: Read / Write

Default value: NULL

### The `“default”` property

      “default”                  char *

Default value.

Owner: GdaDbColumn

Flags: Read / Write

Default value: NULL

### The `“name”` property

      “name”                     char *

Column name.

Owner: GdaDbColumn

Flags: Read / Write

Default value: NULL

### The `“nnul”` property

      “nnul”                     gboolean

Can value be NULL.

Owner: GdaDbColumn

Flags: Read / Write

Default value: TRUE

### The `“pkey”` property

      “pkey”                     gboolean

Is is primery key.

Owner: GdaDbColumn

Flags: Read / Write

Default value: FALSE

### The `“scale”` property

      “scale”                    guint

Number of decimal for numeric type.

Owner: GdaDbColumn

Flags: Read / Write

Allowed values: <= 64

Default value: 2

### The `“size”` property

      “size”                     guint

Column size.

Owner: GdaDbColumn

Flags: Read / Write

Allowed values: <= 9999

Default value: 80

### The `“table”` property

      “table”                    GdaDbTable *

Parent table.

Owner: GdaDbColumn

Flags: Read / Write

### The `“unique”` property

      “unique”                   gboolean

Can value be unique.

Owner: GdaDbColumn

Flags: Read / Write

Default value: FALSE

## See Also

GdaDbTable, GdaDbView, GdaDbBuildable