Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

How to Write Files to Load Database

You can add mass data to the database more rapidly by writing the object input file used in the cubrid loaddb utility. An object input file is a text file in simple table form that consists of comments and command/data lines.

Comment

In CUBRID, a comment is represented by two hyphens (--).

-- This is a comment!

Command Line

A command line begins with a percent character (%) and consists of %class and %id commands; the former defines classes, and the latter defines aliases and identifiers used for class identification.

Assigning an identifier to a class

You can assign an identifier to class reference relationships by using the %id command.

Syntax

%id class_name class_id

class_name:

    identifier

class_id:

    integer

The class_name specified by the %id command is the class name defined in the database, and class_id is the numeric identifier which is assigned for object reference.

Example 1

%id employee 2

%id office 22

%id project 23

%id phone 24

Specifying the class and attribute

You can specify the classes (tables) and attributes (columns) upon loading data by using the %class command. The data line should be written based on the order of attributes specified.

Syntax

%class class_name ( attr_name [ { attr_name }_ ]

The schema must be pre-defined in the database to be loaded.

The class_name specified by the %class command is the class name defined in the database and the attr_name is the name of the attribute defined.

Example 2

The following is an example that specifies a class and three attributes by using the %class command to enter data into a class named employee. Three pieces of data should be entered on the data lines after the %class command. For this, see Example 3 in the "Configuring a reference relationship" section.

%class employee (name age department)

Data Line

A data line comes after the %class command line. Data loaded must have the same type as the class attributes specified by the %class command. The data loading operation stops if these two types are different.

Data for each attribute must be separated by at least one space and be basically written as a single line. However, if the data to be loaded takes more than one line, you should specify the plus sign (+) at the end of the first data line to enter data continuously on the following line. Note that no space is allowed between the last character of the data and the plus sign.

Loading an instance

As shown below, you can load an instance that has the same type as the specified class attribute. Each piece of data is separated by at least one space.

Example 1

%class employee (name)

'jordan'

'james'

'garnett'

'malone'

Assigning an instance number

You can assign a number to a given instance at the beginning of the data line. An instance number is a unique positive number in the specified class. Spaces are not allowed between the number and the colon (:). Assigning an instance number is used to configure the reference relationship for later.

Example 2

%class employee (name)

1: 'jordan'

2: 'james'

3: 'garnett'

4: 'malone'

Configuring a reference relationship

You can configure the object reference relationship by specifying the reference class after an "at sign (@)" and the instance number after the "vertical line (|)."

Syntax

@class_ref | instance_no

class_ref:

     class_name

     class_id

Specify a class name or a class id after the @ sign, and an instance number after a vertical line (|). Spaces are not allowed before and after a vertical line (|).

Example 3

The following is an example that loads class instances into the paycheck class. The name attribute references an instance of the employee class. As in the last line, data is loaded as NULL if you configure the reference relationship by using an instance number not specified earlier.

%class paycheck(name department salary)

@employee|1   'planning'   8000000

@employee|2   'planning'   6000000 

@employee|3   'sales'   5000000

@employee|4   'development'   4000000

@employee|5   'development'   5000000

Example 4

Since the id 21 was assigned to the employee class by using the %id command in the Assigning an identifier to a class section, Example 3 can be written as follows:

%class paycheck(name department salary)

@21|1   'planning'   8000000   

@21|2   'planning'   6000000 

@21|3   'sales'   5000000 

@21|4   'development'   4000000

@21|5   'development'   5000000