# Dbc

`kvadblib.``DATABASE_FLAG_J1939` = 1

## Dbc

class `canlib.kvadblib.``Dbc`(filename=None, name=None, protocol=None)

  Holds a dbc database.

  There are three ways to create a database:

  1. To load data from an existing database file, only set filename to the database filename.
  2. To add an empty database, set only name.
  3. To load data from an existing database file and give it a new name, set name to the new name and filename to the existing database filename.

  Either a name or a filename must be given.

  Parameters: | filename (str, optional) – The existing database file is read. name (str, optional) – The database name will be set.
  Raises: | `KvdDbFileParse` – If the database file can’t be parsed.

  When parsing a database file fails, `get_last_parse_error` can be called:

      try:
          kvadblib.Dbc(filename="database.dbc")
      except kvadblib.KvdDbFileParse:
          print(kvadblib.get_last_parse_error())

  Changed in version 1.10: `Dbc` now raises specific errors depending on the situation.

  `attribute_definitions`()

    Return a generator over all database attribute definitions.

  `attributes`()

    Return a generator over all database attributes.

    New in version 1.6.

  `close`()

    Close an open database handle.

  `delete_attribute`(name)

    Delete attribute from database.

    New in version 1.6.

  `delete_attribute_definition`(name)

    Delete attribute definition from database.

    New in version 1.7.

  `delete_message`(message)

    Delete message from database.

    Parameters: | message (`Message`) – message to be deleted

  `delete_node`(node)

    Delete node from database.

    Parameters: | node (`Node`) – node to be deleted

  `flags`

    Get the database flags.

    E.g. DATABASE_FLAG_J1939

  `get_attribute_definition_by_name`(name)

    Find attribute definition using name.

    Parameters: | name (str) – name of attribute definition

    Returns an attribute definition object depending on type, e.g. if the type is AttributeType.INTEGER, an `IntegerAttributeDefinition` is returned.

  `get_attribute_value`(name)

    Return attribute value

    If the attribute is not set on the database, we return the attribute definition default value.

    New in version 1.6.

  `get_message`(id=None, name=None)

    Find message by id or name

    If both id and name is given, both most match.

    Parameters: | id (str) – message id to look for name (str) – message name to look for
    Returns: | `Message`
    Raises: | `KvdNoMessage` – If no match was found, or if none of `id` and `name` were given.

  `get_message_by_id`(id)

    Find message by id

    Parameters: | id (str) – message id to look for
    Returns: | `Message`
    Raises: | `KvdNoMessage` – If no match was found.

  `get_message_by_name`(name)

    Find message by name

    Parameters: | name (str) – message name to look for
    Returns: | `Message`
    Raises: | `KvdNoMessage` – If no match was found.

  `get_node_by_name`(name)

    Find node by name

    Parameters: | name (str) – node name to look for
    Returns: | `Node`
    Raises: | `KvdNoNode` – If no match was found.

  `interpret`(frame)

    Interprets a given Frame object, returning a BoundMessage

  `messages`(show_all=True)

    Return a generator of all database messages.

    If you would like to omit the special message ‘VECTOR__INDEPENDENT_SIG_MSG’, which is used to collect removed signals under, set show_all to False or use the Dbc iterator directly:

        db = kvadblib.Dbc(filename='mydb.dbc')
        for message in db:
            print(msg)

    Parameters: | show_all (`bool`) – If true, all messages, including any special message such as ‘VECTOR__INDEPENDENT_SIG_MSG’ will be returned

    Changed in version 1.8: Added argument show_all.

  `name`

    The current database name (read-only)

    Type: | `str`

  `new_attribute_definition`(name, owner, type, definition)

    Create a new attribute definition in the database.

    The owner specify where the attribute is applicable, e.g. `AttributeOwner.MESSAGE` specifies that this attribute is only applicable on messages (`Message`).

    Parameters: | name (str) – a unique name. owner (`AttributeOwner`) – the owner type
    Returns: | `AttributeDefinition`

  `new_message`(name, id, flags=0, dlc=None, comment=None)

    Create a new message in the database.

    Parameters: | name (str) – name of message id (int) – message id flags (int, optional) – message flags, e.g. `kvadblib.MessageFlag.EXT`
    Returns: | `canlib.kvadblib.message.Message`

  `new_node`(name, comment=None)

    Create a new node in the database.

    Parameters: | name (str) – name of message comment (str, optional) – message comment
    Returns: | `Node`

  `node_in_signal`(node, signal)

    Check if signal has been added to node.

    Returns: | True – signals contains node False: otherwise

  `nodes`()

    Return a generator containing all database nodes.

  `protocol`

    The database protocol

    Type: | `ProtocolType`

  `set_attribute_value`(name, value)

    Set value of attribute name on database.

    If no attribute called name is set on database, attach a database attribute from the database attribute definition first.

    New in version 1.6.

  `write_file`(filename)

    Write a database to file.

    Parameters: | filename (str) – file to write database to

## get_last_parse_error()

`canlib.kvadblib.``get_last_parse_error`()

  Can be used to get the specific reason why `KvdDbFileParse` was raised.

  Returns: | `str` – Error message from the parser.

  New in version 1.10.