protected virtual void OnRenameIndexesTables(IndexesTableNames oldIndexesTableNames, IndexesTableNames newIndexesTableNames, string oldStructureTableName, string newStructureTableName)
        {
            using (var cmd = CreateSpCommand("sp_rename"))
            {
                for (var i = 0; i < oldIndexesTableNames.All.Length; i++)
                {
                    var oldTableName = oldIndexesTableNames[i];
                    var newTableName = newIndexesTableNames[i];

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", oldTableName),
                                                  new DacParameter("newname", newTableName),
                                                  new DacParameter("objtype", "OBJECT"));
                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", string.Format("FK_{0}_{1}", oldTableName, oldStructureTableName)),
                                                  new DacParameter("newname", string.Format("FK_{0}_{1}", newTableName, newStructureTableName)),
                                                  new DacParameter("objtype", "OBJECT"));
                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", string.Format("{0}.IX_{1}_Q", newTableName, oldTableName)),
                                                  new DacParameter("newname", string.Format("IX_{0}_Q", newTableName)),
                                                  new DacParameter("objtype", "INDEX"));
                    cmd.ExecuteNonQuery();
                }
            }
        }
        protected virtual void OnRenameSpatialTable(string oldTableName, string newTableName, string oldStructureTableName, string newStructureTableName)
        {
            using (var cmd = CreateSpCommand("sp_rename",
                                             new DacParameter("objname", oldTableName),
                                             new DacParameter("newname", newTableName),
                                             new DacParameter("objtype", "OBJECT")))
            {
                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
                Driver.AddCommandParametersTo(cmd,
                                              new DacParameter("objname", string.Concat("PK_", oldTableName)),
                                              new DacParameter("newname", string.Concat("PK_", newTableName)),
                                              new DacParameter("objtype", "OBJECT"));
                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
                Driver.AddCommandParametersTo(cmd,
                                              new DacParameter("objname", string.Format("FK_{0}_{1}", oldTableName, oldStructureTableName)),
                                              new DacParameter("newname", string.Format("FK_{0}_{1}", newTableName, newStructureTableName)),
                                              new DacParameter("objtype", "OBJECT"));
                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
                Driver.AddCommandParametersTo(cmd,
                                              new DacParameter("objname", string.Format("{0}.SPK_{1}", newTableName, oldTableName)),
                                              new DacParameter("newname", string.Format("SPK_{0}", newTableName)),
                                              new DacParameter("objtype", "INDEX"));
                cmd.ExecuteNonQuery();
            }
        }
Example #3
0
        public override IEnumerable <string> GetJsonByIds(IEnumerable <IStructureId> ids, IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();
            var sqlFormat = SqlStatements.GetSql("GetJsonByIds").Inject(structureSchema.GetStructureTableName(), "{0}");

            using (var cmd = CreateCommand(string.Empty))
            {
                foreach (var batchedIds in ids.Batch <IStructureId, IDacParameter>(MaxBatchedIdsSize, (id, batchCount) => new DacParameter(string.Concat("id", batchCount), id.Value)))
                {
                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd, batchedIds);

                    var paramsString = string.Join(",", batchedIds.Select(p => p.Name));
                    cmd.CommandText = sqlFormat.Inject(paramsString);

                    using (var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SequentialAccess))
                    {
                        while (reader.Read())
                        {
                            yield return(reader.GetString(0));
                        }
                        reader.Close();
                    }
                }
            }
        }
Example #4
0
        public override void DeleteByIds(IEnumerable <IStructureId> ids, IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();
            var sqlFormat = SqlStatements.GetSql("DeleteByIds").Inject(structureSchema.GetStructureTableName(), "{0}");

            using (var cmd = CreateCommand(string.Empty))
            {
                foreach (var batchedIds in ids.Batch <IStructureId, IDacParameter>(MaxBatchedIdsSize, (id, batchCount) => new DacParameter(string.Concat("id", batchCount), id.Value)))
                {
                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd, batchedIds);

                    var paramsString = string.Join(",", batchedIds.Select(p => p.Name));
                    cmd.CommandText = sqlFormat.Inject(paramsString);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Example #5
0
        protected override void OnRenameIndexesTables(IndexesTableNames oldIndexesTableNames, IndexesTableNames newIndexesTableNames, string oldStructureTableName, string newStructureTableName)
        {
            using (var cmd = CreateCommand(null))
            {
                for (var i = 0; i < oldIndexesTableNames.All.Length; i++)
                {
                    var oldTableName = oldIndexesTableNames[i];
                    var newTableName = newIndexesTableNames[i];

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", oldTableName),
                                                  new DacParameter("newname", newTableName),
                                                  new DacParameter("objtype", "OBJECT"));
                    cmd.CommandText = "sp_rename @objname=@objname, @newname=@newname, @objtype=@objtype";
                    cmd.ExecuteNonQuery();
                }
            }
        }