1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +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

@ -50,22 +50,25 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpacka
std::string defaultSchema /*= ""*/)
{
CalpontDMLPackage* packagePtr = 0;
try
{
std::string dmlStatement = vpackage.get_DMLStatement();
//@Bug 2680. DMLParser is not thread safe.
boost::mutex::scoped_lock lk(fParserLock);
//@Bug 2680. DMLParser is not thread safe.
boost::mutex::scoped_lock lk(fParserLock);
DMLParser parser;
if (defaultSchema.size())
{
{
parser.setDefaultSchema(defaultSchema);
}
}
parser.parse(dmlStatement.c_str());
if (parser.good())
{
const ParseTree &ptree = parser.getParseTree();
const ParseTree& ptree = parser.getParseTree();
SqlStatement* statementPtr = ptree[0];
int dmlStatementType = statementPtr->getStatementType();
@ -75,21 +78,21 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpacka
case DML_INSERT:
packagePtr = new InsertDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID() );
packagePtr->set_SQLStatement(dmlStatement);
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_UPDATE:
packagePtr = new UpdateDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID() );
packagePtr->set_SQLStatement(dmlStatement);
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID() );
packagePtr->set_SQLStatement(dmlStatement);
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
@ -122,32 +125,38 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpacka
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffer(dmlpackage::VendorDMLStatement& vpackage)
{
CalpontDMLPackage* packagePtr = 0;
try
{
int dmlStatementType = vpackage.get_DMLStatementType();
switch (dmlStatementType)
{
case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(),vpackage.get_Columns(), vpackage.get_Rows());
(), vpackage.get_Columns(), vpackage.get_Rows());
break;
case DML_UPDATE:
packagePtr = new UpdateDMLPackage(vpackage.get_SchemaName(),
vpackage.get_TableName(),vpackage.get_DMLStatement(), vpackage.get_SessionID());
vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(),vpackage.get_Columns(), vpackage.get_Rows());
(), vpackage.get_Columns(), vpackage.get_Rows());
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(),
vpackage.get_TableName(),vpackage.get_DMLStatement(), vpackage.get_SessionID());
vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(),vpackage.get_Columns(), vpackage.get_Rows());
(), vpackage.get_Columns(), vpackage.get_Rows());
break;
case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
break;
default:
cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
break;
@ -161,34 +170,40 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffe
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
}
return packagePtr;
}
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage)
{
CalpontDMLPackage* packagePtr = 0;
try
try
{
int dmlStatementType = vpackage.get_DMLStatementType();
switch (dmlStatementType)
{
case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
break;
case DML_COMMAND:
case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
break;
case DML_DELETE:
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID() );
vpackage.get_DMLStatement(), vpackage.get_SessionID() );
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
break;
default:
default:
cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
break;
}
}
}
}
catch (std::exception& ex)
{
cerr << "makeCalpontDMLPackage:" << ex.what() << endl;
@ -197,16 +212,17 @@ dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysql
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
}
return packagePtr;
return packagePtr;
}
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontUpdatePackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage, dmlpackage::UpdateSqlStatement& updateStmt)
{
CalpontDMLPackage* packagePtr = new UpdateDMLPackage((updateStmt.fNamePtr)->fSchema, (updateStmt.fNamePtr)->fName,
vpackage.get_DMLStatement(), vpackage.get_SessionID() );
UpdateDMLPackage* updatePkgPtr = dynamic_cast<UpdateDMLPackage*>(packagePtr);
CalpontDMLPackage* packagePtr = new UpdateDMLPackage((updateStmt.fNamePtr)->fSchema, (updateStmt.fNamePtr)->fName,
vpackage.get_DMLStatement(), vpackage.get_SessionID() );
UpdateDMLPackage* updatePkgPtr = dynamic_cast<UpdateDMLPackage*>(packagePtr);
updatePkgPtr->buildUpdateFromMysqlBuffer(updateStmt);
packagePtr = dynamic_cast<CalpontDMLPackage*>(updatePkgPtr);
return packagePtr;
packagePtr = dynamic_cast<CalpontDMLPackage*>(updatePkgPtr);
return packagePtr;
}
} //namespace dmlpackage

View File

@ -58,14 +58,14 @@ public:
* @param vpackage the VendorDMLStatement
*/
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackageFromBuffer(dmlpackage::VendorDMLStatement& vpackage);
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage);
static dmlpackage::CalpontDMLPackage* makeCalpontUpdatePackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage, dmlpackage::UpdateSqlStatement& updateStmt);
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage);
static dmlpackage::CalpontDMLPackage* makeCalpontUpdatePackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage, dmlpackage::UpdateSqlStatement& updateStmt);
protected:
private:
static boost::mutex fParserLock;
static boost::mutex fParserLock;
};
}

View File

@ -26,59 +26,62 @@ using namespace std;
namespace dmlpackage
{
/**
* Constructors/Destructors
*/
/**
* Constructors/Destructors
*/
CalpontDMLPackage::CalpontDMLPackage()
:fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(0), fLogging(true), fIsInsertSelect(false), fIsBatchInsert(false), fIsAutocommitOn(false), fTableOid(0)
CalpontDMLPackage::CalpontDMLPackage()
: fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(0), fLogging(true), fIsInsertSelect(false), fIsBatchInsert(false), fIsAutocommitOn(false), fTableOid(0)
{
}
CalpontDMLPackage::CalpontDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID )
: fSchemaName(schemaName), fTableName( tableName ), fDMLStatement( dmlStatement ),
fSessionID(sessionID), fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(false), fLogging(true), fIsInsertSelect(false),
fIsBatchInsert(false), fIsAutocommitOn(false), fIsWarnToError(false), fTableOid(0)
{
}
CalpontDMLPackage::~CalpontDMLPackage()
{
if ( 0 != fTable )
delete fTable;
}
/*
* strip off whitespaces from a string
*/
std::string CalpontDMLPackage::StripLeadingWhitespace( std::string value )
{
for (;;)
{
string::size_type pos = value.find (' ', 0);
}
CalpontDMLPackage::CalpontDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID )
:fSchemaName(schemaName), fTableName( tableName ), fDMLStatement( dmlStatement ),
fSessionID(sessionID), fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(false), fLogging(true), fIsInsertSelect(false),
fIsBatchInsert(false), fIsAutocommitOn(false), fIsWarnToError(false), fTableOid(0)
{
}
CalpontDMLPackage::~CalpontDMLPackage()
{
if ( 0 != fTable )
delete fTable;
}
/*
* strip off whitespaces from a string
*/
std::string CalpontDMLPackage::StripLeadingWhitespace( std::string value )
{
for(;;)
if (pos == 0)
{
string::size_type pos = value.find (' ',0);
if (pos == 0)
{
value = value.substr (pos+1,10000);
}
else
{ // no more whitespace
break;
}
value = value.substr (pos + 1, 10000);
}
return value;
}
void CalpontDMLPackage::initializeTable()
{
if (0 == fTable)
else
{
fTable = new DMLTable();
fTable->set_SchemaName(fSchemaName);
fTable->set_TableName(fTableName);
// no more whitespace
break;
}
}
return value;
}
void CalpontDMLPackage::initializeTable()
{
if (0 == fTable)
{
fTable = new DMLTable();
fTable->set_SchemaName(fSchemaName);
fTable->set_TableName(fTableName);
}
}
} // namespace dmlpackage

View File

@ -36,231 +36,335 @@
namespace dmlpackage
{
/** @brief abstract class that defines the general interface and
* implemetation of a CalpontDMLPackage
/** @brief abstract class that defines the general interface and
* implemetation of a CalpontDMLPackage
*/
class CalpontDMLPackage
{
public:
/** @brief ctor
*/
class CalpontDMLPackage
CalpontDMLPackage();
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session id
*/
CalpontDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief dtor
*/
virtual ~CalpontDMLPackage();
/** @brief write a CalpontDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
virtual int write( messageqcpp::ByteStream& bytestream ) = 0;
/** @brief read a CalpontDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
virtual int read( messageqcpp::ByteStream& bytestream ) = 0;
/** @brief build a CalpontDMLPackage from a string buffer
*
* @param buffer the row buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
virtual int buildFromBuffer( std::string& buffer, int columns, int rows ) = 0;
/** @brief build a CalpontDMLPackage from a parsed SqlStatement
*
* @param sqlStatement the parsed SqlStatement
*/
virtual int buildFromSqlStatement( SqlStatement& sqlStatement ) = 0;
/** @brief build a CalpontDMLPackage from valuelist built from mysql table fields
*
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
*/
virtual int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues) = 0;
/** @brief get the table object
*/
DMLTable* get_Table()
{
return fTable;
}
public:
/** @brief ctor
*/
CalpontDMLPackage();
/** @brief set the DML statement (the parsed statement)
*
* @param statement the dml statement to set
*/
void set_DMLStatement( const std::string& statement )
{
fDMLStatement = statement;
}
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session id
*/
CalpontDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief get the DML statement (the parsed statement)
*/
const std::string get_DMLStatement() const
{
return fDMLStatement;
}
/** @brief dtor
*/
virtual ~CalpontDMLPackage();
/** @brief set the SQL statement (the original SQL statement)
*
* @param statement the SQL statement to set (the original SQL statement with quotes)
*/
void set_SQLStatement( const std::string& statement )
{
fSQLStatement = statement;
}
/** @brief write a CalpontDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
virtual int write( messageqcpp::ByteStream& bytestream ) = 0;
/** @brief get the SQL statement (the original SQL statement)
*/
const std::string get_SQLStatement() const
{
return fSQLStatement;
}
/** @brief read a CalpontDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
virtual int read( messageqcpp::ByteStream& bytestream ) = 0;
/** @brief get the logging flag
*/
const bool get_Logging() const
{
return fLogging;
}
/** @brief build a CalpontDMLPackage from a string buffer
*
* @param buffer the row buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
virtual int buildFromBuffer( std::string& buffer, int columns, int rows ) = 0;
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
void set_Logging( bool logging )
{
fLogging = logging;
}
/** @brief build a CalpontDMLPackage from a parsed SqlStatement
*
* @param sqlStatement the parsed SqlStatement
*/
virtual int buildFromSqlStatement( SqlStatement& sqlStatement ) = 0;
/** @brief get the logending flag
*/
const bool get_Logending() const
{
return fLogending;
}
/** @brief build a CalpontDMLPackage from valuelist built from mysql table fields
*
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
*/
virtual int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues) = 0;
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
void set_Logending( bool logending )
{
fLogending = logending;
}
/** @brief get the table object
*/
DMLTable* get_Table() { return fTable; }
/** @brief get the isFromCol flag
*/
const bool get_IsFromCol() const
{
return fIsFromCol;
}
/** @brief set the DML statement (the parsed statement)
*
* @param statement the dml statement to set
*/
void set_DMLStatement( const std::string& statement ) { fDMLStatement = statement; }
/** @brief set the update column from column flag
*
* @param logging the logging flag to set
*/
void set_IsFromCol ( bool isFromCol )
{
fIsFromCol = isFromCol;
}
/** @brief set the Table name
*
* @param tableName the name to set
*/
void set_TableName( std::string& tableName )
{
fTableName = tableName;
/** @brief get the DML statement (the parsed statement)
*/
const std::string get_DMLStatement() const { return fDMLStatement; }
if (fTable != 0)
fTable->set_TableName(tableName);
}
/** @brief set the SQL statement (the original SQL statement)
*
* @param statement the SQL statement to set (the original SQL statement with quotes)
*/
void set_SQLStatement( const std::string& statement ) { fSQLStatement = statement; }
/** @brief get the Table name
*/
const std::string get_TableName() const
{
return fTableName;
}
/** @brief get the SQL statement (the original SQL statement)
*/
const std::string get_SQLStatement() const { return fSQLStatement; }
/** @brief set the Schema name
*
* @param the schema to set
*/
void set_SchemaName( std::string& schemaName )
{
fSchemaName = schemaName;
/** @brief get the logging flag
*/
const bool get_Logging() const { return fLogging; }
if (fTable != 0)
fTable->set_SchemaName(schemaName);
}
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
void set_Logging( bool logging ) { fLogging = logging; }
/** @brief get the Schema name
*/
const std::string get_SchemaName() const
{
return fSchemaName;
}
/** @brief get the logending flag
*/
const bool get_Logending() const { return fLogending; }
/** @brief does this dml statement have a filter
*/
bool HasFilter() const
{
return fHasFilter;
}
void HasFilter( bool hasFilter)
{
fHasFilter = hasFilter;
}
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
void set_Logending( bool logending ) { fLogending = logending; }
/** @brief get the filter statement
*/
const std::string get_QueryString() const
{
return fQueryString;
}
/** @brief get the isFromCol flag
*/
const bool get_IsFromCol() const { return fIsFromCol; }
/** @brief set the sessionID associated with this package
*/
void set_SessionID( int sessionID )
{
fSessionID = sessionID;
}
/** @brief set the update column from column flag
*
* @param logging the logging flag to set
*/
void set_IsFromCol ( bool isFromCol ) { fIsFromCol = isFromCol; }
/** @brief set the Table name
*
* @param tableName the name to set
*/
void set_TableName( std::string& tableName )
{
fTableName = tableName;
if(fTable != 0)
fTable->set_TableName(tableName);
}
/** @brief get the sessionID associated with this package
*/
int get_SessionID() const
{
return fSessionID;
}
/** @brief get the Table name
*/
const std::string get_TableName() const { return fTableName; }
/** @brief set the transaction ID associated with this package
*/
void set_TxnID( execplan::CalpontSystemCatalog::SCN txnID )
{
fTxnId = txnID;
}
/** @brief set the Schema name
*
* @param the schema to set
*/
void set_SchemaName( std::string& schemaName )
{
fSchemaName = schemaName;
if(fTable != 0)
fTable->set_SchemaName(schemaName);
}
/** @brief get the transaction ID associated with this package
*/
execplan::CalpontSystemCatalog::SCN get_TxnID() const
{
return fTxnId;
}
/** @brief set the chunkmanager associated with this package
*/
void set_ChunkManager( WriteEngine::ChunkManager* cm )
{
fCM = cm;
}
/** @brief get the Schema name
*/
const std::string get_SchemaName() const { return fSchemaName; }
/** @brief get the chunkmanager associated with this package
*/
WriteEngine::ChunkManager* get_ChunkManager() const
{
return fCM;
}
/** @brief does this dml statement have a filter
*/
bool HasFilter() const { return fHasFilter; }
void HasFilter( bool hasFilter) { fHasFilter = hasFilter; }
/** @brief get the ExecutionPlan associated with this package
*/
boost::shared_ptr<messageqcpp::ByteStream> get_ExecutionPlan()
{
return fPlan;
}
/** @brief get the filter statement
*/
const std::string get_QueryString() const { return fQueryString; }
bool get_isInsertSelect()
{
return fIsInsertSelect;
}
void set_isInsertSelect( const bool isInsertSelect )
{
fIsInsertSelect = isInsertSelect;
}
/** @brief set the sessionID associated with this package
*/
void set_SessionID( int sessionID ) { fSessionID = sessionID; }
bool get_isBatchInsert()
{
return fIsBatchInsert;
}
void set_isBatchInsert( const bool isBatchInsert )
{
fIsBatchInsert = isBatchInsert;
}
/** @brief get the sessionID associated with this package
*/
int get_SessionID() const { return fSessionID; }
bool get_isAutocommitOn()
{
return fIsAutocommitOn;
}
void set_isAutocommitOn( const bool isAutocommitOn )
{
fIsAutocommitOn = isAutocommitOn;
}
/** @brief set the transaction ID associated with this package
*/
void set_TxnID( execplan::CalpontSystemCatalog::SCN txnID ) { fTxnId = txnID; }
bool get_isWarnToError()
{
return fIsWarnToError;
}
void set_isWarnToError( const bool isWarnToError )
{
fIsWarnToError = isWarnToError;
}
/** @brief get the transaction ID associated with this package
*/
execplan::CalpontSystemCatalog::SCN get_TxnID() const { return fTxnId; }
/** @brief set the chunkmanager associated with this package
*/
void set_ChunkManager( WriteEngine::ChunkManager* cm ) { fCM = cm; }
uint32_t getTableOid()
{
return fTableOid;
}
void setTableOid( const uint32_t tableOid )
{
fTableOid = tableOid;
}
/** @brief get the chunkmanager associated with this package
*/
WriteEngine::ChunkManager* get_ChunkManager() const { return fCM; }
void uuid(const boost::uuids::uuid& uuid)
{
fUuid = uuid;
}
const boost::uuids::uuid& uuid() const
{
return fUuid;
}
/** @brief get the ExecutionPlan associated with this package
*/
boost::shared_ptr<messageqcpp::ByteStream> get_ExecutionPlan()
{
return fPlan;
}
protected:
bool get_isInsertSelect() { return fIsInsertSelect; }
void set_isInsertSelect( const bool isInsertSelect ) { fIsInsertSelect = isInsertSelect; }
void initializeTable();
bool get_isBatchInsert() { return fIsBatchInsert; }
void set_isBatchInsert( const bool isBatchInsert ) { fIsBatchInsert = isBatchInsert; }
bool get_isAutocommitOn() { return fIsAutocommitOn; }
void set_isAutocommitOn( const bool isAutocommitOn ) { fIsAutocommitOn = isAutocommitOn; }
bool get_isWarnToError() { return fIsWarnToError; }
void set_isWarnToError( const bool isWarnToError ) { fIsWarnToError = isWarnToError; }
uint32_t getTableOid() { return fTableOid; }
void setTableOid( const uint32_t tableOid ) { fTableOid = tableOid; }
void uuid(const boost::uuids::uuid& uuid) { fUuid = uuid; }
const boost::uuids::uuid& uuid() const { return fUuid; }
protected:
void initializeTable();
std::string fSchemaName;
std::string fTableName;
std::string fDMLStatement;
std::string fSQLStatement;
std::string fQueryString;
int fSessionID;
boost::uuids::uuid fUuid;
execplan::CalpontSystemCatalog::SCN fTxnId;
boost::shared_ptr<messageqcpp::ByteStream> fPlan;
DMLTable *fTable;
bool fHasFilter;
bool fLogging;
bool fLogending;
bool fIsFromCol;
std::string StripLeadingWhitespace( std::string value );
bool fIsInsertSelect;
bool fIsBatchInsert;
bool fIsAutocommitOn;
bool fIsWarnToError;
uint32_t fTableOid;
WriteEngine::ChunkManager* fCM;
};
std::string fSchemaName;
std::string fTableName;
std::string fDMLStatement;
std::string fSQLStatement;
std::string fQueryString;
int fSessionID;
boost::uuids::uuid fUuid;
execplan::CalpontSystemCatalog::SCN fTxnId;
boost::shared_ptr<messageqcpp::ByteStream> fPlan;
DMLTable* fTable;
bool fHasFilter;
bool fLogging;
bool fLogending;
bool fIsFromCol;
std::string StripLeadingWhitespace( std::string value );
bool fIsInsertSelect;
bool fIsBatchInsert;
bool fIsAutocommitOn;
bool fIsWarnToError;
uint32_t fTableOid;
WriteEngine::ChunkManager* fCM;
};
}
#endif //CALPONTDMLPACKAGE_H

View File

@ -32,67 +32,67 @@ using namespace std;
namespace dmlpackage
{
CommandDMLPackage::CommandDMLPackage()
{}
CommandDMLPackage::CommandDMLPackage()
{}
CommandDMLPackage::CommandDMLPackage( std::string dmlStatement, int sessionID)
:CalpontDMLPackage( "", "", dmlStatement, sessionID)
{}
CommandDMLPackage::CommandDMLPackage( std::string dmlStatement, int sessionID)
: CalpontDMLPackage( "", "", dmlStatement, sessionID)
{}
CommandDMLPackage::~CommandDMLPackage()
{}
CommandDMLPackage::~CommandDMLPackage()
{}
int CommandDMLPackage::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int CommandDMLPackage::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_COMMAND;
bytestream << package_type;
messageqcpp::ByteStream::byte package_type = DML_COMMAND;
bytestream << package_type;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
bytestream << fUuid;
bytestream << fUuid;
bytestream << fDMLStatement;
bytestream << fSQLStatement; // for cleartablelock, this is table lockID
bytestream << (uint8_t)fLogging;
bytestream << fSchemaName;
bytestream << fTableName;
bytestream << fTableOid;
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsAutocommitOn);
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert);
return retval;
}
bytestream << fDMLStatement;
bytestream << fSQLStatement; // for cleartablelock, this is table lockID
bytestream << (uint8_t)fLogging;
bytestream << fSchemaName;
bytestream << fTableName;
bytestream << fTableOid;
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsAutocommitOn);
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert);
return retval;
}
int CommandDMLPackage::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int CommandDMLPackage::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement; // for cleartablelock, this is table lockID
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
bytestream >> fSchemaName;
bytestream >> fTableName;
bytestream >> fTableOid;
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsBatchInsert);
return retval;
}
bytestream >> fDMLStatement;
bytestream >> fSQLStatement; // for cleartablelock, this is table lockID
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
bytestream >> fSchemaName;
bytestream >> fTableName;
bytestream >> fTableOid;
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsBatchInsert);
return retval;
}
int CommandDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
CommandSqlStatement& cmdStmt = dynamic_cast<CommandSqlStatement&>(sqlStatement);
fDMLStatement = cmdStmt.fCommandText;
int CommandDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
CommandSqlStatement& cmdStmt = dynamic_cast<CommandSqlStatement&>(sqlStatement);
fDMLStatement = cmdStmt.fCommandText;
return 1;
}
return 1;
}
} // namespace dmlpackage

View File

@ -36,67 +36,67 @@
namespace dmlpackage
{
/** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing COMMAND DML Statements
/** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing COMMAND DML Statements
*/
class CommandDMLPackage : public CalpontDMLPackage
{
public:
/** @brief ctor
*/
class CommandDMLPackage : public CalpontDMLPackage
EXPORT CommandDMLPackage();
/** @brief ctor
*/
EXPORT CommandDMLPackage( std::string dmlStatement, int sessionID );
/** @brief dtor
*/
EXPORT virtual ~CommandDMLPackage();
/** @brief write a CommandDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief read CommandDMLPackage from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief do nothing
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
inline int buildFromBuffer(std::string& buffer, int columns = 0, int rows = 0)
{
public:
/** @brief ctor
*/
EXPORT CommandDMLPackage();
/** @brief ctor
*/
EXPORT CommandDMLPackage( std::string dmlStatement, int sessionID );
/** @brief dtor
*/
EXPORT virtual ~CommandDMLPackage();
/** @brief write a CommandDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief read CommandDMLPackage from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief do nothing
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
inline int buildFromBuffer(std::string& buffer, int columns=0, int rows=0)
{
return 1;
};
/** @brief build a CommandDMLPackage from a CommandSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues)
{
return 1;
};
protected:
private:
return 1;
};
/** @brief build a CommandDMLPackage from a CommandSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues)
{
return 1;
};
protected:
private:
};
}
#undef EXPORT

View File

@ -38,7 +38,7 @@ DeleteDMLPackage::DeleteDMLPackage()
DeleteDMLPackage::DeleteDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID)
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
{}
DeleteDMLPackage::~DeleteDMLPackage()
@ -54,11 +54,11 @@ int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
/* if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
/* if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter;
@ -67,11 +67,13 @@ int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
bytestream << fDMLStatement;
bytestream << fSQLStatement;
bytestream << fSchemaName;
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
if(fHasFilter)
if (fHasFilter)
{
bytestream += *(fPlan.get());
}
@ -103,9 +105,10 @@ int DeleteDMLPackage::read(messageqcpp::ByteStream& bytestream)
fTable = new DMLTable();
retval = fTable->read(bytestream);
if(fHasFilter)
if (fHasFilter)
{
fPlan.reset(new messageqcpp::ByteStream(bytestream));
fPlan.reset(new messageqcpp::ByteStream(bytestream));
}
return retval;
@ -124,6 +127,7 @@ int DeleteDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
fHasFilter = true;
fQueryString = deleteStmt.getQueryString();
}
// else all rows are deleted
return retval;
@ -146,6 +150,7 @@ int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":");
tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
@ -153,7 +158,8 @@ int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
}
int n = 0;
for (int i=0; i < rows; i++)
for (int i = 0; i < rows; i++)
{
//get a new row
Row aRow;
@ -195,21 +201,21 @@ int DeleteDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
initializeTable();
//The row already built from MySql parser.
/* Row *aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
/* Row *aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
colValList = tableValuesMap[j];
colValList = tableValuesMap[j];
DMLColumn* aColumn = new DMLColumn(colName, colValList, false);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr); */
DMLColumn* aColumn = new DMLColumn(colName, colValList, false);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr); */
return retval;
}

View File

@ -36,69 +36,69 @@
namespace dmlpackage
{
/** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing DELETE DML Statements
/** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing DELETE DML Statements
*/
class DeleteDMLPackage : public CalpontDMLPackage
{
public:
/** @brief ctor
*/
class DeleteDMLPackage : public CalpontDMLPackage
{
EXPORT DeleteDMLPackage();
public:
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT DeleteDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief ctor
*/
EXPORT DeleteDMLPackage();
/** @brief dtor
*/
EXPORT virtual ~DeleteDMLPackage();
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT DeleteDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief write a DeleteDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief dtor
*/
EXPORT virtual ~DeleteDMLPackage();
/** @brief read a DeleteDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief write a DeleteDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief build a DeleteDMLPackage from a string buffer
*
* @param buffer [rowId, columnName, colValue]
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief read a DeleteDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief build a DeleteDMLPackage from a parsed DeleteSqlStatement
*
* @param sqlStatement the parsed DeleteSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
/** @brief build a DeleteDMLPackage from a string buffer
*
* @param buffer [rowId, columnName, colValue]
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
protected:
/** @brief build a DeleteDMLPackage from a parsed DeleteSqlStatement
*
* @param sqlStatement the parsed DeleteSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
private:
protected:
private:
};
};
}
#undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@ -1,182 +1,183 @@
/* 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 {
NAME = 258,
STRING = 259,
INTNUM = 260,
APPROXNUM = 261,
SELECT = 262,
ALL = 263,
DISTINCT = 264,
NULLX = 265,
USER = 266,
INDICATOR = 267,
AMMSC = 268,
PARAMETER = 269,
ANY = 270,
SOME = 271,
OR = 272,
AND = 273,
NOT = 274,
COMPARISON = 275,
UMINUS = 276,
AS = 277,
ASC = 278,
AUTHORIZATION = 279,
BETWEEN = 280,
BY = 281,
CHARACTER = 282,
CHECK = 283,
CLOSE = 284,
COMMIT = 285,
CONTINUE = 286,
CREATE = 287,
CURRENT = 288,
CURSOR = 289,
IDB_DECIMAL = 290,
DECLARE = 291,
DEFAULT = 292,
DELETE = 293,
DESC = 294,
IDB_DOUBLE = 295,
ESCAPE = 296,
EXISTS = 297,
FETCH = 298,
IDB_FLOAT = 299,
FOR = 300,
FOREIGN = 301,
FOUND = 302,
FROM = 303,
GOTO = 304,
GRANT = 305,
IDB_GROUP = 306,
HAVING = 307,
IN = 308,
INSERT = 309,
INTEGER = 310,
INTO = 311,
IS = 312,
KEY = 313,
LANGUAGE = 314,
LIKE = 315,
NUMERIC = 316,
OF = 317,
ON = 318,
OPEN = 319,
OPTION = 320,
ORDER = 321,
PRECISION = 322,
PRIMARY = 323,
PRIVILEGES = 324,
PROCEDURE = 325,
PUBLIC = 326,
REAL = 327,
REFERENCES = 328,
ROLLBACK = 329,
SCHEMA = 330,
SET = 331,
SMALLINT = 332,
SQLCODE = 333,
SQLERROR = 334,
TABLE = 335,
TO = 336,
UNION = 337,
UNIQUE = 338,
UPDATE = 339,
VALUES = 340,
VIEW = 341,
WHENEVER = 342,
WHERE = 343,
WITH = 344,
WORK = 345
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
int intval;
double floatval;
char *strval;
int subtok;
dmlpackage::SqlStatementList *sqlStmtList;
dmlpackage::SqlStatement *sqlStmt;
dmlpackage::TableName* tblName;
dmlpackage::ColumnNameList* colNameList;
dmlpackage::ValuesOrQuery* valsOrQuery;
dmlpackage::ValuesList* valsList;
dmlpackage::QuerySpec* querySpec;
dmlpackage::TableNameList* tableNameList;
dmlpackage::TableExpression* tableExpression;
dmlpackage::WhereClause* whereClause;
dmlpackage::SearchCondition* searchCondition;
dmlpackage::ExistanceTestPredicate* existPredicate;
dmlpackage::AllOrAnyPredicate* allOrAnyPredicate;
dmlpackage::InPredicate* inPredicate;
dmlpackage::NullTestPredicate* nullTestPredicate;
dmlpackage::LikePredicate* likePredicate;
dmlpackage::BetweenPredicate* betweenPredicate;
dmlpackage::ComparisonPredicate* comparisonPredicate;
dmlpackage::Predicate* predicate;
dmlpackage::FromClause* fromClause;
dmlpackage::SelectFilter* selectFilter;
dmlpackage::GroupByClause* groupByClause;
dmlpackage::HavingClause* havingClause;
dmlpackage::Escape* escape;
dmlpackage::AtomList* atomList;
dmlpackage::ColumnAssignment* colAssignment;
dmlpackage::ColumnAssignmentList* colAssignmentList;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE dmllval;
/* 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
{
NAME = 258,
STRING = 259,
INTNUM = 260,
APPROXNUM = 261,
SELECT = 262,
ALL = 263,
DISTINCT = 264,
NULLX = 265,
USER = 266,
INDICATOR = 267,
AMMSC = 268,
PARAMETER = 269,
ANY = 270,
SOME = 271,
OR = 272,
AND = 273,
NOT = 274,
COMPARISON = 275,
UMINUS = 276,
AS = 277,
ASC = 278,
AUTHORIZATION = 279,
BETWEEN = 280,
BY = 281,
CHARACTER = 282,
CHECK = 283,
CLOSE = 284,
COMMIT = 285,
CONTINUE = 286,
CREATE = 287,
CURRENT = 288,
CURSOR = 289,
IDB_DECIMAL = 290,
DECLARE = 291,
DEFAULT = 292,
DELETE = 293,
DESC = 294,
IDB_DOUBLE = 295,
ESCAPE = 296,
EXISTS = 297,
FETCH = 298,
IDB_FLOAT = 299,
FOR = 300,
FOREIGN = 301,
FOUND = 302,
FROM = 303,
GOTO = 304,
GRANT = 305,
IDB_GROUP = 306,
HAVING = 307,
IN = 308,
INSERT = 309,
INTEGER = 310,
INTO = 311,
IS = 312,
KEY = 313,
LANGUAGE = 314,
LIKE = 315,
NUMERIC = 316,
OF = 317,
ON = 318,
OPEN = 319,
OPTION = 320,
ORDER = 321,
PRECISION = 322,
PRIMARY = 323,
PRIVILEGES = 324,
PROCEDURE = 325,
PUBLIC = 326,
REAL = 327,
REFERENCES = 328,
ROLLBACK = 329,
SCHEMA = 330,
SET = 331,
SMALLINT = 332,
SQLCODE = 333,
SQLERROR = 334,
TABLE = 335,
TO = 336,
UNION = 337,
UNIQUE = 338,
UPDATE = 339,
VALUES = 340,
VIEW = 341,
WHENEVER = 342,
WHERE = 343,
WITH = 344,
WORK = 345
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
int intval;
double floatval;
char* strval;
int subtok;
dmlpackage::SqlStatementList* sqlStmtList;
dmlpackage::SqlStatement* sqlStmt;
dmlpackage::TableName* tblName;
dmlpackage::ColumnNameList* colNameList;
dmlpackage::ValuesOrQuery* valsOrQuery;
dmlpackage::ValuesList* valsList;
dmlpackage::QuerySpec* querySpec;
dmlpackage::TableNameList* tableNameList;
dmlpackage::TableExpression* tableExpression;
dmlpackage::WhereClause* whereClause;
dmlpackage::SearchCondition* searchCondition;
dmlpackage::ExistanceTestPredicate* existPredicate;
dmlpackage::AllOrAnyPredicate* allOrAnyPredicate;
dmlpackage::InPredicate* inPredicate;
dmlpackage::NullTestPredicate* nullTestPredicate;
dmlpackage::LikePredicate* likePredicate;
dmlpackage::BetweenPredicate* betweenPredicate;
dmlpackage::ComparisonPredicate* comparisonPredicate;
dmlpackage::Predicate* predicate;
dmlpackage::FromClause* fromClause;
dmlpackage::SelectFilter* selectFilter;
dmlpackage::GroupByClause* groupByClause;
dmlpackage::HavingClause* havingClause;
dmlpackage::Escape* escape;
dmlpackage::AtomList* atomList;
dmlpackage::ColumnAssignment* colAssignment;
dmlpackage::ColumnAssignmentList* colAssignmentList;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE dmllval;

File diff suppressed because it is too large Load Diff

View File

@ -40,14 +40,16 @@ DMLColumn::DMLColumn(std::string name, std::string value, bool isFromCol, uint32
{
fName = name;
fData = value;
if (( strcasecmp(value.c_str(), "NULL") == 0) || (value.length() == 0) )
{
isNULL = true;
}
isNULL = true;
}
fisNULL = isNULL;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
}
DMLColumn::DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol, uint32_t funcScale, bool isNULL)
@ -55,8 +57,8 @@ DMLColumn::DMLColumn(std::string name, std::vector<std::string>& valueList, bool
fName = name;
fColValuesList = valueList;
fisNULL = isNULL;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
}
DMLColumn::~DMLColumn()
@ -66,30 +68,32 @@ int DMLColumn::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
bytestream >> fName;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
uint32_t vectorSize;
bytestream >> vectorSize;
if (vectorSize > 0 )
{
for ( uint32_t i = 0; i < vectorSize; i++ )
{
std::string dataStr;
bytestream >> dataStr;
// if ( !fisNULL && (dataStr.length() == 0 ))
// dataStr = (char) 0;
fColValuesList.push_back( dataStr);
}
}
else
bytestream >> fData; //deprecated.
if ( (fColValuesList.size() <1) && (fColValuesList.size() > 0) ) //deprecated.
fData =fColValuesList[0] ; //deprecated.
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
uint32_t vectorSize;
bytestream >> vectorSize;
if (vectorSize > 0 )
{
for ( uint32_t i = 0; i < vectorSize; i++ )
{
std::string dataStr;
bytestream >> dataStr;
// if ( !fisNULL && (dataStr.length() == 0 ))
// dataStr = (char) 0;
fColValuesList.push_back( dataStr);
}
}
else
bytestream >> fData; //deprecated.
if ( (fColValuesList.size() < 1) && (fColValuesList.size() > 0) ) //deprecated.
fData = fColValuesList[0] ; //deprecated.
//bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsFromCol);
bytestream >> (uint32_t&) fFuncScale;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsFromCol);
bytestream >> (uint32_t&) fFuncScale;
return retval;
}
@ -97,22 +101,24 @@ int DMLColumn::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
bytestream << fName;
bytestream << static_cast<uint8_t>(fisNULL);
uint32_t vectorSize = fColValuesList.size();
bytestream << vectorSize;
if (vectorSize > 0 )
{
for ( uint32_t i = 0; i < vectorSize; i++ )
{
bytestream << fColValuesList[i];
}
}
else
bytestream << fData; //deprecated.
bytestream << static_cast<uint8_t>(fisNULL);
uint32_t vectorSize = fColValuesList.size();
bytestream << vectorSize;
if (vectorSize > 0 )
{
for ( uint32_t i = 0; i < vectorSize; i++ )
{
bytestream << fColValuesList[i];
}
}
else
bytestream << fData; //deprecated.
//bytestream << static_cast<uint8_t>(fisNULL);
bytestream << static_cast<uint8_t>(fIsFromCol);
bytestream <<(uint32_t)fFuncScale;
bytestream << static_cast<uint8_t>(fIsFromCol);
bytestream << (uint32_t)fFuncScale;
return retval;
}

View File

@ -52,80 +52,110 @@ public:
/** @brief ctor
*/
EXPORT DMLColumn(std::string name, std::string value, bool isFromCol = false, uint32_t funcScale=0, bool isNULL=false);
/** @brief new ctor
* isNUll is currently not in use. It supposed to indicate whether each value is null or not.
EXPORT DMLColumn(std::string name, std::string value, bool isFromCol = false, uint32_t funcScale = 0, bool isNULL = false);
/** @brief new ctor
* isNUll is currently not in use. It supposed to indicate whether each value is null or not.
*/
EXPORT DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol = false, uint32_t funcScale=0, bool isNULL=false );
EXPORT DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol = false, uint32_t funcScale = 0, bool isNULL = false );
/** @brief dtor
*/
EXPORT ~DMLColumn();
/** @brief read a DMLColumn from a ByteStream
*
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief write a DML column to a ByteStream
*
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief get the data for the column
*/
const std::string get_Data() const { return fData; }
const std::vector<std::string>& get_DataVector() const { return fColValuesList; }
const std::string get_Data() const
{
return fData;
}
/** @brief get the data for the column
const std::vector<std::string>& get_DataVector() const
{
return fColValuesList;
}
/** @brief get the data for the column
*/
const bool get_isnull() const
{
return fisNULL;
}
/** @brief get the fIsFromCol data for the column
*/
const bool get_isnull() const { return fisNULL; }
/** @brief get the fIsFromCol data for the column
const bool get_isFromCol() const
{
return fIsFromCol;
}
/** @brief get the fFuncScale data for the column
*/
const bool get_isFromCol() const { return fIsFromCol; }
/** @brief get the fFuncScale data for the column
*/
const uint32_t get_funcScale() const { return fFuncScale; }
const uint32_t get_funcScale() const
{
return fFuncScale;
}
/** @brief get the column name
*/
const std::string get_Name() const { return fName; }
const std::string get_Name() const
{
return fName;
}
/** @brief set the column name
*/
EXPORT void set_Name( std::string name)
{ boost::algorithm::to_lower(name);
fName = name; }
EXPORT void set_Name( std::string name)
{
boost::algorithm::to_lower(name);
fName = name;
}
/** @brief set the NULL flag
*/
void set_isnull( bool isNULL)
{ fisNULL = isNULL; }
/** @brief set the fIsFromCol flag
void set_isnull( bool isNULL)
{
fisNULL = isNULL;
}
/** @brief set the fIsFromCol flag
*/
void set_isFromCol( bool isFromCol)
{ fIsFromCol = isFromCol; }
/** @brief set the fFuncScale
void set_isFromCol( bool isFromCol)
{
fIsFromCol = isFromCol;
}
/** @brief set the fFuncScale
*/
void set_funcScale( uint32_t funcScale)
{ fFuncScale = funcScale; }
void set_funcScale( uint32_t funcScale)
{
fFuncScale = funcScale;
}
void set_Data ( std::string data)
{ fData = data; }
void set_DataVector ( std::vector<std::string>& dataVec)
{ fColValuesList = dataVec; }
{
fData = data;
}
void set_DataVector ( std::vector<std::string>& dataVec)
{
fColValuesList = dataVec;
}
protected:
private:
std::string fName;
std::string fData;
std::vector<std::string> fColValuesList;
std::vector<std::string> fColValuesList;
bool fisNULL;
bool fIsFromCol;
uint32_t fFuncScale;
bool fIsFromCol;
uint32_t fFuncScale;
};

View File

@ -23,7 +23,8 @@
#include "dmlobject.h"
namespace dmlpackage {
namespace dmlpackage
{
DMLObject::DMLObject()
{

View File

@ -49,13 +49,13 @@ public:
virtual ~DMLObject();
/** @brief read a DMLObject from a ByteStream
*
*
* @param bytestream the ByteStream to read from
*/
virtual int read(messageqcpp::ByteStream& bytestream) = 0;
/** @brief write a DMLObject to a ByteStream
*
*
* @param bytestream the ByteStream to write to
*/
virtual int write(messageqcpp::ByteStream& bytestream) = 0;

View File

@ -29,10 +29,10 @@
namespace dmlpackage
{
#define DML_DEBUG 0 // debug flag 0 for off, 1 for on
#define DML_DEBUG 0 // debug flag 0 for off, 1 for on
const std::string nullValue = "nvl";
//const size_t maxThreads = 100;
//const size_t queueSize = 200;
const std::string nullValue = "nvl";
//const size_t maxThreads = 100;
//const size_t queueSize = 200;
} // namespace dmlpackage
#endif //DMLPACKAGE_H

View File

@ -44,119 +44,128 @@ int dmlparse(void* yyscanner);
namespace dmlpackage
{
using namespace std;
using namespace std;
void scanner_finish(void* yyscanner);
void scanner_init(const char *str, void* yyscanner);
void grammar_init(dmlpackage::ParseTree* _ptree, bool);
valbuf_t get_valbuffer(void);
void free_copybuffer();
void set_defaultSchema(std::string schema);
void scanner_finish(void* yyscanner);
void scanner_init(const char* str, void* yyscanner);
void grammar_init(dmlpackage::ParseTree* _ptree, bool);
valbuf_t get_valbuffer(void);
DMLParser::DMLParser() :
void free_copybuffer();
void set_defaultSchema(std::string schema);
DMLParser::DMLParser() :
fStatus(-1), fDebug(false)
{}
{}
DMLParser::~DMLParser()
{
scanner_finish(scanner);
dmllex_destroy(scanner);
}
DMLParser::~DMLParser()
{
scanner_finish(scanner);
dmllex_destroy(scanner);
}
void DMLParser::setDebug(bool debug)
{
fDebug = true;
}
void DMLParser::setDebug(bool debug)
{
fDebug = true;
}
int DMLParser::parse(const char* dmltext)
int DMLParser::parse(const char* dmltext)
{
dmllex_init_extra(&scanData, &scanner);
scanner_init(dmltext, scanner);
grammar_init(&fParseTree, fDebug);
fStatus = dmlparse(scanner);
if (fStatus == 0)
{
dmllex_init_extra(&scanData, &scanner);
scanner_init(dmltext, scanner);
grammar_init(&fParseTree, fDebug);
fStatus = dmlparse(scanner);
if (fStatus == 0)
char* str;
valbuf_t valueBuffer = get_valbuffer();
for (unsigned int i = 0; i < valueBuffer.size(); i++)
{
char* str;
valbuf_t valueBuffer = get_valbuffer();
str = valueBuffer[i];
for(unsigned int i=0; i < valueBuffer.size(); i++)
if (str)
{
str = valueBuffer[i];
if(str)
{
if (i > 0)
fParseTree.fSqlText += " ";
fParseTree.fSqlText += str;
}
if (i > 0)
fParseTree.fSqlText += " ";
fParseTree.fSqlText += str;
}
}
free_copybuffer();
}
free_copybuffer();
return fStatus;
}
const ParseTree& DMLParser::getParseTree()
{
if (!good())
{
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
}
bool DMLParser::good()
{
return fStatus == 0;
}
void DMLParser::setDefaultSchema(std::string schema)
{
set_defaultSchema(schema);
}
DMLFileParser::DMLFileParser()
: DMLParser()
{}
int DMLFileParser::parse(const string& fileName)
{
fStatus = -1;
ifstream ifdml;
ifdml.open(fileName.c_str());
if (!ifdml.is_open())
{
perror(fileName.c_str());
return fStatus;
}
const ParseTree& DMLParser::getParseTree()
{
if (!good())
{
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
char dmlbuf[1024 * 1024];
unsigned length;
ifdml.seekg(0, ios::end);
length = ifdml.tellg();
ifdml.seekg(0, ios::beg);
if (length > sizeof(dmlbuf) - 1)
{
throw length_error("DMLFileParser has file size hard limit of 16K.");
}
bool DMLParser::good()
{
return fStatus == 0;
}
unsigned rcount;
rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1);
void DMLParser::setDefaultSchema(std::string schema)
{
set_defaultSchema(schema);
}
if (rcount < 0)
return fStatus;
DMLFileParser::DMLFileParser()
:DMLParser()
{}
dmlbuf[rcount] = 0;
int DMLFileParser::parse(const string& fileName)
{
fStatus = -1;
// cout << endl << fileName << "(" << rcount << ")" << endl;
//cout << "-----------------------------" << endl;
//cout << dmlbuf << endl;
ifstream ifdml;
ifdml.open(fileName.c_str());
if (!ifdml.is_open())
{
perror(fileName.c_str());
return fStatus;
}
char dmlbuf[1024*1024];
unsigned length;
ifdml.seekg(0, ios::end);
length = ifdml.tellg();
ifdml.seekg(0, ios::beg);
if (length > sizeof(dmlbuf) - 1)
{
throw length_error("DMLFileParser has file size hard limit of 16K.");
}
return DMLParser::parse(dmlbuf);
}
unsigned rcount;
rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1);
if (rcount < 0)
return fStatus;
void end_sql(void)
{
dmlbuf[rcount] = 0;
// cout << endl << fileName << "(" << rcount << ")" << endl;
//cout << "-----------------------------" << endl;
//cout << dmlbuf << endl;
return DMLParser::parse(dmlbuf);
}
void end_sql(void)
{
} /* end_sql */
} /* end_sql */
} // dmlpackage

View File

@ -31,90 +31,90 @@
namespace dmlpackage
{
typedef std::vector<char*> valbuf_t;
typedef std::vector<char*> valbuf_t;
typedef SqlStatementList ParseTree;
// instance data for the parser
typedef std::vector<char*> valbuf_t;
typedef SqlStatementList ParseTree;
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;
};
// instance data for the parser
typedef std::vector<char*> valbuf_t;
/** @brief BISON parser wrapper class
*/
class DMLParser
{
public:
/** @brief ctor
*/
DMLParser();
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;
};
/** @brief dtor
*/
virtual ~DMLParser();
/** @brief parse the supplied dml statement
*
* @param dmltext the dml statement to parse
*/
int parse(const char* dmltext);
/** @brief get the parse tree
*/
const ParseTree& getParseTree();
void setDefaultSchema(std::string schema);
/** @brief was the parse successful
*/
bool good();
/** @brief put the parser in debug mode so as to dump
* diagnostic information
*/
void setDebug(bool debug);
protected:
ParseTree fParseTree;
int fStatus;
bool fDebug;
void* scanner; // yyscan_t * needed for re-entrant flex scanner
scan_data scanData;
private:
};
/** @brief specialization of the DMLParser class
* specifically for reading the dml statement
* from a file
/** @brief BISON parser wrapper class
*/
class DMLParser
{
public:
/** @brief ctor
*/
class DMLFileParser : public DMLParser
{
public:
/** @brief ctor
*/
DMLFileParser();
DMLParser();
/** @brief parse the dml statement contained in the
* supplied file
*
* @param fileName the fully qualified file name to open
* and parse the contents of
*/
int parse(const std::string& fileName);
/** @brief dtor
*/
virtual ~DMLParser();
protected:
/** @brief parse the supplied dml statement
*
* @param dmltext the dml statement to parse
*/
int parse(const char* dmltext);
private:
};
/** @brief get the parse tree
*/
const ParseTree& getParseTree();
void setDefaultSchema(std::string schema);
/** @brief was the parse successful
*/
bool good();
/** @brief put the parser in debug mode so as to dump
* diagnostic information
*/
void setDebug(bool debug);
protected:
ParseTree fParseTree;
int fStatus;
bool fDebug;
void* scanner; // yyscan_t * needed for re-entrant flex scanner
scan_data scanData;
private:
};
/** @brief specialization of the DMLParser class
* specifically for reading the dml statement
* from a file
*/
class DMLFileParser : public DMLParser
{
public:
/** @brief ctor
*/
DMLFileParser();
/** @brief parse the dml statement contained in the
* supplied file
*
* @param fileName the fully qualified file name to open
* and parse the contents of
*/
int parse(const std::string& fileName);
protected:
private:
};
}
#endif // DMLPARSER_H

File diff suppressed because it is too large Load Diff

View File

@ -123,7 +123,7 @@ public:
/** @brief dump to stdout.
*/
virtual std::ostream& put(std::ostream &os) const = 0;
virtual std::ostream& put(std::ostream& os) const = 0;
/** @brief get the query string associated with the
* SqlStatement
@ -225,7 +225,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get a string representation of the query spec
*/
@ -233,7 +233,10 @@ public:
/** @brief get the statement type - DML_INSERT
*/
inline virtual int getStatementType() const { return DML_INSERT; }
inline virtual int getStatementType() const
{
return DML_INSERT;
}
ValuesOrQuery* fValuesOrQueryPtr;
ColumnNameList fColumnList;
@ -267,7 +270,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the
* SET assignment_commalist opt_where_clause
@ -277,7 +280,10 @@ public:
/** @brief get the statement type - DML_UPDATE
*/
inline virtual int getStatementType() const { return DML_UPDATE; }
inline virtual int getStatementType() const
{
return DML_UPDATE;
}
ColumnAssignmentList* fColAssignmentListPtr;
WhereClause* fWhereClausePtr;
@ -309,7 +315,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the WHERE clause
*/
@ -317,7 +323,10 @@ public:
/** @brief get the statement type - DML_DELETE
*/
inline virtual int getStatementType() const { return DML_DELETE; }
inline virtual int getStatementType() const
{
return DML_DELETE;
}
WhereClause* fWhereClausePtr;
};
@ -344,11 +353,14 @@ public:
/** @brief get the statement type - DML_COMMAND
*/
inline virtual int getStatementType() const { return DML_COMMAND; }
inline virtual int getStatementType() const
{
return DML_COMMAND;
}
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the COMMIT or ROLLBACK string
*/
@ -382,7 +394,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
std::string fName;
std::string fSchema;
@ -399,7 +411,7 @@ class ColumnAssignment
public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of
* the column assignment
@ -409,8 +421,8 @@ public:
std::string fColumn;
std::string fOperator;
std::string fScalarExpression;
bool fFromCol;
uint32_t fFuncScale;
bool fFromCol;
uint32_t fFuncScale;
};
/** @brief Stores a value list or a query specification
@ -444,7 +456,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string reperesentation of
* the ValuesList or the QuerySpec
@ -480,7 +492,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string represntation of the SELECT statement
*/
@ -513,7 +525,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the FROM clause
*/
@ -540,7 +552,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the WHERE clause
*/
@ -569,7 +581,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the GROUP BY clause
*/
@ -597,7 +609,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the HAVING clause
*/
@ -618,7 +630,7 @@ class Escape
public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
std::string fEscapeChar;
};
@ -653,7 +665,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @param get the string representation of the predicate
*/
@ -682,7 +694,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the COMPARISON
* predicate
@ -717,7 +729,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the BETWEEN
* predicate
@ -752,7 +764,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the LIKE
* predicate
@ -786,7 +798,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the NULL test
* predicate
@ -820,7 +832,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the IN
* predicate
@ -853,7 +865,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the
* ALL or ANY predicate
@ -886,7 +898,7 @@ public:
/** @brief dump to stdout
*/
virtual std::ostream& put(std::ostream &os) const;
virtual std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the EXISTS
* predicate
@ -919,7 +931,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the striong representation of the
* search condition
@ -965,7 +977,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the
* table expression
@ -1013,7 +1025,7 @@ public:
/** @brief dump to stdout
*/
std::ostream& put(std::ostream &os) const;
std::ostream& put(std::ostream& os) const;
/** @brief get the string representation of the
* query specification

View File

@ -31,21 +31,22 @@ DMLTable::DMLTable()
DMLTable::~DMLTable()
{
try
{
RowList::iterator it = fRows.begin();
while(it != fRows.end())
while (it != fRows.end())
{
delete *it;
it++;
}
}
catch(...)
catch (...)
{
cout << "failed to delete the table rows" << endl;
}
}
int DMLTable::read(messageqcpp::ByteStream& bytestream)
@ -67,6 +68,7 @@ int DMLTable::read(messageqcpp::ByteStream& bytestream)
retval = aRow->read(bytestream);
fRows.push_back(aRow);
}
return retval;
}
@ -82,6 +84,7 @@ int DMLTable::write(messageqcpp::ByteStream& bytestream)
//write the row list
RowList::iterator rowListPtr;
rowListPtr = fRows.begin();
for (; rowListPtr != fRows.end(); ++rowListPtr)
{
retval = (*rowListPtr)->write(bytestream);

View File

@ -51,23 +51,38 @@ public:
/** @brief get the schema name
*/
inline const std::string get_SchemaName() const { return fSchema; }
inline const std::string get_SchemaName() const
{
return fSchema;
}
/** @brief set the schema name
*/
inline void set_SchemaName( std::string& sName ) { fSchema = sName; }
inline void set_SchemaName( std::string& sName )
{
fSchema = sName;
}
/** @brief get the table name
*/
inline const std::string get_TableName() const { return fName; }
inline const std::string get_TableName() const
{
return fName;
}
/** @brief set the table name
*/
inline void set_TableName( std::string& tName ) { fName = tName; }
inline void set_TableName( std::string& tName )
{
fName = tName;
}
/** @brief get the row list
*/
inline RowList& get_RowList() { return fRows; }
inline RowList& get_RowList()
{
return fRows;
}
/** @brief read a DMLTable from a ByteStream
*

View File

@ -37,13 +37,14 @@ int main(int argc, char* argv[])
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");
("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> ();
@ -51,14 +52,15 @@ int main(int argc, char* argv[])
count = vm["count"].as<int>();
DMLFileParser parser;
if (vm.count ("bisond"))
parser.setDebug(true);
parser.parse(sqlfile);
if(parser.good())
if (parser.good())
{
const ParseTree &ptree = parser.getParseTree();
const ParseTree& ptree = parser.getParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
@ -66,8 +68,10 @@ int main(int argc, char* argv[])
cout << ptree;
SqlStatement* statementPtr = ptree[0];
if (statementPtr)
cout << statementPtr->getQueryString();
cout << endl;
}
else

View File

@ -41,7 +41,7 @@ InsertDMLPackage::InsertDMLPackage()
InsertDMLPackage::InsertDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID )
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
{}
InsertDMLPackage::~InsertDMLPackage()
@ -64,10 +64,12 @@ int InsertDMLPackage::write(messageqcpp::ByteStream& bytestream)
bytestream << fSchemaName;
bytestream << (uint8_t)fLogging;
bytestream << (uint8_t)fLogending;
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
bytestream << fTableOid;
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsInsertSelect);
bytestream << static_cast<const messageqcpp::ByteStream::byte>(fIsBatchInsert);
@ -108,7 +110,7 @@ int InsertDMLPackage::read(messageqcpp::ByteStream& bytestream)
int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows)
{
#ifdef DML_PACKAGE_DEBUG
// cout << "The data buffer received: " << buffer << endl;
// cout << "The data buffer received: " << buffer << endl;
#endif
int retval = 1;
@ -118,6 +120,7 @@ int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(",");
tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
@ -125,12 +128,14 @@ int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
}
int n = 0;
for (int i=0; i < rows; i++)
for (int i = 0; i < rows; i++)
{
//get a new row
Row *aRowPtr = new Row();
Row* aRowPtr = new Row();
std::string colName;
std::string colValue;
for (int j = 0; j < columns; j++)
{
//Build a column list
@ -144,6 +149,7 @@ int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
DMLColumn* aColumn = new DMLColumn(colName, colValue, false);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
}
@ -156,19 +162,21 @@ int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
int retval = 1;
initializeTable();
Row *aRowPtr = new Row();
Row* aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
//Build a column list
colName = colNameList[j];
colValList = tableValuesMap[j];
colValList = tableValuesMap[j];
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
aRowPtr = NULL;
@ -188,6 +196,7 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
initializeTable();
bool isNULL = false;
// only if we don't have a select statement
if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr)
{
@ -198,16 +207,20 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
if (columnNameList.size() != valuesList.size())
{
throw logic_error("Column names and values count mismatch!");
}
Row* aRow = new Row();
for (unsigned int i = 0; i < columnNameList.size(); i++)
{
DMLColumn *aColumn = new DMLColumn(columnNameList[i],valuesList[i], isNULL);
DMLColumn* aColumn = new DMLColumn(columnNameList[i], valuesList[i], isNULL);
(aRow->get_ColumnList()).push_back(aColumn);
}
fTable->get_RowList().push_back(aRow);
}
@ -218,9 +231,11 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
Row* aRow = new Row();
std::string colName = "";
std::string colValue;
while (iter != valuesList.end())
{
colValue = *iter;
if ( strcasecmp(colValue.c_str(), "NULL") == 0)
{
isNULL = true;
@ -229,11 +244,13 @@ int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
isNULL = false;
}
DMLColumn *aColumn = new DMLColumn(colName,colValue, isNULL);
DMLColumn* aColumn = new DMLColumn(colName, colValue, isNULL);
(aRow->get_ColumnList()).push_back(aColumn);
++iter;
}
fTable->get_RowList().push_back(aRow);
}

View File

@ -55,7 +55,7 @@ public:
* @param sessionID the session id
*/
EXPORT InsertDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
std::string dmlStatement, int sessionID );
/** @brief dtor
*/
@ -80,13 +80,13 @@ public:
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a InsertDMLPackage from MySQL buffer
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);

View File

@ -35,7 +35,7 @@ class MySQLDMLStatement : public VendorDMLStatement
{
public:
MySQLDMLStatement() : VendorDMLStatement("", 0) {}
MySQLDMLStatement() : VendorDMLStatement("", 0) {}
protected:

View File

@ -36,7 +36,7 @@ class OracleDMLStatement : public VendorDMLStatement
{
public:
OracleDMLStatement() : VendorDMLStatement("", 0) {}
OracleDMLStatement() : VendorDMLStatement("", 0) {}
protected:

View File

@ -30,7 +30,7 @@ namespace dmlpackage
{
Row::Row()
:fRowID(std::numeric_limits<WriteEngine::RID>::max())
: fRowID(std::numeric_limits<WriteEngine::RID>::max())
{}
Row::~Row()
@ -39,17 +39,19 @@ Row::~Row()
{
delete fColumnList[i];
}
fColumnList.clear();
}
Row::Row(const Row& row)
{
for(unsigned int i = 0; i < row.fColumnList.size(); i++)
for (unsigned int i = 0; i < row.fColumnList.size(); i++)
{
const DMLColumn* aColumn = row.get_ColumnAt(i);
DMLColumn* newColumn = new DMLColumn(aColumn->get_Name(), aColumn->get_Data());
fColumnList.push_back(newColumn);
const DMLColumn* aColumn = row.get_ColumnAt(i);
DMLColumn* newColumn = new DMLColumn(aColumn->get_Name(), aColumn->get_Data());
fColumnList.push_back(newColumn);
}
fRowID = row.fRowID;
}
int Row::read(messageqcpp::ByteStream& bytestream)
@ -60,12 +62,14 @@ int Row::read(messageqcpp::ByteStream& bytestream)
set_RowID(rowID);
messageqcpp::ByteStream::quadbyte col_count;
bytestream >> col_count;
for (unsigned int i = 0; i < col_count; i++)
{
DMLColumn* aColumn = new DMLColumn();
retval = aColumn->read(bytestream);
fColumnList.push_back(aColumn);
}
return retval;
}
@ -79,6 +83,7 @@ int Row::write(messageqcpp::ByteStream& bytestream)
colListPtr = fColumnList.begin();
messageqcpp::ByteStream::quadbyte col_count = fColumnList.size();
bytestream << col_count;
for (; colListPtr != fColumnList.end(); ++colListPtr)
{
retval = (*colListPtr)->write(bytestream);

View File

@ -56,7 +56,7 @@ public:
/** @brief copy constructor
*/
EXPORT Row(const Row&);
/** @brief read a Row from a ByteStream
*
* @param bytestream the ByteStream to read from
@ -64,26 +64,38 @@ public:
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief write a Row to a ByteStream
*
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief get the list of columns in the row
*/
inline ColumnList& get_ColumnList() { return fColumnList; }
inline ColumnList& get_ColumnList()
{
return fColumnList;
}
/** @brief get the row id
*/
inline WriteEngine::RID get_RowID() const { return fRowID; }
inline WriteEngine::RID get_RowID() const
{
return fRowID;
}
/** @brief set the row id
*/
inline void set_RowID(WriteEngine::RID rowId) { fRowID = rowId; }
inline void set_RowID(WriteEngine::RID rowId)
{
fRowID = rowId;
}
/** @brief get the number of columns
*/
inline unsigned int get_NumberOfColumns() const { return static_cast<unsigned int>(fColumnList.size()); }
inline unsigned int get_NumberOfColumns() const
{
return static_cast<unsigned int>(fColumnList.size());
}
/** @brief get the column at the specified index
*

View File

@ -46,9 +46,10 @@ bool parse_file(char* fileName)
DMLFileParser parser;
parser.parse(fileName);
bool good = parser.good();
if (good)
{
const ParseTree &ptree = parser.getParseTree();
const ParseTree& ptree = parser.getParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
@ -56,8 +57,10 @@ bool parse_file(char* fileName)
cout << ptree;
SqlStatement* statementPtr = ptree[0];
if (statementPtr)
cout << statementPtr->getQueryString();
cout << endl;
}
@ -87,39 +90,69 @@ public:
void tearDown() {}
void test_i01() { CPPUNIT_ASSERT(parse_file("sql/i01.sql")); }
void test_i01()
{
CPPUNIT_ASSERT(parse_file("sql/i01.sql"));
}
void test_i02() { CPPUNIT_ASSERT(parse_file("sql/i02.sql")); }
void test_i02()
{
CPPUNIT_ASSERT(parse_file("sql/i02.sql"));
}
void test_i03() { CPPUNIT_ASSERT(parse_file("sql/i03.sql")); }
void test_i03()
{
CPPUNIT_ASSERT(parse_file("sql/i03.sql"));
}
void test_i04() { CPPUNIT_ASSERT(parse_file("sql/i04.sql")); }
void test_i04()
{
CPPUNIT_ASSERT(parse_file("sql/i04.sql"));
}
void test_u01() { CPPUNIT_ASSERT(parse_file("sql/u01.sql")); }
void test_u01()
{
CPPUNIT_ASSERT(parse_file("sql/u01.sql"));
}
void test_u02() { CPPUNIT_ASSERT(parse_file("sql/u02.sql")); }
void test_u02()
{
CPPUNIT_ASSERT(parse_file("sql/u02.sql"));
}
void test_d01() { CPPUNIT_ASSERT(parse_file("sql/d01.sql")); }
void test_d01()
{
CPPUNIT_ASSERT(parse_file("sql/d01.sql"));
}
void test_d02() { CPPUNIT_ASSERT(parse_file("sql/d02.sql")); }
void test_d02()
{
CPPUNIT_ASSERT(parse_file("sql/d02.sql"));
}
void test_d03() { CPPUNIT_ASSERT(parse_file("sql/d03.sql")); }
void test_d03()
{
CPPUNIT_ASSERT(parse_file("sql/d03.sql"));
}
void test_d04() { CPPUNIT_ASSERT(parse_file("sql/d04.sql")); }
void test_d04()
{
CPPUNIT_ASSERT(parse_file("sql/d04.sql"));
}
};
class DMLTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( DMLTest );
// CPPUNIT_TEST( test_direct_insert );
// CPPUNIT_TEST( test_query_insert );
// CPPUNIT_TEST( test_direct_insert );
// CPPUNIT_TEST( test_query_insert );
CPPUNIT_TEST( test_direct_update );
// CPPUNIT_TEST( test_query_update );
// CPPUNIT_TEST( test_delete_all );
// CPPUNIT_TEST( test_delete_query );
// CPPUNIT_TEST( test_commit );
// CPPUNIT_TEST( test_rollback );
// CPPUNIT_TEST( test_query_update );
// CPPUNIT_TEST( test_delete_all );
// CPPUNIT_TEST( test_delete_query );
// CPPUNIT_TEST( test_commit );
// CPPUNIT_TEST( test_rollback );
CPPUNIT_TEST_SUITE_END();
private:
@ -154,6 +187,7 @@ public:
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
if ( pDMLPackage->HasFilter() )
{
cout << "This INSERT statement has a filter:" << endl;
@ -180,7 +214,7 @@ public:
CPPUNIT_ASSERT( DML_INSERT == package_type );
InsertDMLPackage *pObject = new InsertDMLPackage();
InsertDMLPackage* pObject = new InsertDMLPackage();
pObject->read( bs );
@ -196,7 +230,7 @@ public:
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
@ -212,15 +246,17 @@ public:
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
if (pDMLPackage->HasFilter())
{
cout << "This DELETE statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl;
}
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_delete_object(bytestream);
@ -235,7 +271,7 @@ public:
CPPUNIT_ASSERT( DML_DELETE == package_type );
DeleteDMLPackage *pObject = new DeleteDMLPackage();
DeleteDMLPackage* pObject = new DeleteDMLPackage();
pObject->read( bs );
@ -249,7 +285,7 @@ public:
std::string dmlStatement = "UPDATE tpch.part SET p_partno = 1, p_name = 'joe' where p_partno=2;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
@ -267,6 +303,7 @@ public:
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
if (pDMLPackage->HasFilter())
{
cout << "This UPDATE statement has a filter:" << endl;
@ -286,7 +323,7 @@ public:
CPPUNIT_ASSERT( DML_UPDATE == package_type );
UpdateDMLPackage *pObject = new UpdateDMLPackage();
UpdateDMLPackage* pObject = new UpdateDMLPackage();
pObject->read( bs );
@ -300,7 +337,7 @@ public:
std::string dmlStatement = "COMMIT;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
@ -315,7 +352,7 @@ public:
std::string dmlStatement = "ROLLBACK;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
@ -331,7 +368,7 @@ public:
CPPUNIT_ASSERT( DML_COMMAND == package_type );
CommandDMLPackage *pObject = new CommandDMLPackage();
CommandDMLPackage* pObject = new CommandDMLPackage();
pObject->read( bs );
@ -346,10 +383,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DMLTest );
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char **argv)
int main( int argc, char** argv)
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);

View File

@ -38,7 +38,7 @@ UpdateDMLPackage::UpdateDMLPackage()
UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID)
:CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID)
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID)
{}
UpdateDMLPackage::~UpdateDMLPackage()
@ -52,12 +52,12 @@ int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
/*
if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
/*
if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter;
@ -67,11 +67,13 @@ int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
bytestream << fSQLStatement;
bytestream << fSchemaName;
bytestream << (uint8_t)fIsFromCol;
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
if(fHasFilter)
if (fHasFilter)
{
bytestream += *(fPlan.get());
}
@ -105,7 +107,8 @@ int UpdateDMLPackage::read(messageqcpp::ByteStream& bytestream)
fIsFromCol = (isFromCol != 0);
fTable = new DMLTable();
retval = fTable->read(bytestream);
if(fHasFilter)
if (fHasFilter)
{
fPlan.reset(new messageqcpp::ByteStream(bytestream));
}
@ -130,6 +133,7 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
// Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
while (iter != updateStmt.fColAssignmentListPtr->end())
{
ColumnAssignment* colaPtr = *iter;
@ -138,7 +142,9 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
++iter;
}
fTable->get_RowList().push_back(rowPtr);
if (0 != updateStmt.fWhereClausePtr)
{
// We need to filter the rows...get row ids
@ -166,6 +172,7 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":,");
tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
@ -173,10 +180,11 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
}
int n = 0;
for (int i=0; i < rows; i++)
for (int i = 0; i < rows; i++)
{
//get a new row
Row *aRowPtr = new Row();
Row* aRowPtr = new Row();
std::string colName;
std::string colValue;
//get row ID from the buffer
@ -200,6 +208,7 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows
DMLColumn* aColumn = new DMLColumn(colName, colValue);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
}
@ -211,19 +220,21 @@ int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues
int retval = 1;
initializeTable();
Row *aRowPtr = new Row();
Row* aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
//Build a column list
colName = colNameList[j];
colValList = tableValuesMap[j];
colValList = tableValuesMap[j];
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
return retval;
@ -242,6 +253,7 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStm
// Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
while (iter != updateStmt.fColAssignmentListPtr->end())
{
ColumnAssignment* colaPtr = *iter;
@ -250,6 +262,7 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStm
++iter;
}
fTable->get_RowList().push_back(rowPtr);
}
} // namespace dmlpackage

View File

@ -36,71 +36,71 @@
namespace dmlpackage
{
/** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing UPDATE DML Statements
/** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing UPDATE DML Statements
*/
class UpdateDMLPackage : public CalpontDMLPackage
{
public:
/** @brief ctor
*/
class UpdateDMLPackage : public CalpontDMLPackage
{
EXPORT UpdateDMLPackage();
public:
/** @brief ctor
*/
EXPORT UpdateDMLPackage();
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT UpdateDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT UpdateDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief dtor
*/
EXPORT virtual ~UpdateDMLPackage();
/** @brief dtor
*/
EXPORT virtual ~UpdateDMLPackage();
/** @brief write a UpdateDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a UpdateDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief read a UpdateDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read a UpdateDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief build a UpdateDMLPackage from a string buffer
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a UpdateDMLPackage from a string buffer
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a UpdateDMLPackage from a parsed UpdateSqlStatement
*
* @param sqlStatement the parsed UpdateSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a UpdateDMLPackage from a parsed UpdateSqlStatement
*
* @param sqlStatement the parsed UpdateSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt );
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt );
protected:
protected:
private:
private:
};
};
}
#undef EXPORT

View File

@ -30,30 +30,30 @@ using namespace std;
namespace dmlpackage
{
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int sessionID)
:fDMLStatement(dmlstatement),fSessionID(sessionID), fLogging(true),fLogending(true)
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int sessionID)
: fDMLStatement(dmlstatement), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID)
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype), fSessionID(sessionID),fLogging(true),fLogending(true)
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype,
std::string tName, std::string schema,
int rows, int columns, std::string buf,
int sessionID)
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
fDataBuffer(buf), fSessionID(sessionID), fLogging(true),fLogending(true)
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID)
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID)
:fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
fColNameList(colNameList), fTableValuesMap(tableValuesMap), fNullValues(nullValues), fSessionID(sessionID), fLogging(true),fLogending(true)
{}
VendorDMLStatement::~VendorDMLStatement()
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype,
std::string tName, std::string schema,
int rows, int columns, std::string buf,
int sessionID)
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
fDataBuffer(buf), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID)
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
fColNameList(colNameList), fTableValuesMap(tableValuesMap), fNullValues(nullValues), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
VendorDMLStatement::~VendorDMLStatement()
{}
}

View File

@ -36,152 +36,215 @@
#endif
namespace dmlpackage
{
typedef std::vector<std::string> ColValuesList;
typedef std::vector<std::string> ColNameList;
typedef std::map<uint32_t, ColValuesList> TableValuesMap;
typedef std::bitset<4096> NullValuesBitset;
typedef std::vector<std::string> ColValuesList;
typedef std::vector<std::string> ColNameList;
typedef std::map<uint32_t, ColValuesList> TableValuesMap;
typedef std::bitset<4096> NullValuesBitset;
/** @brief describes the general interface
* and implementation of a Vendor DML Statement
/** @brief describes the general interface
* and implementation of a Vendor DML Statement
*/
class VendorDMLStatement
{
public:
/** @brief ctor
*/
class VendorDMLStatement
EXPORT VendorDMLStatement(std::string dmlstatement, int sessionID);
/** @brief ctor
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID);
/** @brief old ctor!
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName,
std::string schema, int rows, int columns, std::string buf,
int sessionID);
/** @brief ctor for mysql
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID);
/** @brief destructor
*/
EXPORT ~VendorDMLStatement();
/** @brief Get the table name
*/
inline std::string get_TableName() const
{
return fTableName;
}
public:
/** @brief ctor
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int sessionID);
/** @brief ctor
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID);
/** @brief Set the table name
*/
inline void set_TableName( std::string value )
{
fTableName = value;
}
/** @brief old ctor!
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName,
std::string schema, int rows, int columns, std::string buf,
int sessionID);
/** @brief ctor for mysql
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID);
/** @brief destructor
*/
EXPORT ~VendorDMLStatement();
/** @brief Get the schema name
*/
inline std::string get_SchemaName() const
{
return fSchema;
}
/** @brief Get the table name
*/
inline std::string get_TableName() const { return fTableName; }
/** @brief Set the schema name
*/
inline void set_SchemaName( std::string value )
{
fSchema = value;
}
/** @brief Set the table name
*/
inline void set_TableName( std::string value ) { fTableName = value; }
/** @brief Get the DML statVendorDMLStatement classement type
*/
inline int get_DMLStatementType() const
{
return fDMLStatementType;
}
/** @brief Get the schema name
*/
inline std::string get_SchemaName() const { return fSchema; }
/** @brief Set the DML statement type
*/
inline void set_DMLStatementType( int value )
{
fDMLStatementType = value;
}
/** @brief Set the schema name
*/
inline void set_SchemaName( std::string value ) { fSchema = value; }
/** @brief Get the DML statement
*/
inline const std::string get_DMLStatement() const
{
return fDMLStatement;
}
/** @brief Get the DML statVendorDMLStatement classement type
*/
inline int get_DMLStatementType() const { return fDMLStatementType; }
/** @brief Set the DML statVendorDMLStatement classement
*/
inline void set_DMLStatement( std::string dmlStatement )
{
fDMLStatement = dmlStatement;
}
/** @brief Set the DML statement type
*/
inline void set_DMLStatementType( int value ) { fDMLStatementType = value; }
/** @brief Get the number of rows
*/
inline int get_Rows() const
{
return fRows;
}
/** @brief Get the DML statement
*/
inline const std::string get_DMLStatement() const { return fDMLStatement; }
/** @brief Set the number of rows
*/
inline void set_Rows( int value )
{
fRows = value;
}
/** @brief Set the DML statVendorDMLStatement classement
*/
inline void set_DMLStatement( std::string dmlStatement ) { fDMLStatement = dmlStatement; }
/** @brief Get the number of columns
*/
inline int get_Columns() const
{
return fColumns;
}
/** @brief Get the number of rows
*/
inline int get_Rows() const { return fRows; }
/** @brief Set the number of columns
*/
inline void set_Columns( int value )
{
fColumns = value;
}
/** @brief Set the number of rows
*/
inline void set_Rows( int value ) { fRows = value; }
/** @brief Get the data buffer
*/
inline std::string& get_DataBuffer()
{
return fDataBuffer;
}
/** @brief Get the number of columns
*/
inline int get_Columns() const { return fColumns; }
/** @brief Set the data buffer
*/
inline void set_DataBuffer( std::string value )
{
fDataBuffer = value;
}
/** @brief Get the session ID
*/
inline int get_SessionID()
{
return fSessionID;
}
/** @brief Set the number of columns
*/
inline void set_Columns( int value ) { fColumns = value; }
inline NullValuesBitset& get_nullValues()
{
return fNullValues;
}
/** @brief Get the data buffer
*/
inline std::string& get_DataBuffer() { return fDataBuffer; }
/** @brief Set the session ID
*/
inline void set_SessionID( int value )
{
fSessionID = value;
}
/** @brief Set the data buffer
*/
inline void set_DataBuffer( std::string value ) { fDataBuffer= value; }
/** @brief Get the session ID
*/
inline int get_SessionID() { return fSessionID; }
inline ColNameList& get_ColNames()
{
return fColNameList;
}
inline TableValuesMap& get_values()
{
return fTableValuesMap;
}
/** @brief get the logging flag
*/
inline const bool get_Logging() const
{
return fLogging;
}
inline NullValuesBitset& get_nullValues() { return fNullValues; }
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
inline void set_Logging( bool logging )
{
fLogging = logging;
}
/** @brief Set the session ID
*/
inline void set_SessionID( int value ) { fSessionID = value; }
/** @brief get the logging flag
*/
inline const bool get_Logending() const
{
return fLogending;
}
inline ColNameList& get_ColNames() { return fColNameList; }
inline TableValuesMap& get_values() { return fTableValuesMap; }
/** @brief get the logging flag
*/
inline const bool get_Logging() const { return fLogging; }
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
inline void set_Logging( bool logging )
{
fLogging = logging;
}
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
inline void set_Logending( bool logending )
{
fLogending = logending;
}
/** @brief get the logging flag
*/
inline const bool get_Logending() const { return fLogending; }
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
inline void set_Logending( bool logending )
{
fLogending = logending;
}
protected:
protected:
private:
std::string fDMLStatement;
int fDMLStatementType;
std::string fTableName;
std::string fSchema;
int fRows;
int fColumns;
std::string fDataBuffer;
ColNameList fColNameList;
TableValuesMap fTableValuesMap;
NullValuesBitset fNullValues;
int fSessionID;
bool fLogging;
bool fLogending;
private:
std::string fDMLStatement;
int fDMLStatementType;
std::string fTableName;
std::string fSchema;
int fRows;
int fColumns;
std::string fDataBuffer;
ColNameList fColNameList;
TableValuesMap fTableValuesMap;
NullValuesBitset fNullValues;
int fSessionID;
bool fLogging;
bool fLogending;
};
};
}