Beispiel #1
0
        internal static string GetDropDatabaseCommand(string catalog)
        {
            var builder = new StringBuilder();

            builder.AppendFormat("DROP DATABASE {0}", MySqlIdentifier.QuoteIdentifier(catalog));
            return(builder.ToString());
        }
Beispiel #2
0
 private static void BuildPrimaryKey(MetaTable table, StringBuilder sb)
 {
     foreach (MetaDataMember member in table.RowType.IdentityMembers)
     {
         if (sb.Length > 0)
         {
             sb.Append(", ");
         }
         sb.Append(MySqlIdentifier.QuoteIdentifier(member.MappedName));
     }
 }
Beispiel #3
0
        public static string GetCreateDatabaseCommand(string catalog, string dataFilename, string logFilename)
        {
            var builder = new StringBuilder();

            builder.AppendFormat("CREATE DATABASE {0};", MySqlIdentifier.QuoteIdentifier(catalog));
            //if (dataFilename != null)
            //{
            //    builder.AppendFormat(" ON PRIMARY (NAME='{0}', FILENAME='{1}')", Path.GetFileName(dataFilename), dataFilename);
            //    builder.AppendFormat(" LOG ON (NAME='{0}', FILENAME='{1}')", Path.GetFileName(logFilename), logFilename);
            //}
            builder.AppendLine();
            builder.AppendFormat("Use {0};", catalog);
            return(builder.ToString());
        }
Beispiel #4
0
        private static string BuildKey(IEnumerable <MetaDataMember> members)
        {
            var builder = new StringBuilder();

            foreach (MetaDataMember member in members)
            {
                if (builder.Length > 0)
                {
                    builder.Append(", ");
                }
                builder.Append(MySqlIdentifier.QuoteIdentifier(member.MappedName));
            }
            return(builder.ToString());
        }
Beispiel #5
0
        private static int BuildFieldDeclarations(MetaType type, IDictionary <object, string> memberNameToMappedName, StringBuilder sb)
        {
            int num = 0;

            foreach (var member in type.DataMembers)
            {
                string str;
                if ((!member.IsDeclaredBy(type) || member.IsAssociation) || !member.IsPersistent)
                {
                    continue;
                }
                object key = InheritanceRules.DistinguishedMemberName(member.Member);
                if (memberNameToMappedName.TryGetValue(key, out str))
                {
                    if (!(str == member.MappedName))
                    {
                        goto Label_0075;
                    }
                    continue;
                }
                memberNameToMappedName.Add(key, member.MappedName);
Label_0075:
                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.AppendLine();
                sb.Append(string.Format(CultureInfo.InvariantCulture, "  {0} ",
                                        new object[] { MySqlIdentifier.QuoteCompoundIdentifier(member.MappedName) }));
                if (!string.IsNullOrEmpty(member.Expression))
                {
                    sb.Append("AS " + member.Expression);
                }
                else
                {
                    sb.Append(GetDbType(member));
                }
                num++;
            }
            return(num);
        }
Beispiel #6
0
 private static IEnumerable <string> GetCreateForeignKeyCommands(MetaType metaType)
 {
     foreach (var member in metaType.DataMembers)
     {
         if (member.IsDeclaredBy(metaType) && member.IsAssociation)
         {
             MetaAssociation association = member.Association;
             if (association.IsForeignKey)
             {
                 var stringBuilder = new StringBuilder();
                 var thisKey       = BuildKey(association.ThisKey);
                 var otherKey      = BuildKey(association.OtherKey);
                 var otherTable    = association.OtherType.Table.TableName;
                 var mappedName    = member.MappedName;
                 if (mappedName == member.Name)
                 {
                     mappedName = string.Format(CultureInfo.InvariantCulture, "FK_{0}_{1}",
                                                new object[] { MySqlIdentifier.QuoteIdentifier(metaType.Table.TableName), MySqlIdentifier.QuoteIdentifier(member.Name) });
                 }
                 var command     = "ALTER TABLE {0}" + Environment.NewLine + "  ADD CONSTRAINT {1} FOREIGN KEY ({2}) REFERENCES {3}({4})";
                 var otherMember = association.OtherMember;
                 if (otherMember != null)
                 {
                     string deleteRule = association.DeleteRule;
                     if (deleteRule != null)
                     {
                         command += Environment.NewLine + "  ON DELETE " + deleteRule;
                     }
                 }
                 yield return(stringBuilder.AppendFormat(command, new object[]
                 {
                     metaType.Table.TableName,
                     mappedName,
                     thisKey,
                     otherTable,
                     otherKey
                 }).ToString());
             }
         }
     }
 }
Beispiel #7
0
        public static string GetCreateTableCommand(MetaTable table)
        {
            var builder = new StringBuilder();
            var sb      = new StringBuilder();

            BuildFieldDeclarations(table, sb);
            builder.AppendFormat("CREATE TABLE {0}", MySqlIdentifier.QuoteIdentifier(table.TableName));
            builder.Append("(");
            builder.Append(sb.ToString());
            sb = new StringBuilder();
            BuildPrimaryKey(table, sb);
            if (sb.Length > 0)
            {
                string s = string.Format(CultureInfo.InvariantCulture, "PK_{0}",
                                         new object[] { table.TableName });
                builder.Append(", ");
                builder.AppendLine();
                builder.AppendFormat("  CONSTRAINT {0} PRIMARY KEY ({1})", s, sb);
            }
            builder.AppendLine();
            builder.Append("  )");
            return(builder.ToString());
        }
Beispiel #8
0
 //
 protected override void WriteName(string name)
 {
     sb.Append(MySqlIdentifier.QuoteCompoundIdentifier(name));
 }