create_table#

View page source

Create a Database Table#

Syntax#

dismod_at.create_table (
      connection , tbl_name , col_name , col_type , row_list
)

connection#

is a connection for this database.

tbl_name#

is a str that specifies the name of the table.

col_name#

is a list of str where the elements are the column names in the table that is created. The column name for the primary key, tbl_name _ id must not be included in the list.

unique#

If the column name tbl_name _ name is in the list, the corresponding column will have the unique constraint.

col_type#

is a list of str where the elements are the column types in the same order as col_name . The valid types are integer , real , text .

row_list#

is a possibly empty list of rows contain data that is written to the table. Each row is itself a list containing the data for one row of the table in the same order as col_name .

  1. The primary key column is not included in row_list .

  2. The value in each column gets converted to unicode before being written to the database.

  3. The special value None gets converted to null in the database.

  4. If a column has type real, its values cannot be nan.

tbl_name_id#

A column with name tbl_name _ id and type integer primary key is included as the first column in the table. Its values start with zero (for the first row) and increment by one for each row.

Side Effects#

This routine does a

connection . commit ()

to make sure the table exists before returning.

Example#

The file create_table.py is an example use of create_table .