#include "SqlGenerator_Oracle.h"
#include <qdebug.h>

SqlGenerator_Oracle::SqlGenerator_Oracle()
	: QxSqlGenerator_Oracle()
{
	setManageLastInsertId(true);
	setOldLimitSyntax(true);
}

SqlGenerator_Oracle::~SqlGenerator_Oracle()
{
}

void SqlGenerator_Oracle::onBeforeInsert(qx::dao::detail::IxDao_Helper * pDaoHelper, void * pOwner) const
{
	autoAssignUpdateTime(pDaoHelper, pOwner);
	QxSqlGenerator_Oracle::onBeforeInsert(pDaoHelper, pOwner);
}

void SqlGenerator_Oracle::onBeforeUpdate(qx::dao::detail::IxDao_Helper * pDaoHelper, void * pOwner) const
{
	autoAssignUpdateTime(pDaoHelper, pOwner);
	QxSqlGenerator_Oracle::onBeforeUpdate(pDaoHelper, pOwner);
}

void SqlGenerator_Oracle::onBeforeSqlPrepare(qx::dao::detail::IxDao_Helper * pDaoHelper, QString & sql) const
{
}

void SqlGenerator_Oracle::autoAssignUpdateTime(qx::dao::detail::IxDao_Helper * pDaoHelper, void * pOwner)const
{
	qx::IxDataMemberX *pDataMembers = pDaoHelper->getDataMemberX();
	QString timeFieldName;
	if (pDataMembers->exist("UPDATETIME"))
		timeFieldName = "UPDATETIME";
    else if (pDataMembers->exist("IMPORTTIME"))
		timeFieldName = "IMPORTTIME";
	if (!timeFieldName.isEmpty())
			pDataMembers->get(timeFieldName)->fromVariant(pOwner, QDateTime::currentDateTime());
}
