@@ -359,28 +359,11 @@ protected void renderOffsetExpression(Expression offsetExpression) {
359359 protected void renderComparison (Expression lhs , ComparisonOperator operator , Expression rhs ) {
360360 // In Sybase ASE, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
361361 final boolean isLob = isLob ( lhs .getExpressionType () );
362+ final boolean ansiNullOn = ((SybaseASEDialect ) getDialect ()).isAnsiNullOn ();
362363 if ( isLob ) {
363364 switch ( operator ) {
364- case EQUAL :
365- lhs .accept ( this );
366- appendSql ( " like " );
367- rhs .accept ( this );
368- return ;
369- case NOT_EQUAL :
370- lhs .accept ( this );
371- appendSql ( " not like " );
372- rhs .accept ( this );
373- return ;
374- default :
375- // Fall through
376- break ;
377- }
378- }
379- // I think intersect is only supported in 16.0 SP3
380- if ( ( (SybaseASEDialect ) getDialect () ).isAnsiNullOn () ) {
381- if ( isLob ) {
382- switch ( operator ) {
383- case DISTINCT_FROM :
365+ case DISTINCT_FROM :
366+ if ( ansiNullOn ) {
384367 appendSql ( "case when " );
385368 lhs .accept ( this );
386369 appendSql ( " like " );
@@ -390,8 +373,20 @@ protected void renderComparison(Expression lhs, ComparisonOperator operator, Exp
390373 appendSql ( " is null and " );
391374 rhs .accept ( this );
392375 appendSql ( " is null then 0 else 1 end=1" );
393- return ;
394- case NOT_DISTINCT_FROM :
376+ }
377+ else {
378+ lhs .accept ( this );
379+ appendSql ( " not like " );
380+ rhs .accept ( this );
381+ appendSql ( " and (" );
382+ lhs .accept ( this );
383+ appendSql ( " is not null or " );
384+ rhs .accept ( this );
385+ appendSql ( " is not null)" );
386+ }
387+ return ;
388+ case NOT_DISTINCT_FROM :
389+ if ( ansiNullOn ) {
395390 appendSql ( "case when " );
396391 lhs .accept ( this );
397392 appendSql ( " like " );
@@ -401,12 +396,42 @@ protected void renderComparison(Expression lhs, ComparisonOperator operator, Exp
401396 appendSql ( " is null and " );
402397 rhs .accept ( this );
403398 appendSql ( " is null then 0 else 1 end=0" );
404- return ;
405- default :
406- // Fall through
407- break ;
408- }
399+ }
400+ else {
401+ lhs .accept ( this );
402+ appendSql ( " like " );
403+ rhs .accept ( this );
404+ appendSql ( " or " );
405+ lhs .accept ( this );
406+ appendSql ( " is null and " );
407+ rhs .accept ( this );
408+ appendSql ( " is null" );
409+ }
410+ return ;
411+ case EQUAL :
412+ lhs .accept ( this );
413+ appendSql ( " like " );
414+ rhs .accept ( this );
415+ return ;
416+ case NOT_EQUAL :
417+ lhs .accept ( this );
418+ appendSql ( " not like " );
419+ rhs .accept ( this );
420+ if ( !ansiNullOn ) {
421+ appendSql ( " and " );
422+ lhs .accept ( this );
423+ appendSql ( " is not null and " );
424+ rhs .accept ( this );
425+ appendSql ( " is not null" );
426+ }
427+ return ;
428+ default :
429+ // Fall through
430+ break ;
409431 }
432+ }
433+ // I think intersect is only supported in 16.0 SP3
434+ if ( ansiNullOn ) {
410435 if ( supportsDistinctFromPredicate () ) {
411436 renderComparisonEmulateIntersect ( lhs , operator , rhs );
412437 }
@@ -417,50 +442,28 @@ protected void renderComparison(Expression lhs, ComparisonOperator operator, Exp
417442 else {
418443 // The ansinull setting only matters if using a parameter or literal and the eq operator according to the docs
419444 // http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc32300.1570/html/sqlug/sqlug89.htm
420- boolean rhsNotNullPredicate =
421- lhs instanceof Literal
422- || isParameter ( lhs );
423- boolean lhsNotNullPredicate =
424- rhs instanceof Literal
425- || isParameter ( rhs );
426- if ( rhsNotNullPredicate || lhsNotNullPredicate ) {
445+ boolean lhsAffectedByAnsiNullOff = lhs instanceof Literal || isParameter ( lhs );
446+ boolean rhsAffectedByAnsiNullOff = rhs instanceof Literal || isParameter ( rhs );
447+ if ( lhsAffectedByAnsiNullOff || rhsAffectedByAnsiNullOff ) {
427448 lhs .accept ( this );
428449 switch ( operator ) {
429450 case DISTINCT_FROM :
430- if ( isLob ) {
431- appendSql ( " not like " );
432- }
433- else {
434- appendSql ( "<>" );
435- }
451+ // Since this is the ansinull=off case, this comparison is enough
452+ appendSql ( "<>" );
436453 break ;
437454 case NOT_DISTINCT_FROM :
438- if ( isLob ) {
439- appendSql ( " like " );
440- }
441- else {
442- appendSql ( '=' );
443- }
455+ // Since this is the ansinull=off case, this comparison is enough
456+ appendSql ( '=' );
444457 break ;
445- case LESS_THAN :
446- case GREATER_THAN :
447- case LESS_THAN_OR_EQUAL :
448- case GREATER_THAN_OR_EQUAL :
449- // These operators are not affected by ansinull=off
450- lhsNotNullPredicate = false ;
451- rhsNotNullPredicate = false ;
452458 default :
453459 appendSql ( operator .sqlText () );
454460 break ;
455461 }
456462 rhs .accept ( this );
457- if ( lhsNotNullPredicate ) {
463+ if ( operator == ComparisonOperator . EQUAL || operator == ComparisonOperator . NOT_EQUAL ) {
458464 appendSql ( " and " );
459465 lhs .accept ( this );
460- appendSql ( " is not null" );
461- }
462- if ( rhsNotNullPredicate ) {
463- appendSql ( " and " );
466+ appendSql ( " is not null and " );
464467 rhs .accept ( this );
465468 appendSql ( " is not null" );
466469 }
0 commit comments