1/************* TabCol C++ Functions Source Code File (.CPP) ************/
2/* Name: TABCOL.CPP Version 2.7 */
3/* */
4/* (C) Copyright to the author Olivier BERTRAND 1998-2015 */
5/* */
6/* This file contains the PlugDB++ XTAB, COLUMN and XORDER methods. */
7/***********************************************************************/
8
9/***********************************************************************/
10/* Include relevant MariaDB header file. */
11/***********************************************************************/
12#include "my_global.h"
13
14/***********************************************************************/
15/* Include required application header files */
16/* global.h is header containing all global Plug declarations. */
17/* plgdbsem.h is header containing the DB applic. declarations. */
18/* tabcol.h is header containing XTAB, and XORDER declares. */
19/***********************************************************************/
20#include "global.h"
21#include "plgdbsem.h"
22#include "xtable.h"
23#include "tabcol.h"
24
25/***********************************************************************/
26/* XTAB public constructor. */
27/***********************************************************************/
28XTAB::XTAB(LPCSTR name, LPCSTR srcdef) : Name(name)
29 {
30 Next = NULL;
31 To_Tdb = NULL;
32 Srcdef = srcdef;
33 Schema = NULL;
34 Qualifier = NULL;
35
36 if (trace(1))
37 htrc("XTAB: making new TABLE %s %s\n", Name, Srcdef);
38
39 } // end of XTAB constructor
40
41/***********************************************************************/
42/* XTAB public constructor as a copy of another table. */
43/***********************************************************************/
44XTAB::XTAB(PTABLE tp) : Name(tp->Name)
45 {
46 Next = NULL;
47 To_Tdb = NULL;
48 Srcdef = tp->Srcdef;
49 Schema = tp->Schema;
50 Qualifier = tp->Qualifier;
51
52 if (trace(1))
53 htrc(" making copy TABLE %s %s\n", Name, SVP(Srcdef));
54
55 } // end of XTAB constructor
56
57/***********************************************************************/
58/* Link the tab2 tables to the tab1(this) table chain. */
59/***********************************************************************/
60PTABLE XTAB::Link(PTABLE tab2)
61 {
62 PTABLE tabp;
63
64 if (trace(1))
65 htrc("Linking tables %s... to %s\n", Name, tab2->Name);
66
67 for (tabp = this; tabp->Next; tabp = tabp->Next) ;
68
69 tabp->Next = tab2;
70 return (this);
71 } /* end of Link */
72
73/***********************************************************************/
74/* Make file output of XTAB contents. */
75/***********************************************************************/
76void XTAB::Printf(PGLOBAL g, FILE *f, uint n)
77 {
78 char m[64];
79
80 memset(m, ' ', n); /* Make margin string */
81 m[n] = '\0';
82
83 for (PTABLE tp = this; tp; tp = tp->Next) {
84 fprintf(f, "%sTABLE: %s.%s %s\n",
85 m, SVP(tp->Schema), tp->Name, SVP(tp->Srcdef));
86 PlugPutOut(g, f, TYPE_TDB, tp->To_Tdb, n + 2);
87 } /* endfor tp */
88
89 } /* end of Printf */
90
91/***********************************************************************/
92/* Make string output of XTAB contents. */
93/***********************************************************************/
94void XTAB::Prints(PGLOBAL, char *ps, uint z)
95 {
96 char buf[128];
97 int i, n = (int)z - 1;
98
99 *ps = '\0';
100
101 for (PTABLE tp = this; tp && n > 0; tp = tp->Next) {
102 i = sprintf(buf, "TABLE: %s.%s %s To_Tdb=%p ",
103 SVP(tp->Schema), tp->Name, SVP(tp->Srcdef), tp->To_Tdb);
104 strncat(ps, buf, n);
105 n -= i;
106 } // endif tp
107
108 } /* end of Prints */
109
110
111/***********************************************************************/
112/* COLUMN public constructor. */
113/***********************************************************************/
114COLUMN::COLUMN(LPCSTR name) : Name(name)
115 {
116 To_Table = NULL;
117 To_Col = NULL;
118 Qualifier = NULL;
119
120 if (trace(1))
121 htrc(" making new COLUMN %s\n", Name);
122
123 } // end of COLUMN constructor
124
125/***********************************************************************/
126/* COLUMN SetFormat: should never be called. */
127/***********************************************************************/
128bool COLUMN::SetFormat(PGLOBAL g, FORMAT&)
129 {
130 strcpy(g->Message, MSG(NO_FORMAT_COL));
131 return true;
132 } // end of SetFormat
133
134/***********************************************************************/
135/* Make file output of COLUMN contents. */
136/***********************************************************************/
137void COLUMN::Printf(PGLOBAL g, FILE *f, uint n)
138 {
139 char m[64];
140
141 memset(m, ' ', n); // Make margin string
142 m[n] = '\0';
143
144 if (Name)
145 fprintf(f, "%sCOLUMN: %s.%s\n", m,
146 ((!Qualifier) ? (PSZ)"?" : Qualifier), Name);
147 else // LNA
148 fprintf(f, "%sC%d\n", m, (!Qualifier) ? 0 : *(int *)Qualifier);
149
150 PlugPutOut(g, f, TYPE_TABLE, To_Table, n + 2);
151 PlugPutOut(g, f, TYPE_XOBJECT, To_Col, n + 2);
152 } /* end of Printf */
153
154/***********************************************************************/
155/* Make string output of COLUMN contents. */
156/***********************************************************************/
157void COLUMN::Prints(PGLOBAL, char *ps, uint z)
158 {
159 char buf[80];
160
161 if (Name)
162 sprintf(buf, "COLUMN: %s.%s table=%p col=%p",
163 ((!Qualifier) ? (PSZ)"?" : Qualifier), Name, To_Table, To_Col);
164 else // LNA
165 sprintf(buf, "C%d", (!Qualifier) ? 0 : *(int *)Qualifier);
166
167 strncpy(ps, buf, z);
168 ps[z - 1] = '\0';
169 } /* end of Prints */
170