Пример #1
0
        public string GetTopXSqlForColumn(IHasRuntimeName database, IHasFullyQualifiedNameToo table, IHasRuntimeName column, int topX, bool discardNulls)
        {
            var syntax = new MicrosoftQuerySyntaxHelper();

            //[dbx].[table]
            string sql = "SELECT TOP " + topX + " " + syntax.EnsureWrapped(column.GetRuntimeName()) + " FROM " + table.GetFullyQualifiedName();

            if (discardNulls)
            {
                sql += " WHERE " + syntax.EnsureWrapped(column.GetRuntimeName()) + " IS NOT NULL";
            }

            return(sql);
        }
Пример #2
0
        public override void CreateDatabase(DbConnectionStringBuilder builder, IHasRuntimeName newDatabaseName)
        {
            var b = new SqlConnectionStringBuilder(builder.ConnectionString);

            b.InitialCatalog = "master";

            var syntax = new MicrosoftQuerySyntaxHelper();


            using (var con = new SqlConnection(b.ConnectionString))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("CREATE DATABASE " + syntax.EnsureWrapped(newDatabaseName.GetRuntimeName()), con))
                {
                    cmd.CommandTimeout = CreateDatabaseTimeoutInSeconds;
                    cmd.ExecuteNonQuery();
                }
            }
        }
Пример #3
0
        public override DiscoveredStoredprocedure[] ListStoredprocedures(DbConnectionStringBuilder builder, string database)
        {
            List <DiscoveredStoredprocedure> toReturn = new List <DiscoveredStoredprocedure>();
            var querySyntaxHelper = new MicrosoftQuerySyntaxHelper();

            using (var con = new SqlConnection(builder.ConnectionString))
            {
                con.Open();
                using (SqlCommand cmdFindStoredprocedure =
                           new SqlCommand("use " + querySyntaxHelper.EnsureWrapped(database) + ";  SELECT * FROM sys.procedures", con))
                {
                    var result = cmdFindStoredprocedure.ExecuteReader();

                    while (result.Read())
                    {
                        toReturn.Add(new DiscoveredStoredprocedure((string)result["name"]));
                    }
                }
            }

            return(toReturn.ToArray());
        }