private SqlNode getNthExpr ( SqlNode query , int ordinal , int sourceCount ) { if ( query instanceof SqlInsert ) { SqlInsert insert = ( SqlInsert ) query ; if ( insert . getTargetColumnList ( ) != null ) { return insert . getTargetColumnList ( ) . get ( ordinal ) ; } else { return getNthExpr ( insert . getSource ( ) , ordinal , sourceCount ) ; } } else if ( query instanceof SqlUpdate ) { SqlUpdate update = ( SqlUpdate ) query ; if ( update . getTargetColumnList ( ) != null ) { return update . getTargetColumnList ( ) . get ( ordinal ) ; } else if ( update . getSourceExpressionList ( ) != null ) { return update . getSourceExpressionList ( ) . get ( ordinal ) ; } else { return getNthExpr ( update . getSourceSelect ( ) , ordinal , sourceCount ) ; } } else if ( query instanceof SqlSelect ) { SqlSelect select = ( SqlSelect ) query ; if ( select . getSelectList ( ) . size ( ) == sourceCount ) { return select . getSelectList ( ) . get ( ordinal ) ; } else { return query ; // give up } } else { return query ; // give up } }
Locates the n th expression in an INSERT or UPDATE query .