1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 /***********************************************************************
19 *   $Id: ddlpkg.h 9210 2013-01-21 14:10:42Z rdempsey $
20 *
21 *
22 ***********************************************************************/
23 /** @file
24  *
25  * Class definitions for ddl parser objects.  These are the things
26  * manufactured by the bison SQL parser.  SqlStatementList is the
27  * toplevel parser result.
28  *
29  * Parser objects are described as structs.  These objects never
30  * change state following construction.  An accessor/mutator
31  * discipline would amount to clutter.
32  *
33  * The constructor forms here are directly driven by the structure of
34  * the grammar in ddl.y.
35  *
36  */
37 
38 #ifndef DDLPACKAGE_H
39 #define DDLPACKAGE_H
40 
41 #include <vector>
42 #include <string>
43 #include <map>
44 #include <set>
45 #include <utility>
46 #include <iostream>
47 #include "bytestream.h"
48 #include "logicalpartition.h"
49 
50 #if defined(_MSC_VER) && defined(xxxDDLPKG_DLLEXPORT)
51 #define EXPORT __declspec(dllexport)
52 #else
53 #define EXPORT
54 #endif
55 
56 namespace ddlpackage
57 {
58 typedef messageqcpp::ByteStream::byte byte;
59 typedef messageqcpp::ByteStream::doublebyte doublebyte;
60 typedef messageqcpp::ByteStream::quadbyte quadbyte;
61 
62 class AlterTable;
63 struct AlterTableAction;
64 struct ColumnDef;
65 struct ColumnDefaultValue;
66 struct ColumnType;
67 struct QualifiedName;
68 struct CreateTableStatement;
69 struct SqlStatementList;
70 struct SqlStatement;
71 struct ColumnConstraintDef;
72 struct TableConstraintDef;
73 struct SchemaObject;
74 struct ReferentialAction;
75 struct TableDef;
76 
77 typedef SqlStatement DDLPkg;
78 
79 typedef std::vector<ColumnConstraintDef*> ColumnConstraintList;
80 typedef std::vector<SchemaObject*> SchemaObjectList;
81 typedef std::vector<std::string> ColumnNameList;
82 typedef std::vector<AlterTableAction*> AlterTableActionList;
83 typedef std::vector<ColumnDef*> ColumnDefList;
84 typedef std::map<std::string, std::string> TableOptionMap;
85 typedef std::vector<SchemaObject*> TableElementList;
86 typedef std::vector<TableConstraintDef*> TableConstraintDefList;
87 
88 std::ostream& operator<<(std::ostream& os, const ColumnType& columnType);
89 std::ostream& operator<<(std::ostream& os, const QualifiedName& constraint);
90 std::ostream& operator<<(std::ostream& os, const TableConstraintDef& constraint);
91 std::ostream& operator<<(std::ostream& os, const ColumnConstraintDef& con);
92 std::ostream& operator<<(std::ostream& os, const ColumnDef& column);
93 EXPORT std::ostream& operator<<(std::ostream& os, const SqlStatementList& ct);
94 EXPORT std::ostream& operator<<(std::ostream& os, const SqlStatement& stmt);
95 std::ostream& operator<<(std::ostream& os, const ColumnDefList& columnList);
96 std::ostream& operator<<(std::ostream& os, const AlterTableAction& columnList);
97 std::ostream& operator<<(std::ostream& os, const ColumnDefaultValue& defaultValue);
98 std::ostream& operator<<(std::ostream& os, const ColumnNameList& columnNames);
99 std::ostream& operator<<(std::ostream& os, const ReferentialAction& ref);
100 std::ostream& operator<<(std::ostream& os, const TableDef& tableDef);
101 
102 
103 /** @brief Verb List
104 *   Make sure to keep the enum and string list in-sync
105 */
106 enum DDL_VERBS
107 {
108     DDL_CREATE,
109     DDL_ALTER,
110     DDL_DROP,
111     DDL_INVALID_VERB
112 };
113 /** @brief Subject List
114 *   Make sure to keep the enum and string list in-sync
115 */
116 enum DDL_SUBJECTS
117 {
118     DDL_TABLE,
119     DDL_INDEX,
120     DDL_INVALID_SUBJECT
121 };
122 
123 enum DDL_CONSTRAINT_ATTRIBUTES
124 {
125     DDL_DEFERRABLE,
126     DDL_NON_DEFERRABLE,
127     DDL_INITIALLY_IMMEDIATE,
128     DDL_INITIALLY_DEFERRED,
129     DDL_INVALID_ATTRIBUTE
130 };
131 
132 const std::string ConstraintAttrStrings[] =
133 {
134     "deferrable",
135     "non-deferrable",
136     "initially-immediate",
137     "initially-deferred",
138     "invalid"
139 };
140 
141 
142 enum DDL_REFERENTIAL_ACTION
143 {
144     DDL_CASCADE,
145     DDL_SET_NULL,
146     DDL_SET_DEFAULT,
147     DDL_NO_ACTION,
148     DDL_RESTRICT,
149     DDL_INVALID_REFERENTIAL_ACTION
150 };
151 
152 const std::string ReferentialActionStrings[] =
153 {
154     "cascade",
155     "set_null",
156     "set_default",
157     "no_action",
158     "invalid_action"
159 };
160 
161 enum DDL_MATCH_TYPE
162 {
163     DDL_FULL,
164     DDL_PARTIAL,
165     DDL_INVALID_MATCH_TYPE
166 };
167 
168 const std::string MatchTypeStrings[] =
169 {
170     "full",
171     "partial",
172     "invalid_match_type"
173 };
174 
175 
176 /** @brief Constraint List
177  *   Make sure to keep the enum and string list in-sync
178  */
179 enum DDL_CONSTRAINTS
180 {
181     DDL_PRIMARY_KEY,
182     DDL_FOREIGN_KEY,
183     DDL_CHECK,
184     DDL_UNIQUE,
185     DDL_REFERENCES,
186     DDL_NOT_NULL,
187     DDL_AUTO_INCREMENT,
188     DDL_INVALID_CONSTRAINT
189 };
190 /** @brief
191  */
192 const std::string ConstraintString[] =
193 {
194     "primary",
195     "foreign",
196     "check",
197     "unique",
198     "references",
199     "not_null",
200     "auto_increment"
201     ""
202 };
203 
204 /** @brief Datatype List
205  *   Make sure to keep the enum, string, and length list in-sync
206  */
207 enum DDL_DATATYPES
208 {
209     DDL_BIT,
210     DDL_TINYINT,
211     DDL_CHAR,
212     DDL_SMALLINT,
213     DDL_DECIMAL,
214     DDL_MEDINT,
215     DDL_INT,
216     DDL_FLOAT,
217     DDL_DATE,
218     DDL_BIGINT,
219     DDL_DOUBLE,
220     DDL_DATETIME,
221     DDL_VARCHAR,
222     DDL_VARBINARY,
223     DDL_CLOB,
224     DDL_BLOB,
225     DDL_REAL,
226     DDL_NUMERIC,
227     DDL_NUMBER,
228     DDL_INTEGER,
229     DDL_UNSIGNED_TINYINT,
230     DDL_UNSIGNED_SMALLINT,
231     DDL_UNSIGNED_MEDINT,
232     DDL_UNSIGNED_INT,
233     DDL_UNSIGNED_BIGINT,
234     DDL_UNSIGNED_DECIMAL,
235     DDL_UNSIGNED_FLOAT,
236     DDL_UNSIGNED_DOUBLE,
237     DDL_UNSIGNED_NUMERIC,
238     DDL_TEXT,
239     DDL_TIME,
240     DDL_TIMESTAMP,
241     DDL_INVALID_DATATYPE
242 };
243 
244 /** @brief Datatype string list
245  */
246 const std::string DDLDatatypeString[] =
247 {
248     "bit",
249     "tinyint",
250     "char",
251     "smallint",
252     "decimal",
253     "medint",
254     "integer",
255     "float",
256     "date",
257     "bigint",
258     "double",
259     "datetime",
260     "varchar",
261     "varbinary",
262     "clob",
263     "blob",
264     "real",
265     "numeric",
266     "number",
267     "integer",
268     "unsigned-tinyint",
269     "unsigned-smallint",
270     "unsigned-medint",
271     "unsigned-int",
272     "unsigned-bigint",
273     "unsigned-decimal",
274     "unsigned-float",
275     "unsigned-double",
276     "unsigned-numeric",
277     "text",
278     "time",
279     "timestamp"
280     ""
281 };
282 
283 /** @brief Alter table action string list
284  */
285 const std::string AlterActionString[] =
286 {
287     "AtaAddColumn",
288     "AtaAddColumns",
289     "AtaDropColumn",
290     "AtaDropColumns",
291     "AtaAddTableConstraint",
292     "AtaSetColumnDefault",
293     "AtaDropColumnDefault",
294     "AtaDropTableConstraint",
295     "AtaRenameTable",
296     "AtaModifyColumnType",
297     "AtaRenameColumn",
298     "AtaTableComment"
299 };
300 /** @brief Datatype Length list
301  *
302  */
303 const int  DDLDatatypeLength[] =
304 {
305     1,		// BIT
306     1,		// TINYINT
307     1,		// CHAR
308     2,		// SMALLINT
309     2,		// DECIMAL
310     4,		// MEDINT
311     4,		// INT
312     4,		// FLOAT
313     4,		// DATE
314     8,		// BIGINT
315     8,		// DOUBLE
316     8,		// DATETIME
317     8, 		// VARCHAR
318     8, 		// VARBINAR
319     8,		// CLOB
320     8,		// BLOB
321     4,		// REAL
322     2,		// NUMERIC
323     4,		// NUMBER
324     4,		// INTEGER
325     1,      // UNSIGNED_TINYINT,
326     2,      // UNSIGNED_SMALLINT,
327     4,      // UNSIGNED_MEDINT,
328     4,      // UNSIGNED_INT,
329     8,      // UNSIGNED_BIGINT,
330     2,      // UNSIGNED_DECIMAL,
331     4,      // UNSIGNED_FLOAT,
332     8,      // UNSIGNED_DOUBLE,
333     2,      // UNSIGNED_NUMERIC,
334     8,      // TEXT
335     8,      // TIME
336     8,      // TIMESTAMP
337     -1		// INVALID LENGTH
338 };
339 
340 enum DDL_SERIAL_TYPE
341 {
342     DDL_TABLE_DEF,
343     DDL_COLUMN_DEF,
344     DDL_COLUMN_CONSTRAINT_DEF,
345     DDL_TABLE_CONSTRAINT_DEF,
346     DDL_SQL_STATEMENT_LIST,
347     DDL_CREATE_TABLE_STATEMENT,
348     DDL_CREATE_INDEX,
349     DDL_ALTER_TABLE_STATEMENT,
350     DDL_ATA_ADD_COLUMN,
351     DDL_ATA_ADD_COLUMNS,
352     DDL_ATA_DROP_COLUMN,
353     DDL_ATA_ADD_TABLE_CONSTRAINT,
354     DDL_ATA_SET_COLUMN_DEFAULT,
355     DDL_ATA_DROP_COLUMN_DEFAULT,
356     DDL_ATA_DROP_TABLE_CONSTRAINT,
357     DDL_ATA_RENAME_TABLE,
358     DDL_ATA_RENAME_COLUMN,
359     DDL_ATA_MODIFY_COLUMN_TYPE,
360     DDL_ATA_TABLE_COMMENT,
361     DDL_COLUMN_TYPE,
362     DDL_COLUMN_DEFAULT_VALUE,
363     DDL_TABLE_UNIQUE_CONSTRAINT_DEF,
364     DDL_TABLE_PRIMARY_CONSTRAINT_DEF,
365     DDL_REF_ACTION,
366     DDL_TABLE_REFERENCES_CONSTRAINT_DEF,
367     DDL_TABLE_CHECK_CONSTRAINT_DEF,
368     DDL_QUALIFIED_NAME,
369     DDL_CONSTRAINT_ATTRIBUTES_DEF,
370     DDL_DROP_INDEX_STATEMENT,
371     DDL_DROP_TABLE_STATEMENT,
372     DDL_ATA_DROP_COLUMNS,
373     DDL_NULL,
374     DDL_INVALID_SERIAL_TYPE,
375     DDL_TRUNC_TABLE_STATEMENT,
376     DDL_MARK_PARTITION_STATEMENT,
377     DDL_RESTORE_PARTITION_STATEMENT,
378     DDL_DROP_PARTITION_STATEMENT
379 };
380 
381 
382 /** @brief An abstract base for TableDef, ColumnDef, ...
383  *
384  * The primary purpose of this class is to provide a unified type
385  * for things that can appear together in syntactic elements.  For
386  * example, column definitions and table constraints can appear
387  * together in the table_element_list of a create table statement.
388  * We need a base class so that we can return different concrete
389  * types as the semantic value of bison rules, while having a
390  * single, more abstract type to report to bison as the type of
391  * the semantic value.
392  */
393 struct SchemaObject
394 {
~SchemaObjectSchemaObject395     virtual ~SchemaObject()
396     {}
397 
SchemaObjectSchemaObject398     SchemaObject(std::string name):
399         fName(name)
400     {}
401 
SchemaObjectSchemaObject402     SchemaObject() :
403         fName("unnamed")
404     {}
405 
406     std::string fName;
407 
408 };
409 
410 
411 
412 
413 /** @brief SqlStatement represents a toplevel
414  * syntactic element such as a create table or alter table SQL
415  * statement.
416  *
417  * SqlStatements are containers for the various structures
418  * manufactured by the parsing process for a single SQL
419  * statement.
420  */
421 struct SqlStatement
422 {
423     /** @brief Deserialize from ByteStream */
424     virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
425 
426     /** @brief Serialize to ByteStream */
427     virtual int serialize(messageqcpp::ByteStream& bs) = 0;
428 
429 
430     /** @brief Dump to stdout. */
431     virtual std::ostream& put(std::ostream& os) const = 0;
432 
433     EXPORT SqlStatement();
434 
435     EXPORT virtual ~SqlStatement();
436 
437     /** @brief The session ID assigned to this stmt by the front end (in theory)
438      *
439      * XXXPAT: need to fix this.  It should be type execplan::SessionManager::SID, but
440      * that causes a circular dependency in the header files.  Should unravel that at
441      * some point.
442      	 *
443      * Right now this var is initialized from a counter.  At some point we need
444      * to serialize/unserialize it from a byte stream.
445      */
446     uint32_t fSessionID;
447 
448     /** @brief The original sql string
449     */
450     std::string fSql;
451 
452     /** @brief the default schema (owner that will be used when not specified)
453     */
454     std::string fOwner;
455 
456 
457     uint32_t fTableWithAutoi; // has autoincrement column?
458 
459 };
460 
461 
462 
463 /** @brief Collects SqlStatements so that we can support the
464  * parsing of sqltext containing multiple statements.
465  *
466  * The SqlParser also accepts empty statements (a mixture of
467  * whitespace and semicolons) in which case the result can be a
468  * SqlStatementList of zero items.
469  */
470 struct SqlStatementList
471 {
SqlStatementListSqlStatementList472     SqlStatementList()
473     {}
474 
475     SqlStatement* operator[](int i) const
476     {
477         return fList[i];
478     }
479 
480 
481     virtual ~SqlStatementList();
482 
483     /** @brief Add a statement to the underlying container. */
484     void push_back(SqlStatement* v);
485 
486     std::vector<SqlStatement*> fList;
487     std::string fSqlText;
488 
489 private:
490     SqlStatementList(const SqlStatementList& x);
491 
492 };
493 
494 
495 
496 /** @brief Stores catalog, schema, object names.
497  *
498  * ddl.y does not yet support catalog.  So, expect catalog
499  * qualified names to fail parsing for the moment.
500  */
501 struct QualifiedName
502 {
503     /** @brief Deserialize from ByteStream */
504     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
505 
506     /** @brief Serialize to ByteStream */
507     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
508 
509 
QualifiedNameQualifiedName510     QualifiedName()
511     {}
512 
513     EXPORT QualifiedName(const char* name);
514     EXPORT QualifiedName(const char* name, const char* schema);
515     EXPORT QualifiedName(const char* name, const char* schema, const char* catalog);
516 
~QualifiedNameQualifiedName517     virtual ~QualifiedName()
518     {}
519 
520     std::string fCatalog;
521     std::string fName;
522     std::string fSchema;
523 };
524 
525 
526 
527 /** TableDef represents a table definition.
528  */
529 struct TableDef : public SchemaObject
530 {
531     /** @brief Deserialize from ByteStream */
532     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
533 
534     /** @brief Serialize to ByteStream */
535     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
536 
537 
TableDefTableDef538     TableDef() : fQualifiedName(0)
539     {}
540 
541     EXPORT TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options);
542 
543     /** @brief TableDef ctor.
544     * ctor
545     */
TableDefTableDef546     TableDef( QualifiedName* name,
547               ColumnDefList columns,
548               TableConstraintDefList constraints, int tableWithAutoinc) :
549         fQualifiedName (name),
550         fColumns (columns),
551         fConstraints (constraints)
552 
553 
554     {}
555 
556     EXPORT virtual ~TableDef();
557 
558     QualifiedName* fQualifiedName;
559 
560     ColumnDefList fColumns;
561     TableConstraintDefList fConstraints;
562 
563     TableOptionMap fOptions;
564 };
565 
566 
567 
568 /** @brief Represents the create table statement
569  *
570  * @note It takes possession of the TableDef given to it.
571  */
572 struct CreateTableStatement : public SqlStatement
573 {
574     /** @brief Deserialize from ByteStream */
575     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
576 
577     /** @brief Serialize to ByteStream */
578     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
579 
580     /** @brief Ctor for deserialization */
581     EXPORT CreateTableStatement();
582 
583     /** @brief You can't have a CreateTableStatement without a
584     	table defintion */
585     EXPORT CreateTableStatement(TableDef* tableDef);
586 
587     EXPORT virtual ~CreateTableStatement();
588 
589     /** @brief Dump to stdout. */
590     EXPORT virtual std::ostream& put(std::ostream& os) const;
591 
schemaNameCreateTableStatement592     std::string schemaName() const
593     {
594         if (!fTableDef || !fTableDef->fQualifiedName) return "UNKNOWN";
595 
596         return fTableDef->fQualifiedName->fSchema;
597     }
598 
599     TableDef* fTableDef; ///< The table defintion.
600 
601 };
602 
603 
604 /**
605  * @brief The subforms of alter table are represented as
606  * subclasses of AlterTableAction
607  *
608  * SQL-92 specifies that an alter_table_statement has exactly one
609  * alter_table_action.  But many vendors support aggregating
610  * alter_table_actions under one alter_table_statement.  We
611  * support that.  The subforms of alter table are represented as
612  * subclasses of AlterTableAction, all of which are named
613  * according to the convention AtaFoo, where Ata stands for
614  * AlterTableAction.
615  */
616 struct AlterTableAction
617 {
618     /** @brief Deserialize from ByteStream */
619     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
620 
621     /** @brief Serialize to ByteStream */
622     EXPORT virtual int serialize(messageqcpp::ByteStream& bs) = 0;
623 
624     /** @brief Ctor for deserialization */
AlterTableActionAlterTableAction625     AlterTableAction()
626     {}
627 
~AlterTableActionAlterTableAction628     virtual ~AlterTableAction()
629     {}
630 
631     /** @brief QualifiedName of the focal table for this
632     	statement. */
633     //		QualifiedName *fTableName;
634 
635     /** @brief Dump to stdout. */
636     EXPORT virtual std::ostream& put(std::ostream& os) const;
637 };
638 
639 
640 
641 
642 /** @brief Represents alter table add column forms.
643  */
644 struct AtaAddColumn : public AlterTableAction
645 {
646     /** @brief Deserialize from ByteStream */
647     virtual int unserialize(messageqcpp::ByteStream& bs);
648 
649     /** @brief Serialize to ByteStream */
650     virtual int serialize(messageqcpp::ByteStream& bs);
651 
652     /** @brief Ctor for deserialization */
AtaAddColumnAtaAddColumn653     AtaAddColumn() : fColumnDef(0) {}
654 
655     /** @brief You can't add a column without specifying a column
656     	definition. */
657     AtaAddColumn(ColumnDef* columnDef);
658 
659     virtual ~AtaAddColumn();
660 
661     /** @brief Dump to stdout. */
662     virtual std::ostream& put(std::ostream& os) const;
663 
664     /** @brief The focal column definition. */
665     ColumnDef* fColumnDef;
666 };
667 
668 
669 /** @brief Represents the table_element_list style of add column
670 	which is not part of SQL-92.
671  */
672 struct AtaAddColumns : public AlterTableAction
673 {
674     /** @brief Deserialize from ByteStream */
675     virtual int unserialize(messageqcpp::ByteStream& bs);
676 
677     /** @brief Serialize to ByteStream */
678     virtual int serialize(messageqcpp::ByteStream& bs);
679 
680     /** @brief Ctor for deserialization */
AtaAddColumnsAtaAddColumns681     AtaAddColumns()
682     {}
683 
684     AtaAddColumns(TableElementList* tableElements);
685 
686     virtual ~AtaAddColumns();
687 
688     /** @brief Dump to stdout. */
689     virtual std::ostream& put(std::ostream& os) const;
690 
691     ColumnDefList fColumns;
692 };
693 
694 
695 /** @brief Represents the table_element_list style of drop column
696 	which is not part of SQL-92.
697  */
698 struct AtaDropColumns : public AlterTableAction
699 {
700     /** @brief Deserialize from ByteStream */
701     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
702 
703     /** @brief Serialize to ByteStream */
704     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
705 
706     /** @brief Ctor for deserialization */
AtaDropColumnsAtaDropColumns707     AtaDropColumns()
708     {}
709 
710     EXPORT AtaDropColumns(ColumnNameList* tableElements);
711 
712     EXPORT virtual ~AtaDropColumns();
713 
714     /** @brief Dump to stdout. */
715     EXPORT virtual std::ostream& put(std::ostream& os) const;
716 
717     ColumnNameList fColumns;
718 };
719 
720 
721 
722 /** AtaAddTableConstraint
723  */
724 struct AtaAddTableConstraint : public AlterTableAction
725 {
726     /** @brief Deserialize from ByteStream */
727     virtual int unserialize(messageqcpp::ByteStream& bs);
728 
729     /** @brief Serialize to ByteStream */
730     virtual int serialize(messageqcpp::ByteStream& bs);
731 
732     /** @brief Ctor for deserialization */
AtaAddTableConstraintAtaAddTableConstraint733     AtaAddTableConstraint() : fTableConstraint(0)
734     {}
735 
736     AtaAddTableConstraint(TableConstraintDef* tableConstraint);
737 
738     virtual ~AtaAddTableConstraint();
739 
740     /** @brief Dump to stdout. */
741     virtual std::ostream& put(std::ostream& os) const;
742 
743     TableConstraintDef* fTableConstraint;
744 };
745 
746 
747 
748 /** @brief alter table drop column.
749  */
750 struct AtaDropColumn : public AlterTableAction
751 {
752     /** @brief Deserialize from ByteStream */
753     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
754 
755     /** @brief Serialize to ByteStream */
756     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
757 
758     /** @brief Ctor for deserialization */
AtaDropColumnAtaDropColumn759     AtaDropColumn()
760     {}
761 
762     /** @brief Ctor for parser construction */
763     EXPORT AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior);
764 
765     /** @brief Dump to stdout. */
766     EXPORT virtual std::ostream& put(std::ostream& os) const;
767 
~AtaDropColumnAtaDropColumn768     virtual ~AtaDropColumn()
769     {}
770     std::string fColumnName;
771     DDL_REFERENTIAL_ACTION fDropBehavior;
772 };
773 
774 
775 
776 /** @brief alter table set column default */
777 
778 struct AtaSetColumnDefault : AlterTableAction
779 {
780     /** @brief Deserialize from ByteStream */
781     virtual int unserialize(messageqcpp::ByteStream& bs);
782 
783     /** @brief Serialize to ByteStream */
784     virtual int serialize(messageqcpp::ByteStream& bs);
785 
AtaSetColumnDefaultAtaSetColumnDefault786     AtaSetColumnDefault() : fDefaultValue(0) {}
787 
788     /** @brief Dump to stdout. */
789     virtual std::ostream& put(std::ostream& os) const;
790 
791     virtual ~AtaSetColumnDefault();
792 
793     AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue);
794 
795     std::string fColumnName;
796     ColumnDefaultValue* fDefaultValue;
797 
798 };
799 
800 
801 
802 /** @brief alter table drop column default. */
803 struct AtaDropColumnDefault : AlterTableAction
804 {
805     /** @brief Deserialize from ByteStream */
806     virtual int unserialize(messageqcpp::ByteStream& bs);
807 
808     /** @brief Serialize to ByteStream */
809     virtual int serialize(messageqcpp::ByteStream& bs);
810 
811     /** @brief Ctor for deserialization */
AtaDropColumnDefaultAtaDropColumnDefault812     AtaDropColumnDefault()
813     {}
814 
815     /** @brief Dump to stdout. */
816     virtual std::ostream& put(std::ostream& os) const;
817 
~AtaDropColumnDefaultAtaDropColumnDefault818     virtual ~AtaDropColumnDefault()
819     {}
820 
821     /** @brief Ctor for parser construction */
822     AtaDropColumnDefault(const char* colName);
823 
824     std::string fColumnName;
825 };
826 
827 
828 /** @brief alter table drop table constraint. */
829 struct AtaDropTableConstraint : AlterTableAction
830 {
831     /** @brief Deserialize from ByteStream */
832     virtual int unserialize(messageqcpp::ByteStream& bs);
833 
834     /** @brief Serialize to ByteStream */
835     virtual int serialize(messageqcpp::ByteStream& bs);
836 
837 
838     /** @brief Ctor for deserialization */
AtaDropTableConstraintAtaDropTableConstraint839     AtaDropTableConstraint()
840     {}
841 
842     /** @brief Dump to stdout. */
843     virtual std::ostream& put(std::ostream& os) const;
844 
~AtaDropTableConstraintAtaDropTableConstraint845     virtual ~AtaDropTableConstraint()
846     {}
847 
848     AtaDropTableConstraint(const char* constraintName, DDL_REFERENTIAL_ACTION dropBehavior);
849 
850     std::string fConstraintName;
851     DDL_REFERENTIAL_ACTION fDropBehavior;
852 };
853 
854 
855 
856 /** alter table rename */
857 struct AtaRenameTable : public AlterTableAction
858 {
859     /** @brief Deserialize from ByteStream */
860     virtual int unserialize(messageqcpp::ByteStream& bs);
861 
862     /** @brief Serialize to ByteStream */
863     virtual int serialize(messageqcpp::ByteStream& bs);
864 
865     /** @brief Ctor for deserialization */
AtaRenameTableAtaRenameTable866     AtaRenameTable() : fQualifiedName(0) {}
867     AtaRenameTable(QualifiedName* qualifiedName);
868 
869     /** @brief Dump to stdout. */
870     std::ostream& put(std::ostream& os) const;
871 
872     virtual ~AtaRenameTable();
873 
874     QualifiedName* fQualifiedName;
875 };
876 
877 /** alter table comment */
878 struct AtaTableComment : public AlterTableAction
879 {
880     /** @brief Deserialize from ByteStream */
881     virtual int unserialize(messageqcpp::ByteStream& bs);
882 
883     /** @brief Serialize to ByteStream */
884     virtual int serialize(messageqcpp::ByteStream& bs);
885 
886     /** @brief Ctor for deserialization */
AtaTableCommentAtaTableComment887     AtaTableComment() : fTableComment("")
888     {}
889     AtaTableComment(const char* tableComment);
890 
891     /** @brief Dump to stdout. */
892     std::ostream& put(std::ostream& os) const;
893 
894     virtual ~AtaTableComment();
895 
896     std::string fTableComment;
897 };
898 
899 
900 
901 /** @brief alter table modify column */
902 struct AtaModifyColumnType : public AlterTableAction
903 {
904     /** @brief Deserialize from ByteStream */
905     virtual int unserialize(messageqcpp::ByteStream& bs);
906 
907     /** @brief Serialize to ByteStream */
908     virtual int serialize(messageqcpp::ByteStream& bs);
909 
910     /** @brief Ctor for deserialization */
AtaModifyColumnTypeAtaModifyColumnType911     AtaModifyColumnType() : fColumnType(0) {}
912 
913     /** @brief Ctor for parser construction */
AtaModifyColumnTypeAtaModifyColumnType914     AtaModifyColumnType(const char* name, ColumnType* columnType) :
915         fColumnType(columnType),
916         fName(name)
917     {}
918 
919     AtaModifyColumnType(QualifiedName* qualifiedName);
920 
921     /** @brief Dump to stdout. */
922     std::ostream& put(std::ostream& os) const;
923 
924     virtual ~AtaModifyColumnType();
925 
926     ColumnType* fColumnType;
927 
928     std::string fName;
929 };
930 
931 
932 
933 /** @brief alter table rename column */
934 struct AtaRenameColumn : public AlterTableAction
935 {
936     /** @brief Deserialize from ByteStream */
937     virtual int unserialize(messageqcpp::ByteStream& bs);
938 
939     /** @brief Serialize to ByteStream */
940     virtual int serialize(messageqcpp::ByteStream& bs);
941 
942     /** @brief Ctor for deserialization */
AtaRenameColumnAtaRenameColumn943     AtaRenameColumn() : fNewType(0), fDefaultValue(0) { }
944 
945     AtaRenameColumn(const char* name, const char* newName, ColumnType* newType,  const char* comment = NULL) :
fNameAtaRenameColumn946         fName(name),
947         fNewName(newName),
948         fNewType(newType)
949     {
950         if (comment)
951             fComment = comment;
952 
953         fDefaultValue = 0;
954     }
955 
956     AtaRenameColumn(const char* name, const char* newName, ColumnType* newType, ColumnConstraintList* constraint_list,
957                     ColumnDefaultValue* defaultValue, const char* comment = NULL) :
fNameAtaRenameColumn958         fName(name),
959         fNewName(newName),
960         fNewType(newType),
961         fDefaultValue(defaultValue)
962     {
963         if (constraint_list)
964             fConstraints = *constraint_list;
965 
966         //if (defaultValue)
967         //{
968         //fDefaultValue = defaultValue;
969         //}
970 
971         if (comment)
972             fComment = comment;
973     }
974 
975     AtaRenameColumn(QualifiedName* qualifiedName);
976 
977     /** @brief Dump to stdout. */
978     std::ostream& put(std::ostream& os) const;
979 
980     virtual ~AtaRenameColumn();
981 
982     std::string fName; ///< current column name
983     std::string fNewName; ///< new column name
984     ColumnType* fNewType;
985     /** @brief Zero or more constraints. */
986     ColumnConstraintList fConstraints;
987 
988     /** @brief NULL if there was no DEFAULT clause */
989     ColumnDefaultValue* fDefaultValue;
990     std::string fComment;
991 };
992 
993 
994 
995 
996 /** @brief Stores the type information for a column. */
997 
998 struct ColumnType
999 {
1000     /** @brief Deserialize from ByteStream */
1001     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1002 
1003     /** @brief Serialize to ByteStream */
1004     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1005 
1006     /** @brief For deserialization. */
ColumnTypeColumnType1007     ColumnType() : fCharset(NULL), fExplicitLength(false)
1008     {}
1009 
1010     friend std::ostream& operator<<(std::ostream& os, const ColumnType& ac);
1011 
1012     /** @brief This constructor is used by the parser to construct the
1013     	ColumnType when a precision/scale clause is encountered. */
1014 
1015     EXPORT ColumnType(int prec, int scale);
1016 
1017     /** @brief Used in cases where we don't need to create an
1018     	object until we have seen all it's parts. */
1019 
1020     EXPORT ColumnType(int type);
1021 
~ColumnTypeColumnType1022     virtual ~ColumnType()
1023     {}
1024 
1025     /** @brief Type code from DDL_DATATYPES */
1026     int fType;
1027 
1028     /** @brief Length of datatype in bytes */
1029     long fLength;
1030 
1031     /** @brief SQL precision. This is the number of digits in the representation. */
1032     int fPrecision;
1033 
1034     /** @brief SQL scale.  This is is the number of digits to the
1035     	right of the decimal point. */
1036     int fScale;
1037 
1038     /** @brief SQL "with timezone" specifier */
1039     bool fWithTimezone;
1040 
1041     int fCompressiontype;
1042 
1043     std::string fAutoincrement;
1044 
1045     uint64_t fNextvalue;
1046 
1047     /** @brief Column charset (CHAR, VARCHAR and TEXT only) */
1048     const char* fCharset;
1049 
1050     /** @brief Is the TEXT column has explicit defined length, ie TEXT(1717) */
1051     bool fExplicitLength;
1052 
1053 };
1054 
1055 
1056 
1057 /** @brief A column constraint definition.
1058  *
1059  * Since we aren't supporting references constraint specifications
1060  * for columns, it seemed simpler to use a single column
1061  * constraint class instead of articulating the varieties among
1062  * several classes like we do with table constraints.
1063  */
1064 struct ColumnConstraintDef : public SchemaObject
1065 {
1066     /** @brief Deserialize from ByteStream */
1067     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1068 
1069     /** @brief Serialize to ByteStream */
1070     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1071 
1072 
ColumnConstraintDefColumnConstraintDef1073     ColumnConstraintDef()
1074     {}
1075 
1076     /** @brief Constructs as check constraint. */
1077     EXPORT ColumnConstraintDef(const char* check);
1078 
1079 
1080     /** @brief Constructs as other constraint. */
1081     EXPORT ColumnConstraintDef(DDL_CONSTRAINTS type);
1082 
~ColumnConstraintDefColumnConstraintDef1083     virtual ~ColumnConstraintDef()
1084     {}
1085 
1086     /** @brief Whether deferrable. */
1087     bool fDeferrable;
1088 
1089     /** @brief Immediate or defferred */
1090     DDL_CONSTRAINT_ATTRIBUTES fCheckTime;
1091 
1092     /** @brief Distinguish kinds of constraints */
1093     DDL_CONSTRAINTS fConstraintType;
1094 
1095     /** @brief Stores foo from check(foo) */
1096     std::string fCheck;
1097 };
1098 
1099 
1100 
1101 
1102 /** @brief Represents a columns default value. */
1103 struct ColumnDefaultValue
1104 {
1105     /** @brief Deserialize from ByteStream */
1106     virtual int unserialize(messageqcpp::ByteStream& bs);
1107 
1108     /** @brief Serialize to ByteStream */
1109     virtual int serialize(messageqcpp::ByteStream& bs);
1110 
1111 
ColumnDefaultValueColumnDefaultValue1112     ColumnDefaultValue()
1113     {}
1114 
1115     ColumnDefaultValue(const char* value);
1116 
~ColumnDefaultValueColumnDefaultValue1117     virtual ~ColumnDefaultValue()
1118     {}
1119 
1120 
1121     /** @brief Is NULL the default value? */
1122     bool fNull;
1123 
1124     /** @brief Specified default value as a string. */
1125     std::string fValue;
1126 };
1127 
1128 
1129 
1130 /** @brief Represents a column definition. */
1131 
1132 struct ColumnDef : public SchemaObject
1133 {
1134     /** @brief Deserialize from ByteStream */
1135     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1136 
1137     /** @brief Serialize to ByteStream */
1138     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1139 
1140 
1141     /** @brief For deserialization. */
ColumnDefColumnDef1142     ColumnDef() : fType(0) {}
1143 
1144     EXPORT virtual ~ColumnDef();
1145 
1146     /** @brief Parser ctor. */
1147     EXPORT ColumnDef(const char* name,
1148                      ColumnType* type,
1149                      ColumnConstraintList* constraint_list,
1150                      ColumnDefaultValue* defaultValue, const char* comment = NULL);
1151 
1152     /** @brief ColumnDef ctor.
1153      * ctor */
1154     ColumnDef(const char* name,
1155               ColumnType* type,
1156               ColumnConstraintList constraints,
1157               ColumnDefaultValue* defaultValue = NULL, const char* comment = NULL) :
SchemaObjectColumnDef1158         SchemaObject(name),
1159         fType (type),
1160         fConstraints (constraints),
1161         fDefaultValue (defaultValue)
1162     {}
1163 
1164     void convertDecimal();
1165 
1166     /** @brief Never NULL since all Columns must have a type. */
1167     ColumnType* fType;
1168 
1169     /** @brief Zero or more constraints. */
1170     ColumnConstraintList fConstraints;
1171 
1172     /** @brief NULL if there was no DEFAULT clause */
1173     ColumnDefaultValue* fDefaultValue;
1174 
1175     std::string fComment;
1176 };
1177 
1178 
1179 
1180 /** @brief Abstract base for table constraint definitions. */
1181 
1182 struct TableConstraintDef : public SchemaObject
1183 {
1184     /** @brief Return DDL_SERIAL code */
1185     virtual DDL_SERIAL_TYPE getSerialType() = 0;
1186 
1187     /** @brief Deserialize from ByteStream */
1188     virtual int unserialize(messageqcpp::ByteStream& bs) = 0;
1189 
1190     /** @brief Serialize to ByteStream */
1191     virtual int serialize(messageqcpp::ByteStream& bs) = 0;
1192 
1193 
1194     TableConstraintDef();
1195 
1196     TableConstraintDef(DDL_CONSTRAINTS cType);
1197 
1198     /** @brief Dump to stdout. */
1199     virtual std::ostream& put(std::ostream& os) const;
1200 
~TableConstraintDefTableConstraintDef1201     virtual ~TableConstraintDef()
1202     {}
1203     //		std::string fName;
1204     DDL_CONSTRAINTS fConstraintType;
1205 };
1206 
1207 
1208 
1209 
1210 /** @brief Unique table constraint. */
1211 
1212 struct TableUniqueConstraintDef : public TableConstraintDef
1213 {
1214     /** @brief Return DDL_SERIAL code */
getSerialTypeTableUniqueConstraintDef1215     virtual DDL_SERIAL_TYPE getSerialType()
1216     {
1217         return DDL_TABLE_UNIQUE_CONSTRAINT_DEF;
1218     }
1219 
1220 
1221     /** @brief Deserialize from ByteStream */
1222     virtual int unserialize(messageqcpp::ByteStream& bs);
1223 
1224     /** @brief Serialize to ByteStream */
1225     virtual int serialize(messageqcpp::ByteStream& bs);
1226 
1227 
TableUniqueConstraintDefTableUniqueConstraintDef1228     TableUniqueConstraintDef() : TableConstraintDef(DDL_UNIQUE)
1229     {}
1230 
1231     TableUniqueConstraintDef(ColumnNameList* columns);
~TableUniqueConstraintDefTableUniqueConstraintDef1232     virtual ~TableUniqueConstraintDef()
1233     {}
1234 
1235     /** @brief Dump to stdout. */
1236     virtual std::ostream& put(std::ostream& os) const;
1237 
1238     ColumnNameList fColumnNameList;
1239 };
1240 
1241 
1242 
1243 /** @brief Primary key table constraint.
1244  */
1245 struct TablePrimaryKeyConstraintDef : public TableConstraintDef
1246 {
1247     /** @brief Return DDL_SERIAL code */
getSerialTypeTablePrimaryKeyConstraintDef1248     virtual DDL_SERIAL_TYPE getSerialType()
1249     {
1250         return DDL_TABLE_PRIMARY_CONSTRAINT_DEF;
1251     }
1252 
1253     /** @brief Deserialize from ByteStream */
1254     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1255 
1256     /** @brief Serialize to ByteStream */
1257     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1258 
1259 
TablePrimaryKeyConstraintDefTablePrimaryKeyConstraintDef1260     TablePrimaryKeyConstraintDef() : TableConstraintDef(DDL_PRIMARY_KEY)
1261     {}
1262 
1263     EXPORT TablePrimaryKeyConstraintDef(ColumnNameList* columns);
1264 
~TablePrimaryKeyConstraintDefTablePrimaryKeyConstraintDef1265     virtual ~TablePrimaryKeyConstraintDef()
1266     {}
1267 
1268     /** @brief Dump to stdout. */
1269     EXPORT virtual std::ostream& put(std::ostream& os) const;
1270 
1271     ColumnNameList fColumnNameList;
1272 };
1273 
1274 
1275 
1276 /** @brief ReferentialAction specifies what to do about table
1277 	relationships when elements are updated and deleted.
1278  */
1279 struct ReferentialAction
1280 {
~ReferentialActionReferentialAction1281     virtual ~ReferentialAction()
1282     {}
1283 
1284     /** @brief Deserialize from ByteStream */
1285     virtual int unserialize(messageqcpp::ByteStream& bs);
1286 
1287     /** @brief Serialize to ByteStream */
1288     virtual int serialize(messageqcpp::ByteStream& bs);
1289 
1290 
1291     DDL_REFERENTIAL_ACTION fOnUpdate;
1292     DDL_REFERENTIAL_ACTION fOnDelete;
1293 };
1294 
1295 
1296 
1297 /** @brief TableReferencesConstraintDef represents a foreign key constraint.
1298  */
1299 struct TableReferencesConstraintDef : public TableConstraintDef
1300 {
1301     /** @brief Return DDL_SERIAL code */
getSerialTypeTableReferencesConstraintDef1302     virtual DDL_SERIAL_TYPE getSerialType()
1303     {
1304         return DDL_TABLE_REFERENCES_CONSTRAINT_DEF;
1305     }
1306 
1307     /** @brief Deserialize from ByteStream */
1308     virtual int unserialize(messageqcpp::ByteStream& bs);
1309 
1310     /** @brief Serialize to ByteStream */
1311     virtual int serialize(messageqcpp::ByteStream& bs);
1312 
1313 
TableReferencesConstraintDefTableReferencesConstraintDef1314     TableReferencesConstraintDef() :
1315         TableConstraintDef(DDL_REFERENCES),
1316         fTableName(0),
1317         fRefAction(0)
1318     {}
1319 
1320     TableReferencesConstraintDef
1321     (ColumnNameList* columns,
1322      QualifiedName* fTableName,
1323      ColumnNameList* foreignColumns,
1324      DDL_MATCH_TYPE matchType,
1325      ReferentialAction* refAction);
1326 
1327     virtual ~TableReferencesConstraintDef();
1328 
1329     /** @brief Dump to stdout. */
1330     virtual std::ostream& put(std::ostream& os) const;
1331 
1332     ColumnNameList fColumns;
1333     QualifiedName* fTableName;
1334     ColumnNameList fForeignColumns;
1335     DDL_MATCH_TYPE fMatchType;
1336     ReferentialAction* fRefAction;
1337 };
1338 
1339 
1340 
1341 /** @brief Table check constraint.
1342  */
1343 struct TableCheckConstraintDef : public TableConstraintDef
1344 {
1345     /** @brief Return DDL_SERIAL code */
getSerialTypeTableCheckConstraintDef1346     virtual DDL_SERIAL_TYPE getSerialType()
1347     {
1348         return DDL_TABLE_CHECK_CONSTRAINT_DEF;
1349     }
1350 
1351     /** @brief Deserialize from ByteStream */
1352     virtual int unserialize(messageqcpp::ByteStream& bs);
1353 
1354     /** @brief Serialize to ByteStream */
1355     virtual int serialize(messageqcpp::ByteStream& bs);
1356 
1357 
TableCheckConstraintDefTableCheckConstraintDef1358     TableCheckConstraintDef() : TableConstraintDef(DDL_CHECK)
1359     {}
1360 
1361     TableCheckConstraintDef(const char* check);
1362 
1363     /** @brief Dump to stdout. */
1364     virtual std::ostream& put(std::ostream& os) const;
1365 
~TableCheckConstraintDefTableCheckConstraintDef1366     virtual ~TableCheckConstraintDef()
1367     {}
1368     std::string fCheck;
1369 };
1370 
1371 
1372 
1373 /** @brief Represents the alter table command.
1374  *
1375  * All forms of alter_table_statements are represented as
1376  * subclasses of this.
1377  */
1378 
1379 struct AlterTableStatement : public SqlStatement
1380 {
1381     /** @brief Deserialize from ByteStream */
1382     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1383 
1384     /** @brief Serialize to ByteStream */
1385     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1386 
1387 
AlterTableStatementAlterTableStatement1388     AlterTableStatement() : fTableName(0)
1389     {}
1390 
1391     EXPORT AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList);
1392 
1393     /** @brief Dump to stdout. */
1394     EXPORT virtual std::ostream& put(std::ostream& os) const;
1395 
1396     /** @brief Delete members. */
1397     EXPORT virtual ~AlterTableStatement();
1398 
schemaNameAlterTableStatement1399     std::string schemaName() const
1400     {
1401         if (!fTableName) return "UNKNOWN";
1402 
1403         return fTableName->fSchema;
1404     }
1405 
1406     QualifiedName* fTableName;
1407     AlterTableActionList fActions;
1408     std::string fTimeZone;
1409 };
1410 
1411 
1412 
1413 /** @brief This is used during parsing when constraint attributes
1414 	are recognized.  This is always before the parent column def
1415 	is recognized.  That's why we need a separate structure during
1416 	parsing.  When the column def is recognized, we'll just copy
1417 	these into the Column structure.
1418 */
1419 struct ConstraintAttributes
1420 {
1421     /** @brief Deserialize from ByteStream */
1422     virtual int unserialize(messageqcpp::ByteStream& bs);
1423 
1424     /** @brief Serialize to ByteStream */
1425     virtual int serialize(messageqcpp::ByteStream& bs);
1426 
1427 
ConstraintAttributesConstraintAttributes1428     ConstraintAttributes()
1429     {}
1430 
ConstraintAttributesConstraintAttributes1431     ConstraintAttributes(DDL_CONSTRAINT_ATTRIBUTES checkTime, bool deferrable) :
1432         fCheckTime(checkTime),
1433         fDeferrable(deferrable)
1434     {}
1435 
~ConstraintAttributesConstraintAttributes1436     virtual ~ConstraintAttributes()
1437     {}
1438 
1439 
1440     DDL_CONSTRAINT_ATTRIBUTES fCheckTime;
1441     bool fDeferrable;
1442 };
1443 
1444 /** @brief CreateIndex represents the CreateIndex operation.
1445  *
1446  * @note This currently takes ownership of the objects assigned to
1447  * fIndexName & fTableName.
1448  */
1449 struct CreateIndexStatement : public SqlStatement
1450 {
1451     /** @brief Deserialize from ByteStream */
1452     virtual int unserialize(messageqcpp::ByteStream& bs);
1453 
1454     /** @brief Serialize to ByteStream */
1455     virtual int serialize(messageqcpp::ByteStream& bs);
1456 
1457     CreateIndexStatement();
1458     CreateIndexStatement(QualifiedName* qualifiedName1, QualifiedName* qualifiedName2,
1459                          ColumnNameList* columnNames, bool unique);
1460 
1461     /** @brief Dump to stdout. */
1462     std::ostream& put(std::ostream& os) const;
1463 
1464     virtual ~CreateIndexStatement();
1465 
1466     QualifiedName* fIndexName;
1467     QualifiedName* fTableName;
1468     ColumnNameList fColumnNames;
1469     bool fUnique;
1470 };
1471 
1472 /** @brief DropIndexStatement represents the drop index operation. */
1473 
1474 struct DropIndexStatement : public SqlStatement
1475 {
1476     /** @brief Deserialize from ByteStream */
1477     virtual int unserialize(messageqcpp::ByteStream& bs);
1478 
1479     /** @brief Serialize to ByteStream */
1480     virtual int serialize(messageqcpp::ByteStream& bs);
1481 
1482 
DropIndexStatementDropIndexStatement1483     DropIndexStatement() : fIndexName(0)
1484     {}
1485     DropIndexStatement(QualifiedName* qualifiedName);
1486 
1487     /** @brief Dump to stdout. */
1488     std::ostream& put(std::ostream& os) const;
1489 
1490     virtual ~DropIndexStatement();
1491 
1492     QualifiedName* fIndexName;
1493 };
1494 
1495 /** @brief DropTableStatement represents the drop table operation
1496  */
1497 struct DropTableStatement : public SqlStatement
1498 {
1499     /** @brief Deserialize from ByteStream */
1500     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1501 
1502     /** @brief Serialize to ByteStream */
1503     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1504 
1505 
DropTableStatementDropTableStatement1506     DropTableStatement() : fTableName(0)
1507     {}
1508     EXPORT DropTableStatement(QualifiedName* qualifiedName, bool cascade);
1509 
1510     /** @brief Dump to stdout. */
1511     EXPORT std::ostream& put(std::ostream& os) const;
1512 
~DropTableStatementDropTableStatement1513     virtual ~DropTableStatement()
1514     {
1515         delete fTableName;
1516     }
1517 
schemaNameDropTableStatement1518     std::string schemaName() const
1519     {
1520         if (!fTableName) return "UNKNOWN";
1521 
1522         return fTableName->fSchema;
1523     }
1524 
1525     QualifiedName* fTableName;
1526     bool fCascade;
1527 };
1528 
1529 /** @brief TruncTableStatement represents the drop table operation
1530  */
1531 struct TruncTableStatement : public SqlStatement
1532 {
1533     /** @brief Deserialize from ByteStream */
1534     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1535 
1536     /** @brief Serialize to ByteStream */
1537     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1538 
1539 
TruncTableStatementTruncTableStatement1540     TruncTableStatement() : fTableName(0)
1541     {}
1542     EXPORT TruncTableStatement(QualifiedName* qualifiedName);
1543 
1544     /** @brief Dump to stdout. */
1545     EXPORT std::ostream& put(std::ostream& os) const;
1546 
~TruncTableStatementTruncTableStatement1547     virtual ~TruncTableStatement()
1548     {
1549         delete fTableName;
1550     }
1551 
schemaNameTruncTableStatement1552     std::string schemaName() const
1553     {
1554         if (!fTableName) return "UNKNOWN";
1555 
1556         return fTableName->fSchema;
1557     }
1558 
1559     QualifiedName* fTableName;
1560 };
1561 
1562 /** @brief Represents the mark partition out of service statement
1563  *
1564  */
1565 struct MarkPartitionStatement : public SqlStatement
1566 {
1567     /** @brief Deserialize from ByteStream */
1568     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1569 
1570     /** @brief Serialize to ByteStream */
1571     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1572 
1573     /** @brief Ctor for deserialization */
MarkPartitionStatementMarkPartitionStatement1574     MarkPartitionStatement() : fTableName(0)
1575     {}
1576 
1577     /** @brief You can't have a CreateTableStatement without a table defintion */
1578     EXPORT MarkPartitionStatement(QualifiedName* qualifiedName);
1579 
1580     /** @brief Dump to stdout. */
1581     EXPORT virtual std::ostream& put(std::ostream& os) const;
1582 
~MarkPartitionStatementMarkPartitionStatement1583     virtual ~MarkPartitionStatement()
1584     {
1585         delete fTableName;
1586     }
1587 
1588     QualifiedName* fTableName; ///< The table defintion
1589     std::set<BRM::LogicalPartition> fPartitions; // partition numbers
1590 };
1591 
1592 /** @brief Represents the mark partition out of service statement
1593  *
1594  */
1595 struct RestorePartitionStatement : public SqlStatement
1596 {
1597     /** @brief Deserialize from ByteStream */
1598     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1599 
1600     /** @brief Serialize to ByteStream */
1601     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1602 
1603     /** @brief Ctor for deserialization */
RestorePartitionStatementRestorePartitionStatement1604     RestorePartitionStatement() : fTableName(0)
1605     {}
1606 
1607     EXPORT RestorePartitionStatement(QualifiedName* qualifiedName);
1608 
1609     /** @brief Dump to stdout. */
1610     EXPORT virtual std::ostream& put(std::ostream& os) const;
1611 
~RestorePartitionStatementRestorePartitionStatement1612     virtual ~RestorePartitionStatement()
1613     {
1614         delete fTableName;
1615     }
1616 
1617     QualifiedName* fTableName; ///< The table name.
1618     std::set<BRM::LogicalPartition> fPartitions; // partition numbers
1619 };
1620 
1621 /** @brief Represents the mark partition out of service statement
1622  *
1623  */
1624 struct DropPartitionStatement : public SqlStatement
1625 {
1626     /** @brief Deserialize from ByteStream */
1627     EXPORT virtual int unserialize(messageqcpp::ByteStream& bs);
1628 
1629     /** @brief Serialize to ByteStream */
1630     EXPORT virtual int serialize(messageqcpp::ByteStream& bs);
1631 
1632     /** @brief Ctor for deserialization */
DropPartitionStatementDropPartitionStatement1633     DropPartitionStatement() : fTableName(0)
1634     {}
1635 
1636     EXPORT DropPartitionStatement(QualifiedName* qualifiedName);
1637 
1638     /** @brief Dump to stdout. */
1639     EXPORT virtual std::ostream& put(std::ostream& os) const;
1640 
~DropPartitionStatementDropPartitionStatement1641     virtual ~DropPartitionStatement()
1642     {
1643         delete fTableName;
1644     }
1645 
1646     QualifiedName* fTableName; ///< The table name.
1647     std::set<BRM::LogicalPartition> fPartitions; // partition numbers
1648 };
1649 
1650 }
1651 
1652 #undef EXPORT
1653 
1654 #endif
1655