1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -25,287 +25,299 @@
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
namespace ddlpackage {
using namespace std;
AlterTableStatement::AlterTableStatement(QualifiedName *qName, AlterTableActionList *ataList):
fTableName(qName),
fActions(*ataList)
{
delete ataList;
}
AlterTableStatement::~AlterTableStatement()
{
delete fTableName;
AlterTableActionList::iterator itr;
for(itr=fActions.begin(); itr != fActions.end(); ++itr) {
delete *itr;
}
}
std::ostream& AlterTableStatement::put(std::ostream& os) const
{
AlterTableActionList::const_iterator itr;
os << "Alter Table " << *fTableName << endl;
for(itr = fActions.begin(); itr != fActions.end(); ++itr) {
os << **itr << endl;
}
return os;
}
/** @brief Format to ostream. Diagnostic. */
std::ostream& AlterTableAction::put(std::ostream& os) const
{
os << "AlterTableAction put stub";
return os;
}
/** @brief Invokes the virtual function put, to dispatch to subclass
ostream writers. */
std::ostream &operator<<(std::ostream& os, const AlterTableAction &ata)
{
return ata.put(os);
}
namespace ddlpackage
{
using namespace std;
AtaAddColumn::~AtaAddColumn()
{
delete fColumnDef;
}
AlterTableStatement::AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList):
fTableName(qName),
fActions(*ataList)
{
delete ataList;
}
AlterTableStatement::~AlterTableStatement()
{
delete fTableName;
AlterTableActionList::iterator itr;
/** @brief ostream output */
std::ostream& AtaAddColumn::put(std::ostream& os) const
{
os << "Add Column" << endl;
os << *fColumnDef << endl;
return os;
}
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
delete *itr;
}
}
std::ostream& AlterTableStatement::put(std::ostream& os) const
{
AlterTableActionList::const_iterator itr;
os << "Alter Table " << *fTableName << endl;
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
os << **itr << endl;
}
AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior) :
fColumnName(columnName),
fDropBehavior(dropBehavior)
{
}
return os;
}
std::ostream& AtaDropColumn::put(std::ostream& os) const
{
os << "Drop Column: " << fColumnName << " "
<< ReferentialActionStrings[fDropBehavior];
return os;
}
AtaModifyColumnType::~AtaModifyColumnType()
{
delete fColumnType;
}
std::ostream& AtaModifyColumnType::put(std::ostream& os) const
{
os << "Modify column type: " << fName << " " << *fColumnType;
return os;
}
/** @brief Format to ostream. Diagnostic. */
std::ostream& AlterTableAction::put(std::ostream& os) const
{
os << "AlterTableAction put stub";
return os;
}
/** @brief Invokes the virtual function put, to dispatch to subclass
ostream writers. */
std::ostream& operator<<(std::ostream& os, const AlterTableAction& ata)
{
return ata.put(os);
}
AtaRenameColumn::~AtaRenameColumn()
{
delete fNewType;
}
std::ostream& AtaRenameColumn::put(std::ostream& os) const
{
os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')';
return os;
}
AtaSetColumnDefault::AtaSetColumnDefault(const char *colName, ColumnDefaultValue *defaultValue) :
fColumnName(colName),
fDefaultValue(defaultValue)
{
}
AtaSetColumnDefault::~AtaSetColumnDefault()
{
delete fDefaultValue;
}
std::ostream& AtaSetColumnDefault::put(std::ostream& os) const
{
os << "Set Column Default: " << fColumnName << " "
<< *fDefaultValue << endl;
return os;
}
AtaDropColumnDefault::AtaDropColumnDefault(const char *colName) :
fColumnName(colName)
{
}
std::ostream& AtaDropColumnDefault::put(std::ostream& os) const
{
os << "Drop Column Default: " << fColumnName << " ";
return os;
}
AtaRenameTable::AtaRenameTable(QualifiedName *qualifiedName) :
fQualifiedName(qualifiedName)
{
}
AtaRenameTable::~AtaRenameTable()
{
delete fQualifiedName;
}
std::ostream& AtaRenameTable::put(std::ostream& os) const
{
os << "Rename Table: " << *fQualifiedName << endl;
return os;
}
AtaAddColumn::~AtaAddColumn()
{
delete fColumnDef;
}
AtaTableComment::AtaTableComment(const char *tableComment) :
fTableComment(tableComment)
{
}
AtaTableComment::~AtaTableComment()
{
}
/** @brief ostream output */
std::ostream& AtaAddColumn::put(std::ostream& os) const
{
os << "Add Column" << endl;
os << *fColumnDef << endl;
return os;
}
std::ostream& AtaTableComment::put(std::ostream& os) const
{
os << "TableComment: " << fTableComment << endl;
return os;
}
AtaAddColumns::~AtaAddColumns()
{
ColumnDefList::iterator itr;
for(itr=fColumns.begin(); itr != fColumns.end(); itr++)
delete *itr;
}
AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior) :
fColumnName(columnName),
fDropBehavior(dropBehavior)
{
}
std::ostream& AtaDropColumn::put(std::ostream& os) const
{
os << "Drop Column: " << fColumnName << " "
<< ReferentialActionStrings[fDropBehavior];
return os;
}
AtaAddColumns::AtaAddColumns(TableElementList *tableElements)
{
/* It is convenient to reuse the grammar rules for
table_element_list, and we do. So, it is possible for
there to be errant table constraint defs in the input list.
We ignore them. That is all we are doing here.
*/
ColumnDef *column;
TableElementList::const_iterator itr;
for(itr = tableElements->begin();
itr != tableElements->end();
++itr)
{
column = dynamic_cast<ColumnDef *>(*itr);
if(0 != column) {
fColumns.push_back(column);
}
}
delete tableElements;
}
std::ostream& AtaAddColumns::put(std::ostream& os) const
{
os << "Add Columns: " << endl;
ColumnDefList::const_iterator itr;
for(itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << **itr << endl;
}
return os;
}
//////////////////////////
AtaDropColumns::~AtaDropColumns()
{
}
AtaDropColumns::AtaDropColumns(ColumnNameList *columnNames)
{
fColumns = *columnNames;
delete columnNames;
}
std::ostream& AtaDropColumns::put(std::ostream& os) const
{
os << "Drop Columns: " << endl;
ColumnNameList::const_iterator itr;
for(itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << *itr << endl;
}
return os;
}
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef *tableConstraint) :
fTableConstraint(tableConstraint)
{
}
AtaAddTableConstraint::~AtaAddTableConstraint()
{
delete fTableConstraint;
}
std::ostream& AtaAddTableConstraint::put(std::ostream& os) const
{
os << "Add Table Constraint:" << endl;
os << *fTableConstraint << endl;
return os;
}
AtaDropTableConstraint::AtaDropTableConstraint
(const char *constraintName, DDL_REFERENTIAL_ACTION dropBehavior) :
fConstraintName(constraintName),
fDropBehavior(dropBehavior)
{
}
std::ostream& AtaDropTableConstraint::put(std::ostream& os) const
{
os << "Drop Table Constraint: " << fConstraintName;
return os;
}
AtaModifyColumnType::~AtaModifyColumnType()
{
delete fColumnType;
}
std::ostream& AtaModifyColumnType::put(std::ostream& os) const
{
os << "Modify column type: " << fName << " " << *fColumnType;
return os;
}
AtaRenameColumn::~AtaRenameColumn()
{
delete fNewType;
}
std::ostream& AtaRenameColumn::put(std::ostream& os) const
{
os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')';
return os;
}
AtaSetColumnDefault::AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue) :
fColumnName(colName),
fDefaultValue(defaultValue)
{
}
AtaSetColumnDefault::~AtaSetColumnDefault()
{
delete fDefaultValue;
}
std::ostream& AtaSetColumnDefault::put(std::ostream& os) const
{
os << "Set Column Default: " << fColumnName << " "
<< *fDefaultValue << endl;
return os;
}
AtaDropColumnDefault::AtaDropColumnDefault(const char* colName) :
fColumnName(colName)
{
}
std::ostream& AtaDropColumnDefault::put(std::ostream& os) const
{
os << "Drop Column Default: " << fColumnName << " ";
return os;
}
AtaRenameTable::AtaRenameTable(QualifiedName* qualifiedName) :
fQualifiedName(qualifiedName)
{
}
AtaRenameTable::~AtaRenameTable()
{
delete fQualifiedName;
}
std::ostream& AtaRenameTable::put(std::ostream& os) const
{
os << "Rename Table: " << *fQualifiedName << endl;
return os;
}
AtaTableComment::AtaTableComment(const char* tableComment) :
fTableComment(tableComment)
{
}
AtaTableComment::~AtaTableComment()
{
}
std::ostream& AtaTableComment::put(std::ostream& os) const
{
os << "TableComment: " << fTableComment << endl;
return os;
}
AtaAddColumns::~AtaAddColumns()
{
ColumnDefList::iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
delete *itr;
}
AtaAddColumns::AtaAddColumns(TableElementList* tableElements)
{
/* It is convenient to reuse the grammar rules for
table_element_list, and we do. So, it is possible for
there to be errant table constraint defs in the input list.
We ignore them. That is all we are doing here.
*/
ColumnDef* column;
TableElementList::const_iterator itr;
for (itr = tableElements->begin();
itr != tableElements->end();
++itr)
{
column = dynamic_cast<ColumnDef*>(*itr);
if (0 != column)
{
fColumns.push_back(column);
}
}
delete tableElements;
}
std::ostream& AtaAddColumns::put(std::ostream& os) const
{
os << "Add Columns: " << endl;
ColumnDefList::const_iterator itr;
for (itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << **itr << endl;
}
return os;
}
//////////////////////////
AtaDropColumns::~AtaDropColumns()
{
}
AtaDropColumns::AtaDropColumns(ColumnNameList* columnNames)
{
fColumns = *columnNames;
delete columnNames;
}
std::ostream& AtaDropColumns::put(std::ostream& os) const
{
os << "Drop Columns: " << endl;
ColumnNameList::const_iterator itr;
for (itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << *itr << endl;
}
return os;
}
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef* tableConstraint) :
fTableConstraint(tableConstraint)
{
}
AtaAddTableConstraint::~AtaAddTableConstraint()
{
delete fTableConstraint;
}
std::ostream& AtaAddTableConstraint::put(std::ostream& os) const
{
os << "Add Table Constraint:" << endl;
os << *fTableConstraint << endl;
return os;
}
AtaDropTableConstraint::AtaDropTableConstraint
(const char* constraintName, DDL_REFERENTIAL_ACTION dropBehavior) :
fConstraintName(constraintName),
fDropBehavior(dropBehavior)
{
}
std::ostream& AtaDropTableConstraint::put(std::ostream& os) const
{
os << "Drop Table Constraint: " << fConstraintName;
return os;
}
}

View File

@ -28,120 +28,133 @@
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
namespace ddlpackage {
namespace ddlpackage
{
using namespace std;
using namespace std;
ColumnDef::~ColumnDef()
{
delete fType;
delete fDefaultValue;
ColumnConstraintList::iterator itr;
for(itr=fConstraints.begin(); itr != fConstraints.end(); ++itr) {
delete *itr;
}
}
ColumnDef::ColumnDef(const char *name, ColumnType* columnType, ColumnConstraintList *constraints,
ColumnDefaultValue *defaultValue, const char * comment ) :
SchemaObject(name),
fType(columnType),
fDefaultValue(defaultValue)
{
if(constraints) {
fConstraints = *constraints;
delete constraints;
}
if ( comment )
fComment = comment;
}
ColumnDef::~ColumnDef()
{
delete fType;
delete fDefaultValue;
ColumnConstraintList::iterator itr;
for (itr = fConstraints.begin(); itr != fConstraints.end(); ++itr)
{
delete *itr;
}
}
ColumnDef::ColumnDef(const char* name, ColumnType* columnType, ColumnConstraintList* constraints,
ColumnDefaultValue* defaultValue, const char* comment ) :
SchemaObject(name),
fType(columnType),
fDefaultValue(defaultValue)
{
if (constraints)
{
fConstraints = *constraints;
delete constraints;
}
if ( comment )
fComment = comment;
}
ostream& operator<<(ostream& os, const ColumnType& columnType)
{
os << setw(12) << left << DDLDatatypeString[columnType.fType]
<< "["
<< "L=" << setw(2) << columnType.fLength << ","
<< "P=" << setw(2) << columnType.fPrecision << ","
<< "S=" << setw(2) << columnType.fScale << ","
<< "T=" << setw(2) << columnType.fWithTimezone
<< "]";
return os;
}
ostream& operator<<(ostream& os, const ColumnDef& column)
{
os << "Column: " << column.fName << " " << *column.fType;
if (column.fDefaultValue)
{
os << " def=";
if (column.fDefaultValue->fNull)
os << "NULL";
else
os << column.fDefaultValue->fValue;
}
os << endl << " " << column.fConstraints.size()
<< " constraints ";
ColumnConstraintList::const_iterator itr;
for (itr = column.fConstraints.begin();
itr != column.fConstraints.end();
++itr)
{
ColumnConstraintDef* con = *itr;
os << *con;
}
return os;
}
ostream& operator<<(ostream& os, const ColumnConstraintDef& con)
{
os << " Constraint: "
<< con.fName << " "
<< ConstraintString[con.fConstraintType] << " "
<< "defer=" << con.fDeferrable << " "
<< ConstraintAttrStrings[con.fCheckTime] << " ";
if (!con.fCheck.empty())
os << "check=" << "\"" << con.fCheck << "\"";
return os;
}
std::ostream& operator<<(std::ostream& os, const ColumnDefList& clist)
{
ColumnDefList::const_iterator itr;
for (itr = clist.begin(); itr != clist.end(); ++itr)
{
os << **itr;
}
return os;
}
ColumnDefaultValue::ColumnDefaultValue(const char* value) :
fNull(false)
{
if (0 == value)
fNull = true;
else
fValue = value;
}
std::ostream& operator<<(std::ostream& os, const ColumnDefaultValue& defaultValue)
{
os << " def=";
if (defaultValue.fNull)
os << "NULL";
else
os << defaultValue.fValue;
return os;
}
ostream &operator<<(ostream& os, const ColumnType& columnType)
{
os << setw(12) << left << DDLDatatypeString[columnType.fType]
<< "["
<< "L=" << setw(2) << columnType.fLength << ","
<< "P=" << setw(2) << columnType.fPrecision << ","
<< "S=" << setw(2) << columnType.fScale << ","
<< "T=" << setw(2) << columnType.fWithTimezone
<< "]";
return os;
}
ostream &operator<<(ostream& os, const ColumnDef &column)
{
os << "Column: " << column.fName << " " << *column.fType;
if(column.fDefaultValue) {
os << " def=";
if (column.fDefaultValue->fNull)
os << "NULL";
else
os << column.fDefaultValue->fValue;
}
os << endl << " " << column.fConstraints.size()
<< " constraints ";
ColumnConstraintList::const_iterator itr;
for(itr = column.fConstraints.begin();
itr != column.fConstraints.end();
++itr) {
ColumnConstraintDef *con = *itr;
os << *con;
}
return os;
}
ostream &operator<<(ostream& os, const ColumnConstraintDef &con)
{
os << " Constraint: "
<< con.fName << " "
<< ConstraintString[con.fConstraintType] << " "
<< "defer=" << con.fDeferrable << " "
<< ConstraintAttrStrings[con.fCheckTime] << " ";
if(!con.fCheck.empty())
os << "check=" << "\"" << con.fCheck << "\"";
return os;
}
std::ostream &operator<<(std::ostream& os, const ColumnDefList &clist)
{
ColumnDefList::const_iterator itr;
for(itr = clist.begin(); itr != clist.end(); ++itr){
os << **itr;
}
return os;
}
ColumnDefaultValue::ColumnDefaultValue(const char *value) :
fNull(false)
{
if(0 == value)
fNull = true;
else
fValue = value;
}
std::ostream &operator<<(std::ostream& os, const ColumnDefaultValue &defaultValue)
{
os << " def=";
if (defaultValue.fNull)
os << "NULL";
else
os << defaultValue.fValue;
return os;
}
}

View File

@ -23,38 +23,39 @@
#include "ddlpkg.h"
namespace ddlpackage {
using namespace std;
CreateIndexStatement::CreateIndexStatement():
fIndexName(NULL),
fTableName(NULL),
fColumnNames(),
fUnique(false)
{
}
CreateIndexStatement::CreateIndexStatement(QualifiedName *indexName, QualifiedName *tableName,
ColumnNameList *columnNames, bool unique) :
fIndexName(indexName),
fTableName(tableName),
fColumnNames(*columnNames),
fUnique(unique)
{
delete columnNames;
}
namespace ddlpackage
{
using namespace std;
CreateIndexStatement::CreateIndexStatement():
fIndexName(NULL),
fTableName(NULL),
fColumnNames(),
fUnique(false)
{
}
CreateIndexStatement::CreateIndexStatement(QualifiedName* indexName, QualifiedName* tableName,
ColumnNameList* columnNames, bool unique) :
fIndexName(indexName),
fTableName(tableName),
fColumnNames(*columnNames),
fUnique(unique)
{
delete columnNames;
}
CreateIndexStatement::~CreateIndexStatement()
{
delete fIndexName;
delete fTableName;
}
std::ostream& CreateIndexStatement::put(std::ostream& os) const
{
os << "Create Index: " << *fIndexName << " on " << *fTableName
<< fColumnNames << endl;
return os;
}
CreateIndexStatement::~CreateIndexStatement()
{
delete fIndexName;
delete fTableName;
}
std::ostream& CreateIndexStatement::put(std::ostream& os) const
{
os << "Create Index: " << *fIndexName << " on " << *fTableName
<< fColumnNames << endl;
return os;
}
}

View File

@ -27,34 +27,35 @@
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
namespace ddlpackage {
namespace ddlpackage
{
using namespace std;
CreateTableStatement::CreateTableStatement() :
fTableDef(0)
{
}
CreateTableStatement::CreateTableStatement(TableDef* tableDef) :
fTableDef(tableDef)
{
}
using namespace std;
CreateTableStatement::~CreateTableStatement()
{
if (fTableDef)
{
delete fTableDef;
}
}
/** \brief Put to ostream. */
ostream& CreateTableStatement::put(ostream& os) const
{
os << "CreateTable "
<< *fTableDef;
return os;
}
CreateTableStatement::CreateTableStatement() :
fTableDef(0)
{
}
CreateTableStatement::CreateTableStatement(TableDef* tableDef) :
fTableDef(tableDef)
{
}
CreateTableStatement::~CreateTableStatement()
{
if (fTableDef)
{
delete fTableDef;
}
}
/** \brief Put to ostream. */
ostream& CreateTableStatement::put(ostream& os) const
{
os << "CreateTable "
<< *fTableDef;
return os;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,173 +1,174 @@
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
ACTION = 258,
ADD = 259,
ALTER = 260,
AUTO_INCREMENT = 261,
BIGINT = 262,
BIT = 263,
IDB_BLOB = 264,
CASCADE = 265,
IDB_CHAR = 266,
CHARACTER = 267,
CHECK = 268,
CLOB = 269,
COLUMN = 270,
COLUMNS = 271,
COMMENT = 272,
CONSTRAINT = 273,
CONSTRAINTS = 274,
CREATE = 275,
CURRENT_USER = 276,
DATETIME = 277,
DEC = 278,
DECIMAL = 279,
DEFAULT = 280,
DEFERRABLE = 281,
DEFERRED = 282,
IDB_DELETE = 283,
DROP = 284,
ENGINE = 285,
FOREIGN = 286,
FULL = 287,
IMMEDIATE = 288,
INDEX = 289,
INITIALLY = 290,
IDB_INT = 291,
INTEGER = 292,
KEY = 293,
MATCH = 294,
MAX_ROWS = 295,
MIN_ROWS = 296,
MODIFY = 297,
NO = 298,
NOT = 299,
NULL_TOK = 300,
NUMBER = 301,
NUMERIC = 302,
ON = 303,
PARTIAL = 304,
PRECISION = 305,
PRIMARY = 306,
REFERENCES = 307,
RENAME = 308,
RESTRICT = 309,
SET = 310,
SMALLINT = 311,
TABLE = 312,
TIME = 313,
TINYINT = 314,
TO = 315,
UNIQUE = 316,
UNSIGNED = 317,
UPDATE = 318,
USER = 319,
SESSION_USER = 320,
SYSTEM_USER = 321,
VARCHAR = 322,
VARBINARY = 323,
VARYING = 324,
WITH = 325,
ZONE = 326,
DOUBLE = 327,
IDB_FLOAT = 328,
REAL = 329,
CHARSET = 330,
IDB_IF = 331,
EXISTS = 332,
CHANGE = 333,
TRUNCATE = 334,
IDENT = 335,
FCONST = 336,
SCONST = 337,
CP_SEARCH_CONDITION_TEXT = 338,
ICONST = 339,
DATE = 340
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
ddlpackage::AlterTableStatement *alterTableStmt;
ddlpackage::AlterTableAction *ata;
ddlpackage::AlterTableActionList *ataList;
ddlpackage::DDL_CONSTRAINT_ATTRIBUTES cattr;
std::pair<std::string, std::string> *tableOption;
const char *columnOption;
ddlpackage::ColumnConstraintDef *columnConstraintDef;
ddlpackage::ColumnNameList *columnNameList;
ddlpackage::ColumnType* columnType;
ddlpackage::ConstraintAttributes *constraintAttributes;
ddlpackage::ColumnConstraintList *constraintList;
ddlpackage::DDL_CONSTRAINTS constraintType;
double dval;
bool flag;
int ival;
ddlpackage::QualifiedName *qualifiedName;
ddlpackage::SchemaObject *schemaObject;
ddlpackage::SqlStatement *sqlStmt;
ddlpackage::SqlStatementList *sqlStmtList;
const char *str;
ddlpackage::TableConstraintDef *tableConstraint;
ddlpackage::TableElementList *tableElementList;
ddlpackage::TableOptionMap *tableOptionMap;
ddlpackage::ColumnDefaultValue *colDefault;
ddlpackage::DDL_MATCH_TYPE matchType;
ddlpackage::DDL_REFERENTIAL_ACTION refActionCode;
ddlpackage::ReferentialAction *refAction;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE ddllval;
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype
{
ACTION = 258,
ADD = 259,
ALTER = 260,
AUTO_INCREMENT = 261,
BIGINT = 262,
BIT = 263,
IDB_BLOB = 264,
CASCADE = 265,
IDB_CHAR = 266,
CHARACTER = 267,
CHECK = 268,
CLOB = 269,
COLUMN = 270,
COLUMNS = 271,
COMMENT = 272,
CONSTRAINT = 273,
CONSTRAINTS = 274,
CREATE = 275,
CURRENT_USER = 276,
DATETIME = 277,
DEC = 278,
DECIMAL = 279,
DEFAULT = 280,
DEFERRABLE = 281,
DEFERRED = 282,
IDB_DELETE = 283,
DROP = 284,
ENGINE = 285,
FOREIGN = 286,
FULL = 287,
IMMEDIATE = 288,
INDEX = 289,
INITIALLY = 290,
IDB_INT = 291,
INTEGER = 292,
KEY = 293,
MATCH = 294,
MAX_ROWS = 295,
MIN_ROWS = 296,
MODIFY = 297,
NO = 298,
NOT = 299,
NULL_TOK = 300,
NUMBER = 301,
NUMERIC = 302,
ON = 303,
PARTIAL = 304,
PRECISION = 305,
PRIMARY = 306,
REFERENCES = 307,
RENAME = 308,
RESTRICT = 309,
SET = 310,
SMALLINT = 311,
TABLE = 312,
TIME = 313,
TINYINT = 314,
TO = 315,
UNIQUE = 316,
UNSIGNED = 317,
UPDATE = 318,
USER = 319,
SESSION_USER = 320,
SYSTEM_USER = 321,
VARCHAR = 322,
VARBINARY = 323,
VARYING = 324,
WITH = 325,
ZONE = 326,
DOUBLE = 327,
IDB_FLOAT = 328,
REAL = 329,
CHARSET = 330,
IDB_IF = 331,
EXISTS = 332,
CHANGE = 333,
TRUNCATE = 334,
IDENT = 335,
FCONST = 336,
SCONST = 337,
CP_SEARCH_CONDITION_TEXT = 338,
ICONST = 339,
DATE = 340
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
ddlpackage::AlterTableStatement* alterTableStmt;
ddlpackage::AlterTableAction* ata;
ddlpackage::AlterTableActionList* ataList;
ddlpackage::DDL_CONSTRAINT_ATTRIBUTES cattr;
std::pair<std::string, std::string>* tableOption;
const char* columnOption;
ddlpackage::ColumnConstraintDef* columnConstraintDef;
ddlpackage::ColumnNameList* columnNameList;
ddlpackage::ColumnType* columnType;
ddlpackage::ConstraintAttributes* constraintAttributes;
ddlpackage::ColumnConstraintList* constraintList;
ddlpackage::DDL_CONSTRAINTS constraintType;
double dval;
bool flag;
int ival;
ddlpackage::QualifiedName* qualifiedName;
ddlpackage::SchemaObject* schemaObject;
ddlpackage::SqlStatement* sqlStmt;
ddlpackage::SqlStatementList* sqlStmtList;
const char* str;
ddlpackage::TableConstraintDef* tableConstraint;
ddlpackage::TableElementList* tableElementList;
ddlpackage::TableOptionMap* tableOptionMap;
ddlpackage::ColumnDefaultValue* colDefault;
ddlpackage::DDL_MATCH_TYPE matchType;
ddlpackage::DDL_REFERENTIAL_ACTION refActionCode;
ddlpackage::ReferentialAction* refAction;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE ddllval;

File diff suppressed because it is too large Load Diff

View File

@ -27,182 +27,192 @@
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
namespace ddlpackage
namespace ddlpackage
{
using namespace std;
using namespace std;
QualifiedName::QualifiedName(const char *name):
fName(name)
{
}
QualifiedName::QualifiedName(const char* name):
fName(name)
{
}
QualifiedName::QualifiedName(const char *schema, const char *name):
fName(name),
fSchema(schema)
{
}
QualifiedName::QualifiedName(const char* schema, const char* name):
fName(name),
fSchema(schema)
{
}
QualifiedName::QualifiedName(const char* catalog, const char *schema, const char *name):
fCatalog(catalog),
fName(name),
fSchema(schema)
{
}
QualifiedName::QualifiedName(const char* catalog, const char* schema, const char* name):
fCatalog(catalog),
fName(name),
fSchema(schema)
{
}
ostream& operator<<(ostream &os, const QualifiedName& qname)
{
if(!qname.fCatalog.empty())
os << qname.fCatalog << ".";
if(!qname.fSchema.empty())
os << qname.fSchema << ".";
os << qname.fName;
return os;
}
ostream& operator<<(ostream& os, const QualifiedName& qname)
{
if (!qname.fCatalog.empty())
os << qname.fCatalog << ".";
if (!qname.fSchema.empty())
os << qname.fSchema << ".";
os << qname.fName;
return os;
}
/** @brief Map a DECIMAL precision to data width in bytes */
unsigned int precision_width(unsigned p)
{
switch(p)
{
case 1:
case 2:
return 1;
case 3:
case 4:
return 2;
case 5:
case 6:
case 7:
case 8:
case 9:
return 4;
default:
return 8;
}
}
ColumnType::ColumnType(int prec, int scale) :
fType(DDL_INVALID_DATATYPE),
fLength(0),
fPrecision(prec),
fScale(scale),
fWithTimezone(false)
{
fLength = precision_width(fPrecision);
}
ColumnType::ColumnType(int type) :
fType(type),
fLength(0),
fScale(0),
fWithTimezone(false)
{
switch ( type )
{
case DDL_TINYINT:
case DDL_UNSIGNED_TINYINT:
fPrecision = 3;
break;
case DDL_SMALLINT:
case DDL_UNSIGNED_SMALLINT:
fPrecision = 5;
break;
case DDL_INT:
case DDL_UNSIGNED_INT:
case DDL_MEDINT:
fPrecision = 10;
break;
case DDL_BIGINT:
fPrecision = 19;
case DDL_UNSIGNED_BIGINT:
fPrecision = 20;
break;
default:
fPrecision = 10;
break;
}
}
#if 0
ColumnType::ColumnType(int type, int length, int precision, int scale, int compressiontype, const char* autoIncrement, int64_t nextValue, bool withTimezone) :
fType(type) ,
fLength(length),
fPrecision(precision),
fScale(scale),
fWithTimezone(withTimezone),
fCompressiontype(compressiontype),
fAutoincrement(autoIncrement),
fNextvalue(nextValue)
/** @brief Map a DECIMAL precision to data width in bytes */
unsigned int precision_width(unsigned p)
{
switch (p)
{
}
#endif
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) :
SchemaObject(),
fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(type),
fCheck("")
{
}
ColumnConstraintDef::ColumnConstraintDef(const char *check) :
SchemaObject(),
fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(DDL_CHECK),
fCheck(check)
{
}
case 1:
case 2:
return 1;
AtaAddColumn::AtaAddColumn(ColumnDef *columnDef) :
fColumnDef(columnDef)
{
}
case 3:
case 4:
return 2;
ostream &operator<<(ostream& os, const ReferentialAction& ref)
{
os << "ref action: u=" << ReferentialActionStrings[ref.fOnUpdate] << " "
<< "d=" << ReferentialActionStrings[ref.fOnDelete];
return os;
}
case 5:
case 6:
case 7:
case 8:
case 9:
return 4;
void ColumnDef::convertDecimal()
{
//@Bug 2089 decimal precision default to 10 if 0 is used.
if (fType->fPrecision <= 0)
fType->fPrecision = 10;
if (fType->fPrecision == -1 || fType->fPrecision == 0)
{
fType->fType = DDL_BIGINT;
fType->fLength = 8;
fType->fScale = 0;
}
else if ((fType->fPrecision > 0) && (fType->fPrecision < 3))
{
//dataType = CalpontSystemCatalog::TINYINT;
fType->fType = DDL_TINYINT;
fType->fLength = 1;
}
else if (fType->fPrecision < 5 && (fType->fPrecision > 2))
{
//dataType = CalpontSystemCatalog::SMALLINT;
fType->fType = DDL_SMALLINT;
fType->fLength = 2;
}
else if (fType->fPrecision > 4 && fType->fPrecision < 10)
{
//dataType = CalpontSystemCatalog::INT;
fType->fType = DDL_INT;
fType->fLength = 4;
}
else if (fType->fPrecision > 9 && fType->fPrecision < 19)
{
//dataType = CalpontSystemCatalog::BIGINT;
fType->fType = DDL_BIGINT;
fType->fLength = 8;
}
default:
return 8;
}
}
ColumnType::ColumnType(int prec, int scale) :
fType(DDL_INVALID_DATATYPE),
fLength(0),
fPrecision(prec),
fScale(scale),
fWithTimezone(false)
{
fLength = precision_width(fPrecision);
}
ColumnType::ColumnType(int type) :
fType(type),
fLength(0),
fScale(0),
fWithTimezone(false)
{
switch ( type )
{
case DDL_TINYINT:
case DDL_UNSIGNED_TINYINT:
fPrecision = 3;
break;
case DDL_SMALLINT:
case DDL_UNSIGNED_SMALLINT:
fPrecision = 5;
break;
case DDL_INT:
case DDL_UNSIGNED_INT:
case DDL_MEDINT:
fPrecision = 10;
break;
case DDL_BIGINT:
fPrecision = 19;
case DDL_UNSIGNED_BIGINT:
fPrecision = 20;
break;
default:
fPrecision = 10;
break;
}
}
#if 0
ColumnType::ColumnType(int type, int length, int precision, int scale, int compressiontype, const char* autoIncrement, int64_t nextValue, bool withTimezone) :
fType(type),
fLength(length),
fPrecision(precision),
fScale(scale),
fWithTimezone(withTimezone),
fCompressiontype(compressiontype),
fAutoincrement(autoIncrement),
fNextvalue(nextValue)
{
}
#endif
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) :
SchemaObject(),
fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(type),
fCheck("")
{
}
ColumnConstraintDef::ColumnConstraintDef(const char* check) :
SchemaObject(),
fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(DDL_CHECK),
fCheck(check)
{
}
AtaAddColumn::AtaAddColumn(ColumnDef* columnDef) :
fColumnDef(columnDef)
{
}
ostream& operator<<(ostream& os, const ReferentialAction& ref)
{
os << "ref action: u=" << ReferentialActionStrings[ref.fOnUpdate] << " "
<< "d=" << ReferentialActionStrings[ref.fOnDelete];
return os;
}
void ColumnDef::convertDecimal()
{
//@Bug 2089 decimal precision default to 10 if 0 is used.
if (fType->fPrecision <= 0)
fType->fPrecision = 10;
if (fType->fPrecision == -1 || fType->fPrecision == 0)
{
fType->fType = DDL_BIGINT;
fType->fLength = 8;
fType->fScale = 0;
}
else if ((fType->fPrecision > 0) && (fType->fPrecision < 3))
{
//dataType = CalpontSystemCatalog::TINYINT;
fType->fType = DDL_TINYINT;
fType->fLength = 1;
}
else if (fType->fPrecision < 5 && (fType->fPrecision > 2))
{
//dataType = CalpontSystemCatalog::SMALLINT;
fType->fType = DDL_SMALLINT;
fType->fLength = 2;
}
else if (fType->fPrecision > 4 && fType->fPrecision < 10)
{
//dataType = CalpontSystemCatalog::INT;
fType->fType = DDL_INT;
fType->fLength = 4;
}
else if (fType->fPrecision > 9 && fType->fPrecision < 19)
{
//dataType = CalpontSystemCatalog::BIGINT;
fType->fType = DDL_BIGINT;
fType->fLength = 8;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -23,23 +23,24 @@
#include "ddlpkg.h"
namespace ddlpackage {
using namespace std;
namespace ddlpackage
{
using namespace std;
DropIndexStatement::~DropIndexStatement()
{
delete fIndexName;
}
DropIndexStatement::~DropIndexStatement()
{
delete fIndexName;
}
DropIndexStatement::DropIndexStatement(QualifiedName *qualifiedName) :
fIndexName(qualifiedName)
{
}
DropIndexStatement::DropIndexStatement(QualifiedName* qualifiedName) :
fIndexName(qualifiedName)
{
}
std::ostream& DropIndexStatement::put(std::ostream& os) const
{
os << "Drop Index: " << *fIndexName << endl;
return os;
}
std::ostream& DropIndexStatement::put(std::ostream& os) const
{
os << "Drop Index: " << *fIndexName << endl;
return os;
}
}

View File

@ -27,22 +27,25 @@
using namespace std;
namespace ddlpackage {
namespace ddlpackage
{
DropPartitionStatement::DropPartitionStatement(QualifiedName *qualifiedName) :
fTableName(qualifiedName)
DropPartitionStatement::DropPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
{
}
ostream& DropPartitionStatement::put(ostream& os) const
{
os << "Mark partitions out of service: " << *fTableName << endl;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it=fPartitions.begin(); it!=fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
os << "Mark partitions out of service: " << *fTableName << endl;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
}
}

View File

@ -27,29 +27,30 @@
using namespace std;
namespace ddlpackage {
namespace ddlpackage
{
DropTableStatement::DropTableStatement(QualifiedName *qualifiedName, bool cascade) :
fTableName(qualifiedName),
fCascade(cascade)
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade) :
fTableName(qualifiedName),
fCascade(cascade)
{
}
ostream& DropTableStatement::put(ostream& os) const
{
os << "Drop Table: " << *fTableName << " " << "C=" << fCascade << endl;
return os;
os << "Drop Table: " << *fTableName << " " << "C=" << fCascade << endl;
return os;
}
TruncTableStatement::TruncTableStatement(QualifiedName *qualifiedName) :
fTableName(qualifiedName)
TruncTableStatement::TruncTableStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
{
}
ostream& TruncTableStatement::put(ostream& os) const
{
os << "Truncate Table: " << *fTableName << endl;
return os;
os << "Truncate Table: " << *fTableName << endl;
return os;
}
}

View File

@ -31,44 +31,48 @@ namespace po = boost::program_options;
int main(int argc, char* argv[])
{
string sqlfile;
int count;
string sqlfile;
int count;
po::options_description desc ("Allowed options");
desc.add_options ()
("help", "produce help message")
("bisond", /* po::value <string>(),*/ "Have bison produce debug output")
("count", po::value <int>(), "number of runs")
("sql", po::value < string > (), "sql file");
po::variables_map vm;
po::store (po::parse_command_line (argc, argv, desc), vm);
po::notify (vm);
if (vm.count ("sql"))
sqlfile = vm["sql"].as <string> ();
po::options_description desc ("Allowed options");
desc.add_options ()
("help", "produce help message")
("bisond", /* po::value <string>(),*/ "Have bison produce debug output")
("count", po::value <int>(), "number of runs")
("sql", po::value < string > (), "sql file");
po::variables_map vm;
po::store (po::parse_command_line (argc, argv, desc), vm);
po::notify (vm);
if (vm.count ("sql"))
sqlfile = vm["sql"].as <string> ();
if (vm.count("count"))
count = vm["count"].as<int>();
SqlFileParser parser;
if (vm.count ("bisond"))
parser.SetDebug(true);
parser.Parse(sqlfile);
if (vm.count("count"))
count = vm["count"].as<int>();
if(parser.Good()) {
const ParseTree &ptree = parser.GetParseTree();
SqlFileParser parser;
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree;
cout << endl;
}
else {
cout << "Parser failed." << endl;
}
return parser.Good() ? 0 : -1;
if (vm.count ("bisond"))
parser.SetDebug(true);
parser.Parse(sqlfile);
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree;
cout << endl;
}
else
{
cout << "Parser failed." << endl;
}
return parser.Good() ? 0 : -1;
}

View File

@ -27,22 +27,25 @@
using namespace std;
namespace ddlpackage {
namespace ddlpackage
{
MarkPartitionStatement::MarkPartitionStatement(QualifiedName *qualifiedName) :
fTableName(qualifiedName)
MarkPartitionStatement::MarkPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
{
}
ostream& MarkPartitionStatement::put(ostream& os) const
{
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it=fPartitions.begin(); it!=fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -27,22 +27,25 @@
using namespace std;
namespace ddlpackage {
namespace ddlpackage
{
RestorePartitionStatement::RestorePartitionStatement(QualifiedName *qualifiedName) :
fTableName(qualifiedName)
RestorePartitionStatement::RestorePartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
{
}
ostream& RestorePartitionStatement::put(ostream& os) const
{
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it=fPartitions.begin(); it!=fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -36,102 +36,108 @@
#endif
void scanner_finish(void* yyscanner);
void scanner_init(const char *str, void* yyscanner);
int ddllex_init_extra(void* user_defined,void** yyscanner);
void scanner_init(const char* str, void* yyscanner);
int ddllex_init_extra(void* user_defined, void** yyscanner);
int ddllex_destroy(void* yyscanner);
int ddlparse(ddlpackage::pass_to_bison* x);
void set_schema(std::string schema);
namespace ddlpackage {
using namespace std;
namespace ddlpackage
{
using namespace std;
SqlParser::SqlParser() :
fStatus(-1),
fDebug(false),
x(&fParseTree)
{
}
void SqlParser::SetDebug(bool debug)
{
fDebug = debug;
}
void SqlParser::setDefaultSchema(std::string schema)
{
x.fDBSchema=schema;
}
int SqlParser::Parse(const char* sqltext)
{
ddllex_init_extra(&scanData, &x.scanner);
scanner_init(sqltext, x.scanner);
fStatus = ddlparse(&x);
return fStatus;
}
const ParseTree& SqlParser::GetParseTree(void)
{
if(!Good()) {
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
}
bool SqlParser::Good()
{
return fStatus == 0;
}
SqlParser::~SqlParser()
{
scanner_finish(x.scanner); // free scanner allocated memory
ddllex_destroy(x.scanner);
}
SqlFileParser::SqlFileParser() :
SqlParser()
{
}
int SqlFileParser::Parse(const string& sqlfile)
{
fStatus = -1;
ifstream ifsql;
ifsql.open(sqlfile.c_str());
if(!ifsql.is_open()) {
perror(sqlfile.c_str());
return fStatus;
}
char sqlbuf[1024*1024];
unsigned length;
ifsql.seekg (0, ios::end);
length = ifsql.tellg();
ifsql.seekg (0, ios::beg);
if(length > sizeof(sqlbuf) - 1) {
throw length_error("SqlFileParser has file size hard limit of 16K.");
}
unsigned rcount;
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
if(rcount < 0)
return fStatus;
sqlbuf[rcount] = 0;
//cout << endl << sqlfile << "(" << rcount << ")" << endl;
//cout << "----------------------" << endl;
//cout << sqlbuf << endl;
return SqlParser::Parse(sqlbuf);
}
SqlParser::SqlParser() :
fStatus(-1),
fDebug(false),
x(&fParseTree)
{
}
void SqlParser::SetDebug(bool debug)
{
fDebug = debug;
}
void SqlParser::setDefaultSchema(std::string schema)
{
x.fDBSchema = schema;
}
int SqlParser::Parse(const char* sqltext)
{
ddllex_init_extra(&scanData, &x.scanner);
scanner_init(sqltext, x.scanner);
fStatus = ddlparse(&x);
return fStatus;
}
const ParseTree& SqlParser::GetParseTree(void)
{
if (!Good())
{
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
}
bool SqlParser::Good()
{
return fStatus == 0;
}
SqlParser::~SqlParser()
{
scanner_finish(x.scanner); // free scanner allocated memory
ddllex_destroy(x.scanner);
}
SqlFileParser::SqlFileParser() :
SqlParser()
{
}
int SqlFileParser::Parse(const string& sqlfile)
{
fStatus = -1;
ifstream ifsql;
ifsql.open(sqlfile.c_str());
if (!ifsql.is_open())
{
perror(sqlfile.c_str());
return fStatus;
}
char sqlbuf[1024 * 1024];
unsigned length;
ifsql.seekg (0, ios::end);
length = ifsql.tellg();
ifsql.seekg (0, ios::beg);
if (length > sizeof(sqlbuf) - 1)
{
throw length_error("SqlFileParser has file size hard limit of 16K.");
}
unsigned rcount;
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
if (rcount < 0)
return fStatus;
sqlbuf[rcount] = 0;
//cout << endl << sqlfile << "(" << rcount << ")" << endl;
//cout << "----------------------" << endl;
//cout << sqlbuf << endl;
return SqlParser::Parse(sqlbuf);
}
}

View File

@ -42,20 +42,20 @@ typedef SqlStatementList ParseTree;
/** @brief SqlParser is a class interface around the Bison parser
* machinery for DDL.
*
*
* Example:
*
* @verbatim
SqlParser parser;
parser.Parse(sqlbuf);
or
SqlFileParser parser;
parser.setDefaultSchema("tpch");
parser.Parse(sqlFileName);
if (parser.Good()) {
const ParseTree &ptree = parser.GetParseTree();
cout << ptree.fList.size() << " " << "SQL statements" << endl;
@ -64,29 +64,30 @@ typedef SqlStatementList ParseTree;
else {
cout << "Parser failed." << endl;
}
@endverbatim
*/
/*
Instance specific data for use by the scanner.
Instance specific data for use by the scanner.
*/
typedef std::vector<char*> valbuf_t;
struct scan_data
{
/* Handles to the buffer that the lexer uses internally */
char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf;
/* Handles to the buffer that the lexer uses internally */
char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf;
};
struct pass_to_bison {
struct pass_to_bison
{
ParseTree* fParseTree;
std::string fDBSchema;
void* scanner;
void* scanner;
pass_to_bison(ParseTree* pt) : fParseTree(pt), scanner(NULL) {};
pass_to_bison(ParseTree* pt) : fParseTree(pt), scanner(NULL) {};
};
class SqlParser
@ -99,33 +100,33 @@ public:
EXPORT int Parse(const char* sqltext);
/** @brief Return the ParseTree if state is Good. Otherwise
* throw a logic_error.
* throw a logic_error.
*/
EXPORT const ParseTree& GetParseTree(void);
/** @brief Tells whether current state resulted from a good
* parse.
* parse.
*/
EXPORT bool Good(void);
/** @brief Control bison debugging
*/
EXPORT void SetDebug(bool debug);
/** @brief Control bison debugging
*/
EXPORT void SetDebug(bool debug);
/** @brief Set the default schema to use if it is not
* supplied in the DDL statement
*
* @param schema the default schema
*/
/** @brief Set the default schema to use if it is not
* supplied in the DDL statement
*
* @param schema the default schema
*/
EXPORT void setDefaultSchema(std::string schema);
protected:
ParseTree fParseTree;
std::string fDBSchema;
std::string fDBSchema;
int fStatus; ///< return from yyparse() stored here.
bool fDebug; ///< Turn on bison debugging.
scan_data scanData;
pass_to_bison x;
scan_data scanData;
pass_to_bison x;
};

View File

@ -25,22 +25,23 @@
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
namespace ddlpackage {
using namespace std;
static uint32_t sessionID = 1;
SqlStatement::SqlStatement()
{
fSessionID = sessionID;
}
SqlStatement::~SqlStatement()
{
}
namespace ddlpackage
{
using namespace std;
ostream& operator<<(ostream &os, const SqlStatement& stmt)
{
return stmt.put(os);
}
static uint32_t sessionID = 1;
SqlStatement::SqlStatement()
{
fSessionID = sessionID;
}
SqlStatement::~SqlStatement()
{
}
ostream& operator<<(ostream& os, const SqlStatement& stmt)
{
return stmt.put(os);
}
}

View File

@ -25,34 +25,39 @@
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
namespace ddlpackage {
using namespace std;
ostream &operator<<(ostream& os, const SqlStatementList &ssl)
{
vector<SqlStatement*>::const_iterator itr;
for(itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr) {
SqlStatement &stmt = **itr;
os << stmt;
}
return os;
}
namespace ddlpackage
{
using namespace std;
void SqlStatementList::push_back(SqlStatement* v)
{
fList.push_back(v);
}
ostream& operator<<(ostream& os, const SqlStatementList& ssl)
{
vector<SqlStatement*>::const_iterator itr;
for (itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr)
{
SqlStatement& stmt = **itr;
os << stmt;
}
return os;
}
void SqlStatementList::push_back(SqlStatement* v)
{
fList.push_back(v);
}
SqlStatementList::~SqlStatementList()
{
vector<SqlStatement*>::iterator itr;
for (itr = fList.begin(); itr != fList.end(); ++itr)
{
delete *itr;
}
}
SqlStatementList::~SqlStatementList()
{
vector<SqlStatement*>::iterator itr;
for(itr = fList.begin(); itr != fList.end(); ++itr) {
delete *itr;
}
}
}

View File

@ -26,268 +26,297 @@
#include "ddlpkg.h"
#undef DDLPKG_DLLEXPORT
namespace ddlpackage
namespace ddlpackage
{
using namespace std;
TableDef::~TableDef()
{
{
ColumnDefList::iterator itr;
for(itr=fColumns.begin(); itr != fColumns.end(); itr++) {
delete *itr;
}
}
{
TableConstraintDefList::iterator itr;
for(itr=fConstraints.begin(); itr != fConstraints.end(); itr++) {
delete *itr;
}
}
delete fQualifiedName;
}
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) :
fQualifiedName(name)
{
if(options) {
fOptions = *options;
delete options;
}
ColumnDef *column;
TableConstraintDef *constraint;
/* When parsing, it is necessary to collect ColumnDefs and
TableConstraintDefs as TableElements. Here we separate
them out into separately typed lists.
*/
TableElementList::iterator itr;
for(itr = elements->begin(); itr != elements->end(); ++itr) {
column = dynamic_cast<ColumnDef*>(*itr);
if(column) {
fColumns.push_back(column);
}
else {
constraint = dynamic_cast<TableConstraintDef *>(*itr);
if(constraint) {
fConstraints.push_back(constraint);
}
}
}
delete elements;
}
using namespace std;
/** \brief Put to ostream. */
ostream& operator<<(ostream& os, const TableDef& tableDef)
{
os << "CreateTable ";
if(tableDef.fQualifiedName->fSchema != "")
//cout << tableDef.fQualifiedName->fSchema << ".";
os << tableDef.fQualifiedName->fName
<< " " << tableDef.fConstraints.size()
<< " table constraints"
<< endl;
TableDef::~TableDef()
{
{
ColumnDefList::iterator itr;
{
ColumnDefList::const_iterator itr;
for(itr = tableDef.fColumns.begin();
itr != tableDef.fColumns.end(); ++itr)
{
ColumnDef* col = *itr;
os << *col << endl;
}
}
{
TableConstraintDefList::const_iterator itr;
for(itr = tableDef.fConstraints.begin();
itr != tableDef.fConstraints.end();
++itr)
{
os << (**itr);
}
}
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
{
delete *itr;
}
}
{
TableConstraintDefList::iterator itr;
pair<string, string> oval;
TableOptionMap::const_iterator oitr;
os << "Table Options" << endl;
if(!tableDef.fOptions.empty()) {
TableOptionMap::const_iterator oitr;
for(oitr = tableDef.fOptions.begin();
oitr != tableDef.fOptions.end(); ++oitr) {
oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl;
}
}
return os;
}
for (itr = fConstraints.begin(); itr != fConstraints.end(); itr++)
{
delete *itr;
}
}
delete fQualifiedName;
}
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) :
fQualifiedName(name)
{
if (options)
{
fOptions = *options;
delete options;
}
ColumnDef* column;
TableConstraintDef* constraint;
/* When parsing, it is necessary to collect ColumnDefs and
TableConstraintDefs as TableElements. Here we separate
them out into separately typed lists.
*/
TableElementList::iterator itr;
for (itr = elements->begin(); itr != elements->end(); ++itr)
{
column = dynamic_cast<ColumnDef*>(*itr);
if (column)
{
fColumns.push_back(column);
}
else
{
constraint = dynamic_cast<TableConstraintDef*>(*itr);
if (constraint)
{
fConstraints.push_back(constraint);
}
}
}
delete elements;
}
/** \brief Put to ostream. */
ostream& operator<<(ostream& os, const TableDef& tableDef)
{
os << "CreateTable ";
if (tableDef.fQualifiedName->fSchema != "")
//cout << tableDef.fQualifiedName->fSchema << ".";
os << tableDef.fQualifiedName->fName
<< " " << tableDef.fConstraints.size()
<< " table constraints"
<< endl;
{
ColumnDefList::const_iterator itr;
for (itr = tableDef.fColumns.begin();
itr != tableDef.fColumns.end(); ++itr)
{
ColumnDef* col = *itr;
os << *col << endl;
}
}
{
TableConstraintDefList::const_iterator itr;
for (itr = tableDef.fConstraints.begin();
itr != tableDef.fConstraints.end();
++itr)
{
os << (**itr);
}
}
pair<string, string> oval;
TableOptionMap::const_iterator oitr;
os << "Table Options" << endl;
if (!tableDef.fOptions.empty())
{
TableOptionMap::const_iterator oitr;
for (oitr = tableDef.fOptions.begin();
oitr != tableDef.fOptions.end(); ++oitr)
{
oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl;
}
}
return os;
}
ostream& operator<<(ostream& os, const TableConstraintDef& constraint)
{
return constraint.put(os);
}
std::ostream& TableConstraintDef::put(std::ostream& os) const
{
os << "No!!!" << endl;
return os;
}
TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) :
fConstraintType(cType)
{
}
TableConstraintDef::TableConstraintDef() :
fConstraintType(DDL_INVALID_CONSTRAINT)
{
}
TableCheckConstraintDef::TableCheckConstraintDef(const char* check) :
TableConstraintDef(DDL_CHECK),
fCheck(check)
{
}
std::ostream& TableCheckConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< ConstraintString[fConstraintType] << " ";
os << "\"" << fCheck << "\"";
os << endl;
return os;
}
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList* columns) :
TableConstraintDef(DDL_UNIQUE),
fColumnNameList(*columns)
{
delete columns;
}
std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "(";
for (itr = fColumnNameList.begin();
itr != fColumnNameList.end();
++itr)
{
os << *itr << " ";
}
os << ")";
return os;
}
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList* columns) :
TableConstraintDef(DDL_PRIMARY_KEY),
fColumnNameList(*columns)
{
delete columns;
}
std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "(";
for (itr = fColumnNameList.begin();
itr != fColumnNameList.end();
++itr)
{
os << *itr << " ";
}
os << ")";
return os;
}
TableReferencesConstraintDef::TableReferencesConstraintDef
(ColumnNameList* columns,
QualifiedName* tableName,
ColumnNameList* foreignColumns,
DDL_MATCH_TYPE matchType,
ReferentialAction* refAction) :
TableConstraintDef(DDL_REFERENCES),
fColumns(*columns),
fTableName(tableName),
fForeignColumns(*foreignColumns),
fMatchType(matchType),
fRefAction(refAction)
{
delete columns;
delete foreignColumns;
}
std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "lcols (";
for (itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << *itr << " ";
}
os << ")";
os << " ftable=" << *fTableName;
os << " ";
os << "fcols (";
for (itr = fForeignColumns.begin();
itr != fForeignColumns.end();
++itr)
{
os << *itr << " ";
}
os << ")";
return os;
}
std::ostream& operator<<(std::ostream& os, const ColumnNameList& columnNames)
{
ColumnNameList::const_iterator itr;
os << '(';
for (itr = columnNames.begin();
itr != columnNames.end();
++itr)
{
os << *itr << " ";
}
os << ')';
return os;
}
TableReferencesConstraintDef::~TableReferencesConstraintDef()
{
delete fTableName;
delete fRefAction;
}
ostream& operator<<(ostream &os, const TableConstraintDef& constraint)
{
return constraint.put(os);
}
std::ostream& TableConstraintDef::put(std::ostream& os) const
{
os << "No!!!" << endl;
return os;
}
TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) :
fConstraintType(cType)
{
}
TableConstraintDef::TableConstraintDef() :
fConstraintType(DDL_INVALID_CONSTRAINT)
{
}
TableCheckConstraintDef::TableCheckConstraintDef(const char *check) :
TableConstraintDef(DDL_CHECK),
fCheck(check)
{
}
std::ostream& TableCheckConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< ConstraintString[fConstraintType] << " ";
os << "\"" << fCheck << "\"";
os << endl;
return os;
}
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList *columns) :
TableConstraintDef(DDL_UNIQUE),
fColumnNameList(*columns)
{
delete columns;
}
std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "(";
for(itr = fColumnNameList.begin();
itr != fColumnNameList.end();
++itr)
{
os << *itr << " ";
}
os << ")";
return os;
}
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList *columns) :
TableConstraintDef(DDL_PRIMARY_KEY),
fColumnNameList(*columns)
{
delete columns;
}
std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "(";
for(itr = fColumnNameList.begin();
itr != fColumnNameList.end();
++itr)
{
os << *itr << " ";
}
os << ")";
return os;
}
TableReferencesConstraintDef::TableReferencesConstraintDef
(ColumnNameList *columns,
QualifiedName *tableName,
ColumnNameList *foreignColumns,
DDL_MATCH_TYPE matchType,
ReferentialAction *refAction) :
TableConstraintDef(DDL_REFERENCES),
fColumns(*columns),
fTableName(tableName),
fForeignColumns(*foreignColumns),
fMatchType(matchType),
fRefAction(refAction)
{
delete columns;
delete foreignColumns;
}
std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "lcols (";
for(itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << *itr << " ";
}
os << ")";
os << " ftable=" << *fTableName;
os << " ";
os << "fcols (";
for(itr = fForeignColumns.begin();
itr != fForeignColumns.end();
++itr)
{
os << *itr << " ";
}
os << ")";
return os;
}
std::ostream &operator<<(std::ostream& os, const ColumnNameList &columnNames)
{
ColumnNameList::const_iterator itr;
os << '(';
for(itr = columnNames.begin();
itr != columnNames.end();
++itr)
{
os << *itr << " ";
}
os << ')';
return os;
}
TableReferencesConstraintDef::~TableReferencesConstraintDef()
{
delete fTableName;
delete fRefAction;
}
}

File diff suppressed because it is too large Load Diff