コード例 #1
0
    // this is a clever way to produce an SQL statement like this:
    //
    // (
    //   SELECT 'Spacesdd' AS Tag, 'default' AS [group]
    //   UNION
    //   SELECT 'Cool' AS tag, 'default' AS [group]
    // ) AS tagSet
    //
    // which we can then use to reduce queries
    //
    private string GetTagSet(IEnumerable <ITag> tags)
    {
        var sql   = new StringBuilder();
        var group = SqlSyntax.GetQuotedColumnName("group");
        var first = true;

        sql.Append("(");

        foreach (ITag tag in tags)
        {
            if (first)
            {
                first = false;
            }
            else
            {
                sql.Append(" UNION ");
            }

            // HACK: SQLite (or rather SQL server setup was a hack)
            if (SqlContext.DatabaseType.IsSqlServer())
            {
                sql.Append("SELECT N'");
            }
            else
            {
                sql.Append("SELECT '");
            }

            sql.Append(SqlSyntax.EscapeString(tag.Text));
            sql.Append("' AS tag, '");
            sql.Append(SqlSyntax.EscapeString(tag.Group));
            sql.Append("' AS ");
            sql.Append(group);
            sql.Append(" , ");
            if (tag.LanguageId.HasValue)
            {
                sql.Append(tag.LanguageId);
            }
            else
            {
                sql.Append("NULL");
            }

            sql.Append(" AS languageId");
        }

        sql.Append(") AS tagSet");

        return(sql.ToString());
    }
コード例 #2
0
        // this is a clever way to produce an SQL statement like this:
        //
        // (
        //   SELECT 'Spacesdd' AS Tag, 'default' AS [group]
        //   UNION
        //   SELECT 'Cool' AS tag, 'default' AS [group]
        // ) AS tagSet
        //
        // which we can then use to reduce queries
        //
        private string GetTagSet(IEnumerable <ITag> tags)
        {
            var sql   = new StringBuilder();
            var group = SqlSyntax.GetQuotedColumnName("group");
            var first = true;

            sql.Append("(");

            foreach (ITag tag in tags)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sql.Append(" UNION ");
                }

                sql.Append("SELECT N'");
                sql.Append(SqlSyntax.EscapeString(tag.Text));
                sql.Append("' AS tag, '");
                sql.Append(SqlSyntax.EscapeString(tag.Group));
                sql.Append("' AS ");
                sql.Append(group);
                sql.Append(" , ");
                if (tag.LanguageId.HasValue)
                {
                    sql.Append(tag.LanguageId);
                }
                else
                {
                    sql.Append("NULL");
                }

                sql.Append(" AS languageId");
            }

            sql.Append(") AS tagSet");

            return(sql.ToString());
        }