001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2008-2013 Pentaho
008// All Rights Reserved.
009*/
010package mondrian.spi.impl;
011
012import java.sql.Connection;
013import java.sql.Date;
014import java.sql.SQLException;
015import java.text.DateFormat;
016import java.text.SimpleDateFormat;
017import java.util.Calendar;
018import java.util.List;
019
020/**
021 * Implementation of {@link mondrian.spi.Dialect} for the Microsoft SQL Server
022 * database.
023 *
024 * @author jhyde
025 * @since Nov 23, 2008
026 */
027public class MicrosoftSqlServerDialect extends JdbcDialectImpl {
028
029    private final DateFormat df =
030        new SimpleDateFormat("yyyyMMdd");
031
032    public static final JdbcDialectFactory FACTORY =
033        new JdbcDialectFactory(
034            MicrosoftSqlServerDialect.class,
035            DatabaseProduct.MSSQL);
036
037    /**
038     * Creates a MicrosoftSqlServerDialect.
039     *
040     * @param connection Connection
041     */
042    public MicrosoftSqlServerDialect(Connection connection) throws SQLException
043    {
044        super(connection);
045    }
046
047    public String generateInline(
048        List<String> columnNames,
049        List<String> columnTypes,
050        List<String[]> valueList)
051    {
052        return generateInlineGeneric(
053            columnNames, columnTypes, valueList, null, false);
054    }
055
056    public boolean requiresAliasForFromQuery() {
057        return true;
058    }
059
060    public boolean requiresUnionOrderByOrdinal() {
061        return false;
062    }
063
064    protected void quoteDateLiteral(StringBuilder buf, String value, Date date)
065    {
066        buf.append("CONVERT(DATE, '");
067        buf.append(df.format(date));
068        // Format 112 is equivalent to "yyyyMMdd" in Java.
069        // See http://msdn.microsoft.com/en-us/library/ms187928.aspx
070        buf.append("', 112)");
071    }
072}
073
074// End MicrosoftSqlServerDialect.java