Exemple #1
0
        public void ShouldAppendUsingPlusOperator()
        {
            SqlScript script = new SqlScript();

            script.Append("line1\r\n");
            script += "line2\r\n";

            Assert.AreEqual("line1\r\nline2\r\n", script.ToScript());
        }
Exemple #2
0
        public void ShouldAppendScriptFromStringBuilder()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("DROP TABLE [table1]");
            builder.AppendLine("DROP TABLE [table2]");

            SqlScript script = new SqlScript();

            script.Append(builder);

            Assert.AreEqual(builder.Length, script.Length, "Lengths are no equals");
            Assert.AreEqual("DROP TABLE [table1]\r\nDROP TABLE [table2]\r\n", script.ToScript(),
                            "Script contents don't matchs");
        }
Exemple #3
0
        protected virtual SqlScript CreateScript(string templatePath, VelocityContext context)
        {
            context.Put("time", DateTime.Now);
            context.Put("SqlScriptHelper", serverScriptHelper);

            StringWriter writer   = new StringWriter();
            Template     template = velocityEngine.GetTemplate(templatePath);

            template.Merge(context, writer);

            SqlScript script = new SqlScript();

            script.Append(writer.GetStringBuilder());
            return(script);
        }
Exemple #4
0
 public ODAScript Merge(ODAScript Child)
 {
     if (Child.SqlScript.Length > 0)
     {
         SqlScript.Append(Child.SqlScript.ToString());
     }
     if (Child.TableList.Count > 0)
     {
         TableList.AddRange(Child.TableList.ToArray());
     }
     if (Child.ParamList.Count > 0)
     {
         ParamList.AddRange(Child.ParamList.ToArray());
     }
     return(this);
 }
        protected override void CopyEntityObjectToMetaObject(EntityObject target, MetaObject metaObject)
        {
            // Base Copy
            base.CopyEntityObjectToMetaObject(target, metaObject);

            // Process not updatable field
            DocumentContentVersionEntity srcVersion = (DocumentContentVersionEntity)target;

            #region Index
            // Only if new object
            if (metaObject.ObjectState == MetaObjectState.Created)
            {
                // Calculate max index
                int maxIndex = 0;
                SqlScript selectMaxIndex = new SqlScript();

                selectMaxIndex.Append("SELECT MAX([Index]) AS [Index] FROM [dbo].[cls_DocumentContentVersion] WHERE [OwnerDocumentId] = @OwnerDocumentId");
                selectMaxIndex.AddParameter("@OwnerDocumentId", (Guid)srcVersion.OwnerDocumentId);

                using (IDataReader reader = SqlHelper.ExecuteReader(SqlContext.Current,
                    CommandType.Text, selectMaxIndex.ToString(), selectMaxIndex.Parameters.ToArray()))
                {
                    if (reader.Read())
                    {
                        object value = reader["Index"];
                        if (value is int)
                        {
                            maxIndex = (int)value;
                        }
                    }
                }

                // update index
                metaObject["Index"] = maxIndex + 1;
            }
            #endregion

            // Update State via Custom Method = UpdateState
        }
Exemple #6
0
        protected override void CopyEntityObjectToMetaObject(EntityObject target, MetaObject metaObject)
        {
            // Base Copy
            base.CopyEntityObjectToMetaObject(target, metaObject);

            // Process not updatable field
            DocumentContentVersionEntity srcVersion = (DocumentContentVersionEntity)target;

            #region Index
            // Only if new object
            if (metaObject.ObjectState == MetaObjectState.Created)
            {
                // Calculate max index
                int       maxIndex       = 0;
                SqlScript selectMaxIndex = new SqlScript();

                selectMaxIndex.Append("SELECT MAX([Index]) AS [Index] FROM [dbo].[cls_DocumentContentVersion] WHERE [OwnerDocumentId] = @OwnerDocumentId");
                selectMaxIndex.AddParameter("@OwnerDocumentId", (Guid)srcVersion.OwnerDocumentId);

                using (IDataReader reader = SqlHelper.ExecuteReader(SqlContext.Current,
                                                                    CommandType.Text, selectMaxIndex.ToString(), selectMaxIndex.Parameters.ToArray()))
                {
                    if (reader.Read())
                    {
                        object value = reader["Index"];
                        if (value is int)
                        {
                            maxIndex = (int)value;
                        }
                    }
                }

                // update index
                metaObject["Index"] = maxIndex + 1;
            }
            #endregion

            // Update State via Custom Method = UpdateState
        }