File: table_operations.hc

package info (click to toggle)
craft 3.5-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,172 kB
  • ctags: 1,605
  • sloc: cpp: 3,794; makefile: 2,322; ansic: 857; sh: 842
file content (155 lines) | stat: -rw-r--r-- 3,469 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*======================================================================*/
/*= CHANGES AND UPDATES                                                =*/
/*======================================================================*/
/*= date   person file                subject                          =*/
/*=--------------------------------------------------------------------=*/
/*=                                                                    =*/
/*= 260493 hua    table_operations.hc created                          =*/
/*=                                                                    =*/
/*======================================================================*/

#include "collist.h"
#include "table.h"
#include "table_operations.h"
#include "bool.h"

void table_id (char t1 [], char t2 [])
  {table *ta;
   table *tb;
   bool  d;

   create_tb;
   gen_id;
   close_tables;

.  close_tables
     {delete (ta);
      delete (tb);
     }.
  
.  create_tb
     {ta = new table ("", t1, d);
      tb = new table ("", t2, d);
      tb->add_column ("id", col_type_int);
      for (int i = 0; i < ta->num_columns (); i++)
        tb->add_column (ta->column_name [i], ta->column_type [i]);
     }.

.  gen_id
     {for (int r = 0; r < ta->num_rows (); r++)
        add_row_to_tb;
     }.

.  add_row_to_tb
     {tb->append (0, r);
      for (int c = 0; c < ta->num_columns (); c++)
        write_column;
     }.

.  write_column
     tb->append (c+1, ta->read_int (r, c)).

  }

void table_join (char t1  [], char cols1 [],
                 char t2  [], char cols2 [],
                 char exp [],
                 char t3  [])

  {table   *ta;
   table   *tb;
   table   *tc;
   collist *colsa;
   collist *colsb;

   open_tables;
   open_collists;
   create_tc;
   exec_join;
   close_tables;

.  close_tables
     {delete (ta);
      delete (tb);
      delete (tc);
     }.

.  open_tables
     {bool d;

      ta = new table ("", t1, d);
      tb = new table ("", t2, d);
      tc = new table ("", t3, d);
     }.

.  open_collists
     {colsa = new collist (cols1);
      colsb = new collist (cols2);
     }.

.  create_tc
     {int c;

      for (c = 0; c < colsa->num (); c++)
        tc->add_column (ta->column_name [colsa->col (c)],
                        ta->column_type [colsa->col (c)]);
      for (c = 0; c < colsb->num (); c++)
        tc->add_column (tb->column_name [colsb->col (c)],
                        tb->column_type [colsb->col (c)]);
     }.

.  exec_join
     {for (int ra = 0; ra < ta->num_rows (); ra++)
        for (int rb = 0; rb < tb->num_rows (); rb ++)
          test_join;
     }.

.  test_join
     if (match)
        append_tc.

.  append_tc
     {int i = 0;
      int c;

      for (c = 0; c < colsa->num (); c++)
        tc->append (i++, ta->read_int (ra, colsa->col (c)));
      for (c = 0; c < colsb->num (); c++)
        tc->append (i++, tb->read_int (rb, colsb->col (c)));
     }.

.  match
     (true).

  }

void table_append (char t1 [], char t2 [])
  {table *ta;
   table *tb;

   open_tables;
   perform_append;
   close_tables;

.  close_tables
     {delete (ta);
      delete (tb);
     }.

.  open_tables
     {bool d;

      ta = new table ("", t1, d);
      tb = new table ("", t2, d);
     }.

.  perform_append
     {for (int r = 0; r < tb->num_rows (); r++)
       for (int c = 0; c < tb->num_columns (); c++)
         append_column;
     }.

.  append_column
     ta->append (c, tb->read_int (r, c)).

  }