Revision 43093 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java

View differences:

SQLBuilderBase.java
409 409
                return this.custom;
410 410
            }
411 411
            if( this.ascending ) {
412
                return this.value + "ASC";
412
                return this.value + " ASC";
413 413
            }
414
            return this.value + "DESC";
414
            return this.value + " DESC";
415 415
        }
416 416
    }
417 417
    
......
527 527

  
528 528
        @Override
529 529
        public OrderByBuilder order_by() {
530
            if( this.order_by == null ) {
531
                this.order_by = new ArrayList<>();
532
            }
530 533
            OrderByBuilder order = createOrderByBuilder();
531 534
            this.order_by.add(order);
532 535
            return order;
......
540 543
            return !this.order_by.isEmpty();
541 544
        }
542 545
        
546
        protected boolean isValid(StringBuilder message) {
547
            if( message == null ) {
548
                message = new StringBuilder();
549
            }
550
            if( this.has_offset() && !this.has_order_by() ) {
551
                // Algunos gestores de BBDD requieren que se especifique un
552
                // orden para poder usar OFFSET. Como eso parece buena idea para
553
                // asegurar que siempre tengamos los mismo resultados, lo exijimos
554
                // siempre.
555
                message.append("Can't use OFFSET without an ORDER BY.");
556
                return false;
557
            }
558
            return true;
559
        }
560
        
543 561
        @Override
544 562
        public String toString() {
545 563
            StringBuilder builder = new StringBuilder();
546

  
564
            if( !this.isValid(builder) ) {
565
                throw new IllegalStateException(builder.toString());
566
            }
547 567
            builder.append("SELECT ");
548 568
            if( this.distinct ) {
549 569
                builder.append("DISTINCT ");
......
1868 1888
        if (this.update_table_statistics != null) {
1869 1889
            return this.update_table_statistics.toString();
1870 1890
        }
1871
        return "";
1891
        if ( this.value != null ) {
1892
            return this.value.toString();
1893
        }
1894
        return ""; 
1872 1895
    }
1873 1896

  
1874 1897
    @Override

Also available in: Unified diff