node_table.py#

View page source

node_table: Example and Test#

def node_table() :
   import dismod_at
   #
   file_name      = 'example.db'
   connection     = dismod_at.create_connection(
      file_name, new = True, readonly = False
   )
   cursor         = connection.cursor()
   #
   # create the node table
   col_name = [ 'node_name',     'parent'    ]
   col_type = [ 'text',          'integer'   ]
   row_list = [
      [ 'world',         None        ],
      [ 'north_america', 0           ],
      [ 'united_states', 1           ],
      [ 'canada',        1           ]
   ]
   tbl_name = 'node'
   dismod_at.create_table(connection, tbl_name, col_name, col_type, row_list)
   # ----------------------------------------------------------------------
   # include primary key in test
   check_name = [ tbl_name + '_id' ] + col_name
   check_list = list()
   for i in range( len(row_list) ) :
      check_list.append( [i] + row_list[i] )
   #
   row_list = dismod_at.get_row_list(connection, tbl_name, check_name)
   assert row_list == check_list
   # ----------------------------------------------------------------------
   connection.close()
   print('node_table: OK')