Esempio n. 1
0
 protected TableModifier(ISQLDriver sQLDriver, Dictionary <string, TableSchema.Column> Columns, string TableName, string PrimaryKeyName)
 {
     this._tableName      = TableName;
     this._primaryKeyName = PrimaryKeyName;
     this._sqlDriver      = sQLDriver;
     this.columns         = Columns;
 }
Esempio n. 2
0
 public UpdateAction(ISQLDriver sQLDriver, Dictionary <string, TableSchema.Column> Columns, string TableName, string PrimaryKeyName)
     : base(sQLDriver, Columns, TableName, PrimaryKeyName)
 {
 }
Esempio n. 3
0
 public MySQLMapper(ISQLDriver driver)
 {
     base.driver = driver;
 }
Esempio n. 4
0
 public void Attach(ISQLDriver driver)
 {
     this.driver = driver;
 }
Esempio n. 5
0
 public PostgresMapper(ISQLDriver driver)
 {
     base.driver = driver;
 }
Esempio n. 6
0
        public static bool Generate(string dbType, string connectionString, string folderPath)
        {
            ISQLDriver driver = SQLDriverFactory.GetInstance().GetDriver(dbType);

            if (driver == null)
            {
                return(false);
            }
            if (!driver.Open(connectionString))
            {
                return(false);
            }
            DatabaseMapper databaseMapper = DatabaseMapperFactory.GetInstance().GetDatabaseMapper(dbType);

            if (databaseMapper == null)
            {
                return(false);
            }
            databaseMapper.Attach(driver);
            List <string> tables = databaseMapper.GetTables();

            foreach (string table in tables)
            {
                Console.WriteLine("Table name: " + table);
                Console.WriteLine("\tTable schema:");
                Dictionary <string, string> tableSchema = databaseMapper.GetTableSchema(table);
                foreach (KeyValuePair <string, string> tmp in tableSchema)
                {
                    Console.WriteLine("\t\t" + tmp.Key + ": " + tmp.Value);
                }
                List <string> primaryKeys = databaseMapper.GetTablePrimaryKey(table);
                if (primaryKeys != null && primaryKeys.Count > 0)
                {
                    Console.Write("\t\tPrimary key: ");
                    foreach (string primaryKey in primaryKeys)
                    {
                        Console.Write(primaryKey + "\t");
                    }
                    Console.WriteLine();
                }
                Dictionary <string, string> foreignKeys = databaseMapper.GetTableForeignKeys(table);
                if (foreignKeys != null && foreignKeys.Count > 0)
                {
                    Console.Write("\t\tForeign key: ");
                    foreach (KeyValuePair <string, string> foreignKey in foreignKeys)
                    {
                        Console.Write("[" + foreignKey.Key + ", " + foreignKey.Value + "]\t");
                    }
                    Console.WriteLine();
                }
                List <string> tablesHaveForeignKey = databaseMapper.GetTableHaveForeignKey(table);
                if (tablesHaveForeignKey != null && tablesHaveForeignKey.Count > 0)
                {
                    Console.Write("\t\tTable have Foreign key: ");
                    foreach (string tableHaveForeignKey in tablesHaveForeignKey)
                    {
                        Console.Write(tableHaveForeignKey + "\t");
                    }
                    Console.WriteLine();
                }
                ClassGenerator.Generate(table, tableSchema, primaryKeys, foreignKeys, tablesHaveForeignKey, folderPath);
            }

            driver.Close();

            return(true);
        }