{
buf.append("insert into ");
buf.append(m_table.getQuotedName());
buf.append('(');
Index pk = m_table.getPrimaryKey();
int nValCount = 0;
for (int i = 0, n = pk.getIndexColumnCount(); i < n; ++i)
{
Column column = pk.getIndexColumn(i).getColumn();
if (getValue(column) == Undefined.VALUE)
{
if (nValCount++ > 0)
{
buf.append(", ");
}
buf.append(column.getQuotedName());
}
}
boolean bCaseConverted = false;
for (int i = 0, n = m_table.getColumnCount(); i < n; ++i)
{
Column column = m_table.getColumn(i);
if (getValue(i) != Undefined.VALUE ||
m_bDenorm && findSource(column) != null)
{
if (nValCount++ > 0)
{
buf.append(", ");
}
buf.append(column.getQuotedName());
if (m_adapter.isCaseConverted(column))
{
buf.append(", ");
m_adapter.appendCaseConvertedColumn(buf, column);
bCaseConverted = true;
}
}
}
buf.append((m_bDenorm) ? ") select " : ") values (");
if (bCaseConverted | m_bDenorm)
{
nValCount = 0;
for (int i = 0, n = pk.getIndexColumnCount(); i < n; ++i)
{
Column column = pk.getIndexColumn(i).getColumn();
if (getValue(column) == Undefined.VALUE)
{
if (nValCount > 0)
{
buf.append(", ");
}
m_adapter.appendBind(buf, nBindCount + nValCount++, column);
}
}
// TODO: Support more than just the primary table denorm
Table denormTable = null;
for (int i = 0, n = m_table.getColumnCount(); i < n; ++i)
{
Column column = m_table.getColumn(i);
if (getValue(i) != Undefined.VALUE)
{
if (nValCount != 0 || denormTable != null)
{
buf.append(", ");
}
m_adapter.appendBind(buf, nBindCount + nValCount++, column);
if (m_adapter.isCaseConverted(column))
{
buf.append(", ");
m_adapter.appendCaseConvertedBind(buf, nBindCount + nValCount++, column);
}
}
else
{
Column srcColumn = findSource(column);
if (srcColumn != null)
{
if (nValCount != 0 || denormTable != null)
{
buf.append(", ");
}
buf.append("A.");
buf.append(srcColumn.getQuotedName());
if (m_adapter.isCaseConverted(column))
{
buf.append(", ");
buf.append("A.");
m_adapter.appendCaseConvertedColumn(buf, srcColumn);
}
denormTable = srcColumn.getTable();
}
}
}
if (m_bDenorm)
{
buf.append(" from ");
buf.append(denormTable.getQuotedName());
buf.append(" A where ");
for (int i = 0, n = pk.getIndexColumnCount(); i < n; ++i)
{
if (i != 0)
{
buf.append(" and ");
}
Column column = pk.getIndexColumn(i).getColumn();
buf.append("A.");
buf.append(column.getQuotedName());
buf.append(" = ");